forked from tokgolich/doctotext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariant.h
80 lines (61 loc) · 2.13 KB
/
variant.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef DOCTOTEXT_VARIANT_H
#define DOCTOTEXT_VARIANT_H
#include <string>
#include <time.h>
namespace doctotext
{
/**
Variant is an object which can represent unsigned number, date or string.
Uninitialized object represents 'null'.
**/
class Variant
{
private:
struct Implementation;
Implementation* impl;
public:
///Creates uninitialized object (represents null)
Variant();
///Creates object which represents string
Variant(const std::string& value);
///Creates object which represents date
Variant(const tm& value);
///Creates object which represents unsigned number
Variant(size_t value);
///Creates a copy of another Variant
Variant(const Variant& variant);
~Variant();
Variant& operator = (const Variant& variant);
///Sets unsigned number value. From this moment, Variant represents unsigned number.
void setValue(size_t number);
///Sets date value. From this moment, Variant represents date.
void setValue(const tm& date_time);
///Sets string value. From this moment, Variant represents string.
void setValue(const std::string& str);
///If Variant has not been initialized with number/date/string, this method returns value true
bool isEmpty() const;
///Checks if Variant represents a string
bool isString() const;
///Checks if Variant represents a number
bool isNumber() const;
///Checks if Variant represents a date
bool isDateTime() const;
/**
If Variant is a date, this method returns const reference to tm object. But if it is not
a date, struct tm can be filled with undefined numbers (usually zeros)
**/
const tm& getDateTime() const;
/**
Returns string value. If Variant is a string, then string is returned (simple). But if variant represents
number or a date, proper value is converted to the string. If variant has no value (represents null),
empty string is returned.
**/
const char* getString() const;
/**
If Variant is a number, then number which is inside this object is returned. In other cases,
returned number may be undefined (usually 0).
**/
size_t getNumber() const;
};
}
#endif