scalar.hpp

См. документацию.
00001 /*
00002 
00003 Copyright (c) 2002-2005, Yauheni Akhotnikau
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009 - Redistributions of source code must retain the above copyright notice, this
00010 list of conditions and the following disclaimer.
00011 
00012 - Redistributions in binary form must reproduce the above copyright notice, this
00013 list of conditions and the following disclaimer in the documentation and/or
00014 other materials provided with the distribution.
00015 
00016 - The name of the author may not be used to endorse or promote products derived
00017 from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00020 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00021 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00022 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00024 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00027 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00028 OF SUCH DAMAGE.
00029 
00030 */
00031 
00037 #if !defined( _OESS_1__TLV__SCALAR_HPP_ )
00038 #define _OESS_1__TLV__SCALAR_HPP_
00039 
00040 #include <oess_1/tlv/h/declspec.hpp>
00041 
00042 #include <string>
00043 
00044 #include <auto_ptr_3/h/vect_ptr.hpp>
00045 
00046 #include <oess_1/defs/h/ex.hpp>
00047 
00048 #include <oess_1/io/h/bin_data_size.hpp>
00049 #include <oess_1/io/h/subbinstream.hpp>
00050 
00051 #include <oess_1/tlv/h/base.hpp>
00052 #include <oess_1/tlv/h/default_processors.hpp>
00053 #include <oess_1/tlv/h/errno.hpp>
00054 
00055 namespace oess_1
00056 {
00057 
00058 namespace tlv
00059 {
00060 
00061 //
00062 // scalar_tlv_t
00063 //
00064 
00066 
00070 template< class Tag_type,
00071   class Scalar,
00072   class Tag_processor = default_tag_processor_t< Tag_type >,
00073   class Length_processor = default_length_processor_t< Tag_type > >
00074 class scalar_tlv_t :
00075   public tlv_base_t
00076 {
00077   public :
00079     typedef Scalar value_type_t;
00080 
00083     typedef scalar_tlv_t< Tag_type, Scalar,
00084         Tag_processor, Length_processor >
00085       self_t;
00086 
00087   private :
00089     Tag_processor m_tag;
00090 
00092     Length_processor  m_length;
00093 
00095     Scalar  m_value;
00096 
00097   public :
00099     scalar_tlv_t( Tag_type id )
00100       :
00101         m_tag( id ),
00102         m_value()
00103     {
00104     }
00105 
00107     scalar_tlv_t(
00108       Tag_type id,
00109       const Scalar & value )
00110       :
00111         m_tag( id ),
00112         m_value( value )
00113     {
00114     }
00115 
00117     scalar_tlv_t(
00118       const self_t & o )
00119       :
00120         m_tag( o.m_tag ),
00121         m_length( o.m_length ),
00122         m_value( o.m_value )
00123     {
00124     }
00125 
00126     virtual ~scalar_tlv_t()
00127     {
00128     }
00129 
00131     self_t &
00132     operator=( const self_t & o )
00133     {
00134       if( &o != this )
00135       {
00136         m_tag = o.m_tag;
00137         m_length = o.m_length;
00138         m_value = o.m_value;
00139       }
00140       return *this;
00141     }
00142 
00144     const Scalar &
00145     query_value() const
00146     {
00147       return m_value;
00148     }
00149 
00151     void
00152     set_value(
00154       const Scalar & value )
00155     {
00156       m_value = value;
00157     }
00158 
00160     virtual default_tag_type_t
00161     tlv_tag() const
00162     {
00163       return m_tag.query_tag();
00164     }
00165 
00169     virtual size_t
00170     tlv_size() const
00171     {
00172       size_t length = oess_1::io::bin_data_size_t<
00173         Scalar >::image_size;
00174       length += m_length.tlv_length_size( length );
00175       length += m_tag.tlv_tag_size();
00176 
00177       return length;
00178     }
00179 
00181 
00189     virtual void
00190     tlv_unpack(
00193       oess_1::io::ibinstream_t & s,
00195       default_tag_type_t )
00196     {
00197       size_t length;
00198       m_length.tlv_unpack_length( s,  length );
00199       if( length )
00200       {
00201         oess_1::io::isubbinstream_t substream( s, length );
00202         substream >> m_value;
00203       }
00204       else
00205       {
00206         OESS_THROW_PHYSIC( err::c_zero_length,
00207           "awaiting length: " << oess_1::io::bin_data_size_t<
00208             Scalar >::image_size )
00209       }
00210     }
00211 
00213 
00216     virtual void
00217     tlv_pack(
00220       oess_1::io::obinstream_t & s ) const
00221     {
00222       size_t length =
00223         oess_1::io::bin_data_size_t< Scalar >::image_size;
00224 
00225       m_tag.tlv_pack_tag( s );
00226       m_length.tlv_pack_length( s, length );
00227       s << m_value;
00228     }
00229 };
00230 
00231 } /* namespace tlv */
00232 
00233 } /* namespace oess_1 */
00234 
00235 #endif
00236 

Документация по ObjESSty. Последние изменения: Fri Oct 13 18:35:36 2006. Создано системой  doxygen 1.4.7
Hosted by uCoz