2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief PacketParser internal header */
24 #ifndef IH_PacketParser_
25 #define IH_PacketParser_ 1
28 #include "../Utils/mpl.hh"
30 ///////////////////////////////ih.p////////////////////////////////////////
35 // PLEASE don't add this to doxygen ... it just looks to weird and does not help ...
39 // Use SFINAE to check, if Parser has an integer-valued fixed_bytes member. If not,
40 // 'Parser_TakeNum<Parser::fixed_bytes>' fails and the overload is removed from the overload
42 template <class Parser>
43 PacketParserBase::size_type packetParserSize(
44 Parser p, int, senf::mpl::take_uint<Parser::fixed_bytes> * = 0);
46 // An ellipsis is always the worst match. A call 'packetParserSize(p,0) will prefer above
47 // overload if that is not disabled by SFINAE.
48 template <class Parser>
49 PacketParserBase::size_type packetParserSize(Parser p, ...);
51 // Same as above: This overload is only enabled, if Parser has an integer values 'init_bytes'
53 template <class Parser>
54 senf::mpl::rv<0> ParserInitBytes_Choose_(senf::mpl::take_uint<Parser::init_bytes> *);
56 template <class Parser>
57 senf::mpl::rv<1> ParserInitBytes_Choose_(...);
59 // This version of ParserInitBytes_Choose uses 'Parser::init_bytes' to provide 'value' (via
60 // 'boost::integral_constant')
61 template <class Parser, unsigned _>
62 struct ParserInitBytes_Choose
63 : public boost::integral_constant<PacketParserBase::size_type, Parser::init_bytes> {};
64 // ^^-- g++ error signaled here:
65 // error: 'fixed_bytes' is not a member of 'some-class-name'
67 // The 'some-class-name' class (as given in the error message) does not seem to be a parser at
68 // all (it has neither a 'fixed_bytes' nor an 'init_bytes' member).
70 // Either 'some-class-name' is not the class you wanted to use (it really is no parser) or you
71 // left out either 'init_bytes' or 'fixed_bytes' when defining the parser. This will also
72 // happen, if you forget to call 'SENF_PARSER_FINALIZE()' when defining a composite parser.
73 ///////////////////////////////////////////////////////////////////////////////////////////////
75 // If Parser::init_bytes is not defined, this specialization is chosen which instead uses
76 // 'Parser::fixed_bytes'
77 template <class Parser>
78 struct ParserInitBytes_Choose<Parser, 1>
79 : public boost::integral_constant<PacketParserBase::size_type, Parser::fixed_bytes> {};
81 template <class Parser>
82 struct ParserInitBytes
83 : public ParserInitBytes_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
89 ///////////////////////////////ih.e////////////////////////////////////////
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u test"
100 // comment-column: 40