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