LibCT 2.0

Include/TemplateVariable.h

Go to the documentation of this file.
00001 // ------------------------------------------------------------------
00012 #ifndef _LIBCT_TEMPLATEVARIABLE_H
00013 #define _LIBCT_TEMPLATEVARIABLE_H
00014 
00015 #include "VariableInterface.h"
00016 #include "VariableTypes.h"
00017 #include "Exception.h"
00018 #include "FormatString.h"
00019 
00020 namespace LibCT
00021 {
00023         template<typename T>
00024         class TemplateVariable : public VariableInterface
00025         {
00026         public:
00027 
00029                 TemplateVariable(VariableContainer* pContainer, const std::string& name)
00030                         : VariableInterface(pContainer, name)
00031                 {
00032                 }
00033 
00035                 explicit
00036                 TemplateVariable(const T& val)
00037                         : m_Value(val)
00038                 {
00039                 }
00040 
00042                 TemplateVariable(const TemplateVariable<T>& rhs)
00043                 {
00044                         m_Value = rhs.m_Value;
00045                 }
00046 
00048                 virtual ~TemplateVariable()
00049                 {
00050                 }
00051 
00054                 TemplateVariable<T>& operator = (
00055                         const TemplateVariable<T>& rhs  
00056                         )
00057                 {
00058                         if(this != &rhs)
00059                         {
00060                                 m_Value = rhs.m_Value;
00061                         }
00062                         return *this;
00063                 }
00064 
00068                 virtual bool operator == (
00069                         const VariableInterface& rhs    
00070                         ) const
00071                 {
00072                         const TemplateVariable<T>* pRhs = dynamic_cast<const TemplateVariable<T>*>(&rhs);
00073                         if(pRhs)
00074                         {
00075                                 return m_Value == pRhs->m_Value;
00076                         }
00077                         LIBCTEXCEPTION(ExceptionCodeVariable, 
00078                                 FormatString<1024>("Invalid cast from %s to %s", rhs.GetTypeString().c_str(), GetTypeString().c_str()), 
00079                                                         "TemplateVarable::operator==");
00080                 }
00081 
00085                 virtual bool operator != (
00086                         const VariableInterface& rhs    
00087                         ) const
00088                 {
00089                         const TemplateVariable<T>* pRhs = dynamic_cast<const TemplateVariable<T>*>(&rhs);
00090                         if(pRhs)
00091                         {
00092                                 return m_Value != pRhs->m_Value;
00093                         }
00094                         LIBCTEXCEPTION(ExceptionCodeVariable, 
00095                                                         FormatString<1024>("Invalid cast from %s to %s", rhs.GetTypeString().c_str(), GetTypeString().c_str()), 
00096                                                         "TemplateVarable::operator!=");
00097                 }
00098 
00102                 virtual bool operator <	 (
00103                         const VariableInterface& rhs    
00104                         ) const
00105                 {
00106                         const TemplateVariable<T>* pRhs = dynamic_cast<const TemplateVariable<T>*>(&rhs);
00107                         if(pRhs)
00108                         {
00109                                 return m_Value < pRhs->m_Value;
00110                         }
00111                         LIBCTEXCEPTION(ExceptionCodeVariable, 
00112                                                         FormatString<1024>("Invalid cast from %s to %s", rhs.GetTypeString().c_str(), GetTypeString().c_str()), 
00113                                                         "TemplateVarable::operator<");
00114                 }
00115 
00119                 virtual bool operator <= (
00120                         const VariableInterface& rhs    
00121                         ) const
00122                 {
00123                         const TemplateVariable<T>* pRhs = dynamic_cast<const TemplateVariable<T>*>(&rhs);
00124                         if(pRhs)
00125                         {
00126                                 return m_Value <= pRhs->m_Value;
00127                         }
00128                         LIBCTEXCEPTION(ExceptionCodeVariable, 
00129                                                         FormatString<1024>("Invalid cast from %s to %s", rhs.GetTypeString().c_str(), GetTypeString().c_str()), 
00130                                                         "TemplateVarable::operator<=");
00131                 }
00132 
00136                 virtual bool operator >	 (
00137                         const VariableInterface& rhs    
00138                         ) const
00139                 {
00140                         const TemplateVariable<T>* pRhs = dynamic_cast<const TemplateVariable<T>*>(&rhs);
00141                         if(pRhs)
00142                         {
00143                                 return m_Value > pRhs->m_Value;
00144                         }
00145                         LIBCTEXCEPTION(ExceptionCodeVariable, 
00146                                                         FormatString<1024>("Invalid cast from %s to %s", rhs.GetTypeString().c_str(), GetTypeString().c_str()), 
00147                                                         "TemplateVarable::operator>");
00148                 }
00149 
00153                 virtual bool operator >= (
00154                         const VariableInterface& rhs    
00155                         ) const
00156                 {
00157                         const TemplateVariable<T>* pRhs = dynamic_cast<const TemplateVariable<T>*>(&rhs);
00158                         if(pRhs)
00159                         {
00160                                 return m_Value >= pRhs->m_Value;
00161                         }
00162                         LIBCTEXCEPTION(ExceptionCodeVariable, 
00163                                                         FormatString<1024>("Invalid cast from %s to %s", rhs.GetTypeString().c_str(), GetTypeString().c_str()), 
00164                                                         "TemplateVarable::operator>=");
00165                 }
00166 
00169                 virtual VariableType GetType() const
00170                 {
00171                         return VariableTypeUnknown;
00172                 }
00173 
00176                 T GetValue() const
00177                 {
00178                         return m_Value;
00179                 }
00180 
00182                 void SetValue(
00183                         const T& newVal 
00184                         )
00185                 {
00186                         m_Value = newVal;
00187                 }
00188 
00189         protected:
00190                 T m_Value;      
00191         };
00192 }
00193 
00194 #endif // _LIBCT_TEMPLATEVARIABLE_H