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
81
82
83
84
85
|
#ifndef VARIABLES_H
#define VARIABLES_H
#include <boost/intrusive_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <stdint.h>
#include <glibmm/ustring.h>
#include <libxml++/nodes/element.h>
#include <libxml++/attribute.h>
#include "intrusivePtrBase.h"
#include <boost/variant.hpp>
#include <boost/shared_ptr.hpp>
class RowUser;
typedef boost::variant<
// Strings
Glib::ustring,
boost::shared_ptr<const Glib::ustring>,
// Numbers
long long unsigned int,
long unsigned int,
unsigned int,
short unsigned int,
long long int,
long int,
int,
short int,
double,
float,
// DateTimes
boost::posix_time::ptime,
boost::shared_ptr<const boost::posix_time::ptime>
> _VT;
class VariableType : public _VT {
public:
typedef void(*Freer)(const void*);
template<typename T>
VariableType(const T & t) : _VT(t), convertCache(NULL), freer(NULL) { }
VariableType();
VariableType(const VariableType &);
~VariableType();
void operator=(const VariableType &);
operator const Glib::ustring &() const;
operator const std::string &() const;
operator const char *() const;
operator const unsigned char *() const;
private:
template <typename T> friend const T * set(const VariableType * var, const T * t, Freer);
mutable const void * convertCache;
mutable Freer freer;
};
class VariableImpl : public virtual IntrusivePtrBase {
public:
virtual const VariableType & value() const = 0;
protected:
virtual ~VariableImpl() = 0;
};
class Variable {
public:
typedef boost::intrusive_ptr<VariableImpl> VariableImplPtr;
Variable(const xmlpp::Element *, const Glib::ustring & n, bool required = true, VariableType def = VariableType());
static Variable makeFromCode(const Glib::ustring & s);
static Variable makeParent(const Glib::ustring & name, bool attr, unsigned int depth);
operator const VariableType & () const { return var->value(); }
const VariableType & operator()() const { return var->value(); }
private:
Variable(VariableImpl *);
friend class VariableParse;
static VariableImplPtr create(const Glib::ustring & s, RowUser * dep = NULL);
VariableImplPtr var;
};
#endif
|