it_bus/min_max_list_t.h

00001 #ifndef _IT_BUS_MIN_MAX_LIST_T_H_
00002 #define _IT_BUS_MIN_MAX_LIST_T_H_
00003 
00004 // @Copyright 2003 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #include <it_dsa/vector.h>
00008 #include <it_bus/complex_type_reader.h>
00009 #include <it_bus/complex_type_writer.h>
00010 #include <it_bus/deserialization_exception.h>
00011 
00012 namespace IT_Bus
00013 {
00014     template<typename T>
00015     class MinMaxListT : public IT_Vector<T>
00016     {
00017       public:
00018         MinMaxListT(
00019             const size_t min_occurs,
00020             const size_t max_occurs,
00021             const size_t list_size
00022         ) :
00023             m_min_occurs(min_occurs),
00024             m_max_occurs(max_occurs)
00025         {
00026             if (list_size > 0)
00027             {
00028                 this->insert(this->end(), list_size, T());
00029             }
00030         }
00031 
00032         MinMaxListT(
00033             const T & elem,
00034             const size_t min_occurs,
00035             const size_t max_occurs,
00036             const size_t list_size
00037         ) :
00038             m_min_occurs(min_occurs),
00039             m_max_occurs(max_occurs)
00040         {
00041             if (list_size > 0)
00042             {
00043                 this->insert(this->end(), list_size, elem);
00044             }
00045         }
00046 
00047         size_t
00048         get_min_occurs() const
00049         {
00050             return m_min_occurs;
00051         }
00052 
00053         void
00054         set_min_occurs(
00055             size_t min_occurs
00056         )
00057         {
00058             m_min_occurs = min_occurs;
00059         }
00060 
00061         size_t
00062         get_max_occurs() const
00063         {
00064             return m_max_occurs;
00065         }
00066 
00067         void
00068         set_max_occurs(
00069             size_t max_occurs
00070         )
00071         {
00072             m_max_occurs = max_occurs;
00073         }
00074 
00075         void
00076         set_size(
00077             size_t new_size
00078         )
00079         {
00080             if (m_max_occurs != UINT_MAX && new_size > m_max_occurs)
00081             {
00082                 throw DeserializationException(
00083                     "Invalid size specified for MinMaxListT::set_size().  Value is greater than maxOccurs."
00084                 );
00085             }
00086 
00087             if (new_size < m_min_occurs)
00088             {
00089                 throw DeserializationException(
00090                     "Invalid size specified for MinMaxListT::set_size().  Value is less than minOccurs."
00091                 );
00092             }
00093 
00094             while (this->size() > new_size)
00095             {
00096                 this->pop_back();
00097             }
00098 
00099             
00100             if (this->size() < new_size)
00101             {
00102                 this->insert(this->end(), new_size - this->size(), T());
00103             }
00104         }
00105 
00106         size_t
00107         get_size() const
00108         {
00109             return this->size();
00110         }
00111 
00115         void
00116         read_list_member(
00117             size_t pos,
00118             const QName & member_name,
00119             ComplexTypeReader & reader
00120         ) IT_THROW_DECL((DeserializationException))
00121         {
00122             if (m_max_occurs != UINT_MAX && pos >= m_max_occurs)
00123             {
00124                 throw DeserializationException(
00125                     "maxOccurs limit hit when deserializing array."
00126                 );
00127             }
00128 
00129             if (pos >= this->size())
00130             {
00131                 this->insert(this->end(), pos  + 1 - this->size(), T());
00132             }
00133         
00134             reader.read(member_name, this->operator[](pos));
00135         }
00136 
00137 
00141         void
00142         write_list_member(
00143             size_t pos,
00144             const QName & member_name,
00145             ComplexTypeWriter & writer
00146         ) const IT_THROW_DECL((SerializationException))
00147         {
00148             writer.write(member_name, this->operator[](pos));
00149         }
00150 
00151         MinMaxListT&
00152         operator=(
00153             const IT_Vector<T> & rhs
00154         )
00155         {
00156             IT_Vector<T>::operator=(rhs);
00157             return *this;
00158         }
00159 
00160         MinMaxListT&
00161         operator=(
00162             const MinMaxListT & rhs
00163         )
00164         {
00165             m_min_occurs = rhs.m_min_occurs;
00166             m_max_occurs = rhs.m_max_occurs;
00167 
00168             *this = IT_DYNAMIC_CAST(const IT_Vector<T>&, rhs);
00169             return *this;
00170         }
00171 
00172       private:
00173         size_t m_min_occurs;
00174         size_t m_max_occurs;
00175     };
00176 }
00177 
00178 #endif  

Generated on Thu Sep 7 11:38:55 2006 for Artix by  doxygen 1.4.7