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 ) IT_THROW_DECL(()); 00025 00029 virtual ~NillableRawPtrImplT() IT_THROW_DECL(()); 00030 00031 virtual IT_Bus::Boolean 00032 get_is_nil() const IT_THROW_DECL(()); 00033 00034 virtual void 00035 set_is_nil() IT_THROW_DECL(()); 00036 00037 virtual const Reflection* 00038 get_value() const IT_THROW_DECL((ReflectException)); 00039 00040 virtual Reflection* 00041 use_value() IT_THROW_DECL((ReflectException)); 00042 00047 virtual const IT_Bus::QName& 00048 get_type_name() const IT_THROW_DECL(()); 00049 00054 virtual IT_Bus::AnyType::Kind 00055 get_type_kind() const IT_THROW_DECL(()); 00056 00060 virtual const IT_Bus::AnyType& 00061 get_reflected() const IT_THROW_DECL(()); 00062 00066 virtual IT_Bus::AnyType& 00067 get_reflected() IT_THROW_DECL(()); 00068 00074 virtual IT_Bus::AnyType* 00075 clone() const IT_THROW_DECL((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 ) IT_THROW_DECL(()) 00086 : 00087 m_data(IT_CONST_CAST(T*&, data)) 00088 { 00089 // Complete. 00090 } 00091 00092 template <class T> 00093 NillableRawPtrImplT<T>::~NillableRawPtrImplT( 00094 ) IT_THROW_DECL(()) 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 IT_THROW_DECL(()) 00114 { 00115 return this->m_data == 0; 00116 } 00117 00118 template <class T> 00119 void 00120 NillableRawPtrImplT<T>::set_is_nil( 00121 ) IT_THROW_DECL(()) 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 IT_THROW_DECL((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 ) IT_THROW_DECL((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 IT_THROW_DECL(()) 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 IT_THROW_DECL(()) 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 IT_THROW_DECL(()) 00167 { 00168 return check_data(); 00169 } 00170 00171 template <class T> 00172 IT_Bus::AnyType& 00173 NillableRawPtrImplT<T>::get_reflected( 00174 ) IT_THROW_DECL(()) 00175 { 00176 return check_data(); 00177 } 00178 00179 template <class T> 00180 IT_Bus::AnyType* 00181 NillableRawPtrImplT<T>::clone( 00182 ) const IT_THROW_DECL((ReflectException)) 00183 { 00184 return Traits<T>::clone(check_data()); 00185 } 00186 } 00187 00188 00189 #endif