- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/src/frost_utils_var.cpp

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*                                        */
    00005
    00006 #include "frost_utils_var.h"
    00007
    00008 namespace Frost
    00009 {
    00010     const s_type& s_var::VALUE_NONE    = typeid(void);
    00011     const s_type& s_var::VALUE_INT     = typeid(s_int);
    00012     const s_type& s_var::VALUE_UINT    = typeid(s_uint);
    00013     const s_type& s_var::VALUE_FLOAT   = typeid(s_float);
    00014     const s_type& s_var::VALUE_DOUBLE  = typeid(s_double);
    00015     const s_type& s_var::VALUE_BOOL    = typeid(s_bool);
    00016     const s_type& s_var::VALUE_STRING  = typeid(s_str);
    00017     const s_type& s_var::VALUE_POINTER = typeid(void*);
    00018
    00019
    00020     s_var::s_var() : pValue_(NULL)
    00021     {
    00022     }
    00023
    00024     s_var::s_var(const s_var& mVar) : pValue_(mVar.pValue_ ? mVar.pValue_->Clone() : NULL)
    00025     {
    00026     }
    00027
    00028     s_var& s_var::operator = (const s_var& mVar)
    00029     {
    00030         if (&mVar != this)
    00031         {
    00032             s_var mTemp(mVar);
    00033             Swap(mTemp);
    00034         }
    00035         return *this;
    00036     }
    00037
    00038     s_bool s_var::operator == (const s_var& mVar) const
    00039     {
    00040         if (GetType() == mVar.GetType())
    00041         {
    00042             if (IsOfType<s_str>())
    00043             {
    00044                 s_str s1 = Get<s_str>();
    00045                 s_str s2 = mVar.Get<s_str>();
    00046                 return s1 == s2;
    00047             }
    00048             else if (IsOfType<s_float>())
    00049             {
    00050                 s_float f1 = Get<s_float>();
    00051                 s_float f2 = mVar.Get<s_float>();
    00052                 return f1 == f2;
    00053             }
    00054             else if (IsOfType<s_double>())
    00055             {
    00056                 s_double d1 = Get<s_double>();
    00057                 s_double d2 = mVar.Get<s_double>();
    00058                 return d1 == d2;
    00059             }
    00060             else if (IsOfType<s_int>())
    00061             {
    00062                 s_int i1 = Get<s_int>();
    00063                 s_int i2 = mVar.Get<s_int>();
    00064                 return i1 == i2;
    00065             }
    00066             else if (IsOfType<s_uint>())
    00067             {
    00068                 s_uint ui1 = Get<s_uint>();
    00069                 s_uint ui2 = mVar.Get<s_uint>();
    00070                 return ui1 == ui2;
    00071             }
    00072             else if (IsOfType<s_bool>())
    00073             {
    00074                 s_bool b1 = Get<s_bool>();
    00075                 s_bool b2 = mVar.Get<s_bool>();
    00076                 return b1 == b2;
    00077             }
    00078             else if (IsOfType<void>())
    00079                 return true;
    00080         }
    00081
    00082         return false;
    00083     }
    00084
    00085     s_bool s_var::operator != (const s_var& mVar) const
    00086     {
    00087         return !(operator == (mVar));
    00088     }
    00089
    00090     void s_var::Swap(s_var& mVar)
    00091     {
    00092         std::swap(pValue_, mVar.pValue_);
    00093     }
    00094
    00095     s_bool s_var::IsEmpty() const
    00096     {
    00097         return (pValue_ == NULL);
    00098     }
    00099
    00100
    00101     const s_type& s_var::GetType() const
    00102     {
    00103         if (pValue_)
    00104         {
    00105             return pValue_->GetType();
    00106         }
    00107         else
    00108         {
    00109             return typeid(void);
    00110         }
    00111     }
    00112
    00113     s_str s_var::ToString() const
    00114     {
    00115         const s_type& mType = GetType();
    00116         if (mType == VALUE_INT) return s_str::Convert(Get<s_int>());
    00117         else if (mType == VALUE_UINT) return s_str::Convert(Get<s_uint>())+"u";
    00118         else if (mType == VALUE_FLOAT) return s_str::Convert(Get<s_float>())+"f";
    00119         else if (mType == VALUE_DOUBLE) return s_str::Convert(Get<s_double>());
    00120         else if (mType == VALUE_BOOL) return s_str::Convert(Get<s_bool>());
    00121         else if (mType == VALUE_STRING) return "\""+Get<s_str>()+"\"";
    00122         else if (mType == VALUE_POINTER) return s_str::Convert(s_ptr<void>(Get<void*>()));
    00123         else return "<none>";
    00124     }
    00125 }