78de19b95df1c9cc619cfc4ac715962a33f0e751
[senf.git] / senf / Packets / DefaultBundle / ListOptionTypeParser.ih
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Philipp.Batroff@fokus.fraunhofer.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 ListOptionTypeParser internal header */
25
26 #ifndef IH_SENF_Packets_ListOptionTypeParser_
27 #define IH_SENF_Packets_ListOptionTypeParser_ 1
28
29 // Custom includes
30 #include <senf/Packets/ListParser.ih>
31
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33
34 namespace senf {
35     namespace detail {
36
37         /** \brief Internal: ListPolicy defing the ListOptionTypeParser parser
38          \internal
39          \see IPv6HopByHopOptionsPacketParser::ListOptionTypeParser
40          */
41         template <class ElementParser, class AuxPolicy>
42         struct ListOptionTypeParser_Policy
43         : public AuxPolicy
44         {
45             struct container_policy;
46
47             typedef PacketParserBase::data_iterator data_iterator;
48             typedef PacketParserBase::state_type state_type;
49             typedef PacketParserBase::size_type size_type;
50
51             typedef ElementParser element_type;
52             typedef ListParser< ListOptionTypeParser_Policy > parser_type;
53             typedef ListParser_Container< container_policy > container_type;
54
55             static const size_type init_bytes = 6u + AuxPolicy::aux_bytes;
56
57             ListOptionTypeParser_Policy();
58             template <class Arg> ListOptionTypeParser_Policy(Arg const & arg);
59
60             size_type bytes (data_iterator i, state_type s) const;
61             size_type size (data_iterator i, state_type s) const;
62             void init (data_iterator i, state_type s) const;
63
64             /** \brief Internal: ListOptionTypeParser container/wrapper policy */
65             struct container_policy
66             : public AuxPolicy
67             {
68                 typedef PacketParserBase::data_iterator data_iterator;
69                 typedef PacketParserBase::state_type state_type;
70                 typedef PacketParserBase::size_type size_type;
71
72                 typedef ListOptionTypeParser_Policy<ElementParser, AuxPolicy> parser_policy;
73                 typedef typename parser_policy::element_type element_type;
74                 typedef typename parser_policy::parser_type parser_type;
75                 typedef typename parser_policy::container_type container_type;
76
77                 static const size_type init_bytes = parser_policy::init_bytes;
78
79                 container_policy(parser_policy const & p);
80                 ~container_policy();
81                 size_type bytes (data_iterator i, state_type s) const;
82                 size_type size (data_iterator i, state_type s) const;
83                 void init (data_iterator i, state_type s);
84
85                 void erase (container_type & c, data_iterator p);
86                 void insert (container_type & c, data_iterator p);
87                 void update (container_type const & c) const;
88
89                 void destruct(container_type & c);
90                 void construct(container_type & c);
91
92                 /** \brief Internal: ListOptionTypeParser specific iterator data */
93                 struct iterator_data {};
94
95                 data_iterator setBegin (container_type const & c, iterator_data & d) const;
96                 data_iterator setEnd (container_type const & c, iterator_data & d) const;
97                 void setFromPosition (container_type const & c, iterator_data & d,data_iterator p) const;
98
99                 data_iterator next (container_type const & c, iterator_data & d) const;
100                 data_iterator raw (container_type const & c, iterator_data const & d) const;
101
102                 size_type n_;
103                 mutable size_type realAux_;
104                 mutable size_type container_size_;
105             };
106         };
107 }
108 }
109
110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 #endif
112
113 \f
114 // Local Variables:
115 // mode: c++
116 // fill-column: 100
117 // comment-column: 40
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // End: