cgv
Loading...
Searching...
No Matches
variant.h
1#pragma once
2
3#include "operators.h"
4#include <vector>
5#include <map>
6
7#include "lib_begin.h"
8
9namespace cgv {
10 namespace ppp {
11
12 class ph_processor;
13 struct namespace_info;
14
15 enum ValueType {
16 UNDEF_VALUE, BOOL_VALUE, INT_VALUE, DOUBLE_VALUE, STRING_VALUE,
17 REFERENCE_VALUE, NAME_VALUE, LIST_VALUE, MAP_VALUE, FUNC_VALUE
18 };
19
20 struct func_type
21 {
22 unsigned block_begin;
23 unsigned block_end;
24 ph_processor* ph_proc;
26 func_type(unsigned _i, unsigned _j, ph_processor* _ph_proc = 0, namespace_info* _ns = 0);
27 };
28
29 class CGV_API variant
30 {
31 public:
32 typedef std::vector<variant> list_type;
33 typedef std::map<std::string, variant> map_type;
34 protected:
36 ValueType vt;
37 union {
38 bool bool_value;
39 int int_value;
40 double dbl_value;
41 std::string* string_value;
42 variant* reference_value;
43 std::string* name_value;
44 list_type* list_value;
45 map_type* map_value;
46 func_type* func_value;
47 };
48 public:
52 variant();
54 variant(const variant& v);
56 variant(bool v);
58 variant(int v);
60 variant(double v);
62 variant(const std::string& v);
64 variant(variant* v);
66 variant(ValueType vt, const std::string& v);
68 variant(const list_type& v);
70 variant(const map_type& v);
72 variant(const func_type& v);
74 void clear();
76 variant& operator = (const variant& v);
78 ~variant();
80
83 bool is_unary_applicable(OperatorType ot);
84 bool unary_check_defined(OperatorType ot);
85 void apply_unary(OperatorType ot);
86 bool is_binary_applicable(OperatorType ot, const variant& v2);
87 bool binary_check_defined(OperatorType ot, const variant& v2);
88 void apply_binary(OperatorType ot, const variant& v2);
90
94 ValueType get_type() const;
96 ValueType get_value_type() const;
98 bool is_undefined() const;
100 bool is_int() const;
102 bool is_double() const;
104 bool is_bool() const;
106 bool is_str() const;
108 bool is_list() const;
110 bool is_map() const;
112 bool is_func() const;
114 bool is_reference() const;
116 bool is_name() const;
118
122 bool get_bool() const;
124 int get_int() const;
126 double get_double() const;
128 std::string get_str() const;
130 const list_type& get_list() const;
132 const map_type& get_map() const;
134 void ensure_int_type();
136 bool match_number_type(const variant& v2);
138
141 bool& ref_bool();
142 int& ref_int();
143 double& ref_double();
144 std::string& ref_str();
145 list_type& ref_list();
146 map_type& ref_map();
147 func_type& ref_func();
149
152 void set_bool(bool v);
153 void set_int(int v);
154 void set_double(double v);
155 void set_str(const std::string& v);
156 void set_name(const std::string& n);
157 void set_list();
158 void set_list(const std::vector<variant>& l);
159 void set_map();
160 void set_map(const std::map<std::string, variant>& m);
162
166 const variant& get_value() const;
168 variant& ref_value();
170 variant* get_reference() const;
172 const std::string& get_name() const;
174
178 unsigned int get_size() const;
180 unsigned get_total_nr_elements() const;
182 variant& ref_element(unsigned int i);
184 const variant& get_element(unsigned int i) const;
186
189 void append_to_list(const variant& v);
190 void prepend_to_list(const variant& v);
191 void pop_back_from_list();
192 void pop_front_from_list();
194
198 variant& ref_element(const std::string& name);
200 const variant& get_element(const std::string& name);
202 const std::string& get_element_name(unsigned int i) const;
204 void insert(const std::string& name, const variant& v);
206 };
207
209 extern CGV_API std::ostream& operator << (std::ostream& os, const variant& v);
210
211 }
212}
213#include <cgv/config/lib_end.h>
the pre header processor parses a pre header file and converts it to a header file or uses the inform...
ValueType vt
store type of value
Definition variant.h:36
the cgv namespace
Definition print.h:11
for each namespace the following information is stored
Definition variables.h:20