4cd9275f4c8dbb86d56b0c85aad824006c4806a1
[senf.git] / senf / Packets / ArrayParser.ih
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 ArrayParser internal header */
25
26 #ifndef IH_SENF_Packets_ArrayParser_
27 #define IH_SENF_Packets_ArrayParser_ 1
28
29 // Custom includes
30 #include <boost/iterator/iterator_facade.hpp>
31
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33
34 /** \brief Internal: Array and Vector iterator
35
36     \internal
37
38     This is the iterator type used for both ArrayParser and VectorParser. It is a model of random
39     access iterator.
40  */
41 template <class ElementParser>
42 class senf::detail::ArrayParser_iterator
43     : public boost::iterator_facade< ArrayParser_iterator<ElementParser>,
44                                      ElementParser,
45                                      boost::random_access_traversal_tag,
46                                      ElementParser >
47 {
48 public:
49     ArrayParser_iterator();
50     ArrayParser_iterator(PacketParserBase::data_iterator const & i,
51                          PacketParserBase::state_type s);
52
53     // Needed to elide the []-proxy of iterator_facade
54     ElementParser operator[](int i) const;
55
56     PacketParserBase::data_iterator raw() const; ///< Return data_iterator
57                                         /**< Returns the raw data_iterator pointing to the beginning
58                                              of the current element */
59
60 protected:
61
62 private:
63     friend class boost::iterator_core_access;
64
65     // iterator_facade interface
66
67     ElementParser dereference() const;
68     bool equal(ArrayParser_iterator const & other) const;
69     int distance_to(ArrayParser_iterator const & other) const;
70     void increment();
71     void decrement();
72     void advance(int n);
73
74     PacketParserBase::data_iterator i_;
75     PacketParserBase::state_type s_;
76 };
77
78 //-/////////////////////////////////////////////////////////////////////////////////////////////////
79 #endif
80
81 \f
82 // Local Variables:
83 // mode: c++
84 // fill-column: 100
85 // c-file-style: "senf"
86 // indent-tabs-mode: nil
87 // ispell-local-dictionary: "american"
88 // compile-command: "scons -u test"
89 // comment-column: 40
90 // End: