21 #include <boost/lexical_cast.hpp>
51 std::vector<const char*> call_stack;
56 call_stack.push_back(str);
61 call_stack.pop_back();
67 for(std::vector<const char*>::const_iterator
i = call_stack.begin();
68 i != call_stack.end(); ++
i) {
113 , list_iterator_(iter)
122 , map_iterator_(iter)
340 return variant_type_to_string(
type_);
365 : type_(TYPE_CALLABLE), callable_(callable)
400 memcpy(
this, &v,
sizeof(v));
413 memcpy(
this, &v,
sizeof(v));
442 std::map<variant,variant>::const_iterator
i =
map_->
elements.find(v);
451 std::vector<variant> slice;
454 slice.push_back( (*
this)[v[
i]] );
457 }
else if(v.
as_int() < 0) {
463 <<
" expected a list or a map but found " <<
type_string()
472 std::vector<variant> tmp;
474 tmp.push_back(
i->first);
483 std::vector<variant> tmp;
485 tmp.push_back(
i->second);
540 <<
" expected a list or a map but found " <<
type_string()
575 <<
" expected integer or decimal but found " <<
type_string()
628 std::vector<variant>
res;
648 res[
i->first] =
i->second;
680 if( long_int%10 >= 5) {
697 if(denominator == 0) {
707 if( long_int%10 >= 5) {
719 if(denominator == 0) {
723 return variant(numerator/denominator);
731 if(denominator == 0) {
739 if(denominator == 0) {
743 return variant(numerator%denominator);
754 if(res != res)
return variant();
759 return variant(static_cast<int>(
804 if((*
this)[
n] != v[
n]) {
861 if((*
this)[
n] < v[
n]) {
863 }
else if((*
this)[
n] > v[
n]) {
891 return !(*
this >=
v);
896 return !(*
this <=
v);
905 throw type_error(
"Operator '.+' requires two lists of the same length");
907 std::vector< variant >
res;
911 res.push_back( (*
this)[
i] + v[
i] );
923 throw type_error(
"Operator '.-' requires two lists of the same length");
925 std::vector< variant >
res;
929 res.push_back( (*
this)[
i] - v[
i] );
941 throw type_error(
"Operator '.*' requires two lists of the same length");
943 std::vector< variant >
res;
947 res.push_back( (*
this)[
i] * v[
i] );
959 throw type_error(
"Operator './' requires two lists of the same length");
961 std::vector< variant >
res;
965 res.push_back( (*
this)[
i] / v[
i] );
976 std::vector< variant >
res;
980 res.push_back( (*
this)[
i] );
984 res.push_back( v[
i] );
994 <<
" lists or two maps but found " <<
type_string()
1006 int len = abs(rhs - lhs) + 1;
1008 std::vector< variant >
res;
1011 for(
size_t i = lhs; res.size() != res.capacity(); lhs < rhs ? ++
i : --
i) {
1021 << variant_type_to_string(
TYPE_LIST) <<
" or "
1022 << variant_type_to_string(
TYPE_MAP) <<
" but found "
1023 << variant_type_to_string(
type_)
1029 return iter !=
end();
1031 std::map<variant,variant>::const_iterator iter =
map_->
elements.find(v);
1040 << variant_type_to_string(t) <<
" but found " <<
type_string()
1055 std::ostringstream
s;
1060 s << integer <<
".";
1062 fractional = abs(fractional);
1064 if( fractional < 100) {
1065 if( fractional < 10)
1081 bool first_time =
true;
1095 bool first_time =
true;
1101 i->first.serialize_to_string(str);
1103 i->second.serialize_to_string(str);
1173 std::ostringstream
s;
1178 s << integer <<
".";
1180 fractional = abs(fractional);
1182 if( fractional < 100) {
1183 if( fractional < 10)
1214 res +=
i->first.string_cast();
1216 res +=
i->second.string_cast();
1231 std::vector<const game_logic::formula_callable*> seen_stack;
1236 std::ostringstream
s;
1251 s << integer <<
".";
1253 fractional = abs(fractional);
1255 if( fractional < 100) {
1256 if( fractional < 10)
1285 for(
size_t i=0;
i<v.size(); ++
i) {
1291 s << input.
name <<
" ";
1293 s <<
"(read-write) ";
1295 s <<
"(writeonly) ";
1308 bool first_time =
true;
1314 s <<
i->first.to_debug_string(seen, verbose);
1316 s <<
i->second.to_debug_string(seen, verbose);
bool operator<(const variant &) const
size_t num_elements() const
variant operator^(const variant &) const
variant operator*(const variant &) const
variant build_range(const variant &v) const
variant operator/(const variant &) const
std::vector< variant >::iterator list_iterator_
GLuint GLuint GLsizei GLenum type
static l_noret error(LoadState *S, const char *why)
GLenum GLenum GLenum input
std::vector< variant > elements
void must_be(TYPE t) const
variant_iterator end() const
const std::map< variant, variant > & as_map() const
bool contains(const variant &other) const
variant list_elements_sub(const variant &v) const
variant list_elements_mul(const variant &v) const
const game_logic::formula_callable * callable_
std::string get_call_stack()
type_error(const std::string &str)
bool operator<=(const variant &) const
variant list_elements_add(const variant &v) const
std::map< variant, variant > elements
INT32 INT32 * denominator
variant list_elements_div(const variant &v) const
bool operator>(const variant &) const
std::map< variant, variant >::iterator map_iterator_
std::string string_cast() const
Iterator class for the variant.
void push_call_stack(const char *str)
void serialize_to_string(std::string &str) const
variant operator*() const
Templates and utility-routines for strings and numbers.
variant concatenate(const variant &v) const
double round_portable(double d)
variant_iterator begin() const
void intrusive_ptr_add_ref(const reference_counted_object *obj)
variant & operator=(const variant &v)
const std::string & as_string() const
bool operator==(const variant &) const
variant_iterator & operator--()
variant operator%(const variant &) const
variant operator+(const variant &) const
bool operator!=(const variant_iterator &that) const
void increment_refcount()
variant_iterator()
Constructor for a TYPE_NULL variant.
std::string to_debug_string(std::vector< const game_logic::formula_callable * > *seen=nullptr, bool verbose=false) const
void intrusive_ptr_release(const reference_counted_object *obj)
bool find(E event, F functor)
Tests whether an event handler is available.
variant get_values() const
const std::vector< variant > & as_list() const
variant get_member(const std::string &str) const
GLsizei GLenum GLuint GLuint GLsizei char * message
void serialize_from_string(const std::string &str)
variant operator-() const
variant_iterator & operator=(const variant_iterator &that)
variant_iterator & operator++()
GLsizei const GLcharARB ** string
variant operator[](size_t n) const
std::string type_string() const
bool operator>=(const variant &) const
bool operator!=(const variant &) const
bool operator==(const variant_iterator &that) const