summaryrefslogtreecommitdiff
path: root/project2/variables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/variables.cpp')
-rw-r--r--project2/variables.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/project2/variables.cpp b/project2/variables.cpp
index b866165..9108889 100644
--- a/project2/variables.cpp
+++ b/project2/variables.cpp
@@ -18,6 +18,11 @@ SimpleMessageException(UnknownVariableType);
SimpleMessageException(UnknownVariableSource);
SimpleMessageException(NoVariableDefinition);
+bool Null::operator<(const Null &) const
+{
+ return false;
+}
+
enum VT_typeID {
DefaultType,
String,
@@ -111,6 +116,46 @@ VariableType::operator=(const VariableType & vt)
_VT::operator=(*((const _VT *)&vt));
}
+template <class S>
+class compi : public boost::static_visitor<bool> {
+ public:
+ compi(const S & s) : _s(s) { }
+ bool operator()(const S & t) const
+ {
+ return _s < t;
+ }
+ template <class T>
+ bool operator()(const T &) const
+ {
+ // should never be called
+ throw std::logic_error("Shouldn't ever be comparing variables of different type");
+ }
+ private:
+ const S & _s;
+};
+class comp : public boost::static_visitor<bool> {
+ public:
+ comp(const VariableType & a) : _a(a) { }
+ template <class T>
+ bool operator()(const T & t) const
+ {
+ return boost::apply_visitor(compi<T>(t), _a);
+ }
+ private:
+ const VariableType & _a;
+};
+bool
+VariableType::operator<(const VariableType & b) const
+{
+ if (this->which() < b.which()) {
+ return true;
+ }
+ if (this->which() == b.which()) {
+ return boost::apply_visitor(comp(*this), b);
+ }
+ return false;
+}
+
/// Variable implementation whose value is a literal value of some known type
class VariableLiteral : public VariableImpl {
public: