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 (-34 / +118 lines)
 Lines 109-115    Link Here 
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
                                               std::string name, const ObjectPtrVectorValue &vector)
113
{
114
{
114
}
115
}
115
void 
116
void 
 Lines 117-123    Link Here 
117
{
118
{
118
}
119
}
119
void 
120
void 
120
AttributeIterator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
121
AttributeIterator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector,
122
                                          uint32_t index, Ptr<Object> item)
121
{
123
{
122
}
124
}
123
void 
125
void 
 Lines 126-131    Link Here 
126
}
128
}
127
129
128
void 
130
void 
131
AttributeIterator::DoStartVisitMapAttribute (Ptr<Object> object,
132
                                             std::string name, const ObjectPtrMapValue &map)
133
{
134
135
}
136
void 
137
AttributeIterator::DoEndVisitMapAttribute (void)
138
{
139
140
}
141
142
void 
143
AttributeIterator::DoStartVisitMapItem (const ObjectPtrMapValue &vector,
144
                                        uint32_t index, Ptr<Object> item)
145
{
146
147
}
148
149
void 
150
AttributeIterator::DoEndVisitMapItem (void)
151
{
152
153
}
154
155
void 
129
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
156
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
130
{
157
{
131
  m_currentPath.push_back (name);
158
  m_currentPath.push_back (name);
 Lines 160-166    Link Here 
160
  DoEndVisitPointerAttribute ();
187
  DoEndVisitPointerAttribute ();
161
}
188
}
162
void 
189
void 
163
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
190
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object,
191
                                             std::string name, const ObjectPtrVectorValue &vector)
164
{
192
{
165
  m_currentPath.push_back (name);
193
  m_currentPath.push_back (name);
166
  DoStartVisitArrayAttribute (object, name, vector);
194
  DoStartVisitArrayAttribute (object, name, vector);
 Lines 173-179    Link Here 
173
}
201
}
174
202
175
void 
203
void 
176
AttributeIterator::StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
204
AttributeIterator::StartVisitArrayItem (const ObjectPtrVectorValue &vector,
205
                                        uint32_t index, Ptr<Object> item)
177
{
206
{
178
  std::ostringstream oss;
207
  std::ostringstream oss;
179
  oss << index;
208
  oss << index;
 Lines 189-196    Link Here 
189
  DoEndVisitArrayItem ();
218
  DoEndVisitArrayItem ();
190
}
219
}
191
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
}
192
229
193
void
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 
194
AttributeIterator::DoIterate (Ptr<Object> object)
258
AttributeIterator::DoIterate (Ptr<Object> object)
195
{
259
{
196
  if (IsExamined (object))
260
  if (IsExamined (object))
 Lines 198-210    Link Here 
198
      return;
262
      return;
199
    }
263
    }
200
  TypeId tid;
264
  TypeId tid;
201
  for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ())
265
  for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid
266
         = tid.GetParent ())
202
    {
267
    {
203
      NS_LOG_DEBUG ("store " << tid.GetName ());
268
      NS_LOG_DEBUG ("store " << tid.GetName ());
204
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
269
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
205
        {
270
        {
206
          struct TypeId::AttributeInformation info = tid.GetAttribute(i);
271
          struct TypeId::AttributeInformation info = tid.GetAttribute (i);
207
          const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
272
          const PointerChecker *ptrChecker =
273
            dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
208
          if (ptrChecker != 0)
274
          if (ptrChecker != 0)
209
            {
275
            {
210
              NS_LOG_DEBUG ("pointer attribute " << info.name);
276
              NS_LOG_DEBUG ("pointer attribute " << info.name);
 Lines 213-220    Link Here 
213
              Ptr<Object> tmp = ptr.Get<Object> ();
279
              Ptr<Object> tmp = ptr.Get<Object> ();
214
              if (tmp != 0)
280
              if (tmp != 0)
215
                {
281
                {
216
                  StartVisitPointerAttribute (object, info.name,
282
                  StartVisitPointerAttribute (object, info.name, tmp);
217
                                              tmp);
218
                  m_examined.push_back (object);
283
                  m_examined.push_back (object);
219
                  DoIterate (tmp);
284
                  DoIterate (tmp);
220
                  m_examined.pop_back ();
285
                  m_examined.pop_back ();
 Lines 223-233    Link Here 
223
              continue;
288
              continue;
224
            }
289
            }
225
          // attempt to cast to an object vector.
290
          // attempt to cast to an object vector.
226
          const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
291
          const ObjectPtrVectorChecker *vectorChecker =dynamic_cast<const ObjectPtrVectorChecker *> (PeekPointer (
292
                                                                                                       info.checker));
227
          if (vectorChecker != 0)
293
          if (vectorChecker != 0)
228
            {
294
            {
229
              NS_LOG_DEBUG ("vector attribute " << info.name);
295
              NS_LOG_DEBUG ("vector attribute " << info.name);
230
              ObjectPtrContainerValue vector;
296
              ObjectPtrVectorValue vector;
231
              object->GetAttribute (info.name, vector);
297
              object->GetAttribute (info.name, vector);
232
              StartVisitArrayAttribute (object, info.name, vector);
298
              StartVisitArrayAttribute (object, info.name, vector);
233
              for (uint32_t j = 0; j < vector.GetN (); ++j)
299
              for (uint32_t j = 0; j < vector.GetN (); ++j)
 Lines 243-250    Link Here 
243
              EndVisitArrayAttribute ();
309
              EndVisitArrayAttribute ();
244
              continue;
310
              continue;
245
            }
311
            }
246
          if ((info.flags & TypeId::ATTR_GET) && info.accessor->HasGetter () && 
312
          // attempt to cast to an object map.
247
              (info.flags & TypeId::ATTR_SET) && info.accessor->HasSetter ())
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 ())
248
            {
333
            {
249
              VisitAttribute (object, info.name);
334
              VisitAttribute (object, info.name);
250
            }
335
            }
 Lines 253-283    Link Here 
253
              NS_LOG_DEBUG ("could not store " << info.name);
338
              NS_LOG_DEBUG ("could not store " << info.name);
254
            }
339
            }
255
        }
340
        }
256
    }
341
      Object::AggregateIterator iter = object->GetAggregateIterator ();
257
  Object::AggregateIterator iter = object->GetAggregateIterator ();
342
      bool recursiveAggregate = false;
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 ())
343
      while (iter.HasNext ())
271
        {
344
        {
272
          Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
345
          Ptr<const Object> tmp = iter.Next ();
273
          StartVisitObject (tmp);
346
          if (IsExamined (tmp))
274
          m_examined.push_back (object);
347
            {
275
          DoIterate (tmp);
348
              recursiveAggregate = true;
276
          m_examined.pop_back ();
349
            }
277
          EndVisitObject ();
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
            }
278
        }
363
        }
279
    }
364
    }
280
}
365
}
281
366
282
283
} // namespace ns3
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 (-3 / +44 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 106-112    Link Here 
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 (-5 / +8 lines)
 Lines 56-74    Link Here 
56
public:
56
public:
57
  ModelCreator ();
57
  ModelCreator ();
58
58
59
  void Build (GtkTreeStore *treestore);
59
  void
60
  Build (GtkTreeStore *treestore);
60
private:
61
private:
61
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
62
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
62
  virtual void DoStartVisitObject (Ptr<Object> object);
63
  virtual void DoStartVisitObject (Ptr<Object> object);
63
  virtual void DoEndVisitObject (void);
64
  virtual void DoEndVisitObject (void);
64
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
65
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
65
  virtual void DoEndVisitPointerAttribute (void);
66
  virtual void DoEndVisitPointerAttribute (void);
66
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
67
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrVectorValue &vector);
67
                                           const ObjectPtrContainerValue &vector);
68
  virtual void DoEndVisitArrayAttribute (void);
68
  virtual void DoEndVisitArrayAttribute (void);
69
  virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector,
69
  virtual void DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr<Object> item);
70
                                      uint32_t index, Ptr<Object> item);
71
  virtual void DoEndVisitArrayItem (void);
70
  virtual void DoEndVisitArrayItem (void);
71
  virtual void DoStartVisitMapAttribute (Ptr<Object> object, std::string name, const ObjectPtrMapValue &map);
72
  virtual void DoEndVisitMapAttribute (void);
73
  virtual void DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr<Object> item);
74
  virtual void DoEndVisitMapItem (void);
72
  void Add (ModelNode *node);
75
  void Add (ModelNode *node);
73
  void Remove (void);
76
  void Remove (void);
74
77
(-)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
(-)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 (+4 lines)
 Lines 138-143    Link Here 
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-container.cc',
141
        'model/object-ptr-vector.cc',
142
        'model/object-ptr-map.cc',
141
        'model/object-factory.cc',
143
        'model/object-factory.cc',
142
        'model/global-value.cc',
144
        'model/global-value.cc',
143
        'model/trace-source-accessor.cc',
145
        'model/trace-source-accessor.cc',
 Lines 232-237    Link Here 
232
        'model/trace-source-accessor.h',
234
        'model/trace-source-accessor.h',
233
        'model/config.h',
235
        'model/config.h',
234
        'model/object-ptr-container.h',
236
        'model/object-ptr-container.h',
237
        'model/object-ptr-vector.h',
238
        'model/object-ptr-map.h',
235
        'model/object-vector.h',
239
        'model/object-vector.h',
236
        'model/object-map.h',
240
        'model/object-map.h',
237
        'model/deprecated.h',
241
        'model/deprecated.h',

Return to bug 1352