# HG changeset patch # User Jaume Nin # Date 1327948423 -3600 # Node ID f9c13ca8c8a6f90fe94acfee1efcd8cbe6bf2a60 # Parent 90904c14135fba7c40ea351cfbfca369aade4d43 AttributeMap reimplementation diff -r 90904c14135f -r f9c13ca8c8a6 src/config-store/model/attribute-default-iterator.cc --- a/src/config-store/model/attribute-default-iterator.cc Sun Jan 29 01:14:23 2012 +0100 +++ b/src/config-store/model/attribute-default-iterator.cc Mon Jan 30 19:33:43 2012 +0100 @@ -22,7 +22,8 @@ #include "ns3/pointer.h" #include "ns3/global-value.h" #include "ns3/string.h" -#include "ns3/object-ptr-container.h" +#include "ns3/object-ptr-vector.h" +#include "ns3/object-ptr-map.h" namespace ns3 { @@ -70,19 +71,25 @@ //No value, check next attribute continue; } - Ptr vector = DynamicCast (info.initialValue); + Ptr vector = DynamicCast (info.initialValue); if (vector != 0) { //a vector value, won't take it continue; } + Ptr map = DynamicCast (info.initialValue); + if (map != 0) + { + //a map value, won't take it + continue; + } Ptr pointer = DynamicCast (info.initialValue); if (pointer != 0) { //pointer value, won't take it continue; } - //We take only values, no pointers or vectors + //We take only values, no pointers or vectors or maps if (!calledStart) { StartVisitTypeId (tid.GetName ()); diff -r 90904c14135f -r f9c13ca8c8a6 src/config-store/model/attribute-iterator.cc --- a/src/config-store/model/attribute-iterator.cc Sun Jan 29 01:14:23 2012 +0100 +++ b/src/config-store/model/attribute-iterator.cc Mon Jan 30 19:33:43 2012 +0100 @@ -30,254 +30,338 @@ namespace ns3 { -AttributeIterator::AttributeIterator () -{ -} + AttributeIterator::AttributeIterator () + { + } -AttributeIterator::~AttributeIterator () -{ -} + AttributeIterator::~AttributeIterator () + { + } -void -AttributeIterator::Iterate (void) -{ - for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i) - { - Ptr object = Config::GetRootNamespaceObject (i); - StartVisitObject (object); - DoIterate (object); - EndVisitObject (); - } - NS_ASSERT (m_currentPath.empty ()); - NS_ASSERT (m_examined.empty ()); -} + void + AttributeIterator::Iterate (void) + { + for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i) + { + Ptr object = Config::GetRootNamespaceObject (i); + StartVisitObject (object); + DoIterate (object); + EndVisitObject (); + } + NS_ASSERT (m_currentPath.empty ()); + NS_ASSERT (m_examined.empty ()); + } -bool -AttributeIterator::IsExamined (Ptr object) -{ - for (uint32_t i = 0; i < m_examined.size (); ++i) - { - if (object == m_examined[i]) - { - return true; - } - } - return false; -} + bool + AttributeIterator::IsExamined (Ptr object) + { + for (uint32_t i = 0; i < m_examined.size (); ++i) + { + if (object == m_examined[i]) + { + return true; + } + } + return false; + } -std::string -AttributeIterator::GetCurrentPath (std::string attr) const -{ - std::ostringstream oss; - for (uint32_t i = 0; i < m_currentPath.size (); ++i) - { - oss << "/" << m_currentPath[i]; - } - if (attr != "") - { - oss << "/" << attr; - } - return oss.str (); -} + std::string + AttributeIterator::GetCurrentPath (std::string attr) const + { + std::ostringstream oss; + for (uint32_t i = 0; i < m_currentPath.size (); ++i) + { + oss << "/" << m_currentPath[i]; + } + if (attr != "") + { + oss << "/" << attr; + } + return oss.str (); + } -std::string -AttributeIterator::GetCurrentPath (void) const -{ - std::ostringstream oss; - for (uint32_t i = 0; i < m_currentPath.size (); ++i) - { - oss << "/" << m_currentPath[i]; - } - return oss.str (); -} + std::string + AttributeIterator::GetCurrentPath (void) const + { + std::ostringstream oss; + for (uint32_t i = 0; i < m_currentPath.size (); ++i) + { + oss << "/" << m_currentPath[i]; + } + return oss.str (); + } -void -AttributeIterator::DoStartVisitObject (Ptr object) -{ -} -void -AttributeIterator::DoEndVisitObject (void) -{ -} -void -AttributeIterator::DoStartVisitPointerAttribute (Ptr object, std::string name, Ptr item) -{ -} -void -AttributeIterator::DoEndVisitPointerAttribute (void) -{ -} -void -AttributeIterator::DoStartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector) -{ -} -void -AttributeIterator::DoEndVisitArrayAttribute (void) -{ -} -void -AttributeIterator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item) -{ -} -void -AttributeIterator::DoEndVisitArrayItem (void) -{ -} + void + AttributeIterator::DoStartVisitObject (Ptr object) + { + } + void + AttributeIterator::DoEndVisitObject (void) + { + } + void + AttributeIterator::DoStartVisitPointerAttribute (Ptr object, std::string name, Ptr item) + { + } + void + AttributeIterator::DoEndVisitPointerAttribute (void) + { + } + void + AttributeIterator::DoStartVisitArrayAttribute (Ptr object, + std::string name, const ObjectPtrVectorValue &vector) + { + } + void + AttributeIterator::DoEndVisitArrayAttribute (void) + { + } + void + AttributeIterator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, + uint32_t index, Ptr item) + { + } + void + AttributeIterator::DoEndVisitArrayItem (void) + { + } -void -AttributeIterator::VisitAttribute (Ptr object, std::string name) -{ - m_currentPath.push_back (name); - DoVisitAttribute (object, name); - m_currentPath.pop_back (); -} + void + AttributeIterator::DoStartVisitMapAttribute (Ptr object, + std::string name, const ObjectPtrMapValue &map) + { -void -AttributeIterator::StartVisitObject (Ptr object) -{ - m_currentPath.push_back ("$" + object->GetInstanceTypeId ().GetName ()); - DoStartVisitObject (object); -} -void -AttributeIterator::EndVisitObject (void) -{ - m_currentPath.pop_back (); - DoEndVisitObject (); -} -void -AttributeIterator::StartVisitPointerAttribute (Ptr object, std::string name, Ptr value) -{ - m_currentPath.push_back (name); - m_currentPath.push_back ("$" + value->GetInstanceTypeId ().GetName ()); - DoStartVisitPointerAttribute (object, name, value); -} -void -AttributeIterator::EndVisitPointerAttribute (void) -{ - m_currentPath.pop_back (); - m_currentPath.pop_back (); - DoEndVisitPointerAttribute (); -} -void -AttributeIterator::StartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector) -{ - m_currentPath.push_back (name); - DoStartVisitArrayAttribute (object, name, vector); -} -void -AttributeIterator::EndVisitArrayAttribute (void) -{ - m_currentPath.pop_back (); - DoEndVisitArrayAttribute (); -} + } + void + AttributeIterator::DoEndVisitMapAttribute (void) + { -void -AttributeIterator::StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item) -{ - std::ostringstream oss; - oss << index; - m_currentPath.push_back (oss.str ()); - m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ()); - DoStartVisitArrayItem (vector, index, item); -} -void -AttributeIterator::EndVisitArrayItem (void) -{ - m_currentPath.pop_back (); - m_currentPath.pop_back (); - DoEndVisitArrayItem (); -} + } + void + AttributeIterator::DoStartVisitMapItem (const ObjectPtrMapValue &vector, + uint32_t index, Ptr item) + { -void -AttributeIterator::DoIterate (Ptr object) -{ - if (IsExamined (object)) - { - return; - } - TypeId tid; - for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ()) - { - NS_LOG_DEBUG ("store " << tid.GetName ()); - for (uint32_t i = 0; i < tid.GetAttributeN (); ++i) - { - struct TypeId::AttributeInformation info = tid.GetAttribute(i); - const PointerChecker *ptrChecker = dynamic_cast (PeekPointer (info.checker)); - if (ptrChecker != 0) - { - NS_LOG_DEBUG ("pointer attribute " << info.name); - PointerValue ptr; - object->GetAttribute (info.name, ptr); - Ptr tmp = ptr.Get (); - if (tmp != 0) - { - StartVisitPointerAttribute (object, info.name, - tmp); - m_examined.push_back (object); - DoIterate (tmp); - m_examined.pop_back (); - EndVisitPointerAttribute (); - } - continue; - } - // attempt to cast to an object vector. - const ObjectPtrContainerChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); - if (vectorChecker != 0) - { - NS_LOG_DEBUG ("vector attribute " << info.name); - ObjectPtrContainerValue vector; - object->GetAttribute (info.name, vector); - StartVisitArrayAttribute (object, info.name, vector); - for (uint32_t j = 0; j < vector.GetN (); ++j) - { - NS_LOG_DEBUG ("vector attribute item " << j); - Ptr tmp = vector.Get (j); - StartVisitArrayItem (vector, j, tmp); - m_examined.push_back (object); - DoIterate (tmp); - m_examined.pop_back (); - EndVisitArrayItem (); - } - EndVisitArrayAttribute (); - continue; - } - if ((info.flags & TypeId::ATTR_GET) && info.accessor->HasGetter () && - (info.flags & TypeId::ATTR_SET) && info.accessor->HasSetter ()) - { - VisitAttribute (object, info.name); - } - else - { - NS_LOG_DEBUG ("could not store " << info.name); - } - } - } - Object::AggregateIterator iter = object->GetAggregateIterator (); - bool recursiveAggregate = false; - while (iter.HasNext ()) - { - Ptr tmp = iter.Next (); - if (IsExamined (tmp)) - { - recursiveAggregate = true; - } - } - if (!recursiveAggregate) - { - iter = object->GetAggregateIterator (); - while (iter.HasNext ()) - { - Ptr tmp = const_cast (PeekPointer (iter.Next ())); - StartVisitObject (tmp); - m_examined.push_back (object); - DoIterate (tmp); - m_examined.pop_back (); - EndVisitObject (); - } - } -} + } + void + AttributeIterator::DoEndVisitMapItem (void) + { -} // namespace ns3 + } + + void + AttributeIterator::VisitAttribute (Ptr object, std::string name) + { + m_currentPath.push_back (name); + DoVisitAttribute (object, name); + m_currentPath.pop_back (); + } + + void + AttributeIterator::StartVisitObject (Ptr object) + { + m_currentPath.push_back ("$" + object->GetInstanceTypeId ().GetName ()); + DoStartVisitObject (object); + } + void + AttributeIterator::EndVisitObject (void) + { + m_currentPath.pop_back (); + DoEndVisitObject (); + } + void + AttributeIterator::StartVisitPointerAttribute (Ptr object, std::string name, Ptr value) + { + m_currentPath.push_back (name); + m_currentPath.push_back ("$" + value->GetInstanceTypeId ().GetName ()); + DoStartVisitPointerAttribute (object, name, value); + } + void + AttributeIterator::EndVisitPointerAttribute (void) + { + m_currentPath.pop_back (); + m_currentPath.pop_back (); + DoEndVisitPointerAttribute (); + } + void + AttributeIterator::StartVisitArrayAttribute (Ptr object, + std::string name, const ObjectPtrVectorValue &vector) + { + m_currentPath.push_back (name); + DoStartVisitArrayAttribute (object, name, vector); + } + void + AttributeIterator::EndVisitArrayAttribute (void) + { + m_currentPath.pop_back (); + DoEndVisitArrayAttribute (); + } + + void + AttributeIterator::StartVisitArrayItem (const ObjectPtrVectorValue &vector, + uint32_t index, Ptr item) + { + std::ostringstream oss; + oss << index; + m_currentPath.push_back (oss.str ()); + m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ()); + DoStartVisitArrayItem (vector, index, item); + } + void + AttributeIterator::EndVisitArrayItem (void) + { + m_currentPath.pop_back (); + m_currentPath.pop_back (); + DoEndVisitArrayItem (); + } + + void + AttributeIterator::StartVisitMapAttribute (Ptr object, + std::string name, const ObjectPtrMapValue &map) + { + m_currentPath.push_back (name); + DoStartVisitMapAttribute (object, name, map); + NS_LOG_INFO (this << GetCurrentPath ()); + } + + void + AttributeIterator::EndVisitMapAttribute (void) + { + m_currentPath.pop_back (); + DoEndVisitMapAttribute (); + } + + void + AttributeIterator::StartVisitMapItem (const ObjectPtrMapValue &map, + uint32_t index, Ptr item) + { + std::ostringstream oss; + oss << index; + m_currentPath.push_back (oss.str ()); + m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ()); + DoStartVisitMapItem (map, index, item); + NS_LOG_INFO (this << GetCurrentPath ()); + } + + void + AttributeIterator::EndVisitMapItem (void) + { + m_currentPath.pop_back (); + m_currentPath.pop_back (); + DoEndVisitMapItem (); + } + + void + AttributeIterator::DoIterate (Ptr object) + { + if (IsExamined (object)) + { + return; + } + TypeId tid; + for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid + = tid.GetParent ()) + { + NS_LOG_DEBUG ("store " << tid.GetName ()); + for (uint32_t i = 0; i < tid.GetAttributeN (); ++i) + { + struct TypeId::AttributeInformation info = tid.GetAttribute (i); + const PointerChecker *ptrChecker = + dynamic_cast (PeekPointer (info.checker)); + if (ptrChecker != 0) + { + NS_LOG_DEBUG ("pointer attribute " << info.name); + PointerValue ptr; + object->GetAttribute (info.name, ptr); + Ptr < Object > tmp = ptr.Get (); + if (tmp != 0) + { + StartVisitPointerAttribute (object, info.name, tmp); + m_examined.push_back (object); + DoIterate ( tmp); + m_examined.pop_back (); + EndVisitPointerAttribute (); + } + continue; + } + // attempt to cast to an object vector. + const ObjectPtrVectorChecker *vectorChecker =dynamic_cast (PeekPointer ( + info.checker)); + if (vectorChecker != 0) + { + NS_LOG_DEBUG ("vector attribute " << info.name); + ObjectPtrVectorValue vector; + object->GetAttribute (info.name, vector); + StartVisitArrayAttribute (object, info.name, vector); + for (uint32_t j = 0; j < vector.GetN (); ++j) + { + NS_LOG_DEBUG ("vector attribute item " << j); + Ptr < Object > tmp = vector.Get (j); + StartVisitArrayItem (vector, j, tmp); + m_examined.push_back (object); + DoIterate ( tmp); + m_examined.pop_back (); + EndVisitArrayItem (); + } + EndVisitArrayAttribute (); + continue; + } + // attempt to cast to an object map. + const ObjectPtrMapChecker *mapChecker = dynamic_cast (PeekPointer (info.checker)); + if (mapChecker != 0) + { + ObjectPtrMapValue map; + object->GetAttribute (info.name, map); + StartVisitMapAttribute (object, info.name, map); + for (ObjectPtrMapValue::Iterator it = map.Begin (); it != map.End (); it++) + { + NS_LOG_DEBUG ("map attribute index " << (*it).first << " item " << (*it).second); + StartVisitMapItem (map, (*it).first, (*it).second); + m_examined.push_back (object); + DoIterate ((*it).second); + m_examined.pop_back (); + EndVisitMapItem (); + } + EndVisitMapAttribute (); + continue; + } + if ((info.flags & TypeId::ATTR_GET) && info.accessor->HasGetter () + && (info.flags & TypeId::ATTR_SET) && info.accessor->HasSetter ()) + { + VisitAttribute (object, info.name); + } + else + { + NS_LOG_DEBUG ("could not store " << info.name); + } + } + Object::AggregateIterator iter = object->GetAggregateIterator (); + bool recursiveAggregate = false; + while (iter.HasNext ()) + { + Ptr tmp = iter.Next (); + if (IsExamined (tmp)) + { + recursiveAggregate = true; + } + } + if (!recursiveAggregate) + { + iter = object->GetAggregateIterator (); + while (iter.HasNext ()) + { + Ptr tmp = const_cast (PeekPointer (iter.Next ())); + StartVisitObject (tmp); + m_examined.push_back (object); + DoIterate (tmp); + m_examined.pop_back (); + EndVisitObject (); + } + } + } + + + } // namespace ns3 diff -r 90904c14135f -r f9c13ca8c8a6 src/config-store/model/attribute-iterator.h --- a/src/config-store/model/attribute-iterator.h Sun Jan 29 01:14:23 2012 +0100 +++ b/src/config-store/model/attribute-iterator.h Mon Jan 30 19:33:43 2012 +0100 @@ -21,7 +21,8 @@ #include "ns3/ptr.h" #include "ns3/object.h" -#include "ns3/object-ptr-container.h" +#include "ns3/object-ptr-vector.h" +#include "ns3/object-ptr-map.h" #include namespace ns3 { @@ -46,10 +47,14 @@ virtual void DoEndVisitObject (void); virtual void DoStartVisitPointerAttribute (Ptr object, std::string name, Ptr value); virtual void DoEndVisitPointerAttribute (void); - virtual void DoStartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector); + virtual void DoStartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrVectorValue &vector); virtual void DoEndVisitArrayAttribute (void); - virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item); + virtual void DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr item); virtual void DoEndVisitArrayItem (void); + virtual void DoStartVisitMapAttribute (Ptr object, std::string name, const ObjectPtrMapValue &map); + virtual void DoEndVisitMapAttribute (void); + virtual void DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr item); + virtual void DoEndVisitMapItem (void); void DoIterate (Ptr object); bool IsExamined (Ptr object); @@ -60,11 +65,14 @@ void EndVisitObject (void); void StartVisitPointerAttribute (Ptr object, std::string name, Ptr value); void EndVisitPointerAttribute (void); - void StartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector); + void StartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrVectorValue &vector); void EndVisitArrayAttribute (void); - void StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item); + void StartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr item); void EndVisitArrayItem (void); - + void StartVisitMapAttribute (Ptr object, std::string name, const ObjectPtrMapValue &map); + void EndVisitMapAttribute (void); + void StartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr item); + void EndVisitMapItem (void); std::vector > m_examined; std::vector m_currentPath; diff -r 90904c14135f -r f9c13ca8c8a6 src/config-store/model/model-node-creator.cc --- a/src/config-store/model/model-node-creator.cc Sun Jan 29 01:14:23 2012 +0100 +++ b/src/config-store/model/model-node-creator.cc Mon Jan 30 19:33:43 2012 +0100 @@ -91,8 +91,9 @@ { Remove (); } -void -ModelCreator::DoStartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector) +void +ModelCreator::DoStartVisitArrayAttribute (Ptr object, std::string name, + const ObjectPtrVectorValue &vector) { ModelNode *node = new ModelNode (); node->type = ModelNode::NODE_VECTOR; @@ -105,8 +106,9 @@ { Remove (); } -void -ModelCreator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item) +void +ModelCreator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, + uint32_t index, Ptr item) { GtkTreeIter *parent = m_iters.back (); GtkTreeIter *current = g_new (GtkTreeIter, 1); @@ -127,4 +129,43 @@ g_free (iter); m_iters.pop_back (); } + +void +ModelCreator::DoStartVisitMapAttribute (Ptr object, std::string name, + const ObjectPtrMapValue &map) +{ + ModelNode *node = new ModelNode (); + node->type = ModelNode::NODE_VECTOR; + node->object = object; + node->name = name; + Add (node); +} +void +ModelCreator::DoEndVisitMapAttribute (void) +{ + Remove (); +} +void +ModelCreator::DoStartVisitMapItem (const ObjectPtrMapValue &map, uint32_t index, + Ptr item) +{ + GtkTreeIter *parent = m_iters.back (); + GtkTreeIter *current = g_new (GtkTreeIter, 1); + ModelNode *node = new ModelNode (); + node->type = ModelNode::NODE_VECTOR_ITEM; + node->object = item; + node->index = index; + gtk_tree_store_append (m_treestore, current, parent); + gtk_tree_store_set (m_treestore, current, COL_NODE, node, -1); + m_iters.push_back (current); +} + +void +ModelCreator::DoEndVisitMapItem (void) +{ + GtkTreeIter *iter = m_iters.back (); + g_free (iter); + m_iters.pop_back (); +} + } //end namespace ns3 diff -r 90904c14135f -r f9c13ca8c8a6 src/config-store/model/model-node-creator.h --- a/src/config-store/model/model-node-creator.h Sun Jan 29 01:14:23 2012 +0100 +++ b/src/config-store/model/model-node-creator.h Mon Jan 30 19:33:43 2012 +0100 @@ -58,19 +58,42 @@ void Build (GtkTreeStore *treestore); private: - virtual void DoVisitAttribute (Ptr object, std::string name); - virtual void DoStartVisitObject (Ptr object); - virtual void DoEndVisitObject (void); - virtual void DoStartVisitPointerAttribute (Ptr object, std::string name, Ptr value); - virtual void DoEndVisitPointerAttribute (void); - virtual void DoStartVisitArrayAttribute (Ptr object, std::string name, - const ObjectPtrContainerValue &vector); - virtual void DoEndVisitArrayAttribute (void); - virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, - uint32_t index, Ptr item); - virtual void DoEndVisitArrayItem (void); - void Add (ModelNode *node); - void Remove (void); + virtual void + DoVisitAttribute (Ptr object, std::string name); + virtual void + DoStartVisitObject (Ptr object); + virtual void + DoEndVisitObject (void); + virtual void + DoStartVisitPointerAttribute (Ptr object, std::string name, + Ptr value); + virtual void + DoEndVisitPointerAttribute (void); + virtual void + DoStartVisitArrayAttribute (Ptr object, std::string name, + const ObjectPtrVectorValue &vector); + virtual void + DoEndVisitArrayAttribute (void); + virtual void + DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, + Ptr item); + virtual void + DoEndVisitArrayItem (void); + virtual void + DoStartVisitMapAttribute (Ptr object, std::string name, + const ObjectPtrMapValue &map); + virtual void + DoEndVisitMapAttribute (void); + virtual void + DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, + Ptr item); + virtual void + DoEndVisitMapItem (void); + + void + Add (ModelNode *node); + void + Remove (void); GtkTreeStore *m_treestore; std::vector m_iters; diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/config.cc --- a/src/core/model/config.cc Sun Jan 29 01:14:23 2012 +0100 +++ b/src/core/model/config.cc Mon Jan 30 19:33:43 2012 +0100 @@ -21,7 +21,8 @@ #include "singleton.h" #include "object.h" #include "global-value.h" -#include "object-ptr-container.h" +#include "object-ptr-vector.h" +#include "object-ptr-map.h" #include "names.h" #include "pointer.h" #include "log.h" @@ -226,7 +227,8 @@ private: void Canonicalize (void); void DoResolve (std::string path, Ptr root); - void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector); + void DoArrayResolve (std::string path, const ObjectPtrVectorValue &vector); + void DoMapResolve (std::string path, const ObjectPtrMapValue &map); void DoResolveOne (Ptr object); std::string GetResolvedPath (void) const; virtual void DoOne (Ptr object, std::string path) = 0; @@ -403,23 +405,34 @@ m_workStack.pop_back (); } // attempt to cast to an object vector. - const ObjectPtrContainerChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); + const ObjectPtrVectorChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); if (vectorChecker != 0) { NS_LOG_DEBUG ("GetAttribute(vector)="< v = tmp.checker->CreateValidValue (value); diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/object-map.h --- a/src/core/model/object-map.h Sun Jan 29 01:14:23 2012 +0100 +++ b/src/core/model/object-map.h Mon Jan 30 19:33:43 2012 +0100 @@ -20,15 +20,15 @@ #ifndef OBJECT_MAP_H #define OBJECT_MAP_H -#include +#include #include "object.h" #include "ptr.h" #include "attribute.h" -#include "object-ptr-container.h" +#include "object-ptr-map.h" namespace ns3 { -typedef ObjectPtrContainerValue ObjectMapValue; +typedef ObjectPtrMapValue ObjectMapValue; template Ptr @@ -39,12 +39,12 @@ template Ptr -MakeObjectVectorAccessor (Ptr (T::*get)(INDEX) const, +MakeObjectMapAccessor (Ptr (T::*get)(INDEX) const, INDEX (T::*getN)(void) const); template Ptr -MakeObjectVectorAccessor (INDEX (T::*getN)(void) const, +MakeObjectMapAccessor (INDEX (T::*getN)(void) const, Ptr (T::*get)(INDEX) const); } // namespace ns3 @@ -53,9 +53,9 @@ template Ptr -MakeObjectMapAccessor (U T::*memberVector) +MakeObjectMapAccessor (U T::*memberMap) { - struct MemberStdContainer : public ObjectPtrContainerAccessor + struct MemberStdContainer : public ObjectPtrMapAccessor { virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const { const T *obj = dynamic_cast (object); @@ -63,18 +63,20 @@ { return false; } - *n = (obj->*m_memberVector).size (); + + *n = (obj->*m_memberMap).size (); return true; } - virtual Ptr DoGet (const ObjectBase *object, uint32_t i) const { + virtual Ptr DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const { const T *obj = static_cast (object); - typename U::const_iterator begin = (obj->*m_memberVector).begin (); - typename U::const_iterator end = (obj->*m_memberVector).end (); + typename U::const_iterator begin = (obj->*m_memberMap).begin (); + typename U::const_iterator end = (obj->*m_memberMap).end (); uint32_t k = 0; for (typename U::const_iterator j = begin; j != end; j++, k++) { if (k == i) { + *index = (*j).first; return (*j).second; break; } @@ -83,16 +85,16 @@ // quiet compiler. return 0; } - U T::*m_memberVector; + U T::*m_memberMap; } *spec = new MemberStdContainer (); - spec->m_memberVector = memberVector; + spec->m_memberMap = memberMap; return Ptr (spec, false); } template Ptr MakeObjectMapChecker (void) { - return MakeObjectPtrContainerChecker (); + return MakeObjectPtrMapChecker (); } template @@ -100,7 +102,7 @@ MakeObjectMapAccessor (Ptr (T::*get)(INDEX) const, INDEX (T::*getN)(void) const) { - return MakeObjectPtrContainerAccessor(get, getN); + return MakeObjectPtrMapAccessor(get, getN); } template @@ -108,7 +110,7 @@ MakeObjectMapAccessor (INDEX (T::*getN)(void) const, Ptr (T::*get)(INDEX) const) { - return MakeObjectPtrContainerAccessor(get, getN); + return MakeObjectPtrMapAccessor(get, getN); } diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/object-ptr-map.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/model/object-ptr-map.cc Mon Jan 30 19:33:43 2012 +0100 @@ -0,0 +1,121 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA, Mathieu Lacage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Jaume Nin , Mathieu Lacage + */ +#include "object-ptr-map.h" + +namespace ns3 +{ + +ObjectPtrMapValue::ObjectPtrMapValue () +{ +} + +ObjectPtrMapValue::Iterator +ObjectPtrMapValue::Begin (void) const +{ + return m_objects.begin (); +} +ObjectPtrMapValue::Iterator +ObjectPtrMapValue::End (void) const +{ + return m_objects.end (); +} +uint32_t +ObjectPtrMapValue::GetN (void) const +{ + return m_objects.size (); +} +Ptr +ObjectPtrMapValue::Get (uint32_t i) const +{ + return m_objects.find (i)->second; +} + +Ptr +ObjectPtrMapValue::Copy (void) const +{ + return ns3::Create(*this); +} +std::string +ObjectPtrMapValue::SerializeToString (Ptr checker) const +{ + std::ostringstream oss; + Iterator it; + for (it = m_objects.begin (); it != m_objects.end (); ++it) + { + oss << (*it).second; + if (it != m_objects.end ()) + { + oss << " "; + } + } + return oss.str (); +} + +bool +ObjectPtrMapValue::DeserializeFromString (std::string value, + Ptr checker) +{ + NS_FATAL_ERROR ("cannot deserialize a map of object pointers."); + return true; +} + +bool +ObjectPtrMapAccessor::Set (ObjectBase * object, const AttributeValue & value) const +{ + // not allowed. + return false; +} +bool +ObjectPtrMapAccessor::Get (const ObjectBase * object, AttributeValue &value) const +{ + ObjectPtrMapValue *v = dynamic_cast (&value); + if (v == 0) + { + return false; + } + v->m_objects.clear (); + uint32_t n; + bool ok = DoGetN (object, &n); + if (!ok) + { + return false; + } + for (uint32_t i = 0; i < n; i++) + { + + uint32_t k; + Ptr < Object > element = DoGet (object, i, &k); + v->m_objects.insert (std::pair >(k, element)); + } + return true; +} + +bool +ObjectPtrMapAccessor::HasGetter (void) const +{ + return true; +} +bool +ObjectPtrMapAccessor::HasSetter (void) const +{ + return false; +} + +} // name diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/object-ptr-map.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/model/object-ptr-map.h Mon Jan 30 19:33:43 2012 +0100 @@ -0,0 +1,192 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA, Mathieu Lacage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#ifndef OBJECT_PTR_MAP_H +#define OBJECT_PTR_MAP_H + +#include +#include "object.h" +#include "ptr.h" +#include "attribute.h" + +namespace ns3 { + +/** + * \ingroup object + * + * \brief contain a map of ns3::Object pointers. + * + * This class it used to get attribute access to an array of + * ns3::Object pointers. + */ +class ObjectPtrMapValue : public AttributeValue +{ +public: + typedef std::map >::const_iterator Iterator; + + ObjectPtrMapValue (); + + /** + * \returns an iterator to the first object contained in this map + */ + Iterator Begin (void) const; + /** + * \returns an iterator to the last object contained in this map + */ + Iterator End (void) const; + /** + * \returns the number of objects contained in this map. + */ + uint32_t GetN (void) const; + /** + * \param i the index of the requested object. + * \returns the requested object + */ + Ptr Get (uint32_t i) const; + + virtual Ptr Copy (void) const; + virtual std::string SerializeToString (Ptr checker) const; + virtual bool DeserializeFromString (std::string value, Ptr checker); + +private: + friend class ObjectPtrMapAccessor; + std::map > m_objects; +}; + + +template +Ptr +MakeObjectPtrMapAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const); + +template +Ptr +MakeObjectPtrMapAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const); + +class ObjectPtrMapChecker : public AttributeChecker +{ +public: + virtual TypeId GetItemTypeId (void) const = 0; +}; + +template +Ptr MakeObjectPtrMapChecker (void); + +} // namespace ns3 + +namespace ns3 { + +namespace internal { + +template +class AnObjectPtrMapChecker : public ObjectPtrMapChecker +{ +public: + virtual TypeId GetItemTypeId (void) const { + return T::GetTypeId (); + } + virtual bool Check (const AttributeValue &value) const { + return dynamic_cast (&value) != 0; + } + virtual std::string GetValueTypeName (void) const { + return "ns3::ObjectPtrMapValue"; + } + virtual bool HasUnderlyingTypeInformation (void) const { + return true; + } + virtual std::string GetUnderlyingTypeInformation (void) const { + return "ns3::Ptr< " + T::GetTypeId ().GetName () + " >"; + } + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const ObjectPtrMapValue *src = dynamic_cast (&source); + ObjectPtrMapValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; + } +}; + +} // namespace internal + + +class ObjectPtrMapAccessor : public AttributeAccessor +{ +public: + virtual bool Set (ObjectBase * object, const AttributeValue &value) const; + virtual bool Get (const ObjectBase * object, AttributeValue &value) const; + virtual bool HasGetter (void) const; + virtual bool HasSetter (void) const; +private: + virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const = 0; + virtual Ptr DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const = 0; +}; + +template +Ptr +MakeObjectPtrMapAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const) +{ + struct MemberGetters : public ObjectPtrMapAccessor + { + virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const { + const T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + *n = (obj->*m_getN)(); + return true; + } + virtual Ptr DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const { + const T *obj = static_cast (object); + return (obj->*m_get)(i); + } + Ptr (T::*m_get)(INDEX) const; + INDEX (T::*m_getN)(void) const; + } *spec = new MemberGetters (); + spec->m_get = get; + spec->m_getN = getN; + return Ptr (spec, false); +} + +template +Ptr +MakeObjectPtrMapAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const) +{ + return MakeObjectPtrMapAccessor (get, getN); +} + +template +Ptr MakeObjectPtrMapChecker (void) +{ + return Create > (); +} + + +} // namespace ns3 + +#endif /* OBJECT_PTR_MAP_H */ diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/object-ptr-vector.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/model/object-ptr-vector.cc Mon Jan 30 19:33:43 2012 +0100 @@ -0,0 +1,114 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA, Mathieu Lacage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#include "object-ptr-vector.h" + +namespace ns3 { + +ObjectPtrVectorValue::ObjectPtrVectorValue () +{ +} + +ObjectPtrVectorValue::Iterator +ObjectPtrVectorValue::Begin (void) const +{ + return m_objects.begin (); +} +ObjectPtrVectorValue::Iterator +ObjectPtrVectorValue::End (void) const +{ + return m_objects.end (); +} +uint32_t +ObjectPtrVectorValue::GetN (void) const +{ + return m_objects.size (); +} +Ptr +ObjectPtrVectorValue::Get (uint32_t i) const +{ + return m_objects[i]; +} + +Ptr +ObjectPtrVectorValue::Copy (void) const +{ + return ns3::Create (*this); +} +std::string +ObjectPtrVectorValue::SerializeToString (Ptr checker) const +{ + std::ostringstream oss; + for (uint32_t i = 0; i < m_objects.size (); ++i) + { + oss << m_objects[i]; + if (i != m_objects.size () - 1) + { + oss << " "; + } + } + return oss.str (); +} +bool +ObjectPtrVectorValue::DeserializeFromString (std::string value, Ptr checker) +{ + NS_FATAL_ERROR ("cannot deserialize a vector of object pointers."); + return true; +} + +bool +ObjectPtrVectorAccessor::Set (ObjectBase * object, const AttributeValue & value) const +{ + // not allowed. + return false; +} +bool +ObjectPtrVectorAccessor::Get (const ObjectBase * object, AttributeValue &value) const +{ + ObjectPtrVectorValue *v = dynamic_cast (&value); + if (v == 0) + { + return false; + } + v->m_objects.clear (); + uint32_t n; + bool ok = DoGetN (object, &n); + if (!ok) + { + return false; + } + for (uint32_t i = 0; i < n; i++) + { + Ptr o = DoGet (object, i); + v->m_objects.push_back (o); + } + return true; +} +bool +ObjectPtrVectorAccessor::HasGetter (void) const +{ + return true; +} +bool +ObjectPtrVectorAccessor::HasSetter (void) const +{ + return false; +} + +} // name diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/object-ptr-vector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/model/object-ptr-vector.h Mon Jan 30 19:33:43 2012 +0100 @@ -0,0 +1,192 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA, Mathieu Lacage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#ifndef OBJECT_PTR_VECTOR_H +#define OBJECT_PTR_VECTOR_H + +#include +#include "object.h" +#include "ptr.h" +#include "attribute.h" + +namespace ns3 { + +/** + * \ingroup object + * + * \brief contain a vector of ns3::Object pointers. + * + * This class it used to get attribute access to an array of + * ns3::Object pointers. + */ +class ObjectPtrVectorValue : public AttributeValue +{ +public: + typedef std::vector >::const_iterator Iterator; + + ObjectPtrVectorValue (); + + /** + * \returns an iterator to the first object contained in this vector + */ + Iterator Begin (void) const; + /** + * \returns an iterator to the last object contained in this vector + */ + Iterator End (void) const; + /** + * \returns the number of objects contained in this vector. + */ + uint32_t GetN (void) const; + /** + * \param i the index of the requested object. + * \returns the requested object + */ + Ptr Get (uint32_t i) const; + + virtual Ptr Copy (void) const; + virtual std::string SerializeToString (Ptr checker) const; + virtual bool DeserializeFromString (std::string value, Ptr checker); + +private: + friend class ObjectPtrVectorAccessor; + std::vector > m_objects; +}; + + +template +Ptr +MakeObjectPtrVectorAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const); + +template +Ptr +MakeObjectPtrVectorAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const); + +class ObjectPtrVectorChecker : public AttributeChecker +{ +public: + virtual TypeId GetItemTypeId (void) const = 0; +}; + +template +Ptr MakeObjectPtrVectorChecker (void); + +} // namespace ns3 + +namespace ns3 { + +namespace internal { + +template +class AnObjectPtrVectorChecker : public ObjectPtrVectorChecker +{ +public: + virtual TypeId GetItemTypeId (void) const { + return T::GetTypeId (); + } + virtual bool Check (const AttributeValue &value) const { + return dynamic_cast (&value) != 0; + } + virtual std::string GetValueTypeName (void) const { + return "ns3::ObjectPtrVectorValue"; + } + virtual bool HasUnderlyingTypeInformation (void) const { + return true; + } + virtual std::string GetUnderlyingTypeInformation (void) const { + return "ns3::Ptr< " + T::GetTypeId ().GetName () + " >"; + } + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const ObjectPtrVectorValue *src = dynamic_cast (&source); + ObjectPtrVectorValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; + } +}; + +} // namespace internal + + +class ObjectPtrVectorAccessor : public AttributeAccessor +{ +public: + virtual bool Set (ObjectBase * object, const AttributeValue &value) const; + virtual bool Get (const ObjectBase * object, AttributeValue &value) const; + virtual bool HasGetter (void) const; + virtual bool HasSetter (void) const; +private: + virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const = 0; + virtual Ptr DoGet (const ObjectBase *object, uint32_t i) const = 0; +}; + +template +Ptr +MakeObjectPtrVectorAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const) +{ + struct MemberGetters : public ObjectPtrVectorAccessor + { + virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const { + const T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + *n = (obj->*m_getN)(); + return true; + } + virtual Ptr DoGet (const ObjectBase *object, uint32_t i) const { + const T *obj = static_cast (object); + return (obj->*m_get)(i); + } + Ptr (T::*m_get)(INDEX) const; + INDEX (T::*m_getN)(void) const; + } *spec = new MemberGetters (); + spec->m_get = get; + spec->m_getN = getN; + return Ptr (spec, false); +} + +template +Ptr +MakeObjectPtrVectorAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const) +{ + return MakeObjectPtrVectorAccessor (get, getN); +} + +template +Ptr MakeObjectPtrVectorChecker (void) +{ + return Create > (); +} + + +} // namespace ns3 + +#endif /* OBJECT_PTR_VECTOR_H */ diff -r 90904c14135f -r f9c13ca8c8a6 src/core/model/object-vector.h --- a/src/core/model/object-vector.h Sun Jan 29 01:14:23 2012 +0100 +++ b/src/core/model/object-vector.h Mon Jan 30 19:33:43 2012 +0100 @@ -24,11 +24,11 @@ #include "object.h" #include "ptr.h" #include "attribute.h" -#include "object-ptr-container.h" +#include "object-ptr-vector.h" namespace ns3 { -typedef ObjectPtrContainerValue ObjectVectorValue; +typedef ObjectPtrVectorValue ObjectVectorValue; template Ptr @@ -55,7 +55,7 @@ Ptr MakeObjectVectorAccessor (U T::*memberVector) { - struct MemberStdContainer : public ObjectPtrContainerAccessor + struct MemberStdContainer : public ObjectPtrVectorAccessor { virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const { const T *obj = dynamic_cast (object); @@ -92,23 +92,23 @@ template Ptr MakeObjectVectorChecker (void) { - return MakeObjectPtrContainerChecker (); + return MakeObjectPtrVectorChecker (); } template Ptr MakeObjectVectorAccessor (Ptr (T::*get)(INDEX) const, - INDEX (T::*getN)(void) const) + INDEX (T::*getN)(void) const) { - return MakeObjectPtrContainerAccessor(get, getN); + return MakeObjectPtrVectorAccessor(get, getN); } template Ptr MakeObjectVectorAccessor (INDEX (T::*getN)(void) const, - Ptr (T::*get)(INDEX) const) + Ptr (T::*get)(INDEX) const) { - return MakeObjectPtrContainerAccessor(get, getN); + return MakeObjectPtrVectorAccessor(get, getN); } diff -r 90904c14135f -r f9c13ca8c8a6 src/core/wscript --- a/src/core/wscript Sun Jan 29 01:14:23 2012 +0100 +++ b/src/core/wscript Mon Jan 30 19:33:43 2012 +0100 @@ -137,7 +137,8 @@ 'model/int64x64.cc', 'model/string.cc', 'model/pointer.cc', - 'model/object-ptr-container.cc', + 'model/object-ptr-vector.cc', + 'model/object-ptr-map.cc', 'model/object-factory.cc', 'model/global-value.cc', 'model/trace-source-accessor.cc', @@ -231,7 +232,8 @@ 'model/traced-value.h', 'model/trace-source-accessor.h', 'model/config.h', - 'model/object-ptr-container.h', + 'model/object-ptr-vector.h', + 'model/object-ptr-map.h', 'model/object-vector.h', 'model/object-map.h', 'model/deprecated.h',