Fixed whitespace in all files (no tabs)
[senf.git] / Packets / ParserBase.ih
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 #ifndef IH_ParserBase_
24 #define IH_ParserBase_ 1
25
26 // Custom includes
27
28 ///////////////////////////////ih.p////////////////////////////////////////
29
30 namespace senf {
31
32 namespace impl {
33
34     struct ParserBase {};
35
36     template <unsigned N>
37     struct Parser_traits_sentinel
38     { int v[N]; };
39
40     template <class Parser>
41     struct Parser_traits_fixed_size {
42         // This differentiates between bytes being a static or
43         // non-static member of Parser ...
44         static const bool fixed_size = sizeof(
45             Parser_traits_fixed_size_check(&Parser::bytes))-sizeof(Parser_traits_sentinel<1>);
46     };
47
48     template <class R>
49     Parser_traits_sentinel<2> Parser_traits_fixed_size_check(R (*)());
50
51     template <class R,class T>
52     Parser_traits_sentinel<1> Parser_traits_fixed_size_check(R (T::*)() const);
53
54     template <class Parser, class Iterator>
55     bool check(Iterator const & b, Iterator const & e, ParserBase *);
56
57     template <class Parser, class Iterator>
58     bool check(Iterator const & b, Iterator const & e, void *);
59
60     template <class Parser, bool Fixed>
61     struct ParserCheck {
62         template <class Iterator>
63         static unsigned check(Iterator const & b, Iterator const & e)
64             { return Parser::check(b,e); }
65     };
66
67     template <class Parser>
68     struct ParserCheck<Parser,true> {
69         template <class Iterator>
70         static unsigned check(Iterator const & b, Iterator const & e)
71             { return unsigned(e-b) >= Parser::bytes(); }
72     };
73
74     template <class Parser>
75     unsigned min_bytes(ParserBase *);
76
77     template <class Parser>
78     unsigned min_bytes(void *);
79
80     template <class Parser, bool Fixed>
81     struct ParserMinBytes {
82         static unsigned bytes() { return Parser::min_bytes(); }
83     };
84
85     template <class Parser>
86     struct ParserMinBytes<Parser,true> {
87         static unsigned bytes() { return Parser::bytes(); }
88     };
89
90 }}
91
92 ///////////////////////////////ih.e////////////////////////////////////////
93 #endif
94
95 \f
96 // Local Variables:
97 // mode: c++
98 // fill-column: 100
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // End: