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> {};
65 // If Parser::init_bytes is not defined, this specialization is chosen which instead uses
66 // 'Parser::fixed_bytes'
67 template <class Parser>
68 struct ParserInitBytes_Choose<Parser, 1>
69 : public boost::integral_constant<PacketParserBase::size_type, Parser::fixed_bytes> {};
71 template <class Parser>
72 struct ParserInitBytes
73 : public ParserInitBytes_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
79 ///////////////////////////////ih.e////////////////////////////////////////
86 // c-file-style: "senf"
87 // indent-tabs-mode: nil
88 // ispell-local-dictionary: "american"
89 // compile-command: "scons -u test"