OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Variant.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef VARIANT_H_
11 #define VARIANT_H_
12 
13 #include <sys/types.h>
14 #include <string>
15 #include "SecureString.hpp"
16 
17 namespace OpenAB {
26 class Variant
27 {
28  public:
33  Variant();
34 
39  Variant(char value);
40 
45  Variant(bool value);
46 
51  Variant(u_int32_t value);
52 
57  Variant(int32_t value);
58 
63  Variant(double value);
64 
69  Variant(const std::string& value);
70 
75  Variant(void* value);
76 
81  Variant(const char* value);
82 
87  Variant(const OpenAB::SecureString& value);
88 
92  Variant(Variant const &other);
93 
97  virtual ~Variant();
98 
102  Variant& operator=(Variant const &other);
103 
107  bool operator==(Variant const &other);
108 
112  enum DataType
113  {
122  };
123 
128  void set(char value);
129 
134  void set(bool value);
135 
136 
141  void set(int32_t value);
142 
147  void set(u_int32_t value);
148 
153  void set(double value);
154 
159  void set(const std::string& value);
160 
165  void set(const OpenAB::SecureString& value);
166 
171  void set(void* value);
172 
177  void set(const char* value);
178 
183  char getChar() const;
184 
189  bool getBool() const;
190 
195  int32_t getInt() const;
196 
201  double getDouble() const;
202 
207  std::string getString() const;
208 
214 
219  void* getPointer() const;
220 
225  DataType getType() const;
226 
231  bool invalid() const;
232 
233  private:
234  void clear();
235 
236  DataType dataType;
237 
238  union
239  {
240  char c;
241  bool b;
242  int32_t i;
243  double d;
244  void* p;
245  } data;
246 
247  std::string stringData;
248  OpenAB::SecureString secureStringData;
249 };
250 
251 } // namespace OpenAB
252 
253 #endif // VARIANT_H_
Definition: Variant.hpp:114
double d
Definition: Variant.hpp:243
Variant()
Constructor. Creates invalid Variant.
Definition: Variant.cpp:15
Definition: Variant.hpp:121
bool operator==(Variant const &other)
Compare operator.
Definition: Variant.cpp:96
int32_t getInt() const
Definition: Variant.cpp:199
Definition: Variant.hpp:120
Definition: Variant.hpp:118
virtual ~Variant()
Destructor, virtual by default.
Definition: Variant.cpp:254
Definition: Variant.hpp:119
Definition: Variant.hpp:117
char c
Definition: Variant.hpp:240
Definition: Variant.hpp:115
SecureString class, used to store strings like passwords etc. Current implementation encodes string i...
Definition: SecureString.hpp:26
double getDouble() const
Definition: Variant.cpp:206
std::string getString() const
Definition: Variant.cpp:213
int32_t i
Definition: Variant.hpp:242
void * p
Definition: Variant.hpp:244
bool invalid() const
Definition: Variant.cpp:249
char getChar() const
Definition: Variant.cpp:185
bool b
Definition: Variant.hpp:241
DataType
Definition: Variant.hpp:112
OpenAB::SecureString getSecureString() const
Definition: Variant.cpp:221
Variant class that can contains different types of data.
Definition: Variant.hpp:26
DataType getType() const
Definition: Variant.cpp:244
bool getBool() const
Definition: Variant.cpp:192
void set(char value)
Definition: Variant.cpp:122
void * getPointer() const
Definition: Variant.cpp:229
Variant & operator=(Variant const &other)
Assignment operator.
Definition: Variant.cpp:85
Definition: Variant.hpp:116