RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UVariant.h
Go to the documentation of this file.
1/*
2* utilite is a cross-platform library with
3* useful utilities for fast and small developing.
4* Copyright (C) 2010 Mathieu Labbe
5*
6* utilite is free library: you can redistribute it and/or modify
7* it under the terms of the GNU Lesser General Public License as published by
8* the Free Software Foundation, either version 3 of the License, or
9* (at your option) any later version.
10*
11* utilite is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU Lesser General Public License for more details.
15*
16* You should have received a copy of the GNU Lesser General Public License
17* along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef UVARIANT_H
21#define UVARIANT_H
22
23#include "rtabmap/utilite/utilite_export.h" // DLL export/import defines
24#include <string>
25#include <vector>
26
53class UTILITE_EXPORT UVariant
54{
55public:
81public:
87
92 UVariant(const bool & value);
93
98 UVariant(const signed char & value);
99
104 UVariant(const unsigned char & value);
105
110 UVariant(const short & value);
111
116 UVariant(const unsigned short & value);
117
122 UVariant(const int & value);
123
128 UVariant(const unsigned int & value);
129
134 UVariant(const float & value);
135
140 UVariant(const double & value);
141
146 UVariant(const char * value);
147
152 UVariant(const std::string & value);
153
158 UVariant(const std::vector<signed char> & value);
159
164 UVariant(const std::vector<unsigned char> & value);
165
170 UVariant(const std::vector<short> & value);
171
176 UVariant(const std::vector<unsigned short> & value);
177
182 UVariant(const std::vector<int> & value);
183
188 UVariant(const std::vector<unsigned int> & value);
189
194 UVariant(const std::vector<float> & value);
195
200 UVariant(const std::vector<double> & value);
201
206 Type type() const {return type_;}
207
212 bool isUndef() const {return type_ == kUndef;}
213
218 bool isBool() const {return type_ == kBool;}
219
224 bool isChar() const {return type_ == kChar;}
225
230 bool isUChar() const {return type_ == kUChar;}
231
236 bool isShort() const {return type_ == kShort;}
237
242 bool isUShort() const {return type_ == kUShort;}
243
248 bool isInt() const {return type_ == kInt;}
249
254 bool isUInt() const {return type_ == kUInt;}
255
260 bool isFloat() const {return type_ == kFloat;}
261
266 bool isDouble() const {return type_ == kDouble;}
267
272 bool isStr() const {return type_ == kStr;}
273
278 bool isCharArray() const {return type_ == kCharArray;}
279
284 bool isUCharArray() const {return type_ == kUCharArray;}
285
290 bool isShortArray() const {return type_ == kShortArray;}
291
296 bool isUShortArray() const {return type_ == kUShortArray;}
297
302 bool isIntArray() const {return type_ == kIntArray;}
303
308 bool isUIntArray() const {return type_ == kUIntArray;}
309
314 bool isFloatArray() const {return type_ == kFloatArray;}
315
320 bool isDoubleArray() const {return type_ == kDoubleArray;}
321
326 bool toBool() const;
327
333 signed char toChar(bool * ok = 0) const;
334
340 unsigned char toUChar(bool * ok = 0) const;
341
347 short toShort(bool * ok = 0) const;
348
354 unsigned short toUShort(bool * ok = 0) const;
355
361 int toInt(bool * ok = 0) const;
362
368 unsigned int toUInt(bool * ok = 0) const;
369
375 float toFloat(bool * ok = 0) const;
376
382 double toDouble(bool * ok = 0) const;
383
389 std::string toStr(bool * ok = 0) const;
390
396 std::vector<signed char> toCharArray(bool * ok = 0) const;
397
403 std::vector<unsigned char> toUCharArray(bool * ok = 0) const;
404
410 std::vector<short> toShortArray(bool * ok = 0) const;
411
417 std::vector<unsigned short> toUShortArray(bool * ok = 0) const;
418
424 std::vector<int> toIntArray(bool * ok = 0) const;
425
431 std::vector<unsigned int> toUIntArray(bool * ok = 0) const;
432
438 std::vector<float> toFloatArray(bool * ok = 0) const;
439
445 std::vector<double> toDoubleArray(bool * ok = 0) const;
446
450 virtual ~UVariant() {}
451
452private:
453 Type type_;
454 std::vector<unsigned char> data_;
455};
456
457#endif /* UVARIANT_H */
A variant type that can hold values of different types.
Definition UVariant.h:54
bool isUShortArray() const
Check if the variant is an array of unsigned short.
Definition UVariant.h:296
UVariant(const char *value)
Constructor from C string.
UVariant(const std::string &value)
Constructor from std::string.
unsigned char toUChar(bool *ok=0) const
Convert the variant to unsigned char.
UVariant(const double &value)
Constructor from double.
float toFloat(bool *ok=0) const
Convert the variant to float.
bool isBool() const
Check if the variant is a bool.
Definition UVariant.h:218
UVariant(const std::vector< int > &value)
Constructor from array of int.
std::vector< double > toDoubleArray(bool *ok=0) const
Convert the variant to array of double.
bool isFloat() const
Check if the variant is a float.
Definition UVariant.h:260
UVariant(const unsigned int &value)
Constructor from unsigned int.
bool isDouble() const
Check if the variant is a double.
Definition UVariant.h:266
Type
Enumeration of supported data types.
Definition UVariant.h:60
@ kFloatArray
Definition UVariant.h:77
@ kUIntArray
Definition UVariant.h:76
@ kDouble
Definition UVariant.h:69
@ kUShortArray
Definition UVariant.h:74
@ kShortArray
Definition UVariant.h:73
@ kUShort
Definition UVariant.h:65
@ kDoubleArray
Definition UVariant.h:78
@ kIntArray
Definition UVariant.h:75
@ kUCharArray
Definition UVariant.h:72
@ kCharArray
Definition UVariant.h:71
UVariant(const unsigned short &value)
Constructor from unsigned short.
std::vector< unsigned short > toUShortArray(bool *ok=0) const
Convert the variant to array of unsigned short.
bool isInt() const
Check if the variant is an int.
Definition UVariant.h:248
double toDouble(bool *ok=0) const
Convert the variant to double.
Type type() const
Get the type of the stored value.
Definition UVariant.h:206
UVariant(const short &value)
Constructor from short.
unsigned short toUShort(bool *ok=0) const
Convert the variant to unsigned short.
bool isShort() const
Check if the variant is a short.
Definition UVariant.h:236
bool isChar() const
Check if the variant is a signed char.
Definition UVariant.h:224
UVariant(const std::vector< unsigned short > &value)
Constructor from array of unsigned short.
bool isUCharArray() const
Check if the variant is an array of unsigned char.
Definition UVariant.h:284
UVariant(const unsigned char &value)
Constructor from unsigned char.
bool isShortArray() const
Check if the variant is an array of short.
Definition UVariant.h:290
std::string toStr(bool *ok=0) const
Convert the variant to string.
UVariant(const std::vector< unsigned char > &value)
Constructor from array of unsigned char.
UVariant(const std::vector< signed char > &value)
Constructor from array of signed char.
UVariant(const std::vector< short > &value)
Constructor from array of short.
bool isUShort() const
Check if the variant is an unsigned short.
Definition UVariant.h:242
UVariant(const int &value)
Constructor from int.
std::vector< int > toIntArray(bool *ok=0) const
Convert the variant to array of int.
bool isFloatArray() const
Check if the variant is an array of float.
Definition UVariant.h:314
UVariant(const bool &value)
Constructor from bool.
bool isIntArray() const
Check if the variant is an array of int.
Definition UVariant.h:302
bool isDoubleArray() const
Check if the variant is an array of double.
Definition UVariant.h:320
unsigned int toUInt(bool *ok=0) const
Convert the variant to unsigned int.
signed char toChar(bool *ok=0) const
Convert the variant to signed char.
bool isUndef() const
Check if the variant is undefined.
Definition UVariant.h:212
int toInt(bool *ok=0) const
Convert the variant to int.
UVariant(const float &value)
Constructor from float.
bool isCharArray() const
Check if the variant is an array of signed char.
Definition UVariant.h:278
std::vector< unsigned char > toUCharArray(bool *ok=0) const
Convert the variant to array of unsigned char.
std::vector< short > toShortArray(bool *ok=0) const
Convert the variant to array of short.
UVariant(const std::vector< float > &value)
Constructor from array of float.
short toShort(bool *ok=0) const
Convert the variant to short.
std::vector< float > toFloatArray(bool *ok=0) const
Convert the variant to array of float.
std::vector< unsigned int > toUIntArray(bool *ok=0) const
Convert the variant to array of unsigned int.
UVariant(const std::vector< double > &value)
Constructor from array of double.
UVariant(const std::vector< unsigned int > &value)
Constructor from array of unsigned int.
UVariant(const signed char &value)
Constructor from signed char.
std::vector< signed char > toCharArray(bool *ok=0) const
Convert the variant to array of signed char.
bool isUInt() const
Check if the variant is an unsigned int.
Definition UVariant.h:254
virtual ~UVariant()
Virtual destructor.
Definition UVariant.h:450
bool toBool() const
Convert the variant to bool.
UVariant()
Default constructor Creates an undefined variant.
bool isUIntArray() const
Check if the variant is an array of unsigned int.
Definition UVariant.h:308
bool isStr() const
Check if the variant is a string.
Definition UVariant.h:272
bool isUChar() const
Check if the variant is an unsigned char.
Definition UVariant.h:230