it_bus/reflect/value_ref_base.h

00001 #ifndef _IT_REFLECT_VALUE_REF_BASE_CXX_
00002 #define _IT_REFLECT_VALUE_REF_BASE_CXX_
00003 
00004 // @Copyright 2004 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #include <it_bus/reflect/value.h>
00008 #include <it_bus/schema_type_traits.h>
00009 
00010 namespace IT_Reflect
00011 {
00016     template <class T>
00017     class ValueRefBase : public IT_Reflect::Value<T>
00018     {
00019       public:
00020         ValueRefBase(
00021             const T& value
00022         ) IT_THROW_DECL(());
00023 
00024         ValueRefBase(
00025             const T* value
00026         ) IT_THROW_DECL(());
00027 
00028         ~ValueRefBase() IT_THROW_DECL(());
00029 
00030         virtual const T&
00031         get_value() const IT_THROW_DECL(());
00032         
00033         virtual T&
00034         get_value() IT_THROW_DECL(());
00035 
00036         virtual void
00037         set_value(
00038             const T& value
00039         ) IT_THROW_DECL(());
00040 
00041         virtual const IT_Bus::QName&
00042         get_type_name() const IT_THROW_DECL(());
00043 
00044         virtual IT_Bus::AnyType::Kind
00045         get_type_kind() const IT_THROW_DECL(());
00046 
00047         BuiltInType::ValueKind
00048         get_value_kind() const IT_THROW_DECL(());
00049 
00050         virtual void
00051         duplicate(
00052             const IT_Reflect::BuiltInType* other
00053         ) IT_THROW_DECL((ReflectException));
00054 
00059         virtual void
00060         reset(
00061             const T* new_value
00062         ) const IT_THROW_DECL(());
00063         
00064       protected:
00065         T* m_value;
00066     };
00067 
00068 
00069     // Template function definitions
00070     //
00071     
00072     template <class T>
00073     ValueRefBase<T>::ValueRefBase(
00074         const T& value
00075     ) IT_THROW_DECL(())
00076         :
00077         m_value(IT_CONST_CAST(T*, &value))
00078     {
00079         // Complete.
00080     }
00081 
00082     template <class T>
00083     ValueRefBase<T>::ValueRefBase(
00084         const T* value
00085     ) IT_THROW_DECL(())
00086         :
00087         m_value(IT_CONST_CAST(T*, value))
00088     {
00089         // Complete.
00090     }
00091 
00092     template <class T>
00093     ValueRefBase<T>::~ValueRefBase() IT_THROW_DECL(())
00094     {
00095         // Complete.
00096     }
00097 
00098     template <class T>
00099     const T&
00100     ValueRefBase<T>::get_value() const IT_THROW_DECL(())
00101     {
00102         return *m_value;
00103     }
00104 
00105     template <class T>
00106     T&
00107     ValueRefBase<T>::get_value() IT_THROW_DECL(())
00108     {
00109         return *m_value;
00110     }
00111 
00112     template <class T>
00113     void
00114     ValueRefBase<T>::set_value(
00115         const T& value
00116     ) IT_THROW_DECL(())
00117     {
00118         *m_value = value;
00119     }
00120 
00121     template <class T>
00122     const IT_Bus::QName&
00123     ValueRefBase<T>::get_type_name(
00124     ) const IT_THROW_DECL(())
00125     {
00126         return IT_Bus::SchemaTypeTraits<T>::type_name();
00127     }
00128 
00129     template <class T>
00130     IT_Bus::AnyType::Kind
00131     ValueRefBase<T>::get_type_kind(
00132     ) const IT_THROW_DECL(())
00133     {
00134         return IT_Bus::AnyType::BUILT_IN;
00135     }
00136 
00137     template <class T>
00138     void
00139     ValueRefBase<T>::duplicate(
00140         const IT_Reflect::BuiltInType* other
00141     ) IT_THROW_DECL((ReflectException))
00142     {
00143         const IT_Reflect::Value<T>* value =
00144             IT_DYNAMIC_CAST(const IT_Reflect::Value<T>*, other);
00145         if (value == 0)
00146         {
00147             throw ReflectException(get_type_name(), other->get_type_name());
00148         }
00149         *this->m_value = value->get_value();
00150     }
00151 
00152     template <class T>
00153     BuiltInType::ValueKind
00154     ValueRefBase<T>::get_value_kind() const IT_THROW_DECL(())
00155     {
00156         return BuiltInType::ValueKind(IT_Bus::SchemaTypeTraits<T>::value_kind);
00157     }
00158 
00159     template <class T>
00160     void
00161     ValueRefBase<T>::reset(
00162         const T* new_value
00163     ) const IT_THROW_DECL(())
00164     {
00165         IT_CONST_CAST(ValueRefBase<T>*, this)->m_value =
00166             IT_CONST_CAST(T*, new_value);
00167     }
00168 }
00169 
00170 #endif  

Generated on Thu Sep 7 11:39:03 2006 for Artix by  doxygen 1.4.7