Fix SCons 1.2.0 build failure
[senf.git] / Packets / PacketParser.cci
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 non-template implementation */
25
26 // Custom includes
27 #include <iterator>
28 #include "PacketData.hh"
29
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::PacketParserBase
35
36 // public members
37
38 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::i()
39     const
40 {
41     return i_;
42 }
43
44 // private members
45
46 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::end()
47     const
48 {
49     return data_->end();
50 }
51
52 // protected members
53
54 prefix_ bool senf::PacketParserBase::check(size_type size)
55     const
56 {
57     return size <= size_type(std::distance(i(),end()));
58 }
59
60 prefix_ void senf::PacketParserBase::validate(size_type size) 
61    const
62 {
63     if (! check(size))
64         throw TruncatedPacketException();
65 }
66
67 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s)
68     : i_ (i), data_ (s)
69 {}
70
71 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s, 
72                                                  size_type size)
73     : i_ (i), data_ (s)
74 {
75     validate(size);
76 }
77
78 // public members
79
80 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::i(size_type offset)
81     const
82 {
83     validate(offset);
84     return boost::next(i_, offset);
85 }
86
87 prefix_ senf::PacketParserBase::state_type senf::PacketParserBase::state()
88     const
89 {
90     return data_;
91 }
92
93 prefix_ senf::PacketData & senf::PacketParserBase::data()
94     const
95 {
96     return * data_;
97 }
98
99 prefix_ void senf::PacketParserBase::init()
100     const
101 {}
102
103 prefix_ void senf::PacketParserBase::defaultInit()
104     const
105 {}
106
107 prefix_ senf::Packet senf::PacketParserBase::packet()
108     const
109 {
110     // OUCH ... I hate this but for some awkward packet types, access to the packet
111     // from the parser is really needed (e.g. UDP when building the pseudo-header
112     // for calculating the checksum).
113     return Packet(PacketInterpreterBase::ptr(static_cast<PacketInterpreterBase*>(&data())));
114 }
115
116 ///////////////////////////////cci.e///////////////////////////////////////
117 #undef prefix_
118
119 \f
120 // Local Variables:
121 // mode: c++
122 // fill-column: 100
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"
127 // comment-column: 40
128 // End: