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 PacketData public header */
24 #ifndef HH_PacketData_
25 #define HH_PacketData_ 1
28 #include <boost/utility.hpp>
29 #include <boost/type_traits.hpp>
30 #include <boost/iterator/iterator_facade.hpp>
31 #include "Utils/SafeBool.hh"
32 #include "PacketTypes.hh"
34 //#include "PacketData.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
41 PacketData only exists to separate out the container interface from PacketInterpreter.
47 ///////////////////////////////////////////////////////////////////////////
50 typedef senf::detail::packet::smart_pointer<PacketData>::ptr_t ptr;
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 byte value_type;
58 typedef byte & reference;
59 typedef byte const & const_reference;
60 typedef byte * pointer;
61 typedef byte const * const_pointer;
63 ///////////////////////////////////////////////////////////////////////////
64 ///\name Structors and default members
67 // no public constructors
68 // no conversion constructors
71 ///////////////////////////////////////////////////////////////////////////
73 ///\name Sequence interface to raw data
76 iterator begin() const;
78 size_type size() const;
80 byte operator[](size_type n) const;
81 byte & operator[](size_type n);
83 // Modifying the raw packet data
85 // IMPORTANT NOTE: It is not possible to insert data AFTER an empty packet
86 // since for an empty packet begin() == end(). However, I hope this problem is
87 // only academic since what should an empty packet be good for ?
88 void insert(iterator pos, byte v);
89 void insert(iterator pos, size_type n, byte v);
90 template <class InputIterator>
91 void insert(iterator pos, InputIterator f, InputIterator l,
92 typename boost::disable_if< boost::is_convertible<InputIterator,size_type> >::type * = 0);
94 void erase(iterator pos);
95 void erase(iterator first, iterator last);
98 void resize(size_type n, byte v=0);
105 PacketData(size_type b, size_type e);
107 detail::PacketImpl * impl_;
109 detail::PacketImpl & impl() const;
115 friend class detail::PacketImpl;
118 class PacketParserBase;
120 struct TruncatedPacketException : public std::exception
121 { virtual char const * what() const throw() { return "truncated packet"; } };
123 class safe_data_iterator
124 : public boost::iterator_facade< safe_data_iterator,
125 PacketData::value_type,
126 boost::random_access_traversal_tag >,
127 public ComparableSafeBool<safe_data_iterator>
130 typedef PacketData::size_type size_type;
132 safe_data_iterator();
133 explicit safe_data_iterator(PacketData & data);
134 safe_data_iterator(PacketData & data, PacketData::iterator i);
135 explicit safe_data_iterator(PacketParserBase const & parser);
137 safe_data_iterator & operator=(PacketData::iterator i);
138 safe_data_iterator & operator=(PacketParserBase const & parser);
139 operator PacketData::iterator() const;
141 bool boolean_test() const;
143 PacketData & data() const;
146 friend class boost::iterator_core_access;
148 // iterator_facade interface
150 value_type & dereference() const;
151 bool equal(safe_data_iterator const & other) const;
152 difference_type distance_to(safe_data_iterator const & other) const;
155 void advance(difference_type n);
157 PacketData::iterator i() const;
164 ///////////////////////////////hh.e////////////////////////////////////////
166 #if !defined(HH_PacketData_DeclOnly) &&!defined(HH_PacketData_def)
167 #define HH_PacketData_def
168 #include "PacketData.cci"
169 //#include "PacketData.ct"
170 #include "PacketData.cti"
177 // c-file-style: "senf"
178 // indent-tabs-mode: nil
179 // ispell-local-dictionary: "american"
180 // compile-command: "scons -u test"
181 // comment-column: 40