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

(-)a/src/config-store/model/attribute-default-iterator.cc (-3 / +10 lines)
 Lines 22-28    Link Here 
22
#include "ns3/pointer.h"
22
#include "ns3/pointer.h"
23
#include "ns3/global-value.h"
23
#include "ns3/global-value.h"
24
#include "ns3/string.h"
24
#include "ns3/string.h"
25
#include "ns3/object-ptr-container.h"
25
#include "ns3/object-ptr-vector.h"
26
#include "ns3/object-ptr-map.h"
26
27
27
namespace ns3
28
namespace ns3
28
{
29
{
 Lines 70-88    Link Here 
70
              //No value, check next attribute
71
              //No value, check next attribute
71
              continue;
72
              continue;
72
            }
73
            }
73
          Ptr<const ObjectPtrContainerValue> vector = DynamicCast<const ObjectPtrContainerValue> (info.initialValue);
74
          Ptr<const ObjectPtrVectorValue> vector = DynamicCast<const ObjectPtrVectorValue> (info.initialValue);
74
          if (vector != 0)
75
          if (vector != 0)
75
            {
76
            {
76
              //a vector value, won't take it
77
              //a vector value, won't take it
77
              continue;
78
              continue;
78
            }
79
            }
80
          Ptr<const ObjectPtrMapValue> map = DynamicCast<const ObjectPtrMapValue> (info.initialValue);
81
          if (map != 0)
82
            {
83
              //a map value, won't take it
84
              continue;
85
            }
79
          Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (info.initialValue);
86
          Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (info.initialValue);
80
          if (pointer != 0)
87
          if (pointer != 0)
81
            {
88
            {
82
              //pointer value, won't take it
89
              //pointer value, won't take it
83
              continue;
90
              continue;
84
            }
91
            }
85
          //We take only values, no pointers or vectors
92
          //We take only values, no pointers or vectors or maps
86
          if (!calledStart)
93
          if (!calledStart)
87
            {
94
            {
88
              StartVisitTypeId (tid.GetName ());
95
              StartVisitTypeId (tid.GetName ());
(-)a/src/config-store/model/attribute-iterator.cc (-237 / +321 lines)
 Lines 30-283    Link Here 
30
namespace ns3 {
30
namespace ns3 {
31
31
32
32
33
AttributeIterator::AttributeIterator ()
33
  AttributeIterator::AttributeIterator ()
34
{
34
  {
35
}
35
  }
36
36
37
AttributeIterator::~AttributeIterator ()
37
  AttributeIterator::~AttributeIterator ()
38
{
38
  {
39
}
39
  }
40
40
41
void 
41
  void
42
AttributeIterator::Iterate (void)
42
  AttributeIterator::Iterate (void)
43
{
43
  {
44
  for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i)
44
    for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i)
45
    {
45
      {
46
      Ptr<Object> object = Config::GetRootNamespaceObject (i);
46
        Ptr<Object> object = Config::GetRootNamespaceObject (i);
47
      StartVisitObject (object);
47
        StartVisitObject (object);
48
      DoIterate (object);
48
        DoIterate (object);
49
      EndVisitObject ();
49
        EndVisitObject ();
50
    }
50
      }
51
  NS_ASSERT (m_currentPath.empty ());
51
    NS_ASSERT (m_currentPath.empty ());
52
  NS_ASSERT (m_examined.empty ());
52
    NS_ASSERT (m_examined.empty ());
53
}
53
  }
54
54
55
bool
55
  bool
56
AttributeIterator::IsExamined (Ptr<const Object> object)
56
  AttributeIterator::IsExamined (Ptr<const Object> object)
57
{
57
  {
58
  for (uint32_t i = 0; i < m_examined.size (); ++i)
58
    for (uint32_t i = 0; i < m_examined.size (); ++i)
59
    {
59
      {
60
      if (object == m_examined[i])
60
        if (object == m_examined[i])
61
        {
61
          {
62
          return true;
62
            return true;
63
        }
63
          }
64
    }
64
      }
65
  return false;
65
    return false;
66
}
66
  }
67
67
68
68
69
std::string
69
  std::string
70
AttributeIterator::GetCurrentPath (std::string attr) const
70
  AttributeIterator::GetCurrentPath (std::string attr) const
71
{
71
  {
72
  std::ostringstream oss;
72
    std::ostringstream oss;
73
  for (uint32_t i = 0; i < m_currentPath.size (); ++i)
73
    for (uint32_t i = 0; i < m_currentPath.size (); ++i)
74
    {
74
      {
75
      oss << "/" << m_currentPath[i];
75
        oss << "/" << m_currentPath[i];
76
    }
76
      }
77
  if (attr != "")
77
    if (attr != "")
78
    {
78
      {
79
      oss << "/" << attr;
79
        oss << "/" << attr;
80
    }
80
      }
81
  return oss.str ();
81
    return oss.str ();
82
}
82
  }
83
83
84
std::string
84
  std::string
85
AttributeIterator::GetCurrentPath (void) const
85
  AttributeIterator::GetCurrentPath (void) const
86
{
86
  {
87
  std::ostringstream oss;
87
    std::ostringstream oss;
88
  for (uint32_t i = 0; i < m_currentPath.size (); ++i)
88
    for (uint32_t i = 0; i < m_currentPath.size (); ++i)
89
    {
89
      {
90
      oss << "/" << m_currentPath[i];
90
        oss << "/" << m_currentPath[i];
91
    }
91
      }
92
  return oss.str ();
92
    return oss.str ();
93
}
93
  }
94
94
95
void 
95
  void
96
AttributeIterator::DoStartVisitObject (Ptr<Object> object)
96
  AttributeIterator::DoStartVisitObject (Ptr<Object> object)
97
{
97
  {
98
}
98
  }
99
void 
99
  void
100
AttributeIterator::DoEndVisitObject (void)
100
  AttributeIterator::DoEndVisitObject (void)
101
{
101
  {
102
}
102
  }
103
void 
103
  void
104
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
104
  AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
105
{
105
  {
106
}
106
  }
107
void 
107
  void
108
AttributeIterator::DoEndVisitPointerAttribute (void)
108
  AttributeIterator::DoEndVisitPointerAttribute (void)
109
{
109
  {
110
}
110
  }
111
void 
111
  void
112
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
112
  AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object,
113
{
113
                                                 std::string name, const ObjectPtrVectorValue &vector)
114
}
114
  {
115
void 
115
  }
116
AttributeIterator::DoEndVisitArrayAttribute (void)
116
  void
117
{
117
  AttributeIterator::DoEndVisitArrayAttribute (void)
118
}
118
  {
119
void 
119
  }
120
AttributeIterator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
120
  void
121
{
121
  AttributeIterator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector,
122
}
122
                                            uint32_t index, Ptr<Object> item)
123
void 
123
  {
124
AttributeIterator::DoEndVisitArrayItem (void)
124
  }
125
{
125
  void
126
}
126
  AttributeIterator::DoEndVisitArrayItem (void)
127
  {
128
  }
127
129
128
void 
130
  void
129
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
131
  AttributeIterator::DoStartVisitMapAttribute (Ptr<Object> object,
130
{
132
                                               std::string name, const ObjectPtrMapValue &map)
131
  m_currentPath.push_back (name);
133
  {
132
  DoVisitAttribute (object, name);
133
  m_currentPath.pop_back ();
134
}
135
134
136
void 
135
  }
137
AttributeIterator::StartVisitObject (Ptr<Object> object)
136
  void
138
{
137
  AttributeIterator::DoEndVisitMapAttribute (void)
139
  m_currentPath.push_back ("$" + object->GetInstanceTypeId ().GetName ());
138
  {
140
  DoStartVisitObject (object);
141
}
142
void 
143
AttributeIterator::EndVisitObject (void)
144
{
145
  m_currentPath.pop_back ();
146
  DoEndVisitObject ();
147
}
148
void 
149
AttributeIterator::StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
150
{
151
  m_currentPath.push_back (name);
152
  m_currentPath.push_back ("$" + value->GetInstanceTypeId ().GetName ());
153
  DoStartVisitPointerAttribute (object, name, value);
154
}
155
void 
156
AttributeIterator::EndVisitPointerAttribute (void)
157
{
158
  m_currentPath.pop_back ();
159
  m_currentPath.pop_back ();
160
  DoEndVisitPointerAttribute ();
161
}
162
void 
163
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
164
{
165
  m_currentPath.push_back (name);
166
  DoStartVisitArrayAttribute (object, name, vector);
167
}
168
void 
169
AttributeIterator::EndVisitArrayAttribute (void)
170
{
171
  m_currentPath.pop_back ();
172
  DoEndVisitArrayAttribute ();
173
}
174
139
175
void 
140
  }
176
AttributeIterator::StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
177
{
178
  std::ostringstream oss;
179
  oss << index;
180
  m_currentPath.push_back (oss.str ());
181
  m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ());
182
  DoStartVisitArrayItem (vector, index, item);
183
}
184
void 
185
AttributeIterator::EndVisitArrayItem (void)
186
{
187
  m_currentPath.pop_back ();
188
  m_currentPath.pop_back ();
189
  DoEndVisitArrayItem ();
190
}
191
141
142
  void
143
  AttributeIterator::DoStartVisitMapItem (const ObjectPtrMapValue &vector,
144
                                          uint32_t index, Ptr<Object> item)
145
  {
192
146
193
void
147
  }
194
AttributeIterator::DoIterate (Ptr<Object> object)
195
{
196
  if (IsExamined (object))
197
    {
198
      return;
199
    }
200
  TypeId tid;
201
  for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ())
202
    {
203
      NS_LOG_DEBUG ("store " << tid.GetName ());
204
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
205
        {
206
          struct TypeId::AttributeInformation info = tid.GetAttribute(i);
207
          const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
208
          if (ptrChecker != 0)
209
            {
210
              NS_LOG_DEBUG ("pointer attribute " << info.name);
211
              PointerValue ptr;
212
              object->GetAttribute (info.name, ptr);
213
              Ptr<Object> tmp = ptr.Get<Object> ();
214
              if (tmp != 0)
215
                {
216
                  StartVisitPointerAttribute (object, info.name,
217
                                              tmp);
218
                  m_examined.push_back (object);
219
                  DoIterate (tmp);
220
                  m_examined.pop_back ();
221
                  EndVisitPointerAttribute ();
222
                }
223
              continue;
224
            }
225
          // attempt to cast to an object vector.
226
          const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
227
          if (vectorChecker != 0)
228
            {
229
              NS_LOG_DEBUG ("vector attribute " << info.name);
230
              ObjectPtrContainerValue vector;
231
              object->GetAttribute (info.name, vector);
232
              StartVisitArrayAttribute (object, info.name, vector);
233
              for (uint32_t j = 0; j < vector.GetN (); ++j)
234
                {
235
                  NS_LOG_DEBUG ("vector attribute item " << j);
236
                  Ptr<Object> tmp = vector.Get (j);
237
                  StartVisitArrayItem (vector, j, tmp);
238
                  m_examined.push_back (object);
239
                  DoIterate (tmp);
240
                  m_examined.pop_back ();
241
                  EndVisitArrayItem ();
242
                }
243
              EndVisitArrayAttribute ();
244
              continue;
245
            }
246
          if ((info.flags & TypeId::ATTR_GET) && info.accessor->HasGetter () && 
247
              (info.flags & TypeId::ATTR_SET) && info.accessor->HasSetter ())
248
            {
249
              VisitAttribute (object, info.name);
250
            }
251
          else
252
            {
253
              NS_LOG_DEBUG ("could not store " << info.name);
254
            }
255
        }
256
    }
257
  Object::AggregateIterator iter = object->GetAggregateIterator ();
258
  bool recursiveAggregate = false;
259
  while (iter.HasNext ())
260
    {
261
      Ptr<const Object> tmp = iter.Next ();
262
      if (IsExamined (tmp))
263
        {
264
          recursiveAggregate = true;
265
        }
266
    }
267
  if (!recursiveAggregate)
268
    {
269
      iter = object->GetAggregateIterator ();
270
      while (iter.HasNext ())
271
        {
272
          Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
273
          StartVisitObject (tmp);
274
          m_examined.push_back (object);
275
          DoIterate (tmp);
276
          m_examined.pop_back ();
277
          EndVisitObject ();
278
        }
279
    }
280
}
281
148
149
  void
150
  AttributeIterator::DoEndVisitMapItem (void)
151
  {
282
152
283
} // namespace ns3
153
  }
154
155
  void
156
  AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
157
  {
158
    m_currentPath.push_back (name);
159
    DoVisitAttribute (object, name);
160
    m_currentPath.pop_back ();
161
  }
162
163
  void
164
  AttributeIterator::StartVisitObject (Ptr<Object> object)
165
  {
166
    m_currentPath.push_back ("$" + object->GetInstanceTypeId ().GetName ());
167
    DoStartVisitObject (object);
168
  }
169
  void
170
  AttributeIterator::EndVisitObject (void)
171
  {
172
    m_currentPath.pop_back ();
173
    DoEndVisitObject ();
174
  }
175
  void
176
  AttributeIterator::StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
177
  {
178
    m_currentPath.push_back (name);
179
    m_currentPath.push_back ("$" + value->GetInstanceTypeId ().GetName ());
180
    DoStartVisitPointerAttribute (object, name, value);
181
  }
182
  void
183
  AttributeIterator::EndVisitPointerAttribute (void)
184
  {
185
    m_currentPath.pop_back ();
186
    m_currentPath.pop_back ();
187
    DoEndVisitPointerAttribute ();
188
  }
189
  void
190
  AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object,
191
                                               std::string name, const ObjectPtrVectorValue &vector)
192
  {
193
    m_currentPath.push_back (name);
194
    DoStartVisitArrayAttribute (object, name, vector);
195
  }
196
  void
197
  AttributeIterator::EndVisitArrayAttribute (void)
198
  {
199
    m_currentPath.pop_back ();
200
    DoEndVisitArrayAttribute ();
201
  }
202
203
  void
204
  AttributeIterator::StartVisitArrayItem (const ObjectPtrVectorValue &vector,
205
                                          uint32_t index, Ptr<Object> item)
206
  {
207
    std::ostringstream oss;
208
    oss << index;
209
    m_currentPath.push_back (oss.str ());
210
    m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ());
211
    DoStartVisitArrayItem (vector, index, item);
212
  }
213
  void
214
  AttributeIterator::EndVisitArrayItem (void)
215
  {
216
    m_currentPath.pop_back ();
217
    m_currentPath.pop_back ();
218
    DoEndVisitArrayItem ();
219
  }
220
221
  void
222
  AttributeIterator::StartVisitMapAttribute (Ptr<Object> object,
223
                                             std::string name, const ObjectPtrMapValue &map)
224
  {
225
    m_currentPath.push_back (name);
226
    DoStartVisitMapAttribute (object, name, map);
227
    NS_LOG_INFO (this << GetCurrentPath ());
228
  }
229
230
  void
231
  AttributeIterator::EndVisitMapAttribute (void)
232
  {
233
    m_currentPath.pop_back ();
234
    DoEndVisitMapAttribute ();
235
  }
236
237
  void
238
  AttributeIterator::StartVisitMapItem (const ObjectPtrMapValue &map,
239
                                        uint32_t index, Ptr<Object> item)
240
  {
241
    std::ostringstream oss;
242
    oss << index;
243
    m_currentPath.push_back (oss.str ());
244
    m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ());
245
    DoStartVisitMapItem (map, index, item);
246
    NS_LOG_INFO (this << GetCurrentPath ());
247
  }
248
249
  void
250
  AttributeIterator::EndVisitMapItem (void)
251
  {
252
    m_currentPath.pop_back ();
253
    m_currentPath.pop_back ();
254
    DoEndVisitMapItem ();
255
  }
256
257
  void
258
  AttributeIterator::DoIterate (Ptr<Object> object)
259
  {
260
    if (IsExamined (object))
261
      {
262
        return;
263
      }
264
    TypeId tid;
265
    for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid
266
           = tid.GetParent ())
267
      {
268
        NS_LOG_DEBUG ("store " << tid.GetName ());
269
        for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
270
          {
271
            struct TypeId::AttributeInformation info = tid.GetAttribute (i);
272
            const PointerChecker *ptrChecker =
273
              dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
274
            if (ptrChecker != 0)
275
              {
276
                NS_LOG_DEBUG ("pointer attribute " << info.name);
277
                PointerValue ptr;
278
                object->GetAttribute (info.name, ptr);
279
                Ptr < Object > tmp = ptr.Get<Object> ();
280
                if (tmp != 0)
281
                  {
282
                    StartVisitPointerAttribute (object, info.name, tmp);
283
                    m_examined.push_back (object);
284
                    DoIterate ( tmp);
285
                    m_examined.pop_back ();
286
                    EndVisitPointerAttribute ();
287
                  }
288
                continue;
289
              }
290
            // attempt to cast to an object vector.
291
            const ObjectPtrVectorChecker *vectorChecker =dynamic_cast<const ObjectPtrVectorChecker *> (PeekPointer (
292
                                                                                                         info.checker));
293
            if (vectorChecker != 0)
294
              {
295
                NS_LOG_DEBUG ("vector attribute " << info.name);
296
                ObjectPtrVectorValue vector;
297
                object->GetAttribute (info.name, vector);
298
                StartVisitArrayAttribute (object, info.name, vector);
299
                for (uint32_t j = 0; j < vector.GetN (); ++j)
300
                  {
301
                    NS_LOG_DEBUG ("vector attribute item " << j);
302
                    Ptr < Object > tmp = vector.Get (j);
303
                    StartVisitArrayItem (vector, j, tmp);
304
                    m_examined.push_back (object);
305
                    DoIterate ( tmp);
306
                    m_examined.pop_back ();
307
                    EndVisitArrayItem ();
308
                  }
309
                EndVisitArrayAttribute ();
310
                continue;
311
              }
312
            // attempt to cast to an object map.
313
            const ObjectPtrMapChecker *mapChecker = dynamic_cast<const ObjectPtrMapChecker *> (PeekPointer (info.checker));
314
            if (mapChecker != 0)
315
              {
316
                ObjectPtrMapValue map;
317
                object->GetAttribute (info.name, map);
318
                StartVisitMapAttribute (object, info.name, map);
319
                for (ObjectPtrMapValue::Iterator it = map.Begin (); it != map.End (); it++)
320
                  {
321
                    NS_LOG_DEBUG ("map attribute index " << (*it).first <<  " item " << (*it).second);
322
                    StartVisitMapItem (map, (*it).first, (*it).second);
323
                    m_examined.push_back (object);
324
                    DoIterate ((*it).second);
325
                    m_examined.pop_back ();
326
                    EndVisitMapItem ();
327
                  }
328
                EndVisitMapAttribute ();
329
                continue;
330
              }
331
            if ((info.flags & TypeId::ATTR_GET) && info.accessor->HasGetter ()
332
                && (info.flags & TypeId::ATTR_SET) && info.accessor->HasSetter ())
333
              {
334
                VisitAttribute (object, info.name);
335
              }
336
            else
337
              {
338
                NS_LOG_DEBUG ("could not store " << info.name);
339
              }
340
          }
341
        Object::AggregateIterator iter = object->GetAggregateIterator ();
342
        bool recursiveAggregate = false;
343
        while (iter.HasNext ())
344
          {
345
            Ptr<const Object> tmp = iter.Next ();
346
            if (IsExamined (tmp))
347
              {
348
                recursiveAggregate = true;
349
              }
350
          }
351
        if (!recursiveAggregate)
352
          {
353
            iter = object->GetAggregateIterator ();
354
            while (iter.HasNext ())
355
              {
356
                Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
357
                StartVisitObject (tmp);
358
                m_examined.push_back (object);
359
                DoIterate (tmp);
360
                m_examined.pop_back ();
361
                EndVisitObject ();
362
              }
363
          }
364
      }
365
366
367
  } // namespace ns3
(-)a/src/config-store/model/attribute-iterator.h (-6 / +14 lines)
 Lines 21-27    Link Here 
21
21
22
#include "ns3/ptr.h"
22
#include "ns3/ptr.h"
23
#include "ns3/object.h"
23
#include "ns3/object.h"
24
#include "ns3/object-ptr-container.h"
24
#include "ns3/object-ptr-vector.h"
25
#include "ns3/object-ptr-map.h"
25
#include <vector>
26
#include <vector>
26
27
27
namespace ns3 {
28
namespace ns3 {
 Lines 46-55    Link Here 
46
  virtual void DoEndVisitObject (void);
47
  virtual void DoEndVisitObject (void);
47
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
48
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
48
  virtual void DoEndVisitPointerAttribute (void);
49
  virtual void DoEndVisitPointerAttribute (void);
49
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
50
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrVectorValue &vector);
50
  virtual void DoEndVisitArrayAttribute (void);
51
  virtual void DoEndVisitArrayAttribute (void);
51
  virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
52
  virtual void DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr<Object> item);
52
  virtual void DoEndVisitArrayItem (void);
53
  virtual void DoEndVisitArrayItem (void);
54
  virtual void DoStartVisitMapAttribute (Ptr<Object> object, std::string name, const ObjectPtrMapValue &map);
55
  virtual void DoEndVisitMapAttribute (void);
56
  virtual void DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr<Object> item);
57
  virtual void DoEndVisitMapItem (void);
53
58
54
  void DoIterate (Ptr<Object> object);
59
  void DoIterate (Ptr<Object> object);
55
  bool IsExamined (Ptr<const Object> object);
60
  bool IsExamined (Ptr<const Object> object);
 Lines 60-70    Link Here 
60
  void EndVisitObject (void);
65
  void EndVisitObject (void);
61
  void StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
66
  void StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
62
  void EndVisitPointerAttribute (void);
67
  void EndVisitPointerAttribute (void);
63
  void StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
68
  void StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrVectorValue &vector);
64
  void EndVisitArrayAttribute (void);
69
  void EndVisitArrayAttribute (void);
65
  void StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
70
  void StartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr<Object> item);
66
  void EndVisitArrayItem (void);
71
  void EndVisitArrayItem (void);
67
72
  void StartVisitMapAttribute (Ptr<Object> object, std::string name, const ObjectPtrMapValue &map);
73
  void EndVisitMapAttribute (void);
74
  void StartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr<Object> item);
75
  void EndVisitMapItem (void);
68
76
69
  std::vector<Ptr<Object> > m_examined;
77
  std::vector<Ptr<Object> > m_examined;
70
  std::vector<std::string> m_currentPath;
78
  std::vector<std::string> m_currentPath;
(-)a/src/config-store/model/model-node-creator.cc (-4 / +45 lines)
 Lines 91-98    Link Here 
91
{
91
{
92
  Remove ();
92
  Remove ();
93
}
93
}
94
void 
94
void
95
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
95
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
96
                                          const ObjectPtrVectorValue &vector)
96
{
97
{
97
  ModelNode *node = new ModelNode ();
98
  ModelNode *node = new ModelNode ();
98
  node->type = ModelNode::NODE_VECTOR;
99
  node->type = ModelNode::NODE_VECTOR;
 Lines 105-112    Link Here 
105
{
106
{
106
  Remove ();
107
  Remove ();
107
}
108
}
108
void 
109
void
109
ModelCreator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
110
ModelCreator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector,
111
                                     uint32_t index, Ptr<Object> item)
110
{
112
{
111
  GtkTreeIter *parent = m_iters.back ();
113
  GtkTreeIter *parent = m_iters.back ();
112
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
114
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
 Lines 127-130    Link Here 
127
  g_free (iter);
129
  g_free (iter);
128
  m_iters.pop_back ();
130
  m_iters.pop_back ();
129
}
131
}
132
133
void
134
ModelCreator::DoStartVisitMapAttribute (Ptr<Object> object, std::string name,
135
                                        const ObjectPtrMapValue &map)
136
{
137
  ModelNode *node = new ModelNode ();
138
  node->type = ModelNode::NODE_VECTOR;
139
  node->object = object;
140
  node->name = name;
141
  Add (node);
142
}
143
void
144
ModelCreator::DoEndVisitMapAttribute (void)
145
{
146
  Remove ();
147
}
148
void
149
ModelCreator::DoStartVisitMapItem (const ObjectPtrMapValue &map, uint32_t index,
150
                                   Ptr<Object> item)
151
{
152
  GtkTreeIter *parent = m_iters.back ();
153
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
154
  ModelNode *node = new ModelNode ();
155
  node->type = ModelNode::NODE_VECTOR_ITEM;
156
  node->object = item;
157
  node->index = index;
158
  gtk_tree_store_append (m_treestore, current, parent);
159
  gtk_tree_store_set (m_treestore, current, COL_NODE, node, -1);
160
  m_iters.push_back (current);
161
}
162
163
void
164
ModelCreator::DoEndVisitMapItem (void)
165
{
166
  GtkTreeIter *iter = m_iters.back ();
167
  g_free (iter);
168
  m_iters.pop_back ();
169
}
170
130
} //end namespace ns3
171
} //end namespace ns3
(-)a/src/config-store/model/model-node-creator.h (-13 / +36 lines)
 Lines 58-76    Link Here 
58
58
59
  void Build (GtkTreeStore *treestore);
59
  void Build (GtkTreeStore *treestore);
60
private:
60
private:
61
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
61
  virtual void
62
  virtual void DoStartVisitObject (Ptr<Object> object);
62
  DoVisitAttribute (Ptr<Object> object, std::string name);
63
  virtual void DoEndVisitObject (void);
63
  virtual void
64
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
64
  DoStartVisitObject (Ptr<Object> object);
65
  virtual void DoEndVisitPointerAttribute (void);
65
  virtual void
66
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
66
  DoEndVisitObject (void);
67
                                           const ObjectPtrContainerValue &vector);
67
  virtual void
68
  virtual void DoEndVisitArrayAttribute (void);
68
  DoStartVisitPointerAttribute (Ptr<Object> object, std::string name,
69
  virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector,
69
                                Ptr<Object> value);
70
                                      uint32_t index, Ptr<Object> item);
70
  virtual void
71
  virtual void DoEndVisitArrayItem (void);
71
  DoEndVisitPointerAttribute (void);
72
  void Add (ModelNode *node);
72
  virtual void
73
  void Remove (void);
73
  DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
74
                              const ObjectPtrVectorValue &vector);
75
  virtual void
76
  DoEndVisitArrayAttribute (void);
77
  virtual void
78
  DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index,
79
                         Ptr<Object> item);
80
  virtual void
81
  DoEndVisitArrayItem (void);
82
  virtual void
83
  DoStartVisitMapAttribute (Ptr<Object> object, std::string name,
84
                            const ObjectPtrMapValue &map);
85
  virtual void
86
  DoEndVisitMapAttribute (void);
87
  virtual void
88
  DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index,
89
                       Ptr<Object> item);
90
  virtual void
91
  DoEndVisitMapItem (void);
92
93
  void
94
  Add (ModelNode *node);
95
  void
96
  Remove (void);
74
97
75
  GtkTreeStore *m_treestore;
98
  GtkTreeStore *m_treestore;
76
  std::vector<GtkTreeIter *> m_iters;
99
  std::vector<GtkTreeIter *> m_iters;
(-)a/src/core/model/config.cc (-7 / +48 lines)
 Lines 21-27    Link Here 
21
#include "singleton.h"
21
#include "singleton.h"
22
#include "object.h"
22
#include "object.h"
23
#include "global-value.h"
23
#include "global-value.h"
24
#include "object-ptr-container.h"
24
#include "object-ptr-vector.h"
25
#include "object-ptr-map.h"
25
#include "names.h"
26
#include "names.h"
26
#include "pointer.h"
27
#include "pointer.h"
27
#include "log.h"
28
#include "log.h"
 Lines 226-232    Link Here 
226
private:
227
private:
227
  void Canonicalize (void);
228
  void Canonicalize (void);
228
  void DoResolve (std::string path, Ptr<Object> root);
229
  void DoResolve (std::string path, Ptr<Object> root);
229
  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
230
  void DoArrayResolve (std::string path, const ObjectPtrVectorValue &vector);
231
  void DoMapResolve (std::string path, const ObjectPtrMapValue &map);
230
  void DoResolveOne (Ptr<Object> object);
232
  void DoResolveOne (Ptr<Object> object);
231
  std::string GetResolvedPath (void) const;
233
  std::string GetResolvedPath (void) const;
232
  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
234
  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
 Lines 403-425    Link Here 
403
          m_workStack.pop_back ();
405
          m_workStack.pop_back ();
404
        }
406
        }
405
      // attempt to cast to an object vector.
407
      // attempt to cast to an object vector.
406
      const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
408
      const ObjectPtrVectorChecker *vectorChecker = dynamic_cast<const ObjectPtrVectorChecker *> (PeekPointer (info.checker));
407
      if (vectorChecker != 0)
409
      if (vectorChecker != 0)
408
        {
410
        {
409
          NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath ());
411
          NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath ());
410
          ObjectPtrContainerValue vector;
412
          ObjectPtrVectorValue vector;
411
          root->GetAttribute (item, vector);
413
          root->GetAttribute (item, vector);
412
          m_workStack.push_back (item);
414
          m_workStack.push_back (item);
413
          DoArrayResolve (pathLeft, vector);
415
          DoArrayResolve (pathLeft, vector);
414
          m_workStack.pop_back ();
416
          m_workStack.pop_back ();
415
        }
417
        }
418
      // attempt to cast to an object map.
419
      const ObjectPtrMapChecker *mapChecker = dynamic_cast<const ObjectPtrMapChecker *> (PeekPointer (info.checker));
420
      if (mapChecker != 0)
421
        {
422
          NS_LOG_DEBUG ("GetAttribute(map)="<<item<<" on path="<<GetResolvedPath ());
423
          ObjectPtrMapValue map;
424
          root->GetAttribute (item, map);
425
          m_workStack.push_back (item);
426
          DoMapResolve (pathLeft, map);
427
          m_workStack.pop_back ();
428
        }
416
      // this could be anything else and we don't know what to do with it.
429
      // this could be anything else and we don't know what to do with it.
417
      // So, we just ignore it.
430
      // So, we just ignore it.
418
    }
431
    }
419
}
432
}
420
433
421
void 
434
void 
422
Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector)
435
Resolver::DoArrayResolve (std::string path, const ObjectPtrVectorValue &vector)
423
{
436
{
424
  NS_ASSERT (path != "");
437
  NS_ASSERT (path != "");
425
  NS_ASSERT ((path.find ("/")) == 0);
438
  NS_ASSERT ((path.find ("/")) == 0);
 Lines 445-450    Link Here 
445
    }
458
    }
446
}
459
}
447
460
461
void
462
Resolver::DoMapResolve (std::string path, const ObjectPtrMapValue &map)
463
{
464
  NS_ASSERT (path != "");
465
  NS_ASSERT ((path.find ("/")) == 0);
466
  std::string::size_type next = path.find ("/", 1);
467
  if (next == std::string::npos)
468
    {
469
      NS_FATAL_ERROR ("map path includes no index data on path=\""<<path<<"\"");
470
    }
471
  std::string item = path.substr (1, next-1);
472
  std::string pathLeft = path.substr (next, path.size ()-next);
473
474
  ArrayMatcher matcher = ArrayMatcher (item);
475
  ObjectPtrMapValue::Iterator it;
476
  for (it =  map.Begin (); it != map.End ();  ++it)
477
    {
478
      if (matcher.Matches ((*it).first))
479
        {
480
          std::ostringstream oss;
481
          oss << (*it).first;
482
          m_workStack.push_back (oss.str ());
483
          DoResolve (pathLeft, (*it).second);
484
          m_workStack.pop_back ();
485
        }
486
    }
487
}
488
448
489
449
class ConfigImpl 
490
class ConfigImpl 
450
{
491
{
 Lines 608-614    Link Here 
608
}
649
}
609
void SetDefault (std::string name, const AttributeValue &value)
650
void SetDefault (std::string name, const AttributeValue &value)
610
{
651
{
611
  if (!SetDefaultFailSafe(name, value))
652
  if (!SetDefaultFailSafe (name, value))
612
    {
653
    {
613
      NS_FATAL_ERROR ("Could not set default value for " << name);
654
      NS_FATAL_ERROR ("Could not set default value for " << name);
614
    }
655
    }
 Lines 630-636    Link Here 
630
    }
671
    }
631
  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
672
  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
632
    {
673
    {
633
      struct TypeId::AttributeInformation tmp = tid.GetAttribute(j);
674
      struct TypeId::AttributeInformation tmp = tid.GetAttribute (j);
634
      if (tmp.name == paramName)
675
      if (tmp.name == paramName)
635
        {
676
        {
636
          Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
677
          Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
(-)a/src/core/model/object-map.h (-16 / +18 lines)
 Lines 20-34    Link Here 
20
#ifndef OBJECT_MAP_H
20
#ifndef OBJECT_MAP_H
21
#define OBJECT_MAP_H
21
#define OBJECT_MAP_H
22
22
23
#include <vector>
23
#include <map>
24
#include "object.h"
24
#include "object.h"
25
#include "ptr.h"
25
#include "ptr.h"
26
#include "attribute.h"
26
#include "attribute.h"
27
#include "object-ptr-container.h"
27
#include "object-ptr-map.h"
28
28
29
namespace ns3 {
29
namespace ns3 {
30
30
31
typedef ObjectPtrContainerValue ObjectMapValue;
31
typedef ObjectPtrMapValue ObjectMapValue;
32
32
33
template <typename T, typename U>
33
template <typename T, typename U>
34
Ptr<const AttributeAccessor>
34
Ptr<const AttributeAccessor>
 Lines 39-50    Link Here 
39
39
40
template <typename T, typename U, typename INDEX>
40
template <typename T, typename U, typename INDEX>
41
Ptr<const AttributeAccessor>
41
Ptr<const AttributeAccessor>
42
MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
42
MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
43
                          INDEX (T::*getN)(void) const);
43
                          INDEX (T::*getN)(void) const);
44
44
45
template <typename T, typename U, typename INDEX>
45
template <typename T, typename U, typename INDEX>
46
Ptr<const AttributeAccessor>
46
Ptr<const AttributeAccessor>
47
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
47
MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
48
                          Ptr<U> (T::*get)(INDEX) const);
48
                          Ptr<U> (T::*get)(INDEX) const);
49
49
50
} // namespace ns3
50
} // namespace ns3
 Lines 53-61    Link Here 
53
53
54
template <typename T, typename U>
54
template <typename T, typename U>
55
Ptr<const AttributeAccessor>
55
Ptr<const AttributeAccessor>
56
MakeObjectMapAccessor (U T::*memberVector)
56
MakeObjectMapAccessor (U T::*memberMap)
57
{
57
{
58
  struct MemberStdContainer : public ObjectPtrContainerAccessor
58
  struct MemberStdContainer : public ObjectPtrMapAccessor
59
  {
59
  {
60
    virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
60
    virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
61
      const T *obj = dynamic_cast<const T *> (object);
61
      const T *obj = dynamic_cast<const T *> (object);
 Lines 63-80    Link Here 
63
        {
63
        {
64
          return false;
64
          return false;
65
        }
65
        }
66
      *n = (obj->*m_memberVector).size ();
66
67
      *n = (obj->*m_memberMap).size ();
67
      return true;
68
      return true;
68
    }
69
    }
69
    virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) const {
70
    virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const {
70
      const T *obj = static_cast<const T *> (object);
71
      const T *obj = static_cast<const T *> (object);
71
      typename U::const_iterator begin = (obj->*m_memberVector).begin ();
72
      typename U::const_iterator begin = (obj->*m_memberMap).begin ();
72
      typename U::const_iterator end = (obj->*m_memberVector).end ();
73
      typename U::const_iterator end = (obj->*m_memberMap).end ();
73
      uint32_t k = 0;
74
      uint32_t k = 0;
74
      for (typename U::const_iterator j = begin; j != end; j++, k++)
75
      for (typename U::const_iterator j = begin; j != end; j++, k++)
75
        {
76
        {
76
          if (k == i)
77
          if (k == i)
77
            {
78
            {
79
              *index = (*j).first;
78
              return (*j).second;
80
              return (*j).second;
79
              break;
81
              break;
80
            }
82
            }
 Lines 83-98    Link Here 
83
      // quiet compiler.
85
      // quiet compiler.
84
      return 0;
86
      return 0;
85
    }
87
    }
86
    U T::*m_memberVector;
88
    U T::*m_memberMap;
87
  } *spec = new MemberStdContainer ();
89
  } *spec = new MemberStdContainer ();
88
  spec->m_memberVector = memberVector;
90
  spec->m_memberMap = memberMap;
89
  return Ptr<const AttributeAccessor> (spec, false);
91
  return Ptr<const AttributeAccessor> (spec, false);
90
}
92
}
91
93
92
template <typename T>
94
template <typename T>
93
Ptr<const AttributeChecker> MakeObjectMapChecker (void)
95
Ptr<const AttributeChecker> MakeObjectMapChecker (void)
94
{
96
{
95
  return MakeObjectPtrContainerChecker<T> ();
97
  return MakeObjectPtrMapChecker<T> ();
96
}
98
}
97
99
98
template <typename T, typename U, typename INDEX>
100
template <typename T, typename U, typename INDEX>
 Lines 100-106    Link Here 
100
MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
102
MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
101
		       INDEX (T::*getN)(void) const)
103
		       INDEX (T::*getN)(void) const)
102
{
104
{
103
  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
105
  return MakeObjectPtrMapAccessor<T,U,INDEX>(get, getN);
104
}
106
}
105
107
106
template <typename T, typename U, typename INDEX>
108
template <typename T, typename U, typename INDEX>
 Lines 108-114    Link Here 
108
MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
110
MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
109
		       Ptr<U> (T::*get)(INDEX) const)
111
		       Ptr<U> (T::*get)(INDEX) const)
110
{
112
{
111
  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
113
  return MakeObjectPtrMapAccessor<T,U,INDEX>(get, getN);
112
}
114
}
113
115
114
116
(-)90904c14135f (+121 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 INRIA, Mathieu Lacage
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
 * Authors: Jaume Nin <jaume.nin@cttc.cat>,  Mathieu Lacage <mathieu.lacage@gmail.com>
19
 */
20
#include "object-ptr-map.h"
21
22
namespace ns3
23
{
24
25
ObjectPtrMapValue::ObjectPtrMapValue ()
26
{
27
}
28
29
ObjectPtrMapValue::Iterator
30
ObjectPtrMapValue::Begin (void) const
31
{
32
  return m_objects.begin ();
33
}
34
ObjectPtrMapValue::Iterator
35
ObjectPtrMapValue::End (void) const
36
{
37
  return m_objects.end ();
38
}
39
uint32_t
40
ObjectPtrMapValue::GetN (void) const
41
{
42
  return m_objects.size ();
43
}
44
Ptr<Object>
45
ObjectPtrMapValue::Get (uint32_t i) const
46
{
47
  return m_objects.find (i)->second;
48
}
49
50
Ptr<AttributeValue>
51
ObjectPtrMapValue::Copy (void) const
52
{
53
  return ns3::Create<ObjectPtrMapValue>(*this);
54
}
55
std::string
56
ObjectPtrMapValue::SerializeToString (Ptr<const AttributeChecker> checker) const
57
{
58
  std::ostringstream oss;
59
  Iterator it;
60
  for (it = m_objects.begin (); it != m_objects.end (); ++it)
61
    {
62
      oss << (*it).second;
63
      if (it != m_objects.end ())
64
        {
65
          oss << " ";
66
        }
67
    }
68
  return oss.str ();
69
}
70
71
bool
72
ObjectPtrMapValue::DeserializeFromString (std::string value,
73
                                          Ptr<const AttributeChecker> checker)
74
{
75
  NS_FATAL_ERROR ("cannot deserialize a map of object pointers.");
76
  return true;
77
}
78
79
bool
80
ObjectPtrMapAccessor::Set (ObjectBase * object, const AttributeValue & value) const
81
{
82
  // not allowed.
83
  return false;
84
}
85
bool
86
ObjectPtrMapAccessor::Get (const ObjectBase * object, AttributeValue &value) const
87
{
88
  ObjectPtrMapValue *v = dynamic_cast<ObjectPtrMapValue *> (&value);
89
  if (v == 0)
90
    {
91
      return false;
92
    }
93
  v->m_objects.clear ();
94
  uint32_t n;
95
  bool ok = DoGetN (object, &n);
96
  if (!ok)
97
    {
98
      return false;
99
    }
100
  for (uint32_t i = 0; i < n; i++)
101
    {
102
103
      uint32_t k;
104
      Ptr < Object > element = DoGet (object, i, &k);
105
      v->m_objects.insert (std::pair<uint32_t, Ptr<Object> >(k, element));
106
    }
107
  return true;
108
}
109
110
bool
111
ObjectPtrMapAccessor::HasGetter (void) const
112
{
113
  return true;
114
}
115
bool
116
ObjectPtrMapAccessor::HasSetter (void) const
117
{
118
  return false;
119
}
120
121
} // name
(-)90904c14135f (+192 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 INRIA, Mathieu Lacage
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
 * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
19
 */
20
#ifndef OBJECT_PTR_MAP_H
21
#define OBJECT_PTR_MAP_H
22
23
#include <map>
24
#include "object.h"
25
#include "ptr.h"
26
#include "attribute.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup object
32
 * 
33
 * \brief contain a map of ns3::Object pointers.
34
 *
35
 * This class it used to get attribute access to an array of
36
 * ns3::Object pointers.
37
 */
38
class ObjectPtrMapValue : public AttributeValue
39
{
40
public:
41
  typedef std::map<uint32_t, Ptr<Object> >::const_iterator Iterator;
42
43
  ObjectPtrMapValue ();
44
45
  /**
46
   * \returns an iterator to the first object contained in this map
47
   */
48
  Iterator Begin (void) const;
49
  /**
50
   * \returns an iterator to the last object contained in this map
51
   */
52
  Iterator End (void) const;
53
  /**
54
   * \returns the number of objects contained in this map.
55
   */
56
  uint32_t GetN (void) const;
57
  /**
58
   * \param i the index of the requested object.
59
   * \returns the requested object
60
   */
61
  Ptr<Object> Get (uint32_t i) const;
62
63
  virtual Ptr<AttributeValue> Copy (void) const;
64
  virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
65
  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
66
67
private:
68
  friend class ObjectPtrMapAccessor;
69
  std::map<uint32_t, Ptr<Object> > m_objects;
70
};
71
72
73
template <typename T, typename U, typename INDEX>
74
Ptr<const AttributeAccessor>
75
MakeObjectPtrMapAccessor (Ptr<U> (T::*get)(INDEX) const,
76
                          INDEX (T::*getN)(void) const);
77
78
template <typename T, typename U, typename INDEX>
79
Ptr<const AttributeAccessor>
80
MakeObjectPtrMapAccessor (INDEX (T::*getN)(void) const,
81
                          Ptr<U> (T::*get)(INDEX) const);
82
83
class ObjectPtrMapChecker : public AttributeChecker
84
{
85
public:
86
  virtual TypeId GetItemTypeId (void) const = 0;
87
};
88
89
template <typename T>
90
Ptr<const AttributeChecker> MakeObjectPtrMapChecker (void);
91
92
} // namespace ns3
93
94
namespace ns3 {
95
96
namespace internal {
97
98
template <typename T>
99
class AnObjectPtrMapChecker : public ObjectPtrMapChecker
100
{
101
public:
102
  virtual TypeId GetItemTypeId (void) const {
103
    return T::GetTypeId ();
104
  }
105
  virtual bool Check (const AttributeValue &value) const {
106
    return dynamic_cast<const ObjectPtrMapValue *> (&value) != 0;
107
  }
108
  virtual std::string GetValueTypeName (void) const {
109
    return "ns3::ObjectPtrMapValue";
110
  }
111
  virtual bool HasUnderlyingTypeInformation (void) const {
112
    return true;
113
  }
114
  virtual std::string GetUnderlyingTypeInformation (void) const {
115
    return "ns3::Ptr< " + T::GetTypeId ().GetName () + " >";
116
  }
117
  virtual Ptr<AttributeValue> Create (void) const {
118
    return ns3::Create<ObjectPtrMapValue> ();
119
  }
120
  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
121
    const ObjectPtrMapValue *src = dynamic_cast<const ObjectPtrMapValue *> (&source);
122
    ObjectPtrMapValue *dst = dynamic_cast<ObjectPtrMapValue *> (&destination);
123
    if (src == 0 || dst == 0)
124
      {
125
        return false;
126
      }
127
    *dst = *src;
128
    return true;
129
  }
130
};
131
132
} // namespace internal
133
134
135
class ObjectPtrMapAccessor : public AttributeAccessor
136
{
137
public:
138
  virtual bool Set (ObjectBase * object, const AttributeValue &value) const;
139
  virtual bool Get (const ObjectBase * object, AttributeValue &value) const;
140
  virtual bool HasGetter (void) const;
141
  virtual bool HasSetter (void) const;
142
private:
143
  virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const = 0;
144
  virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const = 0;
145
};
146
147
template <typename T, typename U, typename INDEX>
148
Ptr<const AttributeAccessor>
149
MakeObjectPtrMapAccessor (Ptr<U> (T::*get)(INDEX) const,
150
                          INDEX (T::*getN)(void) const)
151
{
152
  struct MemberGetters : public ObjectPtrMapAccessor
153
  {
154
    virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
155
      const T *obj = dynamic_cast<const T *> (object);
156
      if (obj == 0)
157
        {
158
          return false;
159
        }
160
      *n = (obj->*m_getN)();
161
      return true;
162
    }
163
    virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const {
164
      const T *obj = static_cast<const T *> (object);
165
      return (obj->*m_get)(i);
166
    }
167
    Ptr<U> (T::*m_get)(INDEX) const;
168
    INDEX (T::*m_getN)(void) const;
169
  } *spec = new MemberGetters ();
170
  spec->m_get = get;
171
  spec->m_getN = getN;
172
  return Ptr<const AttributeAccessor> (spec, false);
173
}
174
175
template <typename T, typename U, typename INDEX>
176
Ptr<const AttributeAccessor>
177
MakeObjectPtrMapAccessor (INDEX (T::*getN)(void) const,
178
                          Ptr<U> (T::*get)(INDEX) const)
179
{
180
  return MakeObjectPtrMapAccessor (get, getN);
181
}
182
183
template <typename T>
184
Ptr<const AttributeChecker> MakeObjectPtrMapChecker (void)
185
{
186
  return Create<internal::AnObjectPtrMapChecker<T> > ();
187
}
188
189
190
} // namespace ns3
191
192
#endif /* OBJECT_PTR_MAP_H */
(-)90904c14135f (+114 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 INRIA, Mathieu Lacage
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
 * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
19
 */
20
#include "object-ptr-vector.h"
21
22
namespace ns3 {
23
24
ObjectPtrVectorValue::ObjectPtrVectorValue ()
25
{
26
}
27
28
ObjectPtrVectorValue::Iterator
29
ObjectPtrVectorValue::Begin (void) const
30
{
31
  return m_objects.begin ();
32
}
33
ObjectPtrVectorValue::Iterator
34
ObjectPtrVectorValue::End (void) const
35
{
36
  return m_objects.end ();
37
}
38
uint32_t
39
ObjectPtrVectorValue::GetN (void) const
40
{
41
  return m_objects.size ();
42
}
43
Ptr<Object>
44
ObjectPtrVectorValue::Get (uint32_t i) const
45
{
46
  return m_objects[i];
47
}
48
49
Ptr<AttributeValue>
50
ObjectPtrVectorValue::Copy (void) const
51
{
52
  return ns3::Create<ObjectPtrVectorValue> (*this);
53
}
54
std::string 
55
ObjectPtrVectorValue::SerializeToString (Ptr<const AttributeChecker> checker) const
56
{
57
  std::ostringstream oss;
58
  for (uint32_t i = 0; i < m_objects.size (); ++i)
59
    {
60
      oss << m_objects[i];
61
      if (i != m_objects.size () - 1)
62
        {
63
          oss << " ";
64
        }
65
    }
66
  return oss.str ();
67
}
68
bool 
69
ObjectPtrVectorValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
70
{
71
  NS_FATAL_ERROR ("cannot deserialize a vector of object pointers.");
72
  return true;
73
}
74
75
bool 
76
ObjectPtrVectorAccessor::Set (ObjectBase * object, const AttributeValue & value) const
77
{
78
  // not allowed.
79
  return false;
80
}
81
bool 
82
ObjectPtrVectorAccessor::Get (const ObjectBase * object, AttributeValue &value) const
83
{
84
  ObjectPtrVectorValue *v = dynamic_cast<ObjectPtrVectorValue *> (&value);
85
  if (v == 0)
86
    {
87
      return false;
88
    }
89
  v->m_objects.clear ();
90
  uint32_t n;
91
  bool ok = DoGetN (object, &n);
92
  if (!ok)
93
    {
94
      return false;
95
    }
96
  for (uint32_t i = 0; i < n; i++)
97
    {
98
      Ptr<Object> o = DoGet (object, i);
99
      v->m_objects.push_back (o);
100
    }
101
  return true;
102
}
103
bool 
104
ObjectPtrVectorAccessor::HasGetter (void) const
105
{
106
  return true;
107
}
108
bool 
109
ObjectPtrVectorAccessor::HasSetter (void) const
110
{
111
  return false;
112
}
113
114
} // name
(-)90904c14135f (+192 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 INRIA, Mathieu Lacage
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
 * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
19
 */
20
#ifndef OBJECT_PTR_VECTOR_H
21
#define OBJECT_PTR_VECTOR_H
22
23
#include <vector>
24
#include "object.h"
25
#include "ptr.h"
26
#include "attribute.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup object
32
 * 
33
 * \brief contain a vector of ns3::Object pointers.
34
 *
35
 * This class it used to get attribute access to an array of
36
 * ns3::Object pointers.
37
 */
38
class ObjectPtrVectorValue : public AttributeValue
39
{
40
public:
41
  typedef std::vector<Ptr<Object> >::const_iterator Iterator;
42
43
  ObjectPtrVectorValue ();
44
45
  /**
46
   * \returns an iterator to the first object contained in this vector
47
   */
48
  Iterator Begin (void) const;
49
  /**
50
   * \returns an iterator to the last object contained in this vector
51
   */
52
  Iterator End (void) const;
53
  /**
54
   * \returns the number of objects contained in this vector.
55
   */
56
  uint32_t GetN (void) const;
57
  /**
58
   * \param i the index of the requested object.
59
   * \returns the requested object
60
   */
61
  Ptr<Object> Get (uint32_t i) const;
62
63
  virtual Ptr<AttributeValue> Copy (void) const;
64
  virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
65
  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
66
67
private:
68
  friend class ObjectPtrVectorAccessor;
69
  std::vector<Ptr<Object> > m_objects;
70
};
71
72
73
template <typename T, typename U, typename INDEX>
74
Ptr<const AttributeAccessor>
75
MakeObjectPtrVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
76
                             INDEX (T::*getN)(void) const);
77
78
template <typename T, typename U, typename INDEX>
79
Ptr<const AttributeAccessor>
80
MakeObjectPtrVectorAccessor (INDEX (T::*getN)(void) const,
81
                             Ptr<U> (T::*get)(INDEX) const);
82
83
class ObjectPtrVectorChecker : public AttributeChecker
84
{
85
public:
86
  virtual TypeId GetItemTypeId (void) const = 0;
87
};
88
89
template <typename T>
90
Ptr<const AttributeChecker> MakeObjectPtrVectorChecker (void);
91
92
} // namespace ns3
93
94
namespace ns3 {
95
96
namespace internal {
97
98
template <typename T>
99
class AnObjectPtrVectorChecker : public ObjectPtrVectorChecker
100
{
101
public:
102
  virtual TypeId GetItemTypeId (void) const {
103
    return T::GetTypeId ();
104
  }
105
  virtual bool Check (const AttributeValue &value) const {
106
    return dynamic_cast<const ObjectPtrVectorValue *> (&value) != 0;
107
  }
108
  virtual std::string GetValueTypeName (void) const {
109
    return "ns3::ObjectPtrVectorValue";
110
  }
111
  virtual bool HasUnderlyingTypeInformation (void) const {
112
    return true;
113
  }
114
  virtual std::string GetUnderlyingTypeInformation (void) const {
115
    return "ns3::Ptr< " + T::GetTypeId ().GetName () + " >";
116
  }
117
  virtual Ptr<AttributeValue> Create (void) const {
118
    return ns3::Create<ObjectPtrVectorValue> ();
119
  }
120
  virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
121
    const ObjectPtrVectorValue *src = dynamic_cast<const ObjectPtrVectorValue *> (&source);
122
    ObjectPtrVectorValue *dst = dynamic_cast<ObjectPtrVectorValue *> (&destination);
123
    if (src == 0 || dst == 0)
124
      {
125
        return false;
126
      }
127
    *dst = *src;
128
    return true;
129
  }
130
};
131
132
} // namespace internal
133
134
135
class ObjectPtrVectorAccessor : public AttributeAccessor
136
{
137
public:
138
  virtual bool Set (ObjectBase * object, const AttributeValue &value) const;
139
  virtual bool Get (const ObjectBase * object, AttributeValue &value) const;
140
  virtual bool HasGetter (void) const;
141
  virtual bool HasSetter (void) const;
142
private:
143
  virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const = 0;
144
  virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) const = 0;
145
};
146
147
template <typename T, typename U, typename INDEX>
148
Ptr<const AttributeAccessor>
149
MakeObjectPtrVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
150
                             INDEX (T::*getN)(void) const)
151
{
152
  struct MemberGetters : public ObjectPtrVectorAccessor
153
  {
154
    virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
155
      const T *obj = dynamic_cast<const T *> (object);
156
      if (obj == 0)
157
        {
158
          return false;
159
        }
160
      *n = (obj->*m_getN)();
161
      return true;
162
    }
163
    virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) const {
164
      const T *obj = static_cast<const T *> (object);
165
      return (obj->*m_get)(i);
166
    }
167
    Ptr<U> (T::*m_get)(INDEX) const;
168
    INDEX (T::*m_getN)(void) const;
169
  } *spec = new MemberGetters ();
170
  spec->m_get = get;
171
  spec->m_getN = getN;
172
  return Ptr<const AttributeAccessor> (spec, false);
173
}
174
175
template <typename T, typename U, typename INDEX>
176
Ptr<const AttributeAccessor>
177
MakeObjectPtrVectorAccessor (INDEX (T::*getN)(void) const,
178
                             Ptr<U> (T::*get)(INDEX) const)
179
{
180
  return MakeObjectPtrVectorAccessor (get, getN);
181
}
182
183
template <typename T>
184
Ptr<const AttributeChecker> MakeObjectPtrVectorChecker (void)
185
{
186
  return Create<internal::AnObjectPtrVectorChecker<T> > ();
187
}
188
189
190
} // namespace ns3
191
192
#endif /* OBJECT_PTR_VECTOR_H */
(-)a/src/core/model/object-vector.h (-8 / +8 lines)
 Lines 24-34    Link Here 
24
#include "object.h"
24
#include "object.h"
25
#include "ptr.h"
25
#include "ptr.h"
26
#include "attribute.h"
26
#include "attribute.h"
27
#include "object-ptr-container.h"
27
#include "object-ptr-vector.h"
28
28
29
namespace ns3 {
29
namespace ns3 {
30
30
31
typedef ObjectPtrContainerValue ObjectVectorValue;
31
typedef ObjectPtrVectorValue ObjectVectorValue;
32
32
33
template <typename T, typename U>
33
template <typename T, typename U>
34
Ptr<const AttributeAccessor>
34
Ptr<const AttributeAccessor>
 Lines 55-61    Link Here 
55
Ptr<const AttributeAccessor>
55
Ptr<const AttributeAccessor>
56
MakeObjectVectorAccessor (U T::*memberVector)
56
MakeObjectVectorAccessor (U T::*memberVector)
57
{
57
{
58
  struct MemberStdContainer : public ObjectPtrContainerAccessor
58
  struct MemberStdContainer : public ObjectPtrVectorAccessor
59
  {
59
  {
60
    virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
60
    virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
61
      const T *obj = dynamic_cast<const T *> (object);
61
      const T *obj = dynamic_cast<const T *> (object);
 Lines 92-114    Link Here 
92
template <typename T>
92
template <typename T>
93
Ptr<const AttributeChecker> MakeObjectVectorChecker (void)
93
Ptr<const AttributeChecker> MakeObjectVectorChecker (void)
94
{
94
{
95
  return MakeObjectPtrContainerChecker<T> ();
95
  return MakeObjectPtrVectorChecker<T> ();
96
}
96
}
97
97
98
template <typename T, typename U, typename INDEX>
98
template <typename T, typename U, typename INDEX>
99
Ptr<const AttributeAccessor>
99
Ptr<const AttributeAccessor>
100
MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
100
MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
101
			  INDEX (T::*getN)(void) const)
101
                          INDEX (T::*getN)(void) const)
102
{
102
{
103
  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
103
  return MakeObjectPtrVectorAccessor<T,U,INDEX>(get, getN);
104
}
104
}
105
105
106
template <typename T, typename U, typename INDEX>
106
template <typename T, typename U, typename INDEX>
107
Ptr<const AttributeAccessor>
107
Ptr<const AttributeAccessor>
108
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
108
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
109
			  Ptr<U> (T::*get)(INDEX) const)
109
                          Ptr<U> (T::*get)(INDEX) const)
110
{
110
{
111
  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
111
  return MakeObjectPtrVectorAccessor<T,U,INDEX>(get, getN);
112
}
112
}
113
113
114
114
(-)a/src/core/wscript (-2 / +4 lines)
 Lines 137-143    Link Here 
137
        'model/int64x64.cc',
137
        'model/int64x64.cc',
138
        'model/string.cc',
138
        'model/string.cc',
139
        'model/pointer.cc',
139
        'model/pointer.cc',
140
        'model/object-ptr-container.cc',
140
        'model/object-ptr-vector.cc',
141
        'model/object-ptr-map.cc',
141
        'model/object-factory.cc',
142
        'model/object-factory.cc',
142
        'model/global-value.cc',
143
        'model/global-value.cc',
143
        'model/trace-source-accessor.cc',
144
        'model/trace-source-accessor.cc',
 Lines 231-237    Link Here 
231
        'model/traced-value.h',
232
        'model/traced-value.h',
232
        'model/trace-source-accessor.h',
233
        'model/trace-source-accessor.h',
233
        'model/config.h',
234
        'model/config.h',
234
        'model/object-ptr-container.h',
235
        'model/object-ptr-vector.h',
236
        'model/object-ptr-map.h',
235
        'model/object-vector.h',
237
        'model/object-vector.h',
236
        'model/object-map.h',
238
        'model/object-map.h',
237
        'model/deprecated.h',
239
        'model/deprecated.h',

Return to bug 1352