Console: Implement short-option and non-option parsing
[senf.git] / Packets / PacketParser.cti
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 /** \file
24     \brief PacketParser inline template implementation */
25
26 #include "PacketParser.ih"
27
28 // Custom includes
29 #include "../Utils/senfassert.hh"
30 #include "PacketData.hh"
31
32 #define prefix_ inline
33 ///////////////////////////////cti.p///////////////////////////////////////
34
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::PacketParserBase
37
38 template <class Parser>
39 prefix_ Parser senf::PacketParserBase::parse(data_iterator i)
40     const
41 {
42     return Parser(i,state());
43 }
44
45 template <class Parser>
46 prefix_ Parser senf::PacketParserBase::parse(size_type n)
47     const
48 {
49     return Parser(boost::next(i(),n),state());
50 }
51
52 ///////////////////////////////////////////////////////////////////////////
53 // namespace members
54
55 template <class Parser>
56 prefix_ senf::PacketParserBase::size_type senf::bytes(Parser p)
57 {
58     return detail::packetParserSize(p,0);
59 }
60
61 #ifndef DOXYGEN
62 template <class Parser, class Value>
63 prefix_ typename boost::enable_if_c < 
64         boost::is_base_of<senf::PacketParserBase, Parser>::value 
65             && ! boost::is_base_of<senf::PacketParserBase, Value>::value,
66         Parser >::type senf::operator<<(Parser target, Value const & value)
67 {
68     target.value(value);
69     return target;
70 }
71 #else
72 template <class Parser, class Value>
73 prefix_ Parser senf::operator<<(Parser target, Value const & value)
74 {}
75 #endif
76
77 #ifndef DOXYGEN
78 template <class Parser, class Value>
79 prefix_ typename boost::enable_if_c < 
80         boost::is_base_of<senf::PacketParserBase, Parser>::value 
81             && ! boost::is_base_of<senf::PacketParserBase, Value>::value,
82         Parser >::type senf::operator<<(Parser target, boost::optional<Value> const & value)
83 {
84     if (value)
85         target.value(*value);
86     return target;
87 }
88 #else
89 template <class Parser, class Value>
90 prefix_ Parser senf::operator<<(Parser target, Value const & value)
91 {}
92 #endif
93
94
95 template <class Parser>
96 prefix_ senf::PacketParserBase::size_type
97 senf::detail::packetParserSize(Parser p, int, senf::mpl::take_uint<Parser::fixed_bytes> *)
98 {
99     return Parser::fixed_bytes;
100 }
101
102 ///////////////////////////////cti.e///////////////////////////////////////
103 #undef prefix_
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // c-file-style: "senf"
110 // indent-tabs-mode: nil
111 // ispell-local-dictionary: "american"
112 // compile-command: "scons -u test"
113 // comment-column: 40
114 // End: