A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
23
#include <stdint.h>
24
#include <ostream>
25
#include "ns3/type-id.h"
26
27
namespace
ns3 {
28
29
class
Tag;
30
37
#define PACKET_TAG_MAX_SIZE 20
38
39
class
PacketTagList
40
{
41
public
:
42
struct
TagData
{
43
uint8_t
data
[
PACKET_TAG_MAX_SIZE
];
44
struct
TagData
*
next
;
45
TypeId
tid
;
46
uint32_t
count
;
47
};
48
49
inline
PacketTagList
();
50
inline
PacketTagList
(
PacketTagList
const
&o);
51
inline
PacketTagList
&
operator =
(
PacketTagList
const
&o);
52
inline
~PacketTagList
();
53
54
void
Add
(
Tag
const
&tag)
const
;
55
bool
Remove
(
Tag
&tag);
56
bool
Peek
(
Tag
&tag)
const
;
57
inline
void
RemoveAll
(
void
);
58
59
const
struct
PacketTagList::TagData
*
Head
(
void
)
const
;
60
61
private
:
62
63
bool
Remove
(
TypeId
tid);
64
struct
PacketTagList::TagData
*
AllocData
(
void
)
const
;
65
void
FreeData
(
struct
TagData
*
data
)
const
;
66
67
static
struct
PacketTagList::TagData
*
g_free
;
68
static
uint32_t
g_nfree
;
69
70
struct
TagData
*
m_next
;
71
};
72
73
}
// namespace ns3
74
75
/****************************************************
76
* Implementation of inline methods for performance
77
****************************************************/
78
79
namespace
ns3 {
80
81
PacketTagList::PacketTagList
()
82
: m_next ()
83
{
84
}
85
86
PacketTagList::PacketTagList
(
PacketTagList
const
&o)
87
: m_next (o.m_next)
88
{
89
if
(
m_next
!= 0)
90
{
91
m_next
->
count
++;
92
}
93
}
94
95
PacketTagList
&
96
PacketTagList::operator =
(
PacketTagList
const
&o)
97
{
98
// self assignment
99
if
(
m_next
== o.
m_next
)
100
{
101
return
*
this
;
102
}
103
RemoveAll
();
104
m_next
= o.
m_next
;
105
if
(
m_next
!= 0)
106
{
107
m_next
->
count
++;
108
}
109
return
*
this
;
110
}
111
112
PacketTagList::~PacketTagList
()
113
{
114
RemoveAll
();
115
}
116
117
void
118
PacketTagList::RemoveAll
(
void
)
119
{
120
struct
TagData
*prev = 0;
121
for
(
struct
TagData
*cur =
m_next
; cur != 0; cur = cur->
next
)
122
{
123
cur->
count
--;
124
if
(cur->count > 0)
125
{
126
break
;
127
}
128
if
(prev != 0)
129
{
130
FreeData
(prev);
131
}
132
prev = cur;
133
}
134
if
(prev != 0)
135
{
136
FreeData
(prev);
137
}
138
m_next
= 0;
139
}
140
141
}
// namespace ns3
142
143
#endif
/* PACKET_TAG_LIST_H */
src
network
model
packet-tag-list.h
Generated on Fri Dec 21 2012 19:00:43 for ns-3 by
1.8.1.2