RTAB-Map 0.25.2
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UVariant.h
Go to the documentation of this file.
1/*
2Copyright (c) 2010, Mathieu Labbe
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holders nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef UVARIANT_H
29#define UVARIANT_H
30
31#include "rtabmap/utilite/utilite_export.h" // DLL export/import defines
32#include <string>
33#include <vector>
34
61class UTILITE_EXPORT UVariant
62{
63public:
89public:
95
100 UVariant(const bool & value);
101
106 UVariant(const signed char & value);
107
112 UVariant(const unsigned char & value);
113
118 UVariant(const short & value);
119
124 UVariant(const unsigned short & value);
125
130 UVariant(const int & value);
131
136 UVariant(const unsigned int & value);
137
142 UVariant(const float & value);
143
148 UVariant(const double & value);
149
154 UVariant(const char * value);
155
160 UVariant(const std::string & value);
161
166 UVariant(const std::vector<signed char> & value);
167
172 UVariant(const std::vector<unsigned char> & value);
173
178 UVariant(const std::vector<short> & value);
179
184 UVariant(const std::vector<unsigned short> & value);
185
190 UVariant(const std::vector<int> & value);
191
196 UVariant(const std::vector<unsigned int> & value);
197
202 UVariant(const std::vector<float> & value);
203
208 UVariant(const std::vector<double> & value);
209
214 Type type() const {return type_;}
215
220 bool isUndef() const {return type_ == kUndef;}
221
226 bool isBool() const {return type_ == kBool;}
227
232 bool isChar() const {return type_ == kChar;}
233
238 bool isUChar() const {return type_ == kUChar;}
239
244 bool isShort() const {return type_ == kShort;}
245
250 bool isUShort() const {return type_ == kUShort;}
251
256 bool isInt() const {return type_ == kInt;}
257
262 bool isUInt() const {return type_ == kUInt;}
263
268 bool isFloat() const {return type_ == kFloat;}
269
274 bool isDouble() const {return type_ == kDouble;}
275
280 bool isStr() const {return type_ == kStr;}
281
286 bool isCharArray() const {return type_ == kCharArray;}
287
292 bool isUCharArray() const {return type_ == kUCharArray;}
293
298 bool isShortArray() const {return type_ == kShortArray;}
299
304 bool isUShortArray() const {return type_ == kUShortArray;}
305
310 bool isIntArray() const {return type_ == kIntArray;}
311
316 bool isUIntArray() const {return type_ == kUIntArray;}
317
322 bool isFloatArray() const {return type_ == kFloatArray;}
323
328 bool isDoubleArray() const {return type_ == kDoubleArray;}
329
334 bool toBool() const;
335
341 signed char toChar(bool * ok = 0) const;
342
348 unsigned char toUChar(bool * ok = 0) const;
349
355 short toShort(bool * ok = 0) const;
356
362 unsigned short toUShort(bool * ok = 0) const;
363
369 int toInt(bool * ok = 0) const;
370
376 unsigned int toUInt(bool * ok = 0) const;
377
383 float toFloat(bool * ok = 0) const;
384
390 double toDouble(bool * ok = 0) const;
391
397 std::string toStr(bool * ok = 0) const;
398
404 std::vector<signed char> toCharArray(bool * ok = 0) const;
405
411 std::vector<unsigned char> toUCharArray(bool * ok = 0) const;
412
418 std::vector<short> toShortArray(bool * ok = 0) const;
419
425 std::vector<unsigned short> toUShortArray(bool * ok = 0) const;
426
432 std::vector<int> toIntArray(bool * ok = 0) const;
433
439 std::vector<unsigned int> toUIntArray(bool * ok = 0) const;
440
446 std::vector<float> toFloatArray(bool * ok = 0) const;
447
453 std::vector<double> toDoubleArray(bool * ok = 0) const;
454
458 virtual ~UVariant() {}
459
460private:
461 Type type_;
462 std::vector<unsigned char> data_;
463};
464
465#endif /* UVARIANT_H */
A variant type that can hold values of different types.
Definition UVariant.h:62
bool isUShortArray() const
Check if the variant is an array of unsigned short.
Definition UVariant.h:304
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:226
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:268
UVariant(const unsigned int &value)
Constructor from unsigned int.
bool isDouble() const
Check if the variant is a double.
Definition UVariant.h:274
Type
Enumeration of supported data types.
Definition UVariant.h:68
@ kFloatArray
Definition UVariant.h:85
@ kUIntArray
Definition UVariant.h:84
@ kDouble
Definition UVariant.h:77
@ kUShortArray
Definition UVariant.h:82
@ kShortArray
Definition UVariant.h:81
@ kUShort
Definition UVariant.h:73
@ kDoubleArray
Definition UVariant.h:86
@ kIntArray
Definition UVariant.h:83
@ kUCharArray
Definition UVariant.h:80
@ kCharArray
Definition UVariant.h:79
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:256
double toDouble(bool *ok=0) const
Convert the variant to double.
Type type() const
Get the type of the stored value.
Definition UVariant.h:214
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:244
bool isChar() const
Check if the variant is a signed char.
Definition UVariant.h:232
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:292
UVariant(const unsigned char &value)
Constructor from unsigned char.
bool isShortArray() const
Check if the variant is an array of short.
Definition UVariant.h:298
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:250
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:322
UVariant(const bool &value)
Constructor from bool.
bool isIntArray() const
Check if the variant is an array of int.
Definition UVariant.h:310
bool isDoubleArray() const
Check if the variant is an array of double.
Definition UVariant.h:328
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:220
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:286
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:262
virtual ~UVariant()
Virtual destructor.
Definition UVariant.h:458
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:316
bool isStr() const
Check if the variant is a string.
Definition UVariant.h:280
bool isUChar() const
Check if the variant is an unsigned char.
Definition UVariant.h:238