MeVisLab Toolbox Reference
mlStringConversion.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_STRING_CONVERSION_H
14#define ML_STRING_CONVERSION_H
15
17
18#include "mlLinearAlgebra.h"
19#include "mlSubImageBox.h"
20
22
24class SubImageBoxd;
25class Base;
27
30{
31public:
37 [[nodiscard]]
38 static char* newString (const std::string &str);
39
41 static void deleteString (char* str);
43
46
48 static std::string writeToStdString(unsigned char val);
49
51 static std::string writeToStdString(char val);
52
54 static std::string writeToStdString(unsigned short val);
55
57 static std::string writeToStdString(short val);
58
60 static std::string writeToStdString(MLuint32 val);
61
63 static std::string writeToStdString(MLint32 val);
64
66 static std::string writeToStdString(unsigned long val);
67
69 static std::string writeToStdString(long val);
70
72 static std::string writeToStdString(MLuint64 val);
73
75 static std::string writeToStdString(MLint64 val);
76
78 static std::string writeToStdString(MLfloat val);
79
81 static std::string writeToStdString(MLdouble val);
82
84 static std::string writeToStdString(MLldouble val);
85
87 static std::string writeToStdString(const Vector2& val);
88
90 static std::string writeToStdString(const Vector3& val);
91
93 static std::string writeToStdString(const Vector4& val);
94
96 static std::string writeToStdString(const Vector5& val);
97
99 static std::string writeToStdString(const Vector6& val);
100
102 static std::string writeToStdString(const Vector7& val);
103
105 static std::string writeToStdString(const Vector8& val);
106
108 static std::string writeToStdString(const Vector9& val);
109
111 static std::string writeToStdString(const Vector10& val);
112
114 static std::string writeToStdString(const Vector16& val);
115
117 static std::string writeToStdString(const Vector32& val);
118
120 static std::string writeToStdString(const Vector64& val);
121
123 static std::string writeToStdString(const ImageVector& val);
124
126 static std::string writeToStdString(SubImageBox const & box);
127
129 static std::string writeToStdString(SubImageBoxd const & box);
130
132 static std::string writeToStdString(Matrix2 const & mat);
133
135 static std::string writeToStdString(Matrix3 const & mat);
136
138 static std::string writeToStdString(Matrix4 const & mat);
139
141 static std::string writeToStdString(Matrix5 const & mat);
142
144 static std::string writeToStdString(Matrix6 const & mat);
145
147 static std::string writeToStdString(const Base* const obj);
148
150 static std::string writeToStdString(const Base& obj);
151
156 template <typename T>
157 static std::string writeToStdString(const std::vector<T>& vec, const std::string &separatorString)
158 {
159 std::string retVal;
160 for (size_t k = 0; k < vec.size(); k++){
161 if (k){ retVal += separatorString; }
162 retVal += writeToStdString(vec[k]);
163 }
164 return retVal;
165 }
166
169 static std::string writeToStdString(const std::string& str);
171
172
173
176
179 static bool readFromString(const std::string& arg, unsigned char& val);
180
183 static bool readFromString(const std::string& arg, char& val);
184
187 static bool readFromString(const std::string& arg, unsigned short& val);
188
191 static bool readFromString(const std::string& arg, short& val);
192
195 static bool readFromString(const std::string& arg, MLuint32& val);
196
199 static bool readFromString(const std::string& arg, MLint32& val);
200
203 static bool readFromString(const std::string& arg, MLuint64& val);
204
207 static bool readFromString(const std::string& arg, MLint64& val);
208
211 static bool readFromString(std::string const& arg, unsigned long& val);
212
215 static bool readFromString(std::string const& arg, long& val);
216
219 static bool readFromString(std::string const& arg, float& val);
220
223 static bool readFromString(std::string const& arg, double& val);
224
227 static bool readFromString(std::string const& arg, long double& val);
228
231 static bool readFromString(const std::string& vecstr, Vector2& v);
232
235 static bool readFromString(const std::string& vecstr, Vector3& v);
236
239 static bool readFromString(const std::string& vecstr, Vector4& v);
240
243 static bool readFromString(const std::string& vecstr, Vector5& v);
244
247 static bool readFromString(const std::string& vecstr, Vector6& v);
248
251 static bool readFromString(const std::string& vecstr, Vector7& v);
252
255 static bool readFromString(const std::string& vecstr, Vector8& v);
256
259 static bool readFromString(const std::string& vecstr, Vector9& v);
260
263 static bool readFromString(const std::string& vecstr, Vector10& v);
264
267 static bool readFromString(const std::string& vecstr, Vector16& v);
268
271 static bool readFromString(const std::string& vecstr, Vector32& v);
272
275 static bool readFromString(const std::string& vecstr, Vector64& v);
276
279 static bool readFromString(const std::string& vecstr, ImageVector& v);
280
283 static bool readFromString(const std::string& str, Matrix2& val);
284
287 static bool readFromString(const std::string& str, Matrix3& val);
288
291 static bool readFromString(const std::string& str, Matrix4& val);
292
295 static bool readFromString(const std::string& str, Matrix5& val);
296
299 static bool readFromString(const std::string& str, Matrix6& val);
300
305 static bool readFromString (const std::string& arg, SubImageBox& val);
306
311 static bool readFromString (const std::string& arg, SubImageBoxd& val);
312
315 static bool readFromString(const std::string& source, Base& obj);
316
322 template <typename T>
323 static bool readFromString(const std::string& vecstr,
324 std::vector<T>& vec,
325 const std::string& separatorString)
326 {
327 bool retVal = false;
328
329 size_t startPos = 0, endPos = 0;
330 size_t sepLen = separatorString.size();
331 bool eos = false;
332 // Initialize the object with default value of the type to avoid uninitialized object warnings.
333 T item = T();
334
335 while (!eos) {
337 if (endPos == std::string::npos) {
338 endPos = vecstr.size();
339 eos = true;
340 }
341
342 // Use type specific read function to parse the string.
343 retVal = readFromString(vecstr.substr(startPos, endPos - startPos), item);
344
345 // Append the read item to the end of the vector.
346 vec.push_back(item);
347
348 // Set position of the next item to read.
350 }
351 return retVal;
352 }
353
356 static bool readFromString(const std::string& source, std::string& target);
358
359
360
363
365 static MLint getFirstNonSpacePos(const std::string& str, MLint pos = 0);
367
368
369private:
372 static void instantiateTemplateFctDummy(void);
373};
374
376
377
378#endif // __mlStringConversion_H
379
380
@ T
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
The class StringConversion provides static methods to convert ML objects to and from strings.
static bool readFromString(const std::string &vecstr, Vector9 &v)
Reads a 9D double vector value v from string vecstr whose values are space separated; it returns true...
static std::string writeToStdString(const ImageVector &val)
Converts a ImageVector to a std::string which can be parsed by readFromString().
static std::string writeToStdString(MLint32 val)
Converts an int32 to a std::string.
static std::string writeToStdString(const std::vector< T > &vec, const std::string &separatorString)
Converts a std::vector value vec to a string where vector components will be separated by the string ...
static std::string writeToStdString(const Vector9 &val)
Converts a Vector9 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &vecstr, Vector16 &v)
Reads a 16D double vector value v from string vecstr whose values are space separated; it returns tru...
static std::string writeToStdString(char val)
Converts char to a std::string.
static std::string writeToStdString(const Vector2 &val)
Converts a Vector2 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &vecstr, Vector5 &v)
Reads a 5D double vector value v from string vecstr whose values are space separated; it returns true...
static bool readFromString(const std::string &str, Matrix5 &val)
Reads a Matrix5 value val from string str whose values are space separated; and returns true if all c...
static std::string writeToStdString(MLuint64 val)
Converts uint64 to a std::string.
static bool readFromString(const std::string &vecstr, std::vector< T > &vec, const std::string &separatorString)
Reads a std::vector<T> from a string of the form that is generated by stdVectorToString(vec,...
static std::string writeToStdString(MLdouble val)
Converts double to a std::string.
static MLint getFirstNonSpacePos(const std::string &str, MLint pos=0)
Helper method returning the first non-space position starting from pos.
static std::string writeToStdString(const Vector10 &val)
Converts a Vector10 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &str, Matrix4 &val)
Reads a Matrix4 value val from string str whose values are space separated; and returns true if all c...
static std::string writeToStdString(Matrix3 const &mat)
Converts a Matrix3 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(MLldouble val)
Converts long double to a std::string.
static bool readFromString(const std::string &arg, MLuint64 &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static std::string writeToStdString(const Vector7 &val)
Converts a Vector7 to a std::string which can be parsed by readFromString().
static bool readFromString(std::string const &arg, double &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static std::string writeToStdString(const Vector32 &val)
Converts a Vector32 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(const std::string &str)
Writes std::string object to std::string.
static char * newString(const std::string &str)
static bool readFromString(const std::string &arg, MLuint32 &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(const std::string &arg, short &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(const std::string &source, std::string &target)
Reads a std::string object to std::string.
static std::string writeToStdString(unsigned short val)
Converts an unsigned short to a std::string.
static bool readFromString(const std::string &vecstr, Vector3 &v)
Reads a 3D double vector value v from string vecstr whose values are space separated; it returns true...
static bool readFromString(std::string const &arg, float &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(const std::string &arg, MLint32 &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static std::string writeToStdString(MLuint32 val)
Converts uint32 to a std::string.
static bool readFromString(const std::string &vecstr, Vector6 &v)
Reads a 6D double vector value v from string vecstr whose values are space separated; it returns true...
static bool readFromString(const std::string &str, Matrix6 &val)
Reads a Matrix6 value val from string str whose values are space separated; and returns true if all c...
static std::string writeToStdString(MLint64 val)
Converts an int64 to a std::string.
static std::string writeToStdString(const Vector16 &val)
Converts a Vector16 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &arg, SubImageBox &val)
Reads a SubImageBox value val from string arg whose values are space separated; and returns true if a...
static bool readFromString(const std::string &vecstr, ImageVector &v)
Reads a ImageVector value v from string vecstr whose values are space separated; it returns true if a...
static bool readFromString(const std::string &vecstr, Vector10 &v)
Reads a 10D double vector value v from string vecstr whose values are space separated; it returns tru...
static std::string writeToStdString(const Vector6 &val)
Converts a Vector6 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &source, Base &obj)
Reads a Base object from string source to obj by calling obj.setPersistentState(source....
static bool readFromString(const std::string &str, Matrix2 &val)
Reads a Matrix2 value val from string str whose values are space separated; and returns true if all c...
static std::string writeToStdString(const Base &obj)
Writes Base object to std::string.
static bool readFromString(const std::string &arg, MLint64 &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static std::string writeToStdString(Matrix4 const &mat)
Converts a Matrix4 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(unsigned char val)
Converts an unsigned char to a std::string.
static bool readFromString(const std::string &vecstr, Vector8 &v)
Reads a 8D double vector value v from string vecstr whose values are space separated; it returns true...
static std::string writeToStdString(const Base *const obj)
Writes Base object to std::string.
static std::string writeToStdString(MLfloat val)
Converts float to a std::string.
static std::string writeToStdString(Matrix5 const &mat)
Converts a Matrix5 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(Matrix6 const &mat)
Converts a Matrix6 to a std::string which can be parsed by readFromString().
static bool readFromString(std::string const &arg, long &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(const std::string &str, Matrix3 &val)
Reads a Matrix3 value val from string str whose values are space separated; and returns true if all c...
static std::string writeToStdString(SubImageBoxd const &box)
Converts a SubImageBoxd to a std::string which can be parsed by readFromString(SubImageBoxd&).
static std::string writeToStdString(const Vector64 &val)
Converts a Vector64 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &vecstr, Vector32 &v)
Reads a 32D double vector value v from string vecstr whose values are space separated; it returns tru...
static bool readFromString(const std::string &arg, unsigned char &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(const std::string &arg, char &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static std::string writeToStdString(const Vector5 &val)
Converts a Vector5 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(const Vector8 &val)
Converts a Vector8 to a std::string which can be parsed by readFromString().
static bool readFromString(const std::string &arg, unsigned short &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(const std::string &vecstr, Vector2 &v)
Reads a 2D double vector value v from string vecstr whose values are space separated; it returns true...
static bool readFromString(const std::string &arg, SubImageBoxd &val)
Reads a SubImageBox value val from string arg whose values are space separated; and returns true if a...
static bool readFromString(const std::string &vecstr, Vector4 &v)
Reads a 4D double vector value v from string vecstr whose values are space separated; it returns true...
static void deleteString(char *str)
Dispose a string created by newString(); NULL values as str are legal and will be ignored.
static bool readFromString(const std::string &vecstr, Vector64 &v)
Reads a 64D double vector value v from string vecstr whose values are space separated; it returns tru...
static bool readFromString(const std::string &vecstr, Vector7 &v)
Reads a 7D double vector value v from string vecstr whose values are space separated; it returns true...
static std::string writeToStdString(Matrix2 const &mat)
Converts a Matrix2 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(unsigned long val)
Converts unsigned long to std::string.
static std::string writeToStdString(long val)
Converts long to a std::string.
static std::string writeToStdString(const Vector4 &val)
Converts a Vector4 to a std::string which can be parsed by readFromString().
static std::string writeToStdString(SubImageBox const &box)
Converts a SubImageBox to a std::string which can be parsed by readFromString(SubImageBox&).
static std::string writeToStdString(const Vector3 &val)
Converts a Vector3 to a std::string which can be parsed by readFromString().
static bool readFromString(std::string const &arg, unsigned long &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static bool readFromString(std::string const &arg, long double &val)
Reads a value from string arg into val; it returns true if one value has been converted successfully,...
static std::string writeToStdString(short val)
Converts short to a std::string.
SubImageBoxd - SubImageBox with coordinates of float data type.
A 16 dimensional vector class for floating point types.
Definition mlVector16.h:32
A 32 dimensional vector class for floating point types.
Definition mlVector32.h:32
A 64 dimensional vector class for floating point types.
Definition mlVector64.h:32
An seven dimensional vector class for floating point types.
Definition mlVector7.h:32
An eight dimensional vector class for floating point types.
Definition mlVector8.h:32
An nine dimensional vector class for floating point types.
Definition mlVector9.h:32
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition mlTypeDefs.h:425
long double MLldouble
Definition mlTypeDefs.h:232
unsigned int MLuint32
Definition mlTypeDefs.h:185
double MLdouble
Definition mlTypeDefs.h:217
INT64 MLint64
Include 64 bit integer support for Windows or Unix.
Definition mlTypeDefs.h:412
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
signed int MLint32
Definition mlTypeDefs.h:161
float MLfloat
Definition mlTypeDefs.h:201