Packets: Migrate VariantParser to use AuxParser/container infrstructure
[senf.git] / Packets / VariantParser.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
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 VariantParser internal header */
25
26 #ifndef IH_VariantParser_
27 #define IH_VariantParser_ 1
28
29 // Custom includes
30 #include "PacketParser.hh"
31 #include <boost/preprocessor/cat.hpp>
32 #include <boost/preprocessor/seq/enum.hpp>
33
34 ///////////////////////////////ih.p////////////////////////////////////////
35
36 namespace senf {
37 namespace detail {
38
39 #   ifndef DOXYGEN
40
41     template <class Variant, unsigned N>
42     struct VariantBytes {
43         static PacketParserBase::size_type bytes(Variant const & v, unsigned n);
44     };
45
46     template <class Variant>
47     struct VariantBytes<Variant,0> {
48         static PacketParserBase::size_type bytes(Variant const & v, unsigned n);
49     };
50
51 #   endif
52     
53     template <class AuxPolicy, class AuxTag>
54     struct VariantParserPolicy {};
55
56     template <class AuxPolicy>
57     struct VariantParserPolicy<AuxPolicy, senf::detail::auxtag::none>
58     {
59         typedef AuxPolicy type;
60     };
61
62
63     template <class AuxPolicy, class Transform>
64     struct VariantParserPolicy<AuxPolicy, 
65                                senf::detail::auxtag::transform<Transform, 
66                                                                senf::detail::auxtag::none> >
67     {
68         typedef TransformAuxParserPolicy<AuxPolicy, Transform> type;
69     };
70
71     template <class Parsers>
72     struct VariantParserTraits
73     {
74         template <class AuxPolicy, class AuxTag>
75         struct parser {
76             typedef senf::VariantParser<
77                 typename VariantParserPolicy<AuxPolicy, AuxTag>::type,
78                 Parsers> type;
79         };
80     };
81     
82 #   define SENF_PARSER_VARIANT_I(access, name, chooser, types)                                     \
83         typedef boost::mpl::vector< BOOST_PP_SEQ_ENUM(types) > BOOST_PP_CAT(name, _parsers);      \
84         SENF_PARSER_REQUIRE_VAR(variant)                                                          \
85         SENF_PARSER_COLLECTION_I(                                                                 \
86             access,                                                                               \
87             name,                                                                                 \
88             chooser,                                                                              \
89             senf::detail::VariantParserTraits< BOOST_PP_CAT(name, _parsers) > )
90
91 }}
92
93 ///////////////////////////////ih.e////////////////////////////////////////
94 #endif
95
96 \f
97 // Local Variables:
98 // mode: c++
99 // fill-column: 100
100 // comment-column: 40
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // End: