aboutsummaryrefslogtreecommitdiff
path: root/src/variable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/variable.h')
-rw-r--r--src/variable.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/variable.h b/src/variable.h
new file mode 100644
index 0000000..1b5542e
--- /dev/null
+++ b/src/variable.h
@@ -0,0 +1,115 @@
1#ifndef VARIABLE_H
2#define VARIABLE_H
3
4#include "types.h"
5
6/**
7 * A build variable, which is basically a flexible, limited type range variant.
8 */
9class Variable
10{
11public:
12 enum Type
13 {
14 typeNone,
15 typeBool,
16 typeInt,
17 typeFloat,
18 typeVersion,
19 typeString,
20 typeList,
21 typeRef /**< Reference by name, it's just a string. */
22 };
23
24public:
25 Variable();
26 Variable( Type t );
27 Variable( int iVal );
28 Variable( double fVal );
29 Variable( bool bVal );
30 Variable( const Bu::FString &sVal );
31 Variable( const char *sVal );
32 Variable( const Variable &v );
33 Variable( const class AstLeaf &l );
34 /**
35 * This special case function turns the variable into a string if there is
36 * only one string in the list, or a list of strings if there is more or
37 * less than one.
38 */
39 Variable( const StrList &lst );
40 Variable( const VarList &lst );
41 virtual ~Variable();
42
43 static Variable mkRef( const Bu::FString &sVal );
44
45 Type getType() const;
46
47 // Raw aquisition functions, if the type isn't right,
48 // they throw an exception
49 int getInt() const;
50 double getFloat() const;
51 bool getBool() const;
52 const Bu::FString &getString() const;
53 const VarList &getList() const;
54
55 // Conversion functions, they'll return the requested type, maybe an error
56 // if the source data is really bad
57 int toInt() const;
58 double toFloat() const;
59 bool toBool() const;
60 Bu::FString toString() const;
61 VarList toList() const;
62
63 Variable toType( Type eNewType ) const;
64
65 void append( const Variable &v );
66 VarList::iterator begin();
67 VarList::const_iterator begin() const;
68
69 void doNegate();
70 void doNot();
71
72 const Variable &operator=( const Variable &rhs );
73 const Variable &operator=( const int &rhs );
74 const Variable &operator=( const double &rhs );
75 const Variable &operator=( const bool &rhs );
76 const Variable &operator=( const Bu::FString &rhs );
77
78 const Variable &operator+=( const Variable &rhs );
79 const Variable &operator<<( const Variable &rhs );
80
81 bool operator==( const Variable &rhs ) const;
82 bool operator!=( const Variable &rhs ) const;
83 bool operator<( const Variable &rhs ) const;
84 bool operator>( const Variable &rhs ) const;
85 bool operator<=( const Variable &rhs ) const;
86 bool operator>=( const Variable &rhs ) const;
87
88 Variable operator+( const Variable &rhs ) const;
89 Variable operator-( const Variable &rhs ) const;
90 Variable operator*( const Variable &rhs ) const;
91 Variable operator/( const Variable &rhs ) const;
92
93private:
94 Type eType;
95 union
96 {
97 int iVal;
98 double fVal;
99 bool bVal;
100 Bu::FString *sVal;
101 VarList *lVal;
102 } uVal;
103
104 void reset( Type eType );
105};
106
107namespace Bu
108{
109 class Formatter;
110}
111
112Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t );
113Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v );
114
115#endif