4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief PacketParser internal header */
31 #ifndef IH_SENF_Packets_PacketParser_
32 #define IH_SENF_Packets_PacketParser_ 1
35 #include <senf/Utils/mpl.hh>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // PLEASE don't add this to doxygen ... it just looks to weird and does not help ...
46 // Use SFINAE to check, if Parser has an integer-valued init_bytes member. If not,
47 // 'Parser_TakeNum<Parser::init_bytes>' fails and the overload is removed from the overload
49 template <class Parser>
50 PacketParserBase::size_type packetParserSize(
51 Parser const & p, int, senf::mpl::take_uint<Parser::init_bytes> * = 0);
53 // An ellipsis is always the worst match. A call 'packetParserSize(p,0) will prefer above
54 // overload if that is not disabled by SFINAE.
55 template <class Parser>
56 PacketParserBase::size_type packetParserSize(Parser const & p, ...);
58 // Same as above: This overload is only enabled, if Parser has an integer values 'init_bytes'
60 template <class Parser>
61 senf::mpl::rv<0> ParserInitBytes_Choose_(senf::mpl::take_uint<Parser::init_bytes> *);
63 template <class Parser>
64 senf::mpl::rv<1> ParserInitBytes_Choose_(...);
66 // This version of ParserInitBytes_Choose uses 'Parser::init_bytes' to provide 'value' (via
67 // 'boost::integral_constant')
68 template <class Parser, unsigned _>
69 struct ParserInitBytes_Choose
70 : public boost::integral_constant<PacketParserBase::size_type, Parser::init_bytes> {};
71 // ^^-- g++ error signaled here:
72 // error: 'fixed_bytes' is not a member of 'some-class-name'
74 // The 'some-class-name' class (as given in the error message) does not seem to be a parser at
75 // all (it has neither a 'fixed_bytes' nor an 'init_bytes' member).
77 // Either 'some-class-name' is not the class you wanted to use (it really is no parser) or you
78 // left out either 'init_bytes' or 'fixed_bytes' when defining the parser. This will also
79 // happen, if you forget to call 'SENF_PARSER_FINALIZE()' when defining a composite parser.
80 //-/////////////////////////////////////////////////////////////////////////////////////////////
82 // If Parser::init_bytes is not defined, this specialization is chosen which instead uses
83 // 'Parser::fixed_bytes'
84 template <class Parser>
85 struct ParserInitBytes_Choose<Parser, 1>
86 : public boost::integral_constant<PacketParserBase::size_type, Parser::fixed_bytes> {};
88 template <class Parser>
89 struct ParserInitBytes
90 : public ParserInitBytes_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
92 template <class Parser, unsigned _>
93 struct ParserIsFixed_Choose
94 : public boost::false_type {};
96 template <class Parser>
97 struct ParserIsFixed_Choose<Parser, 1>
98 : public boost::true_type {};
100 template <class Parser>
102 : public ParserIsFixed_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
108 //-/////////////////////////////////////////////////////////////////////////////////////////////////
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"
119 // comment-column: 40