it_bus/reflect/nillable_raw_ptr_impl_t.h

00001 #ifndef _IT_REFLECT_NILLABLE_RAW_PTR_IMPL_T_H_
00002 #define _IT_REFLECT_NILLABLE_RAW_PTR_IMPL_T_H_
00003 
00004 // @Copyright 2004 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #include <it_bus/reflect/nillable.h>
00008 
00009 namespace IT_Reflect
00010 {
00014     template <class T>
00015     class NillableRawPtrImplT  : public virtual Nillable
00016     {
00017       public:
00022         NillableRawPtrImplT(
00023             const T*& data
00024         ) throw(());
00025 
00029         virtual ~NillableRawPtrImplT() throw(());
00030 
00031         virtual IT_Bus::Boolean
00032         get_is_nil() const throw(());
00033 
00034         virtual void
00035         set_is_nil() throw(());
00036         
00037         virtual const Reflection*
00038         get_value() const throw((ReflectException));
00039 
00040         virtual Reflection*
00041         use_value() throw((ReflectException));
00042 
00047         virtual const IT_Bus::QName&
00048         get_type_name() const throw(());
00049 
00054         virtual IT_Bus::AnyType::Kind
00055         get_type_kind() const throw(());
00056 
00060         virtual const IT_Bus::AnyType&
00061         get_reflected() const throw(());
00062 
00066         virtual IT_Bus::AnyType&
00067         get_reflected() throw(());
00068 
00074         virtual IT_Bus::AnyType*
00075         clone() const throw((ReflectException));
00076 
00077       protected:
00078         T& check_data();
00079         T*& m_data;
00080     };
00081 
00082     template <class T>
00083     NillableRawPtrImplT<T>::NillableRawPtrImplT(
00084         const T*& data
00085     ) throw(())
00086         :
00087         m_data(IT_CONST_CAST(T*&, data))
00088     {
00089         // Complete.
00090     }
00091 
00092     template <class T>
00093     NillableRawPtrImplT<T>::~NillableRawPtrImplT(
00094     ) throw(())
00095     {
00096         // Complete.
00097     }
00098 
00099     template <class T>
00100     T&
00101     NillableRawPtrImplT<T>::check_data()
00102     {
00103         if (this->m_data == 0)
00104         {
00105             throw IT_Reflect::ReflectException("Attempt to use nil value");
00106         }
00107         return *this->m_data;
00108     }
00109     
00110     template <class T>
00111     IT_Bus::Boolean
00112     NillableRawPtrImplT<T>::get_is_nil(
00113     ) const throw(())
00114     {
00115         return this->m_data == 0;
00116     }
00117 
00118     template <class T>
00119     void
00120     NillableRawPtrImplT<T>::set_is_nil(
00121     ) throw(())
00122     {
00123         delete this->m_data;
00124         this->m_data = 0;
00125     }
00126 
00127     template <class T>
00128     const Reflection*
00129     NillableRawPtrImplT<T>::get_value(
00130     ) const throw((ReflectException))
00131     {
00132         return get_is_nil() ? 0 : Traits<T>::get_reflection(*this->m_data);
00133     }
00134 
00135     template <class T>
00136     Reflection*
00137     NillableRawPtrImplT<T>::use_value(
00138     ) throw((ReflectException))
00139     {
00140         if (get_is_nil())
00141         {
00142             this->m_data = new T;
00143         }
00144         return Traits<T>::get_reflection(*this->m_data);
00145     }
00146 
00147     template <class T>
00148     const IT_Bus::QName&
00149     NillableRawPtrImplT<T>::get_type_name(
00150     ) const throw(())
00151     {
00152         return check_data().get_type();
00153     }
00154 
00155     template <class T>
00156     IT_Bus::AnyType::Kind
00157     NillableRawPtrImplT<T>::get_type_kind(
00158     ) const throw(())
00159     {
00160         return check_data().get_kind();
00161     }
00162 
00163     template <class T>
00164     const IT_Bus::AnyType&
00165     NillableRawPtrImplT<T>::get_reflected(
00166     ) const throw(())
00167     {
00168         return check_data();
00169     }
00170 
00171     template <class T>
00172     IT_Bus::AnyType&
00173     NillableRawPtrImplT<T>::get_reflected(
00174     ) throw(())
00175     {
00176         return check_data();
00177     }
00178 
00179     template <class T>
00180     IT_Bus::AnyType*
00181     NillableRawPtrImplT<T>::clone(
00182     ) const throw((ReflectException))
00183     {
00184         return Traits<T>::clone(check_data());
00185     }
00186 }
00187 
00188         
00189 #endif  

Generated on Tue Mar 20 15:27:43 2007 for Artix by  doxygen 1.5.1-p1