Main Page Class Hierarchy Alphabetical List Compound List Examples

code.h
1/***************************************************************************
2 copyright : (C) 2002-2008 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: code.h,v 1.5 2008-10-07 11:06:26 tat Exp $
6 ***************************************************************************/
7#ifndef _MIMETIC_CODEC_CODE_H_
8#define _MIMETIC_CODEC_CODE_H_
9#include <mimetic/codec/codec_base.h>
10#include <mimetic/codec/codec_chain.h>
11#include <mimetic/codec/other_codecs.h>
12#include <mimetic/utils.h>
13
14 namespace mimetic
15{
16
17
18
19 template<typename InIt, typename OutIt, typename Codec>
20 void code(InIt beg, InIt end, Codec& cc, OutIt out)
21{
22 typedef typename Codec::codec_type codec_type;
23 code(beg, end, cc, out, codec_type());
24}
25
26// code func for buffered codecs
27 template<typename InIt, typename OutIt, typename Codec>
28 void code(InIt beg, InIt end, Codec& cc, OutIt out,const buffered_codec_type_tag&)
29{
30 for(; beg != end; ++beg)
31 cc.process(*beg, out);
32 cc.flush(out);
33}
34
35// code func for unbuffered codecs
36 template<typename InIt, typename OutIt, typename Codec>
37 void code(InIt beg, InIt end,Codec& codec,OutIt out,const unbuffered_codec_type_tag&)
38{
39 for(; beg != end; ++beg)
40 codec.process(*beg, out);
41}
42
43// code func for chained codecs
44 template<typename InIt, typename OutIt, typename Codec, typename Next>
45 void code(InIt beg, InIt end, const codec_chain<Codec,Next>& cc, OutIt out)
46{
47 typedef codec_chain<Codec,Next> Node1;
48 typedef codec_chain< oiterator_wrapper<OutIt> >
49 TailNode;
50 typedef typename push_back_node<Node1, TailNode>::node_type
51 codec_chain_type;
52
53 oiterator_wrapper<OutIt> oiw(out);
54 codec_chain_type chain = build_push_back_node<Node1,TailNode>(cc,TailNode(oiw));
55
56 for(; beg != end; ++beg)
57 chain.process(*beg);
58 chain.flush();
59}
60
61/// Encodes (beg, end] using \p cc codec
62/*!
63 Encodes (beg, end] using \p cc codec and write any
64 output characters to the output iterator \p out.
65
66 \p cc can be a simple codec:
67 \code
68 Base64::Encoder b64;
69 code(beg, end, b64, out);
70 \endcode
71 or a chain of codecs:
72 \code
73 Base64::Encoder b64;
74 ToUpperCase tuc;
75 code(beg, end, tuc | b64, out);
76 \endcode
77 */
78 template<typename InIt, typename OutIt, typename Codec>
79 void encode(InIt beg, InIt end, Codec& cc, OutIt out)
80{
81 code(beg, end, cc, out);
82}
83
84/// decodes (beg, end] using \e cc codec and write any
85/*!
86 decodes (beg, end] using \e cc codec and write any
87 output characters to the output iterator \e out
88 */
89 template<typename InIt, typename OutIt, typename Codec>
90 void decode(InIt beg, InIt end, Codec& cc, OutIt out)
91{
92 code(beg, end, cc, out);
93}
94
95
96 template<typename InIt, typename OutIt, typename Codec, typename Next>
97 void encode(InIt beg, InIt end, const codec_chain<Codec,Next>& cc, OutIt out)
98{
99 code(beg,end,cc,out);
100}
101
102 template<typename InIt, typename OutIt, typename Codec, typename Next>
103 void decode(InIt beg, InIt end, const codec_chain<Codec,Next>& cc, OutIt out)
104{
105 code(beg,end,cc,out);
106}
107
108}
109
110
111
112#endif
113
114
115
116
117
118
mimetic
Definition body.h:18
mimetic::decode
void decode(InIt beg, InIt end, Codec &cc, OutIt out)
decodes (beg, end] using cc codec and write any
Definition code.h:90
mimetic::encode
void encode(InIt beg, InIt end, Codec &cc, OutIt out)
Encodes (beg, end] using cc codec.
Definition code.h:79
mimetic::codec_chain
Defines a chain of codecs.
Definition codec_chain.h:178
mimetic::codec
Codecs base class.
Definition codec_base.h:24