A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 = 20
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);
191  inline PacketTagList &operator = (PacketTagList const &o);
197  inline ~PacketTagList ();
198 
204  void Add (Tag const&tag) const;
212  bool Remove (Tag &tag);
222  bool Replace (Tag &tag);
230  bool Peek (Tag &tag) const;
234  inline void RemoveAll (void);
238  const struct PacketTagList::TagData *Head (void) const;
239 
240 private:
252  typedef bool (PacketTagList::*COWWriter)
253  (Tag & tag, bool preMerge,
254  struct TagData * cur, struct TagData ** prevNext);
262  bool COWTraverse (Tag & tag, PacketTagList::COWWriter Writer);
274  bool RemoveWriter (Tag & tag, bool preMerge,
275  struct TagData * cur, struct TagData ** prevNext);
287  bool ReplaceWriter (Tag & tag, bool preMerge, struct TagData * cur, struct TagData ** prevNext);
288 
292  struct TagData *m_next;
293 };
294 
295 } // namespace ns3
296 
297 /****************************************************
298  * Implementation of inline methods for performance
299  ****************************************************/
300 
301 namespace ns3 {
302 
304  : m_next ()
305 {
306 }
307 
309  : m_next (o.m_next)
310 {
311  if (m_next != 0)
312  {
313  m_next->count++;
314  }
315 }
316 
319 {
320  // self assignment
321  if (m_next == o.m_next)
322  {
323  return *this;
324  }
325  RemoveAll ();
326  m_next = o.m_next;
327  if (m_next != 0)
328  {
329  m_next->count++;
330  }
331  return *this;
332 }
333 
335 {
336  RemoveAll ();
337 }
338 
339 void
341 {
342  struct TagData *prev = 0;
343  for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
344  {
345  cur->count--;
346  if (cur->count > 0)
347  {
348  break;
349  }
350  if (prev != 0)
351  {
352  delete prev;
353  }
354  prev = cur;
355  }
356  if (prev != 0)
357  {
358  delete prev;
359  }
360  m_next = 0;
361 }
362 
363 } // namespace ns3
364 
365 #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.
struct TagData * next
Pointer to next in list.
const struct PacketTagList::TagData * Head(void) const
List of the packet tags stored in a packet.
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 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.
TagData_e
Packet Tag maximum size.
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.
Size of serialization buffer data.
TypeId tid
Type of the tag serialized into data.
PacketTagList & operator=(PacketTagList const &o)
Assignment.
bool(PacketTagList::* COWWriter)(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Typedef of method function pointer for copy-on-write operations.
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
a unique identifier for an interface.
Definition: type-id.h:49
uint32_t count
Number of incoming links.