switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / ListOptionTypeParser.ih
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Philipp Batroff <pug@berlios.de>
27
28 /** \file
29     \brief ListOptionTypeParser internal header */
30
31 #ifndef IH_SENF_Packets_ListOptionTypeParser_
32 #define IH_SENF_Packets_ListOptionTypeParser_ 1
33
34 // Custom includes
35 #include <senf/Packets/ListParser.ih>
36
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40     namespace detail {
41
42         /** \brief Internal: ListPolicy defing the ListOptionTypeParser parser
43          \internal
44          \see IPv6HopByHopOptionsPacketParser::ListOptionTypeParser
45          */
46         template <class ElementParser, class AuxPolicy>
47         struct ListOptionTypeParser_Policy
48         : public AuxPolicy
49         {
50             struct container_policy;
51
52             typedef PacketParserBase::data_iterator data_iterator;
53             typedef PacketParserBase::state_type state_type;
54             typedef PacketParserBase::size_type size_type;
55
56             typedef ElementParser element_type;
57             typedef ListParser< ListOptionTypeParser_Policy > parser_type;
58             typedef ListParser_Container< container_policy > container_type;
59
60             static const size_type init_bytes = 6u + AuxPolicy::aux_bytes;
61
62             ListOptionTypeParser_Policy();
63             template <class Arg> ListOptionTypeParser_Policy(Arg const & arg);
64
65             size_type bytes (data_iterator i, state_type s) const;
66             size_type size (data_iterator i, state_type s) const;
67             void init (data_iterator i, state_type s) const;
68
69             /** \brief Internal: ListOptionTypeParser container/wrapper policy */
70             struct container_policy
71             : public AuxPolicy
72             {
73                 typedef PacketParserBase::data_iterator data_iterator;
74                 typedef PacketParserBase::state_type state_type;
75                 typedef PacketParserBase::size_type size_type;
76
77                 typedef ListOptionTypeParser_Policy<ElementParser, AuxPolicy> parser_policy;
78                 typedef typename parser_policy::element_type element_type;
79                 typedef typename parser_policy::parser_type parser_type;
80                 typedef typename parser_policy::container_type container_type;
81
82                 static const size_type init_bytes = parser_policy::init_bytes;
83
84                 container_policy(parser_policy const & p);
85                 ~container_policy();
86                 size_type bytes (data_iterator i, state_type s) const;
87                 size_type size (data_iterator i, state_type s) const;
88                 void init (data_iterator i, state_type s);
89
90                 void erase (container_type & c, data_iterator p);
91                 void insert (container_type & c, data_iterator p);
92                 void update (container_type const & c) const;
93
94                 void destruct(container_type & c);
95                 void construct(container_type & c);
96
97                 /** \brief Internal: ListOptionTypeParser specific iterator data */
98                 struct iterator_data {};
99
100                 data_iterator setBegin (container_type const & c, iterator_data & d) const;
101                 data_iterator setEnd (container_type const & c, iterator_data & d) const;
102                 void setFromPosition (container_type const & c, iterator_data & d,data_iterator p) const;
103
104                 data_iterator next (container_type const & c, iterator_data & d) const;
105                 data_iterator raw (container_type const & c, iterator_data const & d) const;
106
107                 size_type n_;
108                 mutable size_type realAux_;
109                 mutable size_type container_size_;
110             };
111         };
112 }
113 }
114
115 //-/////////////////////////////////////////////////////////////////////////////////////////////////
116 #endif
117
118 \f
119 // Local Variables:
120 // mode: c++
121 // fill-column: 100
122 // comment-column: 40
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"
127 // End: