4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief PacketParser internal header */
26 #ifndef IH_SENF_Packets_PacketParser_
27 #define IH_SENF_Packets_PacketParser_ 1
30 #include "../Utils/mpl.hh"
32 ///////////////////////////////ih.p////////////////////////////////////////
37 // PLEASE don't add this to doxygen ... it just looks to weird and does not help ...
41 // Use SFINAE to check, if Parser has an integer-valued fixed_bytes member. If not,
42 // 'Parser_TakeNum<Parser::fixed_bytes>' fails and the overload is removed from the overload
44 template <class Parser>
45 PacketParserBase::size_type packetParserSize(
46 Parser p, int, senf::mpl::take_uint<Parser::fixed_bytes> * = 0);
48 // An ellipsis is always the worst match. A call 'packetParserSize(p,0) will prefer above
49 // overload if that is not disabled by SFINAE.
50 template <class Parser>
51 PacketParserBase::size_type packetParserSize(Parser p, ...);
53 // Same as above: This overload is only enabled, if Parser has an integer values 'init_bytes'
55 template <class Parser>
56 senf::mpl::rv<0> ParserInitBytes_Choose_(senf::mpl::take_uint<Parser::init_bytes> *);
58 template <class Parser>
59 senf::mpl::rv<1> ParserInitBytes_Choose_(...);
61 // This version of ParserInitBytes_Choose uses 'Parser::init_bytes' to provide 'value' (via
62 // 'boost::integral_constant')
63 template <class Parser, unsigned _>
64 struct ParserInitBytes_Choose
65 : public boost::integral_constant<PacketParserBase::size_type, Parser::init_bytes> {};
66 // ^^-- g++ error signaled here:
67 // error: 'fixed_bytes' is not a member of 'some-class-name'
69 // The 'some-class-name' class (as given in the error message) does not seem to be a parser at
70 // all (it has neither a 'fixed_bytes' nor an 'init_bytes' member).
72 // Either 'some-class-name' is not the class you wanted to use (it really is no parser) or you
73 // left out either 'init_bytes' or 'fixed_bytes' when defining the parser. This will also
74 // happen, if you forget to call 'SENF_PARSER_FINALIZE()' when defining a composite parser.
75 ///////////////////////////////////////////////////////////////////////////////////////////////
77 // If Parser::init_bytes is not defined, this specialization is chosen which instead uses
78 // 'Parser::fixed_bytes'
79 template <class Parser>
80 struct ParserInitBytes_Choose<Parser, 1>
81 : public boost::integral_constant<PacketParserBase::size_type, Parser::fixed_bytes> {};
83 template <class Parser>
84 struct ParserInitBytes
85 : public ParserInitBytes_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
87 template <class Parser, unsigned _>
88 struct ParserIsFixed_Choose
89 : public boost::false_type {};
91 template <class Parser>
92 struct ParserIsFixed_Choose<Parser, 1>
93 : public boost::true_type {};
95 template <class Parser>
97 : public ParserIsFixed_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
103 ///////////////////////////////ih.e////////////////////////////////////////
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"
114 // comment-column: 40