switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / ListParser.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief ListParser internal header */
30
31 #ifndef IH_SENF_Packets_ListParser_
32 #define IH_SENF_Packets_ListParser_ 1
33
34 // Custom includes
35 #include <boost/iterator/iterator_facade.hpp>
36
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40 namespace detail {
41
42     /** \brief Internal: Iterator used by ListParser
43
44         \internal
45      */
46     template <class Container>
47     class ListParser_Iterator
48         : public boost::iterator_facade< ListParser_Iterator<Container>,
49                                          typename Container::value_type,
50                                          boost::forward_traversal_tag,
51                                          typename Container::value_type >,
52 #ifndef DOXYGEN
53           private Container::policy::iterator_data
54 #endif
55     {
56     public:
57         typedef typename Container::value_type value_type;
58
59         ListParser_Iterator();
60         explicit ListParser_Iterator(Container const & c);
61
62         PacketParserBase::data_iterator raw() const;
63         PacketParserBase::data_iterator i() const;
64
65         static ListParser_Iterator & get(typename Container::policy::iterator_data & d);
66         static ListParser_Iterator const & get(typename Container::policy::iterator_data const & d);
67
68     private:
69         friend class boost::iterator_core_access;
70         template <class P> friend class ListParser_Container;
71
72         value_type dereference() const;
73         bool equal(ListParser_Iterator const & other) const;
74         void increment();
75
76         PacketParserBase::data_iterator i_;
77         Container const * c_;
78     };
79
80 #ifndef DOXYGEN
81
82     template <class ElementParser, class AuxPolicy, class AuxTag>
83     struct ListParserPolicy
84     {};
85
86     template <class ElementParser>
87     struct ListParserTraits
88     {
89         template <class AuxPolicy, class AuxTag>
90         struct parser {
91             typedef senf::ListParser<
92                 typename ListParserPolicy<ElementParser, AuxPolicy, AuxTag>::type > type;
93         };
94     };
95
96 #   define SENF_PARSER_LIST_I(access, name, size, elt_type)                                       \
97         SENF_PARSER_REQUIRE_VAR(list)                                                             \
98             SENF_PARSER_COLLECTION_I( access,                                                     \
99                                       name,                                                       \
100                                       size,                                                       \
101                                       senf::detail::ListParserTraits<elt_type> )
102
103 #endif
104
105 }}
106
107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
108 #endif
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // fill-column: 100
114 // comment-column: 40
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"
119 // End: