ML Reference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00009 //-------------------------------------------------------------------------------- 00010 00011 00012 #ifndef __mlStringConversion_H 00013 #define __mlStringConversion_H 00014 00015 #ifndef __mlInitSystemML_H 00016 #include "mlInitSystemML.h" 00017 #endif 00018 #ifndef __mlLinearAlgebra_H 00019 #include "mlLinearAlgebra.h" 00020 #endif 00021 #ifndef __mlBasics_H 00022 #include "mlBasics.h" 00023 #endif 00024 00025 ML_START_NAMESPACE 00026 00028 class SubImageBoxd; 00029 class Base; 00031 00033 class MLEXPORT StringConversion 00034 { 00035 00036 public: 00037 00039 00040 00041 00042 00043 static char* newString (const std::string &str) ML_RETURN_VALUE_SHOULD_BE_USED; 00044 00046 static void deleteString (char* str); 00048 00050 00051 00053 static std::string writeToStdString(unsigned char val); 00054 00056 static std::string writeToStdString(char val); 00057 00059 static std::string writeToStdString(unsigned short val); 00060 00062 static std::string writeToStdString(short val); 00063 00065 static std::string writeToStdString(MLuint32 val); 00066 00068 static std::string writeToStdString(MLint32 val); 00069 00071 static std::string writeToStdString(unsigned long val); 00072 00074 static std::string writeToStdString(long val); 00075 00077 static std::string writeToStdString(MLuint64 val); 00078 00080 static std::string writeToStdString(MLint64 val); 00081 00083 static std::string writeToStdString(MLfloat val); 00084 00086 static std::string writeToStdString(MLdouble val); 00087 00089 static std::string writeToStdString(MLldouble val); 00090 00092 static std::string writeToStdString(const Vector2& val); 00093 00095 static std::string writeToStdString(const Vector3& val); 00096 00098 static std::string writeToStdString(const Vector4& val); 00099 00101 static std::string writeToStdString(const Vector5& val); 00102 00104 static std::string writeToStdString(const Vector6& val); 00105 00107 static std::string writeToStdString(const Vector7& val); 00108 00110 static std::string writeToStdString(const Vector8& val); 00111 00113 static std::string writeToStdString(const Vector9& val); 00114 00116 static std::string writeToStdString(const Vector10& val); 00117 00119 static std::string writeToStdString(const Vector16& val); 00120 00122 static std::string writeToStdString(const Vector32& val); 00123 00125 static std::string writeToStdString(const Vector64& val); 00126 00128 static std::string writeToStdString(const ImageVector& val); 00129 00131 static std::string writeToStdString(SubImageBox const & box); 00132 00134 static std::string writeToStdString(SubImageBoxd const & box); 00135 00137 static std::string writeToStdString(Matrix2 const & mat); 00138 00140 static std::string writeToStdString(Matrix3 const & mat); 00141 00143 static std::string writeToStdString(Matrix4 const & mat); 00144 00146 static std::string writeToStdString(Matrix5 const & mat); 00147 00149 static std::string writeToStdString(Matrix6 const & mat); 00150 00152 static std::string writeToStdString(const Base* const obj); 00153 00155 static std::string writeToStdString(const Base& obj); 00156 00161 template <typename T> 00162 static std::string writeToStdString(const std::vector<T>& vec, const std::string &separatorString) 00163 { 00164 ML_TRACE_IN("StringConversion::writeToStdString(const std::vector<T>& vec, const std::string &separatorString"); 00165 std::string retVal; 00166 ML_TRY 00167 { 00168 for (size_t k = 0; k < vec.size(); k++){ 00169 if (k){ retVal += separatorString; } 00170 retVal += writeToStdString(vec[k]); 00171 } 00172 return retVal; 00173 } 00174 ML_CATCH_RETHROW; 00175 } 00177 00178 00179 00181 00182 00185 static bool readFromString(const std::string& arg, unsigned char& val); 00186 00189 static bool readFromString(const std::string& arg, char& val); 00190 00193 static bool readFromString(const std::string& arg, unsigned short& val); 00194 00197 static bool readFromString(const std::string& arg, short& val); 00198 00201 static bool readFromString(const std::string& arg, MLuint32& val); 00202 00205 static bool readFromString(const std::string& arg, MLint32& val); 00206 00209 static bool readFromString(const std::string& arg, MLuint64& val); 00210 00213 static bool readFromString(const std::string& arg, MLint64& val); 00214 00217 static bool readFromString(std::string const& arg, unsigned long& val); 00218 00221 static bool readFromString(std::string const& arg, long& val); 00222 00225 static bool readFromString(std::string const& arg, float& val); 00226 00229 static bool readFromString(std::string const& arg, double& val); 00230 00233 static bool readFromString(std::string const& arg, long double& val); 00234 00237 static bool readFromString(const std::string& vecstr, Vector2& v); 00238 00241 static bool readFromString(const std::string& vecstr, Vector3& v); 00242 00245 static bool readFromString(const std::string& vecstr, Vector4& v); 00246 00249 static bool readFromString(const std::string& vecstr, Vector5& v); 00250 00253 static bool readFromString(const std::string& vecstr, Vector6& v); 00254 00257 static bool readFromString(const std::string& vecstr, Vector7& v); 00258 00261 static bool readFromString(const std::string& vecstr, Vector8& v); 00262 00265 static bool readFromString(const std::string& vecstr, Vector9& v); 00266 00269 static bool readFromString(const std::string& vecstr, Vector10& v); 00270 00273 static bool readFromString(const std::string& vecstr, Vector16& v); 00274 00277 static bool readFromString(const std::string& vecstr, Vector32& v); 00278 00281 static bool readFromString(const std::string& vecstr, Vector64& v); 00282 00285 static bool readFromString(const std::string& vecstr, ImageVector& v); 00286 00289 static bool readFromString(const std::string& str, Matrix2& val); 00290 00293 static bool readFromString(const std::string& str, Matrix3& val); 00294 00297 static bool readFromString(const std::string& str, Matrix4& val); 00298 00301 static bool readFromString(const std::string& str, Matrix5& val); 00302 00305 static bool readFromString(const std::string& str, Matrix6& val); 00306 00311 static bool readFromString (const std::string& arg, SubImageBox& val); 00312 00317 static bool readFromString (const std::string& arg, SubImageBoxd& val); 00318 00321 static bool readFromString(const std::string& source, Base& obj); 00322 00328 template <typename T> 00329 static bool readFromString(const std::string& vecstr, 00330 std::vector<T>& vec, 00331 const std::string& separatorString) 00332 { 00333 ML_TRACE_IN("StringConversion::readFromString(const std::string& vecstr, ..., std::string& separatorString)"); 00334 ML_TRY 00335 { 00336 bool retVal = false; 00337 00338 size_t startPos = 0, endPos = 0; 00339 size_t sepLen = separatorString.size(); 00340 bool eos = false; 00341 // Initialize the object with default value of the type to avoid uninitialized object warnings. 00342 T item = T(); 00343 00344 while (!eos) { 00345 endPos = vecstr.find(separatorString, startPos); 00346 if (endPos == std::string::npos) { 00347 endPos = vecstr.size(); 00348 eos = true; 00349 } 00350 00351 // Use type specific read function to parse the string. 00352 retVal = readFromString(vecstr.substr(startPos, endPos - startPos), item); 00353 00354 // Append the read item to the end of the vector. 00355 vec.push_back(item); 00356 00357 // Set position of the next item to read. 00358 startPos = endPos + sepLen; 00359 } 00360 return retVal; 00361 } 00362 ML_CATCH_RETHROW; 00363 } 00365 00366 00367 00369 00370 00372 static MLint getFirstNonSpacePos(const std::string& str, MLint pos = 0); 00374 00375 00376 private: 00379 static void instantiateTemplateFctDummy(void); 00380 }; 00381 00382 ML_END_NAMESPACE 00383 00384 00385 #endif // __mlStringConversion_H 00386 00387