PacketData.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Packets_PacketData_
18 #define HH_SENF_Packets_PacketData_ 1
19 
20 // Custom includes
21 #include <boost/noncopyable.hpp>
22 #include <boost/utility/enable_if.hpp>
23 #include <boost/type_traits/is_convertible.hpp>
24 #include <senf/Utils/Exception.hh>
25 
26 //#include "PacketData.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 
31  class PacketInfo;
32 
61  class PacketData
62  : boost::noncopyable
63  {
64  public:
65  //-////////////////////////////////////////////////////////////////////////
66  // Types
67 
73  typedef byte value_type;
74  typedef byte & reference;
75  typedef byte const & const_reference;
76  typedef byte * pointer;
77  typedef byte const * const_pointer;
78 
79  //-////////////////////////////////////////////////////////////////////////
81  //\{
82 
83  // no public constructors
84  // no conversion constructors
85 
86  //\}
87  //-////////////////////////////////////////////////////////////////////////
88 
90  //\{
91 
92  iterator begin() const;
93 
95  iterator end() const;
96 
98  size_type size() const;
99  bool empty() const;
100 
103  byte operator[](size_type n) const;
104  byte & operator[](size_type n);
105 
106  // Modifying the raw packet data
107 
108  // IMPORTANT NOTE: It is not possible to insert data AFTER an empty packet
109  // since for an empty packet begin() == end(). However, I hope this problem is
110  // only academic since what should an empty packet be good for ?
111  void insert(iterator pos, byte v);
112  void insert(iterator pos, size_type n, byte v);
113 # ifndef DOXYGEN
114  template <class InputIterator>
115  void insert(iterator pos, InputIterator f, InputIterator l,
116  typename boost::disable_if< boost::is_convertible<InputIterator,size_type> >::type * = 0);
117 # else
118  template <class InputIterator>
119  void insert(iterator pos, InputIterator f, InputIterator l);
120 # endif
121 
122  void erase(iterator pos);
123  void erase(iterator first, iterator last);
124  void clear();
125  void zero(iterator first, iterator last);
126 
127  void resize(size_type n, byte v=0);
128 
129  bool usingExternalMemory() const;
130 
138  void releaseExternalMemory();
139 
149  //\}
150 
151  protected:
152  PacketData(size_type b, size_type e);
153 
156 
157  detail::PacketImpl & impl() const;
158 
159  bool valid();
160 
161  private:
162  size_type begin_;
163  size_type end_;
164 
165  friend class detail::PacketImpl;
166  friend class PacketInfo;
167  };
168 
169 
176  {
177  TruncatedPacketException(std::string const & description = "")
178  : senf::Exception("truncated packet") { append( description); }
179  };
180 
181 }
182 
183 //-/////////////////////////////////////////////////////////////////////////////////////////////////
184 #endif
185 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketData_i_)
186 #define HH_SENF_Packets_PacketData_i_
187 #include "PacketData.cci"
188 //#include "PacketData.ct"
189 #include "PacketData.cti"
190 #endif
191 
192 
193 // Local Variables:
194 // mode: c++
195 // fill-column: 100
196 // c-file-style: "senf"
197 // indent-tabs-mode: nil
198 // ispell-local-dictionary: "american"
199 // compile-command: "scons -u test"
200 // comment-column: 40
201 // End:
void clear()
All bytes of the packet data dropped, leaving the container with a size of 0. */. ...
detail::PacketImpl & impl() const
TruncatedPacketException(std::string const &description="")
Definition: PacketData.hh:177
void zero(iterator first, iterator last)
detail::PacketImpl * impl_
Need to make this protected so we can change it in the derived class.
Definition: PacketData.hh:155
senf::detail::packet::iterator iterator
Definition: PacketData.hh:68
bool usingExternalMemory() const
Check for external memory usage.
iterator begin() const
Return iterator to beginning.
void resize(size_type n, byte v=0)
Definition: PacketData.cc:28
byte operator[](size_type n) const
Access byte in the packet data.
PacketData(size_type b, size_type e)
byte const & const_reference
Definition: PacketData.hh:75
byte const * const_pointer
Definition: PacketData.hh:77
iterator end() const
Return iterator to end.
senf::detail::packet::difference_type difference_type
Definition: PacketData.hh:71
raw_container::const_iterator const_iterator
Definition: PacketTypes.hh:70
void releaseExternalMemory()
Release external memory.
Packet data STL-sequence view.
Definition: PacketData.hh:61
raw_container::size_type size_type
Definition: PacketTypes.hh:66
senf::detail::packet::const_iterator const_iterator
Definition: PacketData.hh:69
Internal: Packet data storage.
Definition: PacketImpl.hh:112
raw_container::iterator iterator
Definition: PacketTypes.hh:69
senf::detail::packet::size_type size_type
Definition: PacketData.hh:70
unspecified_keyword_type description
size_type size() const
Returns the number of bytes in the packet data.
raw_container::difference_type difference_type
Definition: PacketTypes.hh:67
void erase(iterator pos)
boost::uint8_t byte
Definition: PacketTypes.hh:60
void insert(iterator pos, byte v)
senf::detail::packet::byte byte
Definition: PacketData.hh:72
bool empty() const
Test whether the packet data is empty.
Invalid packet data access.
Definition: PacketData.hh:175