2fb098a60eb3dcf6d8e016f8ca9ba5547996ac6a
[senf.git] / Packets / PacketParser.ih
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
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.
10 //
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.
15 //
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.
20
21 /** \file
22     \brief PacketParser internal header */
23
24 #ifndef IH_PacketParser_
25 #define IH_PacketParser_ 1
26
27 // Custom includes
28 #include "Utils/mpl.hh"
29
30 ///////////////////////////////ih.p////////////////////////////////////////
31
32 namespace senf {
33 namespace detail {
34
35     // PLEASE don't add this to doxygen ... it just looks to weird and does not help ...
36
37 #   ifndef DOXYGEN
38
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
41     // set. 
42     template <class Parser>
43     PacketParserBase::size_type packetParserSize(
44         Parser p, int, senf::mpl::take_uint<Parser::fixed_bytes> * = 0);
45
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, ...);
50
51     // Same as above: This overload is only enabled, if Parser has an integer values 'init_bytes'
52     // member.
53     template <class Parser>
54     senf::mpl::rv<0> ParserInitBytes_Choose_(senf::mpl::take_uint<Parser::init_bytes> *);
55
56     template <class Parser>
57     senf::mpl::rv<1> ParserInitBytes_Choose_(...);
58
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
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> {};
70
71     template <class Parser>
72     struct ParserInitBytes
73         : public ParserInitBytes_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
74
75 #   endif
76
77 }}
78
79 ///////////////////////////////ih.e////////////////////////////////////////
80 #endif
81
82 \f
83 // Local Variables:
84 // mode: c++
85 // fill-column: 100
86 // c-file-style: "senf"
87 // indent-tabs-mode: nil
88 // ispell-local-dictionary: "american"
89 // compile-command: "scons -u test"
90 // comment-column: 40
91 // End: