4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief ParseListB internal header */
26 #ifndef IH_ParseListB_
27 #define IH_ParseListB_ 1
31 ///////////////////////////////ih.p////////////////////////////////////////
36 /** \brief Internal: ListPolicy defing the Parse_ListB parser
40 template <class ElementParser, class BytesParser>
41 struct Parse_ListB_Policy
43 // This policy needs to work around a serious problem with this type of list: When we change
44 // the size of any (direct or indirect) subelement of the list, This will change will render
45 // the list completely invalid and unparseable since the 'byte' field will now be invalid.
47 // The solution we apply is to store the *size* (i.e. the number of elements) of the list
48 // when creating the container wrapper. We also maintain this value accross insert/erase
49 // statements. Additionally we also safe the complete size of the data container (the vector
50 // holding the bytes). Since we only allow packet changes through this container while it
51 // exists, any change in the container size must be a change within this list and therefore
52 // mandates an update of the 'bytes' field.
54 // The list container wrapper will call 'update' policy member before every access to the
55 // container and also in the destructor. This gives us a chance to fix the bytes header
56 // before the invalid header is seen by anyone (This is so, since we only allow access to
57 // the list through the container wrapper ...). Since we know the number of list elements,
58 // we can always find the correct 'bytes' value by traversing the list for that number of
61 // By caching the container size, all this can be made reasonably efficient and usable: The
62 // updates are done automatically by only if needed. It would of course be more efficient to
63 // just apply the size change directly to the bytes header (no need to traverse the
64 // list). However, the implementation of this approach would be much more complex and even
65 // more invasive and would probably suffer from the same restrictions to the user.
67 struct container_policy;
69 typedef PacketParserBase::data_iterator iterator;
70 typedef PacketParserBase::state_type state_type;
71 typedef PacketParserBase::size_type size_type;
72 typedef ElementParser element_type;
73 typedef Parse_List< Parse_ListB_Policy > parser_type;
74 typedef Parse_List_Container< container_policy > container_type;
76 static const size_type init_bytes = BytesParser::fixed_bytes;
78 size_type bytes (iterator i, state_type s) const;
79 size_type size (iterator i, state_type s) const;
80 void init (iterator i, state_type s) const;
82 /** \brief Internal: Parse_ListB_Policy's iterator policy
85 struct iterator_policy
87 iterator setBegin (iterator i, state_type s);
88 iterator setEnd (iterator i, state_type s);
89 void setFromPosition (iterator i, state_type s, iterator p);
90 iterator next (iterator i, state_type s);
91 iterator raw (iterator i, state_type s) const;
94 /** \brief Internal: Parse_ListB_Policy's container policy
97 struct container_policy
99 typedef typename Parse_ListB_Policy<
100 ElementParser,BytesParser>::iterator_policy iterator_policy;
101 typedef typename Parse_ListB_Policy<
102 ElementParser,BytesParser>::parser_type parser_type;
103 typedef typename Parse_ListB_Policy<
104 ElementParser,BytesParser>::element_type element_type;
106 static const size_type init_bytes = Parse_ListB_Policy<
107 ElementParser,BytesParser>::init_bytes;
109 container_policy(parser_type const & list);
111 size_type bytes (iterator i, state_type s) const;
112 size_type size (iterator i, state_type s) const;
113 void erase (iterator i, state_type s, iterator p);
114 void insert (iterator i, state_type s, iterator p);
115 void init (iterator i, state_type s);
116 void update (iterator i, state_type s) const;
119 mutable size_type container_size_;
125 ///////////////////////////////ih.e////////////////////////////////////////
132 // comment-column: 40
133 // c-file-style: "senf"
134 // indent-tabs-mode: nil
135 // ispell-local-dictionary: "american"
136 // compile-command: "scons -u test"