2c75016b4b4d37692b25c7152690c2d6fa145de7
[senf.git] / Packets / ParseListS.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_ParseListS_
24 #define HH_ParseListS_ 1
25
26 // Custom includes
27 #include <utility> // for std::pair
28 #include <boost/iterator/iterator_facade.hpp>
29 #include <boost/utility.hpp> // for boost::noncopyable
30 #include "ParserBase.hh"
31
32 //#include "ParseListS.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace satcom {
36 namespace pkf {
37
38     template <class Parser, class Sentinel, class Container> class Parse_ListS_wrapper;
39     namespace impl { 
40         template <class Parser, class Sentinel, class Container> class Parse_ListS_iterator; 
41     }
42
43     template <class Parser, class Sentinel, class Iterator=nil, class IPacket=nil>
44     struct Parse_ListS : public ParserBase<Iterator,IPacket>
45     {
46         ///////////////////////////////////////////////////////////////////////////
47         // Parser interface
48
49         template <class I=nil, class P=nil> 
50         struct rebind { typedef Parse_ListS<Parser,Sentinel,I,P> parser; };
51         typedef Iterator byte_iterator;
52         
53         Parse_ListS();
54         Parse_ListS(Iterator const & i);
55         
56         unsigned bytes() const;
57         bool check(Iterator const & e) const;
58         void init() const;
59
60         ///////////////////////////////////////////////////////////////////////////
61         // Container interface
62
63         typedef typename Parser::template rebind<Iterator>::parser value_type;
64         typedef Sentinel sentinel;
65         typedef impl::Parse_ListS_iterator<value_type,sentinel,byte_iterator> iterator;
66         typedef unsigned size_type;
67         typedef int difference_type;
68         typedef std::pair<iterator,iterator> range_type;
69
70         template <class Container>
71         struct wrapper { typedef Parse_ListS_wrapper<value_type, Sentinel, Container> t; };
72
73         size_type size() const;
74         bool empty() const;
75
76         iterator begin() const;
77         iterator end() const;
78         range_type range() const;
79         range_type value() const;
80
81      private:
82         template <class P, class S, class C> friend class Parse_ListS_wrapper;
83     };
84
85     /** \brief
86         
87         Holds a reference to the container !
88       */
89     template <class Parser, class Sentinel, class Container>
90     class Parse_ListS_wrapper
91         : public boost::noncopyable
92     {
93     public:
94         ///////////////////////////////////////////////////////////////////////////
95         // Types
96
97         typedef Container container;
98         typedef Sentinel sentinel;
99         typedef typename Parser::byte_iterator byte_iterator;
100         typedef Parser value_type;
101         typedef impl::Parse_ListS_iterator<value_type,sentinel,byte_iterator> iterator;
102         typedef unsigned size_type;
103         typedef int difference_type;
104         typedef std::pair<iterator,iterator> range_type;
105
106         ///////////////////////////////////////////////////////////////////////////
107         ///\name Structors and default members
108         ///@{
109
110         template <class P, class S, class I, class IP>
111         Parse_ListS_wrapper(Parse_ListS<P,S,I,IP> const & list, Container & container);
112
113         // no default constructor
114         // no copy
115         // default destructor
116         // no conversion constructors
117
118         ///@}
119         ///////////////////////////////////////////////////////////////////////////
120         ///\name Accessors
121         ///@{
122
123         size_type size() const;
124         bool empty() const;
125
126         iterator begin() const;
127         iterator end() const;
128         range_type range() const;
129
130         ///@}
131         ///////////////////////////////////////////////////////////////////////////
132         ///\name Mutators
133         ///@{
134
135         template <class Value> void insert(iterator pos, Value const & t); 
136         template <class Value> void insert(iterator pos, size_type n, Value const & t); 
137         template <class InputIterator> void insert(iterator pos, InputIterator f, InputIterator l); 
138         
139         void erase(iterator pos, size_type n=1); 
140         void erase(iterator f, iterator l); 
141         void clear(); 
142
143         ///@}
144
145     protected:
146
147     private:
148         
149         size_type i_;
150         Container & container_;
151     };
152
153 }}
154
155 ///////////////////////////////hh.e////////////////////////////////////////
156 //#include "ParseListS.cci"
157 #include "ParseListS.ct"
158 #include "ParseListS.cti"
159 #endif
160
161 \f
162 // Local Variables:
163 // mode: c++
164 // c-file-style: "satcom"
165 // End: