A Discrete-Event Network Simulator
API
byte-tag-list.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef BYTE_TAG_LIST_H
20 #define BYTE_TAG_LIST_H
21 
22 #define __STDC_LIMIT_MACROS
23 #include "tag-buffer.h"
24 
25 #include "ns3/type-id.h"
26 
27 #include <stdint.h>
28 
29 namespace ns3
30 {
31 
32 struct ByteTagListData;
33 
66 {
67  public:
74  class Iterator
75  {
76  public:
83  struct Item
84  {
86  uint32_t size;
87  int32_t start;
88  int32_t end;
90 
94 
95  private:
97  friend class ByteTagList;
99  friend class ByteTagList::Iterator;
100  };
101 
107  bool HasNext() const;
108 
115 
121  uint32_t GetOffsetStart() const;
122 
123  private:
125  friend class ByteTagList;
126 
135  Iterator(uint8_t* start,
136  uint8_t* end,
137  int32_t offsetStart,
138  int32_t offsetEnd,
139  int32_t adjustment);
140 
144  void PrepareForNext();
145  uint8_t* m_current;
146  uint8_t* m_end;
147  int32_t m_offsetStart;
148  int32_t m_offsetEnd;
149  int32_t m_adjustment;
150  uint32_t m_nextTid;
151  uint32_t m_nextSize;
152  int32_t m_nextStart;
153  int32_t m_nextEnd;
154  };
155 
156  ByteTagList();
157 
165  ByteTagList(const ByteTagList& o);
166 
176  ByteTagList& operator=(const ByteTagList& o);
177  ~ByteTagList();
178 
189  TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end);
190 
196  void Add(const ByteTagList& o);
197 
202  void RemoveAll();
203 
215  ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const;
216 
222  inline void Adjust(int32_t adjustment);
223 
231  void AddAtEnd(int32_t appendOffset);
239  void AddAtStart(int32_t prependOffset);
245  uint32_t GetSerializedSize() const;
254  uint32_t Serialize(uint32_t* buffer, uint32_t maxSize) const;
263  uint32_t Deserialize(const uint32_t* buffer, uint32_t size);
264 
265  private:
272 
278  ByteTagListData* Allocate(uint32_t size);
279 
285 
286  int32_t m_minStart;
287  int32_t m_maxEnd;
288  int32_t m_adjustment;
289  uint32_t m_used;
291 };
292 
293 void
294 ByteTagList::Adjust(int32_t adjustment)
295 {
296  m_adjustment += adjustment;
297 }
298 
299 } // namespace ns3
300 
301 #endif /* BYTE_TAG_LIST_H */
An iterator for iterating through a byte tag list.
Definition: byte-tag-list.h:75
uint8_t * m_current
Current tag.
int32_t m_adjustment
Adjustment to byte tag offsets.
int32_t m_offsetEnd
Offset to the end of the tag from the virtual byte buffer.
ByteTagList::Iterator::Item Next()
Returns the next Item from the ByteTagList.
void PrepareForNext()
Prepare the iterator for the next tag.
int32_t m_nextEnd
End of the next tag.
uint32_t GetOffsetStart() const
Returns the offset from the start of the virtual byte buffer to the ByteTagList.
int32_t m_nextStart
Start of the next tag.
int32_t m_offsetStart
Offset to the start of the tag from the virtual byte buffer.
uint32_t m_nextSize
Size of the next tag.
Iterator(uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd, int32_t adjustment)
Constructor.
bool HasNext() const
Used to determine if the iterator is at the end of the byteTagList.
uint32_t m_nextTid
TypeId of the next tag.
uint8_t * m_end
End tag.
keep track of the byte tags stored in a packet.
Definition: byte-tag-list.h:66
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Deserialize tag list from the provided buffer.
void AddAtEnd(int32_t appendOffset)
Make sure that all offsets are smaller than appendOffset which represents the location where new byte...
void Deallocate(ByteTagListData *data)
Deallocates a ByteTagListData.
ByteTagList & operator=(const ByteTagList &o)
Assignment operator, deallocates current data and assigns value of passed in ByteTagList.
void Adjust(int32_t adjustment)
Adjust the offsets stored internally by the adjustment delta.
ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const
int32_t m_minStart
minimal start offset
uint32_t m_used
the number of used bytes in the buffer
ByteTagListData * Allocate(uint32_t size)
Allocate the memory for the ByteTagListData.
ByteTagList::Iterator BeginAll() const
Returns an iterator pointing to the very first tag in this list.
void RemoveAll()
Removes all of the tags from the ByteTagList.
int32_t m_adjustment
adjustment to byte tag offsets
TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Serialize the tag list into a byte buffer.
void AddAtStart(int32_t prependOffset)
Make sure that all offsets are bigger than prependOffset which represents the location where new byte...
int32_t m_maxEnd
maximal end offset
ByteTagListData * m_data
the ByteTagListData structure
uint32_t GetSerializedSize() const
Returns number of bytes required for packet serialization.
read and write tag data
Definition: tag-buffer.h:52
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]
An item specifies an individual tag within a byte buffer.
Definition: byte-tag-list.h:84
TypeId tid
type of the tag
Definition: byte-tag-list.h:85
TagBuffer buf
the data for the tag as generated by Tag::Serialize
Definition: byte-tag-list.h:89
uint32_t size
size of tag data
Definition: byte-tag-list.h:86
int32_t end
offset to the end of the tag from the virtual byte buffer
Definition: byte-tag-list.h:88
Item(TagBuffer buf)
Constructs an item with the given TagBuffer.
int32_t start
offset to the start of the tag from the virtual byte buffer
Definition: byte-tag-list.h:87
Internal representation of the byte tags stored in a packet.