1 /*
2
3 Copyright (c) 2002-2008, Yauheni Akhotnikau
4 Copyright (c) 2008-2013, The SObjectizer Project
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 - Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12
13 - Redistributions in binary form must reproduce the above copyright notice, this
14 list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16
17 - The name of the author may not be used to endorse or promote products derived
18 from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
25 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29 OF SUCH DAMAGE.
30
31 */
32
33 /*!
34 \file oess_2/tlv/h/default_processors.hpp
35 \brief ���������� ����������
36 %oess_2::tlv::tag_processor_t,
37 %oess_2::tlv::length_processor_t ��� ����������
38 �������.
39 */
40
41 #if !defined( _OESS_2__TLV__DEFAULT_PROCESSORS_HPP_ )
42 #define _OESS_2__TLV__DEFAULT_PROCESSORS_HPP_
43
44 #include <oess_2/tlv/h/declspec.hpp>
45
46 #include <oess_2/io/h/bin_data_size.hpp>
47
48 #include <oess_2/tlv/h/base.hpp>
49
50 namespace oess_2
51 {
52
53 namespace tlv
54 {
55
56 //
57 // default_tag_processor_t
58 //
59
60 //! ���������� ���������� tag_processor_t.
61 /*!
62 ������������ ��� ������, ����� ���� Tag ������������
63 � ���� ���������� �������������� ��������.
64 */
65 template< class Tag_type = default_tag_type_t >
66 class default_tag_processor_t :
67 public tag_processor_t
68 {
69 public :
70 //! ������� ��� default_tag_processor_t< Tag_type >.
71 typedef default_tag_processor_t< Tag_type > self_t;
72
73 private :
74 //! �������� ���� Tag.
75 Tag_type m_id;
76
77 public :
78 //! ����������� ��-���������.
default_tag_processor_t()79 default_tag_processor_t()
80 :
81 m_id()
82 {
83 }
84
85 //! ��������� ������ � ���������� ��������� Tag.
default_tag_processor_t(Tag_type id)86 default_tag_processor_t( Tag_type id )
87 :
88 m_id( id )
89 {
90 }
~default_tag_processor_t()91 virtual ~default_tag_processor_t()
92 {
93 }
94
95 //! ���������� ������ ��������� ������������� Tag_type.
96 virtual size_t
tlv_tag_size() const97 tlv_tag_size() const
98 {
99 return oess_2::io::bin_data_size_t< Tag_type >::image_size;
100 }
101
102 //! ��������� ��������� ������ Tag_type �� \a s.
103 /*!
104 ��������� �������� ����������� ������
105 ������� default_tag_processor_t.
106 */
107 virtual void
tlv_unpack_tag(oess_2::io::istream_t & s)108 tlv_unpack_tag(
109 //! �����, � ������� ������� �������� �����
110 //! �������������� ������ ���� Tag.
111 oess_2::io::istream_t & s )
112 {
113 s >> m_id;
114 }
115
116 //! ���������� ��������� ������ Tag_type � \a s.
117 /*!
118 ������������ ������� �������� �������
119 default_tag_type_t.
120 */
121 virtual void
tlv_pack_tag(oess_2::io::ostream_t & s) const122 tlv_pack_tag(
123 //! �����, � ������� ������� �������� �����
124 //! �������������� ������ ���� Tag.
125 oess_2::io::ostream_t & s ) const
126 {
127 s << m_id;
128 }
129
130 //! �������� ������� ��������.
131 virtual default_tag_type_t
query_tag() const132 query_tag() const
133 {
134 return (default_tag_type_t) m_id;
135 }
136
137 //! ���������� ������� ��������.
138 virtual void
set_tag(const default_tag_type_t & value)139 set_tag( const default_tag_type_t & value )
140 {
141 m_id = value;
142 }
143 };
144
145 //! �������� ����� tlv_unpack_tag � \a o.
146 inline oess_2::io::istream_t &
operator >>(oess_2::io::istream_t & s,tag_processor_t & o)147 operator>>(
148 //! �����, � ������� ������� �������� �����
149 //! �������������� ������ ���� Tag.
150 oess_2::io::istream_t & s,
151 //! ������ ��� ����������.
152 tag_processor_t & o )
153 {
154 o.tlv_unpack_tag( s );
155 return s;
156 }
157
158 //! �������� ����� tlv_pack_tag � \a o.
159 inline oess_2::io::ostream_t &
operator <<(oess_2::io::ostream_t & s,const tag_processor_t & o)160 operator<<(
161 //! �����, � ������� ������� �������� �����
162 //! �������������� ������ ���� Tag.
163 oess_2::io::ostream_t & s,
164 //! ������ ��� ������.
165 const tag_processor_t & o )
166 {
167 o.tlv_pack_tag( s );
168 return s;
169 }
170
171 //
172 // default_length_processor_t
173 //
174
175 //! ���������� ���������� length_processor_t.
176 /*!
177 ������������ ��� ������, ����� ���� Length ������������
178 � ���� ���������� �������������� ��������.
179 */
180 template< class Length_type >
181 class default_length_processor_t :
182 public length_processor_t
183 {
184 public :
default_length_processor_t()185 default_length_processor_t()
186 {
187 }
188
~default_length_processor_t()189 virtual ~default_length_processor_t()
190 {
191 }
192
193 //! ���������� ������ ��������� �������������
194 //! Length_type
195 virtual size_t
tlv_length_size(size_t value_length) const196 tlv_length_size(
197 //! ����� ���� TLV.
198 size_t value_length ) const
199 {
200 return oess_2::io::bin_data_size_t< Length_type >::image_size;
201 }
202
203 //! ��������� ���������� ������ Length_type �� \a s.
204 virtual void
tlv_unpack_length(oess_2::io::istream_t & s,size_t & value_length)205 tlv_unpack_length(
206 //! �����, � ������� ������� �������� �����
207 //! �������������� ������ ���� Length.
208 oess_2::io::istream_t & s,
209 //! �������� �������� ���� Length
210 size_t & value_length )
211 {
212 Length_type l;
213 s >> l;
214 value_length = l;
215 }
216
217 //! ���������� ��������� ������ Length � \a s.
218 virtual void
tlv_pack_length(oess_2::io::ostream_t & s,size_t value_length) const219 tlv_pack_length(
220 //! �����, � ������� ������� �������� �����
221 //! �������������� ������ ���� Length.
222 oess_2::io::ostream_t & s,
223 //! �������� ���� Length.
224 size_t value_length ) const
225 {
226 Length_type l = value_length;
227 s << l;
228 }
229 };
230
231 } /* namespace tlv */
232
233 } /* namespace oess_2 */
234
235 #endif
236
237