Found a solution to the multi statement/non comma separated argument issue, I think
[fridhskrift.git] / variable / equality.cpp
blob8d34cdd9140260efcf5d2a8044fd5a87ee3620d4
1 #include <ail/exception.hpp>
2 #include <frith/symbol.hpp>
4 namespace frith
6 bool variable::array_equality(variable const & other) const
8 types::vector
9 & vector = *array,
10 & other_vector = *other.array;
12 std::size_t size = vector.size();
13 if(size != vector.size())
14 return false;
16 for(std::size_t i = 0; i < size; i++)
18 if(vector[i] != other_vector[i])
19 return false;
22 return true;
25 bool variable::map_equality(variable const & other) const
27 types::map
28 & this_map = *map,
29 & other_map = *other.map;
31 if(this_map.size() != other_map.size())
32 return false;
34 for(types::map::const_iterator i = this_map.begin(), end = this_map.end(); i != end; i++)
36 types::map::const_iterator iterator = other_map.find(i->first);
37 if(iterator == other_map.end())
38 return false;
40 if(i->second != iterator->second)
41 return false;
44 return true;
47 bool variable::operator==(variable const & other) const
49 if(is_numeric_type() && other.is_numeric_type())
51 if(type == variable_type_identifier::floating_point_value || other.type == variable_type_identifier::floating_point_value)
52 return get_floating_point_value() == other.get_floating_point_value();
53 else
54 return unsigned_integer == other.unsigned_integer;
56 else
58 switch(type)
60 case variable_type_identifier::nil:
61 case variable_type_identifier::none:
62 return type == other.type;
63 return type == other.type;
65 case variable_type_identifier::boolean:
66 return type == other.type && boolean == other.boolean;
68 case variable_type_identifier::string:
69 return type == other.type && *string == *other.string;
71 case variable_type_identifier::array:
72 return array_equality(other);
74 case variable_type_identifier::map:
75 return map_equality(other);
77 case variable_type_identifier::function:
78 throw ail::exception("Comparison of functions has not been implemented yet");
80 case variable_type_identifier::object:
81 throw ail::exception("Comparison of objects has not been implemented yet");
83 case variable_type_identifier::signed_integer:
84 case variable_type_identifier::unsigned_integer:
85 case variable_type_identifier::floating_point_value:
86 default:
87 return false;
92 bool variable::operator!=(variable const & other) const
94 return !operator==(other);