it_bus_pdk/built_in_type.h

00001 #ifndef _IT_BUS_BUILIT_IN_TYPE_H_
00002 #define _IT_BUS_BUILIT_IN_TYPE_H_
00003 
00004 // @Copyright 2003 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #ifndef IT_MINIMISE_INCLUDES
00008 #include <it_bus/binary_type.h>
00009 #include <it_bus/qname.h>
00010 #include <it_bus/complex_type_reader.h>
00011 #include <it_bus/complex_type_writer.h>
00012 #endif
00013 #include <it_bus/types.h>
00014 #include <it_schema_model/w3c_constants.h>
00015 #include <it_bus/reflect/value_ref.h>
00016 
00017 namespace IT_Bus
00018 {
00019     class QName;
00026     template <class T, const QName* TYPE>
00027     class BuiltInType : public AnyType
00028     {
00029       public:
00030         typedef T ValueType;
00031 
00032         BuiltInType();
00033 
00034         BuiltInType(
00035             const BuiltInType& other
00036         );
00037 
00038         explicit BuiltInType(
00039             const T& other
00040         );
00041 
00042         virtual
00043         ~BuiltInType();
00044 
00045         virtual Kind
00046         get_kind() const;
00047 
00048         BuiltInType&
00049         operator=(
00050             const BuiltInType& other
00051         );
00052 
00053         AnyType&
00054         copy(
00055             const AnyType& other
00056         );
00057 
00058         virtual const QName&
00059         get_type() const;
00060 
00061         virtual void 
00062         write(
00063             const QName& name,
00064             ComplexTypeWriter& writer
00065         ) const throw((SerializationException));
00066 
00067         virtual void
00068         read(
00069             const QName& name,
00070             ComplexTypeReader& reader
00071         ) throw((DeserializationException));
00072 
00077         virtual const T&
00078         get() const;
00079         
00084         virtual T&
00085         get();
00086         
00090         virtual void
00091         set(
00092             const T& data
00093         );
00094 
00095         virtual IT_Reflect::Reflection*
00096         get_reflection() throw(());
00097 
00098         virtual const IT_Reflect::Reflection*
00099         get_reflection() const throw(());
00100 
00101       private:
00102         typedef BuiltInType ThisType; // needed for DYNAMIC_CAST macro
00103         T       m_data;
00104     };
00105 
00106 
00107     template <class T, const QName* TYPE>
00108     BuiltInType<T,TYPE>::BuiltInType() 
00109     {
00110         // Complete.
00111     }
00112 
00113     template <class T, const QName* TYPE>
00114     BuiltInType<T,TYPE>::BuiltInType(
00115         const BuiltInType<T,TYPE>& other
00116     ) : m_data(other.m_data)
00117     {
00118         // Complete.
00119     }
00120 
00121     template <class T, const QName* Q>
00122     BuiltInType<T,Q>::BuiltInType(
00123         const T& data
00124     ) : m_data(data)
00125     {
00126         // Complete.
00127     }
00128 
00129     template <class T, const QName* TYPE>
00130     BuiltInType<T,TYPE>::~BuiltInType()
00131     {
00132         // Complete.
00133     }
00134 
00135     template <class T, const QName* TYPE>
00136     BuiltInType<T,TYPE>&
00137     BuiltInType<T,TYPE>::operator=(
00138         const BuiltInType<T,TYPE>& other
00139     ) 
00140     {
00141         set(other.get());
00142         return *this;
00143     }
00144 
00145     template <class T, const QName* TYPE>
00146     AnyType&
00147     BuiltInType<T,TYPE>::copy(
00148         const AnyType& rhs
00149     ) 
00150     {
00151         const ThisType& other = IT_DYNAMIC_CAST(const ThisType&, rhs);
00152         *this = other;
00153         return *this;
00154     }
00155 
00156     template <class T, const QName* TYPE>
00157     AnyType::Kind
00158     BuiltInType<T,TYPE>::get_kind() const
00159     {
00160         return BUILT_IN;
00161     }
00162 
00163     template <class T, const QName* TYPE>
00164     const QName&
00165     BuiltInType<T,TYPE>::get_type() const
00166     {
00167         return *TYPE;
00168     }
00169 
00170     template <class T, const QName* TYPE>
00171     void
00172     BuiltInType<T,TYPE>::write(
00173         const QName& element_name,
00174         ComplexTypeWriter& writer
00175     ) const throw((SerializationException)) 
00176     {
00177         writer.write(element_name, m_data);
00178     }
00179 
00180     template <class T, const QName* TYPE>
00181     void
00182     BuiltInType<T,TYPE>::read(
00183         const QName& name,
00184         ComplexTypeReader& reader
00185     ) throw((DeserializationException))
00186     {
00187         reader.read(name, m_data);
00188     }
00189 
00190     template <class T, const QName* TYPE>    
00191     T&
00192     BuiltInType<T,TYPE>::get() 
00193     {
00194         return m_data;
00195     }
00196 
00197     template <class T, const QName* TYPE>    
00198     const T&
00199     BuiltInType<T,TYPE>::get() const 
00200     {
00201         return m_data;
00202     }
00203 
00204     template <class T, const QName* TYPE>
00205     void
00206     BuiltInType<T,TYPE>::set(
00207         const T& data
00208     )
00209     {
00210         m_data=data;
00211     }
00212 
00213     template <class T, const QName* TYPE>
00214     IT_Reflect::Reflection*
00215     BuiltInType<T,TYPE>::get_reflection() throw(())
00216     {
00217         IT_Reflect::ValueRef<T>* val_ref = new IT_Reflect::ValueRef<T>(m_data);
00218         return val_ref;
00219     }
00220     
00221     template <class T, const QName* TYPE>
00222     const IT_Reflect::Reflection*
00223     BuiltInType<T,TYPE>::get_reflection() const throw(())
00224     {
00225         const IT_Reflect::ValueRef<T>* val_ref = new IT_Reflect::ValueRef<T>(m_data);
00226         return val_ref;
00227     }
00228 
00232     typedef BuiltInType<IT_Bus::Boolean, &IT_W3CConstants::NT_SCHEMA_BOOLEAN>
00233         BooleanHolder;
00234 
00238     typedef BuiltInType<IT_Bus::Byte, &IT_W3CConstants::NT_SCHEMA_BYTE>
00239         ByteHolder;
00240 
00244     typedef BuiltInType<IT_Bus::Short, &IT_W3CConstants::NT_SCHEMA_SHORT>
00245         ShortHolder;
00246 
00250     typedef BuiltInType<IT_Bus::Int, &IT_W3CConstants::NT_SCHEMA_INT>
00251         IntHolder;
00252 
00256     typedef BuiltInType<IT_Bus::Long, &IT_W3CConstants::NT_SCHEMA_LONG>
00257         LongHolder;
00258 
00264     typedef BuiltInType<IT_Bus::String, &IT_W3CConstants::NT_SCHEMA_STRING>
00265         StringHolder;
00266 
00270     typedef BuiltInType<IT_Bus::Float, &IT_W3CConstants::NT_SCHEMA_FLOAT>
00271         FloatHolder;
00272 
00276     typedef BuiltInType<IT_Bus::Double, &IT_W3CConstants::NT_SCHEMA_DOUBLE>
00277         DoubleHolder;
00278 
00282     typedef BuiltInType<IT_Bus::UByte, &IT_W3CConstants::NT_SCHEMA_UBYTE>
00283         UByteHolder;
00284 
00288     typedef BuiltInType<IT_Bus::UShort, &IT_W3CConstants::NT_SCHEMA_USHORT>
00289         UShortHolder;
00290 
00294     typedef BuiltInType<IT_Bus::UInt, &IT_W3CConstants::NT_SCHEMA_UINT>
00295         UIntHolder;
00296 
00300     typedef BuiltInType<IT_Bus::ULong, &IT_W3CConstants::NT_SCHEMA_ULONG>
00301         ULongHolder;
00302 
00306     typedef BuiltInType<IT_Bus::Decimal, &IT_W3CConstants::NT_SCHEMA_DECIMAL>
00307         DecimalHolder;
00308 
00312     typedef BuiltInType<IT_Bus::QName, &IT_W3CConstants::NT_SCHEMA_QNAME>
00313         QNameHolder;
00314 
00318     typedef BuiltInType<IT_Bus::DateTime, &IT_W3CConstants::NT_SCHEMA_DATETIME>
00319         DateTimeHolder;
00320 
00324     typedef BuiltInType<IT_Bus::HexBinary, &IT_W3CConstants::NT_SCHEMA_HBIN>
00325         HexBinaryHolder;
00326 
00330     typedef BuiltInType<IT_Bus::Base64Binary, &IT_W3CConstants::NT_SCHEMA_BASE64>
00331         Base64BinaryHolder;
00332 }
00333 
00334 #endif  

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