#ifndef VARIABLE_H #define VARIABLE_H #include #include #include #include "enums.h" class VariableRef { public: ScopeId sid; Bu::String sName; bool operator==( const VariableRef &rhs ) const; }; class Variable { friend uint32_t Bu::__calcHashCode( const Variable &k ); friend Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ); public: enum Type { tNull, tBool, tInt, tFloat, tSituation, tVariable, tVarPtr, tList, tDictionary, tString, }; public: Variable(); Variable( const Variable &src ); Variable( Type eType ); Variable( int64_t iValue ); Variable( double fValue ); Variable( bool bValue ); Variable( const Bu::String &sValue ); Variable( Variable *pValue ); virtual ~Variable(); static Variable newSituationName( const Bu::String &s ); static Variable newVariableName( const Bu::String &s, ScopeId sid ); Type getType() const { return eType; } typedef Bu::List VariableList; typedef Bu::Hash VariableHash; bool getBool() const; int64_t getInt() const; double getFloat() const; Bu::String getString() const; VariableRef getVariableRef() const; Variable *getVariablePtr() const; const VariableList &getList() const; const VariableHash &getHash() const; Variable to( Type e ) const; void insert( const Variable &vKey, const Variable &vValue ); bool has( const Variable &vKey ); Variable &get( const Variable &vKey ); Variable &operator=( const Variable &rhs ); Variable &operator+=( const Variable &rhs ); Variable &operator-=( const Variable &rhs ); Variable &operator*=( const Variable &rhs ); Variable &operator/=( const Variable &rhs ); Variable operator+( const Variable &rhs ) const; Variable operator-( const Variable &rhs ) const; Variable operator*( const Variable &rhs ) const; Variable operator/( const Variable &rhs ) const; Variable operator-() const; bool operator==( const Variable &rhs ) const; bool operator!=( const Variable &rhs ) const; bool operator>( const Variable &rhs ) const; bool operator<( const Variable &rhs ) const; bool operator>=( const Variable &rhs ) const; bool operator<=( const Variable &rhs ) const; private: void initType(); void deinitType(); Type bestType( Type t1, Type t2 ) const; private: Type eType; union { int64_t iValue; double fValue; bool bValue; Bu::String *sValue; VariableList *lValue; VariableHash *hValue; VariableRef *rValue; Variable *pValue; }; }; namespace Bu { template<> uint32_t __calcHashCode( const Variable &k ); template<> bool __cmpHashKeys( const Variable &a, const Variable &b ); }; Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ); typedef Bu::List VariableList; typedef Bu::Hash VariableHash; #endif