2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief ParseListB internal header */
24 #ifndef IH_ParseListB_
25 #define IH_ParseListB_ 1
29 ///////////////////////////////ih.p////////////////////////////////////////
34 /** \brief Internal: ListPolicy defing the Parse_ListB parser
38 template <class ElementParser, class BytesParser>
39 struct Parse_ListB_Policy
41 // This policy needs to work around a serious problem with this type of list: When we change
42 // the size of any (direct or indirect) subelement of the list, This will change will render
43 // the list completely invalid and unparseable since the 'byte' field will now be invalid.
45 // The solution we apply is to store the *size* (i.e. the number of elements) of the list
46 // when creating the container wrapper. We also maintain this value accross insert/erase
47 // statements. Additionally we also safe the complete size of the data container (the vector
48 // holding the bytes). Since we only allow packet changes through this container while it
49 // exists, any change in the container size must be a change within this list and therefore
50 // mandates an update of the 'bytes' field.
52 // The list container wrapper will call 'update' policy member before every access to the
53 // container and also in the destructor. This gives us a chance to fix the bytes header
54 // before the invalid header is seen by anyone (This is so, since we only allow access to
55 // the list through the container wrapper ...). Since we know the number of list elements,
56 // we can always find the correct 'bytes' value by traversing the list for that number of
59 // By caching the container size, all this can be made reasonably efficient and usable: The
60 // updates are done automatically by only if needed. It would of course be more efficient to
61 // just apply the size change directly to the bytes header (no need to traverse the
62 // list). However, the implementation of this approach would be much more complex and even
63 // more invasive and would probably suffer from the same restrictions to the user.
65 struct container_policy;
67 typedef PacketParserBase::data_iterator iterator;
68 typedef PacketParserBase::state_type state_type;
69 typedef PacketParserBase::size_type size_type;
70 typedef ElementParser element_type;
71 typedef Parse_List< Parse_ListB_Policy > parser_type;
72 typedef Parse_List_Container< container_policy > container_type;
74 static const size_type init_bytes = BytesParser::fixed_bytes;
76 size_type bytes (iterator i, state_type s) const;
77 size_type size (iterator i, state_type s) const;
78 void init (iterator i, state_type s) const;
80 /** \brief Internal: Parse_ListB_Policy's iterator policy
83 struct iterator_policy
85 iterator setBegin (iterator i, state_type s);
86 iterator setEnd (iterator i, state_type s);
87 void setFromPosition (iterator i, state_type s, iterator p);
88 iterator next (iterator i, state_type s);
89 iterator raw (iterator i, state_type s) const;
92 /** \brief Internal: Parse_ListB_Policy's container policy
95 struct container_policy
97 typedef typename Parse_ListB_Policy<
98 ElementParser,BytesParser>::iterator_policy iterator_policy;
99 typedef typename Parse_ListB_Policy<
100 ElementParser,BytesParser>::parser_type parser_type;
101 typedef typename Parse_ListB_Policy<
102 ElementParser,BytesParser>::element_type element_type;
104 static const size_type init_bytes = Parse_ListB_Policy<
105 ElementParser,BytesParser>::init_bytes;
107 container_policy(parser_type const & list);
109 size_type bytes (iterator i, state_type s) const;
110 size_type size (iterator i, state_type s) const;
111 void erase (iterator i, state_type s, iterator p);
112 void insert (iterator i, state_type s, iterator p);
113 void init (iterator i, state_type s);
114 void update (iterator i, state_type s) const;
117 mutable size_type container_size_;
123 ///////////////////////////////ih.e////////////////////////////////////////
130 // comment-column: 40
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"