basic_string.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__BASIC_STRING_HPP_ )
00038 #define _OESS_1__TLV__BASIC_STRING_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/io/h/bin_data_size.hpp>
00047 
00048 #include <oess_1/tlv/h/base.hpp>
00049 #include <oess_1/tlv/h/default_processors.hpp>
00050 
00051 namespace oess_1
00052 {
00053 
00054 namespace tlv
00055 {
00056 
00057 //
00058 // basic_string_tlv_t
00059 //
00060 
00062 
00070 template< class Tag_type,
00071   class Char = oess_1::char_t,
00072   class Tag_processor = default_tag_processor_t< Tag_type >,
00073   class Length_processor = default_length_processor_t< Tag_type > >
00074 class basic_string_tlv_t :
00075   public tlv_base_t
00076 {
00077   public :
00079     typedef std::basic_string< Char > string_type_t;
00080 
00082     typedef string_type_t value_type_t;
00083 
00086     typedef basic_string_tlv_t< Tag_type, Char,
00087         Tag_processor, Length_processor >
00088       self_t;
00089 
00090   private :
00092     Tag_processor m_tag;
00093 
00095     Length_processor  m_length;
00096 
00098     string_type_t m_value;
00099 
00100   public :
00102     basic_string_tlv_t( Tag_type id )
00103       :
00104         m_tag( id )
00105     {
00106     }
00107 
00109     basic_string_tlv_t(
00110       Tag_type id,
00111       const string_type_t & value )
00112       :
00113         m_tag( id ),
00114         m_value( value )
00115     {
00116     }
00117 
00119     basic_string_tlv_t(
00120       const self_t & o )
00121       :
00122         m_tag( o.m_tag ),
00123         m_length( o.m_length ),
00124         m_value( o.m_value )
00125     {
00126     }
00127 
00128     virtual ~basic_string_tlv_t()
00129     {
00130     }
00131 
00133     self_t &
00134     operator=( const self_t & o )
00135     {
00136       if( &o != this )
00137       {
00138         m_tag = o.m_tag;
00139         m_length = o.m_length;
00140         m_value = o.m_value;
00141       }
00142       return *this;
00143     }
00144 
00146     const string_type_t &
00147     query_value() const
00148     {
00149       return m_value;
00150     }
00151 
00153     void
00154     set_value(
00156       const string_type_t & value )
00157     {
00158       m_value = value;
00159     }
00160 
00162     virtual default_tag_type_t
00163     tlv_tag() const
00164     {
00165       return m_tag.query_tag();
00166     }
00167 
00171     virtual size_t
00172     tlv_size() const
00173     {
00174       size_t length = m_value.length() *
00175         oess_1::io::bin_data_size_t< Char >::image_size;
00176       length += m_length.tlv_length_size( length );
00177       length += m_tag.tlv_tag_size();
00178 
00179       return length;
00180     }
00181 
00183 
00188     virtual void
00189     tlv_unpack(
00192       oess_1::io::ibinstream_t & s,
00194       default_tag_type_t )
00195     {
00196       size_t length;
00197       m_length.tlv_unpack_length( s, length );
00198       if( length )
00199       {
00200         auto_ptr_3::vect_ptr_t< Char > tmp(
00201           new Char[ length ], length );
00202         s.read( tmp.query(), length );
00203 
00204         m_value.assign( tmp.query(), length );
00205       }
00206       else
00207         // В VC++ 6.0 в классе basic_string нет метода clear!
00208         m_value.erase( m_value.begin(), m_value.end() );
00209     }
00210 
00212 
00217     virtual void
00218     tlv_pack(
00221       oess_1::io::obinstream_t & s ) const
00222     {
00223       size_t length = m_value.length() *
00224         oess_1::io::bin_data_size_t< Char >::image_size;
00225 
00226       m_tag.tlv_pack_tag( s );
00227       m_length.tlv_pack_length( s, length );
00228       if( length )
00229         s.write( m_value.data(), m_value.length() );
00230     }
00231 };
00232 
00233 } /* namespace tlv */
00234 
00235 } /* namespace oess_1 */
00236 
00237 #endif
00238 

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