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 Packet public header */
28 #include <boost/operators.hpp>
30 #include "Utils/Exception.hh"
31 #include "Utils/SafeBool.hh"
32 #include "PacketInterpreter.hh"
34 //#include "Packet.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
39 template <class PackeType> class ConcretePacket;
44 : public SafeBool<Packet>,
45 public boost::equality_comparable<Packet>
48 ///////////////////////////////////////////////////////////////////////////
52 typedef senf::detail::packet::iterator iterator;
53 typedef senf::detail::packet::const_iterator const_iterator;
54 typedef senf::detail::packet::size_type size_type;
55 typedef senf::detail::packet::difference_type difference_type;
56 typedef senf::detail::packet::byte byte;
57 typedef PacketInterpreterBase::factory_t factory_t;
59 enum NoInit_t { noinit };
61 ///////////////////////////////////////////////////////////////////////////
62 ///\name Structors and default members
65 // default copy constructor
66 // default copy assignment
72 // conversion constructors
74 template <class PacketType>
75 Packet(ConcretePacket<PacketType> packet);
78 ///////////////////////////////////////////////////////////////////////////
80 ///\name Interpreter chain access
84 template <class OtherPacket> OtherPacket next() const;
85 template <class OtherPacket> OtherPacket next(NoThrow_t) const;
86 template <class OtherPacket> OtherPacket findNext() const;
87 template <class OtherPacket> OtherPacket findNext(NoThrow_t) const;
90 template <class OtherPacket> OtherPacket prev() const;
91 template <class OtherPacket> OtherPacket prev(NoThrow_t) const;
92 template <class OtherPacket> OtherPacket findPrev() const;
93 template <class OtherPacket> OtherPacket findPrev(NoThrow_t) const;
96 template <class OtherPacket> OtherPacket first() const;
97 template <class OtherPacket> OtherPacket first(NoThrow_t) const;
100 template <class OtherPacket> OtherPacket last() const;
101 template <class OtherPacket> OtherPacket last(NoThrow_t) const;
104 template <class OtherPacket> OtherPacket parseNextAs() const;
105 Packet parseNextAs(factory_t factory) const;
106 template <class OtherPacket> bool is() const;
107 template <class OtherPacket> OtherPacket as() const;
109 Packet append(Packet packet) const;
116 PacketData & data() const;
117 size_type size() const;
121 ///\name Other methods
124 bool operator==(Packet other) const;
125 bool boolean_test() const;
127 void finalize() const;
129 void dump(std::ostream & os) const;
131 TypeIdValue typeId() const;
132 factory_t factory() const;
137 explicit Packet(PacketInterpreterBase::ptr packet);
139 PacketInterpreterBase::ptr ptr() const;
142 Packet checkNext() const;
143 Packet checkLast() const;
145 PacketInterpreterBase::ptr packet_;
147 template <class PacketType>
148 friend class ConcretePacket;
153 template <class PacketType>
158 ///////////////////////////////////////////////////////////////////////////
161 typedef PacketType type;
162 typedef PacketInterpreter<PacketType> interpreter;
164 ///////////////////////////////////////////////////////////////////////////
165 ///\name Structors and default members
168 // default copy constructor
169 // default copy assignment
170 // default destructor
171 // no conversion constructors
175 static factory_t factory();
177 // Create completely new packet
179 static ConcretePacket create();
180 static ConcretePacket create(NoInit_t);
181 static ConcretePacket create(size_type size);
182 static ConcretePacket create(size_type size, NoInit_t);
183 template <class ForwardReadableRange>
184 static ConcretePacket create(ForwardReadableRange const & range);
186 // Create packet as new packet after a given packet
188 static ConcretePacket createAfter(Packet packet);
189 static ConcretePacket createAfter(Packet packet, NoInit_t);
190 static ConcretePacket createAfter(Packet packet, size_type size);
191 static ConcretePacket createAfter(Packet packet, size_type size, NoInit_t);
192 template <class ForwardReadableRange>
193 static ConcretePacket createAfter(Packet packet,
194 ForwardReadableRange const & range);
196 // Create packet as new packet (header) before a given packet
198 static ConcretePacket createBefore(Packet packet);
199 static ConcretePacket createBefore(Packet packet, NoInit_t);
201 // Create a clone of the current packet
203 ConcretePacket clone() const;
206 ///////////////////////////////////////////////////////////////////////////
210 typename interpreter::parser * operator->() const;
215 ConcretePacket(typename interpreter::ptr packet_);
217 typename interpreter::ptr ptr() const;
220 friend class PacketInterpreter<PacketType>;
225 ///////////////////////////////hh.e////////////////////////////////////////
226 #include "Packet.cci"
228 #include "Packet.cti"
235 // c-file-style: "senf"
236 // indent-tabs-mode: nil
237 // ispell-local-dictionary: "american"
238 // compile-command: "scons -u test"