5e4a427092ccf4256df153413f6f7e79ddb83739
[senf.git] / Packets / AuxParser.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief AuxParser public header */
25
26 #ifndef HH_AuxParser_
27 #define HH_AuxParser_ 1
28
29 #ifndef HH_Packets_
30 #error "Don't include 'AuxParser.hh' directly, include 'Packets.hh'"
31 #endif
32
33 // Custom includes
34 #include "PacketParser.hh"
35 #include "SafeIterator.hh"
36
37 //#include "AuxParser.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41 namespace detail {
42
43     template <class P>
44     struct PrefixAuxParserPolicy
45     {
46         typedef PrefixAuxParserPolicy WrapperPolicy;
47         typedef PrefixAuxParserPolicy ParserPolicy;
48
49         static PacketParserBase::size_type const aux_bytes = P::fixed_bytes;
50         
51         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
52         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
53         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
54     };
55
56     template <class P, unsigned Dist>
57     struct FixedAuxParserPolicy
58     {
59         typedef FixedAuxParserPolicy WrapperPolicy;
60         typedef FixedAuxParserPolicy ParserPolicy;
61
62         static PacketParserBase::size_type const aux_bytes = 0;
63         
64         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
65         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
66         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
67     };
68
69     template <class P> struct DynamicWrapperAuxParserPolicy;
70     
71     template <class P>
72     struct DynamicAuxParserPolicy
73     {
74         typedef DynamicWrapperAuxParserPolicy<P> WrapperPolicy;
75         typedef DynamicAuxParserPolicy<P> ParserPolicy;
76
77         static PacketParserBase::size_type const aux_bytes = 0;
78
79         DynamicAuxParserPolicy(P p);
80         DynamicAuxParserPolicy(WrapperPolicy const & other);
81         
82         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
83         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
84         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
85
86         mutable P p_;
87     };
88
89     template <class P>
90     struct DynamicWrapperAuxParserPolicy
91     {
92         typedef DynamicWrapperAuxParserPolicy<P> WrapperPolicy;
93         typedef DynamicAuxParserPolicy<P> ParserPolicy;
94
95         static PacketParserBase::size_type const aux_bytes = 0;
96
97         DynamicWrapperAuxParserPolicy(ParserPolicy const & other);
98         
99         typename P::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
100         void aux(typename P::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
101         PacketParserBase::data_iterator adjust(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
102
103         mutable SafePacketParserWrapper<P> p_;
104     };
105
106     template <class Policy, class Transform>
107     struct TransformAuxParserPolicy
108         : public Policy
109     {
110         typedef TransformAuxParserPolicy<typename Policy::WrapperPolicy, Transform> WrapperPolicy;
111         typedef TransformAuxParserPolicy<typename Policy::ParserPolicy, Transform> ParserPolicy;
112
113         static PacketParserBase::size_type const aux_bytes = Policy::aux_bytes;
114         
115         TransformAuxParserPolicy();
116         template <class Arg> TransformAuxParserPolicy(Arg const & arg);
117
118         typename Transform::value_type aux(PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
119         void aux(typename Transform::value_type const & v, PacketParserBase::data_iterator i, PacketParserBase::state_type s) const;
120     };
121 }}
122
123 ///////////////////////////////hh.e////////////////////////////////////////
124 #endif
125 #if !defined(HH_Packets__decls_) && !defined(HH_AuxParser_i_)
126 #define HH_AuxParser_i_
127 //#include "AuxParser.cci"
128 //#include "AuxParser.ct"
129 #include "AuxParser.cti"
130 #endif
131
132 \f
133 // Local Variables:
134 // mode: c++
135 // fill-column: 100
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"
141 // End: