00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_CODEC_CODE_H_
00017 #define _MIMETIC_CODEC_CODE_H_
00018 #include <mimetic/codec/codec_base.h>
00019 #include <mimetic/codec/codec_chain.h>
00020 #include <mimetic/codec/other_codecs.h>
00021 #include <mimetic/utils.h>
00022
00023 namespace mimetic
00024 {
00025
00026
00027
00028 template<typename InIt, typename OutIt, typename Codec>
00029 void code(InIt beg, InIt end, Codec& cc, OutIt out)
00030 {
00031 typedef typename Codec::codec_type codec_type;
00032 code(beg, end, cc, out, codec_type());
00033 }
00034
00035
00036 template<typename InIt, typename OutIt, typename Codec>
00037 void code(InIt beg, InIt end, Codec& cc, OutIt out,const buffered_codec_type_tag&)
00038 {
00039 for(; beg != end; ++beg)
00040 cc.process(*beg, out);
00041 cc.flush(out);
00042 }
00043
00044
00045 template<typename InIt, typename OutIt, typename Codec>
00046 void code(InIt beg, InIt end,Codec& codec,OutIt out,const unbuffered_codec_type_tag&)
00047 {
00048 for(; beg != end; ++beg)
00049 codec.process(*beg, out);
00050 }
00051
00052
00053 template<typename InIt, typename OutIt, typename Codec, typename Next>
00054 void code(InIt beg, InIt end, const codec_chain<Codec,Next>& cc, OutIt out)
00055 {
00056 typedef codec_chain<Codec,Next> Node1;
00057 typedef codec_chain< oiterator_wrapper<OutIt> >
00058 TailNode;
00059 typedef typename push_back_node<Node1, TailNode>::node_type
00060 codec_chain_type;
00061
00062 oiterator_wrapper<OutIt> oiw(out);
00063 codec_chain_type chain = build_push_back_node<Node1,TailNode>(cc,TailNode(oiw));
00064
00065 for(; beg != end; ++beg)
00066 chain.process(*beg);
00067 chain.flush();
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 template<typename InIt, typename OutIt, typename Codec>
00088 void encode(InIt beg, InIt end, Codec& cc, OutIt out)
00089 {
00090 code(beg, end, cc, out);
00091 }
00092
00093
00094
00095
00096
00097
00098 template<typename InIt, typename OutIt, typename Codec>
00099 void decode(InIt beg, InIt end, Codec& cc, OutIt out)
00100 {
00101 code(beg, end, cc, out);
00102 }
00103
00104
00105 template<typename InIt, typename OutIt, typename Codec, typename Next>
00106 void encode(InIt beg, InIt end, const codec_chain<Codec,Next>& cc, OutIt out)
00107 {
00108 code(beg,end,cc,out);
00109 }
00110
00111 template<typename InIt, typename OutIt, typename Codec, typename Next>
00112 void decode(InIt beg, InIt end, const codec_chain<Codec,Next>& cc, OutIt out)
00113 {
00114 code(beg,end,cc,out);
00115 }
00116
00117 }
00118
00119
00120
00121 #endif
00122
00123
00124
00125
00126
00127