View | Details | Raw Unified | Return to bug 118
Collapse All | Expand All

(-)a/src/common/packet.h (-3 / +15 lines)
 Lines 158-172   public: Link Here 
158
  template <typename T>
158
  template <typename T>
159
  uint32_t RemoveTrailer (T &trailer);
159
  uint32_t RemoveTrailer (T &trailer);
160
  /**
160
  /**
161
   * \param tag a pointer to the tag to attach to this packet.
162
   *
161
   * Attach a tag to this packet. The tag is fully copied
163
   * Attach a tag to this packet. The tag is fully copied
162
   * in a packet-specific internal buffer. This operation 
164
   * in a packet-specific internal buffer. This operation 
163
   * is expected to be really fast. The copy constructor of the
165
   * is expected to be really fast. The copy constructor of the
164
   * tag is invoked to copy it into the tag buffer.
166
   * tag is invoked to copy it into the tag buffer.
165
   *
167
   *
166
   * \param tag a pointer to the tag to attach to this packet.
168
   * Note that adding a tag is a const operation which is pretty 
169
   * un-intuitive. The rationale is that the content and behavior of
170
   * a packet is _not_ changed when a tag is added to a packet: any
171
   * code which was not aware of the new tag is going to work just
172
   * the same if the new tag is added. The real reason why adding a
173
   * tag was made a const operation is to allow a trace sink which gets
174
   * a packet to tag the packet, even if the packet is const (and most
175
   * trace sources should use const packets because it would be
176
   * totally evil to allow a trace sink to modify the content of a
177
   * packet).
178
   *
167
   */
179
   */
168
  template <typename T>
180
  template <typename T>
169
  void AddTag (T const &tag);
181
  void AddTag (T const &tag) const;
170
  /**
182
  /**
171
   * Remove a tag from this packet. The data stored internally
183
   * Remove a tag from this packet. The data stored internally
172
   * for this tag is copied in the input tag if an instance
184
   * for this tag is copied in the input tag if an instance
 Lines 450-456   Packet::RemoveTrailer (T &trailer) Link Here 
450
462
451
463
452
template <typename T>
464
template <typename T>
453
void Packet::AddTag (T const& tag)
465
void Packet::AddTag (T const& tag) const
454
{
466
{
455
  const Tag *parent;
467
  const Tag *parent;
456
  // if the following assignment fails, it is because the
468
  // if the following assignment fails, it is because the
(-)a/src/common/tags.cc (-4 / +4 lines)
 Lines 30-36   uint32_t Tags::gN_free = 0; Link Here 
30
uint32_t Tags::gN_free = 0;
30
uint32_t Tags::gN_free = 0;
31
31
32
struct Tags::TagData *
32
struct Tags::TagData *
33
Tags::AllocData (void)
33
Tags::AllocData (void) const
34
{
34
{
35
  struct Tags::TagData *retval;
35
  struct Tags::TagData *retval;
36
  if (gFree != 0) 
36
  if (gFree != 0) 
 Lines 47-53   Tags::AllocData (void) Link Here 
47
}
47
}
48
48
49
void
49
void
50
Tags::FreeData (struct TagData *data)
50
Tags::FreeData (struct TagData *data) const
51
{
51
{
52
  if (gN_free > 1000) 
52
  if (gN_free > 1000) 
53
    {
53
    {
 Lines 61-67   Tags::FreeData (struct TagData *data) Link Here 
61
}
61
}
62
#else
62
#else
63
struct Tags::TagData *
63
struct Tags::TagData *
64
Tags::AllocData (void)
64
Tags::AllocData (void) const
65
{
65
{
66
  struct Tags::TagData *retval;
66
  struct Tags::TagData *retval;
67
  retval = new struct Tags::TagData ();
67
  retval = new struct Tags::TagData ();
 Lines 69-75   Tags::AllocData (void) Link Here 
69
}
69
}
70
70
71
void
71
void
72
Tags::FreeData (struct TagData *data)
72
Tags::FreeData (struct TagData *data) const
73
{
73
{
74
  delete data;
74
  delete data;
75
}
75
}
(-)a/src/common/tags.h (-5 / +5 lines)
 Lines 44-50   public: Link Here 
44
  inline ~Tags ();
44
  inline ~Tags ();
45
45
46
  template <typename T>
46
  template <typename T>
47
  void Add (T const&tag);
47
  void Add (T const&tag) const;
48
48
49
  template <typename T>
49
  template <typename T>
50
  bool Remove (T &tag);
50
  bool Remove (T &tag);
 Lines 71-78   private: Link Here 
71
  };
71
  };
72
72
73
  bool Remove (uint32_t id);
73
  bool Remove (uint32_t id);
74
  struct Tags::TagData *AllocData (void);
74
  struct Tags::TagData *AllocData (void) const;
75
  void FreeData (struct TagData *data);
75
  void FreeData (struct TagData *data) const;
76
76
77
  static struct Tags::TagData *gFree;
77
  static struct Tags::TagData *gFree;
78
  static uint32_t gN_free;
78
  static uint32_t gN_free;
 Lines 96-102   namespace ns3 { Link Here 
96
96
97
template <typename T>
97
template <typename T>
98
void 
98
void 
99
Tags::Add (T const&tag)
99
Tags::Add (T const&tag) const
100
{
100
{
101
  const Tag *parent;
101
  const Tag *parent;
102
  // if the following assignment fails, it is because the
102
  // if the following assignment fails, it is because the
 Lines 116-122   Tags::Add (T const&tag) Link Here 
116
  void *buf = &newStart->m_data;
116
  void *buf = &newStart->m_data;
117
  new (buf) T (tag);
117
  new (buf) T (tag);
118
  newStart->m_next = m_next;
118
  newStart->m_next = m_next;
119
  m_next = newStart;
119
  const_cast<Tags *> (this)->m_next = newStart;
120
}
120
}
121
121
122
template <typename T>
122
template <typename T>

Return to bug 118