Socket: BUGFIX: Explicitly copy image
[senf.git] / Packets / ParseArray.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@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 #ifndef HH_ParseArray_
24 #define HH_ParseArray_ 1
25
26 /** \defgroup parsecollection Collection parsers
27
28     Collection parsers are parsers which build collections from other parsers. Examples are a vector
29     of 16bit unsigned integers or a list of lists of 32bit numbers and so on.
30
31     Collection parsers provide a (reduced) STL sequence like interface. It depends on the type of
32     collection parser, what kind of sequence is modelled (e.g. random access sequence, forward
33     sequence etc). Most collections will also provide a kind of container wrapper to allow extensive
34     manipulations of the collection contents. A container wrapper is initialized with the collection
35     parser and then provides a more complete sequence interface. Additionally, the collection
36     wrapper has a longer lifetime than an ordinary parser: While a parser will be invalidated
37     whenever the collection is changed, the container wrapper will stay valid as long as the
38     collection is changed through the wrapper (directly or indirectly, where indirectly means that a
39     sub-field or sub-collection of the collection is changed). Some collections may provide even
40     more lifetime guarantees but this guarantee should be met by all collection wrappers.
41
42     \important Parser lifetime has to be tightly checked when working with collection parsers since
43     \e every change of the collections size will invalidate \e all parsers and iterators referencing
44     the \e complete packet chain. Collection wrappers do \e not invalidate if the change is \e after
45     the collection.
46
47     \ingroup packetparser
48 */
49
50 // Custom includes
51 #include "PacketParser.hh"
52
53 //#include "ParseArray.mpp"
54 ///////////////////////////////hh.p////////////////////////////////////////
55
56 namespace senf {
57
58     namespace detail { template <class> class Parse_Array_iterator; }
59
60     /** \brief Fixed size collection of fixed size elements
61
62         Parse_Array will parse a sequence of <em>fixed size</em> parsers. The number of array
63         elements is given by the \e elements template parameter and is fixed at compile time. 
64         
65         Each element will be parsed by \a ElementParser, which can be any <em>fixed size</em>
66         parser. The array models an STL random-access sequence with the restriction that elements
67         cannot be added or removed since the size is fixed.
68
69         \ingroup parsecollection
70      */
71     template <unsigned elements, class ElementParser>
72     struct Parse_Array : public PacketParserBase
73     {
74         Parse_Array(data_iterator i, state_type s);
75
76         static size_type const fixed_bytes = elements*ElementParser::fixed_bytes;
77
78         void init() const;
79
80         ///////////////////////////////////////////////////////////////////////////
81         // Container interface
82
83         typedef ElementParser value_type;
84         typedef detail::Parse_Array_iterator<value_type> iterator;
85         typedef iterator const_iterator;
86
87         static size_type size();
88
89         iterator begin() const;
90         iterator end() const;
91
92         value_type operator[](difference_type i) const;
93     };
94
95 }
96
97 ///////////////////////////////hh.e////////////////////////////////////////
98 #endif
99 #if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseArray_i_)
100 #define HH_ParseArray_i_
101 //#include "ParseArray.cci"
102 //#include "ParseArray.ct"
103 #include "ParseArray.cti"
104 #endif
105
106 \f
107 // Local Variables:
108 // mode: c++
109 // fill-column: 100
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"
114 // comment-column: 40
115 // End: