A Discrete-Event Network Simulator
API
packet-tag-list.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef PACKET_TAG_LIST_H
21 #define PACKET_TAG_LIST_H
22 
28 #include <stdint.h>
29 #include <ostream>
30 #include "ns3/type-id.h"
31 
32 namespace ns3 {
33 
34 class Tag;
35 
130 {
131 public:
140  struct TagData
141  {
160  {
161  MAX_SIZE = 21
162  };
163 
164  uint8_t data[MAX_SIZE];
165  struct TagData * next;
167  uint32_t count;
168  }; /* struct TagData */
169 
173  inline PacketTagList ();
182  inline PacketTagList (PacketTagList const &o);
192  inline PacketTagList &operator = (PacketTagList const &o);
198  inline ~PacketTagList ();
199 
205  void Add (Tag const&tag) const;
213  bool Remove (Tag &tag);
223  bool Replace (Tag &tag);
231  bool Peek (Tag &tag) const;
235  inline void RemoveAll (void);
239  const struct PacketTagList::TagData *Head (void) const;
240 
241 private:
253  typedef bool (PacketTagList::*COWWriter)
254  (Tag & tag, bool preMerge,
255  struct TagData * cur, struct TagData ** prevNext);
263  bool COWTraverse (Tag & tag, PacketTagList::COWWriter Writer);
275  bool RemoveWriter (Tag & tag, bool preMerge,
276  struct TagData * cur, struct TagData ** prevNext);
288  bool ReplaceWriter (Tag & tag, bool preMerge, struct TagData * cur, struct TagData ** prevNext);
289 
293  struct TagData *m_next;
294 };
295 
296 } // namespace ns3
297 
298 /****************************************************
299  * Implementation of inline methods for performance
300  ****************************************************/
301 
302 namespace ns3 {
303 
305  : m_next ()
306 {
307 }
308 
310  : m_next (o.m_next)
311 {
312  if (m_next != 0)
313  {
314  m_next->count++;
315  }
316 }
317 
320 {
321  // self assignment
322  if (m_next == o.m_next)
323  {
324  return *this;
325  }
326  RemoveAll ();
327  m_next = o.m_next;
328  if (m_next != 0)
329  {
330  m_next->count++;
331  }
332  return *this;
333 }
334 
336 {
337  RemoveAll ();
338 }
339 
340 void
342 {
343  struct TagData *prev = 0;
344  for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
345  {
346  cur->count--;
347  if (cur->count > 0)
348  {
349  break;
350  }
351  if (prev != 0)
352  {
353  delete prev;
354  }
355  prev = cur;
356  }
357  if (prev != 0)
358  {
359  delete prev;
360  }
361  m_next = 0;
362 }
363 
364 } // namespace ns3
365 
366 #endif /* PACKET_TAG_LIST_H */
~PacketTagList()
Destructor.
uint8_t data[MAX_SIZE]
Serialization buffer.
bool Remove(Tag &tag)
Remove (the first instance of) tag from the list.
Size of serialization buffer data.
struct TagData * next
Pointer to next in list.
const struct PacketTagList::TagData * Head(void) const
List of the packet tags stored in a packet.
TagData_e
Packet Tag maximum size.
bool Peek(Tag &tag) const
Find a tag and return its value.
void Add(Tag const &tag) const
Add a tag to the head of this branch.
bool ReplaceWriter(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Copy-on-write implementing Replace.
Tree node for sharing serialized tags.
bool(PacketTagList::* COWWriter)(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Typedef of method function pointer for copy-on-write operations.
bool Replace(Tag &tag)
Replace the value of a tag.
bool RemoveWriter(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Copy-on-write implementing Remove.
PacketTagList()
Create a new PacketTagList.
tag a set of bytes in a packet
Definition: tag.h:36
bool COWTraverse(Tag &tag, PacketTagList::COWWriter Writer)
Traverse the list implementing copy-on-write, using Writer.
struct TagData * m_next
Pointer to first TagData on the list.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TypeId tid
Type of the tag serialized into data.
PacketTagList & operator=(PacketTagList const &o)
Assignment.
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t count
Number of incoming links.