BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
base64< _E, _Tr > Class Template Reference

#include <base64.h>

Classes

struct  crlf
 
struct  crlfsp
 
struct  noline
 
struct  three2four
 

Public Types

typedef unsigned char byte_t
 
typedef _E char_type
 
typedef _Tr traits_type
 

Public Member Functions

template<class _II , class _OI , class _State , class _Endline >
_II put (_II _First, _II _Last, _OI _To, _State &_St, _Endline _Endl) const
 
template<class _II , class _OI , class _State >
_II get (_II _First, _II _Last, _OI _To, _State &_St) const
 

Protected Member Functions

int _getCharType (int _Ch) const
 

Detailed Description

template<class _E = char, class _Tr = std::char_traits<_E>>
class base64< _E, _Tr >

Definition at line 42 of file base64.h.

Member Typedef Documentation

◆ byte_t

template<class _E = char, class _Tr = std::char_traits<_E>>
typedef unsigned char base64< _E, _Tr >::byte_t

Definition at line 46 of file base64.h.

◆ char_type

template<class _E = char, class _Tr = std::char_traits<_E>>
typedef _E base64< _E, _Tr >::char_type

Definition at line 47 of file base64.h.

◆ traits_type

template<class _E = char, class _Tr = std::char_traits<_E>>
typedef _Tr base64< _E, _Tr >::traits_type

Definition at line 48 of file base64.h.

Member Function Documentation

◆ _getCharType()

template<class _E = char, class _Tr = std::char_traits<_E>>
int base64< _E, _Tr >::_getCharType ( int  _Ch) const
inlineprotected

Definition at line 352 of file base64.h.

353 {
354 if(_base64Chars[62] == _Ch)
355 return 62;
356
357 if(_base64Chars[63] == _Ch)
358 return 63;
359
360 if((_base64Chars[0] <= _Ch) && (_base64Chars[25] >= _Ch))
361 return _Ch - _base64Chars[0];
362
363 if((_base64Chars[26] <= _Ch) && (_base64Chars[51] >= _Ch))
364 return _Ch - _base64Chars[26] + 26;
365
366 if((_base64Chars[52] <= _Ch) && (_base64Chars[61] >= _Ch))
367 return _Ch - _base64Chars[52] + 52;
368
369 if(_Ch == _Tr::to_int_type('='))
370 return _EQUAL_CHAR;
371
372 return _UNKNOWN_CHAR;
373 }
#define _EQUAL_CHAR
Definition: base64.h:32
#define _UNKNOWN_CHAR
Definition: base64.h:33

Referenced by base64< _E, _Tr >::get().

◆ get()

template<class _E = char, class _Tr = std::char_traits<_E>>
template<class _II , class _OI , class _State >
_II base64< _E, _Tr >::get ( _II  _First,
_II  _Last,
_OI  _To,
_State &  _St 
) const
inline

Definition at line 215 of file base64.h.

216 {
217 three2four _3to4;
218 int _Char;
219
220 while(_First != _Last)
221 {
222
223 // Take octet
224 _3to4.zero();
225
226 // -- 0 --
227 // Search next valid char...
228 while((_Char = _getCharType(*_First)) < 0 && _Char == _UNKNOWN_CHAR)
229 {
230 if(++_First == _Last)
231 {
232 _St |= _IOS_FAILBIT|_IOS_EOFBIT; return _First; // unexpected EOF
233 }
234 }
235
236 if(_Char == _EQUAL_CHAR){
237 // Error! First character in octet can't be '='
238 _St |= _IOS_FAILBIT;
239 return _First;
240 }
241 else
242 _3to4.b64_0(_Char);
243
244
245 // -- 1 --
246 // Search next valid char...
247 while(++_First != _Last)
248 if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
249 break;
250
251 if(_First == _Last) {
252 _St |= _IOS_FAILBIT|_IOS_EOFBIT; // unexpected EOF
253 return _First;
254 }
255
256 if(_Char == _EQUAL_CHAR){
257 // Error! Second character in octet can't be '='
258 _St |= _IOS_FAILBIT;
259 return _First;
260 }
261 else
262 _3to4.b64_1(_Char);
263
264
265 // -- 2 --
266 // Search next valid char...
267 while(++_First != _Last)
268 if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
269 break;
270
271 if(_First == _Last) {
272 // Error! Unexpected EOF. Must be '=' or base64 character
274 return _First;
275 }
276
277 if(_Char == _EQUAL_CHAR){
278 // OK!
279 _3to4.b64_2(0);
280 _3to4.b64_3(0);
281
282 // chek for EOF
283 if(++_First == _Last)
284 {
285 // Error! Unexpected EOF. Must be '='. Ignore it.
286 //_St |= _IOS_BADBIT|_IOS_EOFBIT;
287 _St |= _IOS_EOFBIT;
288 }
289 else
290 if(_getCharType(*_First) != _EQUAL_CHAR)
291 {
292 // Error! Must be '='. Ignore it.
293 //_St |= _IOS_BADBIT;
294 }
295 else
296 ++_First; // Skip '='
297
298 // write 1 byte to output
299 *_To = (byte_t) _3to4.get_0();
300 return _First;
301 }
302 else
303 _3to4.b64_2(_Char);
304
305
306 // -- 3 --
307 // Search next valid char...
308 while(++_First != _Last)
309 if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR)
310 break;
311
312 if(_First == _Last) {
313 // Unexpected EOF. It's error. But ignore it.
314 //_St |= _IOS_FAILBIT|_IOS_EOFBIT;
315 _St |= _IOS_EOFBIT;
316
317 return _First;
318 }
319
320 if(_Char == _EQUAL_CHAR)
321 {
322 // OK!
323 _3to4.b64_3(0);
324
325 // write to output 2 bytes
326 *_To = (byte_t) _3to4.get_0();
327 *_To = (byte_t) _3to4.get_1();
328
329 ++_First; // set position to next character
330
331 return _First;
332 }
333 else
334 _3to4.b64_3(_Char);
335
336
337 // write to output 3 bytes
338 *_To = (byte_t) _3to4.get_0();
339 *_To = (byte_t) _3to4.get_1();
340 *_To = (byte_t) _3to4.get_2();
341
342 ++_First;
343
344
345 } // while(_First != _Last)
346
347 return (_First);
348 }
#define _IOS_EOFBIT
Definition: base64.h:36
#define _IOS_FAILBIT
Definition: base64.h:35
unsigned char byte_t
Definition: base64.h:46
int _getCharType(int _Ch) const
Definition: base64.h:352

Referenced by XmlRpc::XmlRpcValue::binaryFromXml().

◆ put()

template<class _E = char, class _Tr = std::char_traits<_E>>
template<class _II , class _OI , class _State , class _Endline >
_II base64< _E, _Tr >::put ( _II  _First,
_II  _Last,
_OI  _To,
_State &  _St,
_Endline  _Endl 
) const
inline

Definition at line 155 of file base64.h.

156 {
157 three2four _3to4;
158 int line_octets = 0;
159
160 while(_First != _Last)
161 {
162 _3to4.zero();
163
164 // ���� �� 3 �������
165 _3to4.set_0(*_First);
166 _First++;
167
168 if(_First == _Last)
169 {
170 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
171 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
172 *_To = _Tr::to_char_type('='); ++_To;
173 *_To = _Tr::to_char_type('='); ++_To;
174 goto __end;
175 }
176
177 _3to4.set_1(*_First);
178 _First++;
179
180 if(_First == _Last)
181 {
182 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
183 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
184 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To;
185 *_To = _Tr::to_char_type('='); ++_To;
186 goto __end;
187 }
188
189 _3to4.set_2(*_First);
190 _First++;
191
192 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To;
193 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To;
194 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To;
195 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_3()]); ++_To;
196
197 if(line_octets == 17) // base64 ��������� ����� ������ �� ����� 72 ��������
198 {
199 //_To = _Endl(_To);
200 *_To = '\n'; ++_To;
201 line_octets = 0;
202 }
203 else
204 ++line_octets;
205 }
206
207 __end: ;
208
209 return (_First);
210
211 }

Referenced by XmlRpc::XmlRpcValue::binaryToXml(), and XmlRpc::XmlRpcValue::write().


The documentation for this class was generated from the following file: