#ifndef VARIABLE_H #define VARIABLE_H #include #include #include 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, tString, tSituation, tList, tDictionary }; public: Variable(); Variable( const Variable &src ); Variable( Type eType ); Variable( int64_t iValue ); Variable( double fValue ); Variable( bool bValue ); Variable( const Bu::String &sValue ); virtual ~Variable(); static Variable newSituationName( const Bu::String &s ); Type getType() const { return eType; } Variable to( Type e ) const; 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; 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(); private: Type eType; typedef Bu::List VList; typedef Bu::Hash VHash; union { int64_t iValue; double fValue; bool bValue; Bu::String *sValue; VList *lValue; VHash *hValue; }; }; 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