1 #include <ail/string.hpp>
2 #include <fridh/symbol.hpp>
7 type(variable_type_identifier::undefined
)
11 variable::variable(variable
const & other
)
21 variable
& variable::operator=(variable
const & other
)
28 void variable::copy(variable
const & other
)
32 #define COPY_MEMBER(type) \
33 case variable_type_identifier::type: \
37 #define COPY_MEMBER_POINTER(type, member_type, member) \
38 case variable_type_identifier::type: \
39 member = new member_type(*other.member); \
45 COPY_MEMBER(signed_integer
)
46 COPY_MEMBER(unsigned_integer
)
47 COPY_MEMBER(floating_point_value
)
49 COPY_MEMBER_POINTER(string
, std::string
, string
)
50 COPY_MEMBER_POINTER(array
, types::vector
, array
)
51 COPY_MEMBER_POINTER(map
, types::map
, map
)
54 #undef COPY_MEMBER_POINTER
59 void variable::destroy()
62 #define DELETE_MEMBER(type) \
63 case variable_type_identifier::type: \
74 type
= variable_type_identifier::undefined
;
80 types::floating_point_value
variable::get_floating_point_value() const
84 case variable_type_identifier::signed_integer
:
85 return signed_integer
;
87 case variable_type_identifier::unsigned_integer
:
88 return unsigned_integer
;
90 case variable_type_identifier::floating_point_value
:
91 return floating_point_value
;
94 throw ail::exception("Failed to retrieve floating point value");
97 std::string
variable::get_string_representation() const
101 case variable_type_identifier::boolean
:
102 return ail::bool_to_string(boolean
);
104 case variable_type_identifier::signed_integer
:
105 return ail::number_to_string
<types::signed_integer
>(signed_integer
);
107 case variable_type_identifier::unsigned_integer
:
108 return ail::number_to_string
<types::unsigned_integer
>(unsigned_integer
);
110 case variable_type_identifier::floating_point_value
:
111 return ail::number_to_string
<types::floating_point_value
>(floating_point_value
);
113 case variable_type_identifier::string
:
117 unary_argument_type_error("String representation", type
);
119 //should never get here, suppress warnings
123 bool variable::get_boolean_value() const
127 case variable_type_identifier::boolean
:
130 case variable_type_identifier::signed_integer
:
131 return signed_integer
!= 0;
133 case variable_type_identifier::unsigned_integer
:
134 return unsigned_integer
!= 0;
137 unary_argument_type_error("Boolean representation", type
);
139 //should never get here, suppress warnings
143 bool variable::is_zero() const
147 case variable_type_identifier::signed_integer
:
148 return signed_integer
== 0;
150 case variable_type_identifier::unsigned_integer
:
151 return unsigned_integer
== 0;
153 case variable_type_identifier::floating_point_value
:
154 return floating_point_value
== 0.0;
157 throw ail::exception("Unable to check if variable is zero");
160 bool variable::operator<(variable
const & other
) const
162 if(is_numeric_type() && other
.is_numeric_type())
166 type
== variable_type_identifier::floating_point_value
||
167 other
.type
== variable_type_identifier::floating_point_value
169 return get_floating_point_value() < other
.get_floating_point_value();
172 type
== variable_type_identifier::unsigned_integer
&&
173 other
.type
== variable_type_identifier::unsigned_integer
175 return unsigned_integer
< other
.unsigned_integer
;
177 return signed_integer
< other
.signed_integer
;
179 else if(type
!= other
.type
)
180 return static_cast<word
>(type
) < static_cast<word
>(other
.type
);
183 if(type
== variable_type_identifier::string
)
184 return *string
< *other
.string
;
186 return hash() < other
.hash();
190 std::string
get_type_string(variable_type type
)
194 case variable_type_identifier::undefined
:
197 case variable_type_identifier::nil
:
200 case variable_type_identifier::none
:
203 case variable_type_identifier::boolean
:
206 case variable_type_identifier::signed_integer
:
209 case variable_type_identifier::unsigned_integer
:
210 return "unsigned-integer";
212 case variable_type_identifier::floating_point_value
:
215 case variable_type_identifier::string
:
218 case variable_type_identifier::array
:
221 case variable_type_identifier::map
:
224 case variable_type_identifier::function
:
227 case variable_type_identifier::object
: