4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief PacketData public header */
26 #ifndef HH_SENF_Packets_PacketData_
27 #define HH_SENF_Packets_PacketData_ 1
30 #include <boost/utility.hpp>
31 #include <boost/type_traits.hpp>
32 #include "../Utils/safe_bool.hh"
33 #include "../Utils/Exception.hh"
34 #include "PacketTypes.hh"
36 //#include "PacketData.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
41 /** \brief Packet data STL-sequence view
43 The PacketData class provides an STL-sequence compatible view of the raw packet data. Each
44 packet/header/interpreter in the chain references the same storage area, presenting a
45 different (but nested/overlapping) section of the data.
47 Whenever the data is manipulated through PacketData, the change is assumed to be within the
48 data range of that packet: All insertions take place \e inside \c this packet and \e outside
49 any following packets in the packet chain.
51 \warning It is not permissible to change data belonging to a following
52 packet/header/interpreter even though this data is part of \c this sequence. Doing so
53 will corrupt the packet data.
57 \warning When accessing packet data via the PacketData interface you are on your own: The
58 packet is not validated in any way, you bypass all parsers.
60 All public members are those of an STL random-access sequence.
62 \implementation This class is very tightly integrated with PacketInterpreterBase /
63 PacketInterpreter. It is separated out of those classes primarily to provide a clean
64 sequence interface to the library user and not for implementation reasons (it would have
65 been simpler to implement all these members in PacketInterpreterBase).
67 \ingroup packet_module
73 ///////////////////////////////////////////////////////////////////////////
76 typedef senf::detail::packet::iterator iterator;
77 typedef senf::detail::packet::const_iterator const_iterator;
78 typedef senf::detail::packet::size_type size_type;
79 typedef senf::detail::packet::difference_type difference_type;
80 typedef senf::detail::packet::byte byte;
81 typedef byte value_type;
82 typedef byte & reference;
83 typedef byte const & const_reference;
84 typedef byte * pointer;
85 typedef byte const * const_pointer;
87 ///////////////////////////////////////////////////////////////////////////
88 ///\name Structors and default members
91 // no public constructors
92 // no conversion constructors
95 ///////////////////////////////////////////////////////////////////////////
97 ///\name Sequence interface to raw data
100 iterator begin() const; ///< Return iterator to beginning
101 /**< Returns an <em>random access iterator</em> referring to the
102 first byte of the packet data. */
103 iterator end() const; ///< Return iterator to end
104 /**< Returns an <em>random access iterator</em> referring to the
105 byte past the end of the packet data. */
106 size_type size() const; ///< Returns the number of bytes in the packet data.
107 bool empty() const; ///< Test whether the packet data is empty.
108 /**< Returns whether the packet data is empty, i.e. whether its size
109 is 0. This function does not modify the content of the packet
110 data in any way. To clear the content use clear() */
111 byte operator[](size_type n) const; ///< Access byte in the packet data
112 byte & operator[](size_type n); ///< Access byte in the packet data
114 // Modifying the raw packet data
116 // IMPORTANT NOTE: It is not possible to insert data AFTER an empty packet
117 // since for an empty packet begin() == end(). However, I hope this problem is
118 // only academic since what should an empty packet be good for ?
119 void insert(iterator pos, byte v);
120 void insert(iterator pos, size_type n, byte v);
122 template <class InputIterator>
123 void insert(iterator pos, InputIterator f, InputIterator l,
124 typename boost::disable_if< boost::is_convertible<InputIterator,size_type> >::type * = 0);
126 template <class InputIterator>
127 void insert(iterator pos, InputIterator f, InputIterator l);
130 void erase(iterator pos);
131 void erase(iterator first, iterator last);
132 void clear(); ///< All bytes of the packet data dropped, leaving the container with a size of 0. */
134 void resize(size_type n, byte v=0);
136 void reserve(size_type n);
137 size_type capacity() const;
142 PacketData(size_type b, size_type e);
144 /// Need to make this protected so we can change it in the derived class
145 detail::PacketImpl * impl_;
147 detail::PacketImpl & impl() const;
155 friend class detail::PacketImpl;
158 class PacketParserBase;
160 /** \brief Invalid packet data access
162 This exception is signaled whenever an operation tries to access an out-of-bounds data
163 byte. If the packet has been implemented correctly, this signals a malformed packet.
165 struct TruncatedPacketException : public senf::Exception
166 { TruncatedPacketException() : senf::Exception("truncated packet"){} };
170 ///////////////////////////////hh.e////////////////////////////////////////
172 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketData_i_)
173 #define HH_SENF_Packets_PacketData_i_
174 #include "PacketData.cci"
175 //#include "PacketData.ct"
176 #include "PacketData.cti"
183 // c-file-style: "senf"
184 // indent-tabs-mode: nil
185 // ispell-local-dictionary: "american"
186 // compile-command: "scons -u test"
187 // comment-column: 40