fixed problems with ns-3-dev ObjectMap implementation

This commit is contained in:
Jaume Nin
2011-10-24 18:08:24 +02:00
parent ac91c4f48e
commit 6de5685111
15 changed files with 1083 additions and 262 deletions

View File

@@ -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 @@ AttributeDefaultIterator::Iterate (void)
//No value, check next attribute
continue;
}
Ptr<const ObjectPtrContainerValue> vector = DynamicCast<const ObjectPtrContainerValue> (info.initialValue);
Ptr<const ObjectPtrVectorValue> vector = DynamicCast<const ObjectPtrVectorValue> (info.initialValue);
if (vector != 0)
{
//a vector value, won't take it
continue;
}
Ptr<const ObjectPtrMapValue> map = DynamicCast<const ObjectPtrMapValue> (info.initialValue);
if (map != 0)
{
//a map value, won't take it
continue;
}
Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (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 ());

View File

@@ -15,20 +15,18 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "attribute-iterator.h"
#include "ns3/config.h"
#include "ns3/log.h"
#include "ns3/pointer.h"
#include "ns3/object-ptr-container.h"
#include "ns3/string.h"
#include <fstream>
NS_LOG_COMPONENT_DEFINE ("AttributeIterator");
namespace ns3 {
namespace ns3
{
AttributeIterator::AttributeIterator ()
{
@@ -38,246 +36,331 @@ AttributeIterator::~AttributeIterator ()
{
}
void
void
AttributeIterator::Iterate (void)
{
for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i)
{
Ptr<Object> object = Config::GetRootNamespaceObject (i);
StartVisitObject (object);
DoIterate (object);
EndVisitObject ();
}
NS_ASSERT (m_currentPath.empty ());
NS_ASSERT (m_examined.empty ());
for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN(); ++i)
{
Ptr < Object > object = Config::GetRootNamespaceObject(i);
StartVisitObject ( object);
DoIterate(object);
EndVisitObject();
}
NS_ASSERT(m_currentPath.empty());
NS_ASSERT(m_examined.empty());
}
bool
AttributeIterator::IsExamined (Ptr<const Object> object)
{
for (uint32_t i = 0; i < m_examined.size (); ++i)
for (uint32_t i = 0; i < m_examined.size(); ++i)
{
if (object == m_examined[i])
{
if (object == m_examined[i])
{
return true;
}
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];
}
for (uint32_t i = 0; i < m_currentPath.size(); ++i)
{
oss << "/" << m_currentPath[i];
}
if (attr != "")
{
oss << "/" << attr;
}
return oss.str ();
{
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 ();
for (uint32_t i = 0; i < m_currentPath.size(); ++i)
{
oss << "/" << m_currentPath[i];
}
return oss.str();
}
void
void
AttributeIterator::DoStartVisitObject (Ptr<Object> object)
{
}
void
void
AttributeIterator::DoEndVisitObject (void)
{
}
void
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
void
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object,
std::string name, Ptr<Object> item)
{
}
void
void
AttributeIterator::DoEndVisitPointerAttribute (void)
{
}
void
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
void
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object,
std::string name, const ObjectPtrVectorValue &vector)
{
}
void
void
AttributeIterator::DoEndVisitArrayAttribute (void)
{
}
void
AttributeIterator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
void
AttributeIterator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector,
uint32_t index, Ptr<Object> item)
{
}
void
void
AttributeIterator::DoEndVisitArrayItem (void)
{
}
void
void
AttributeIterator::DoStartVisitMapAttribute (Ptr<Object> object,
std::string name, const ObjectPtrMapValue &map)
{
}
void
AttributeIterator::DoEndVisitMapAttribute (void)
{
}
void
AttributeIterator::DoStartVisitMapItem (const ObjectPtrMapValue &vector,
uint32_t index, Ptr<Object> item)
{
}
void
AttributeIterator::DoEndVisitMapItem (void)
{
}
void
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
{
m_currentPath.push_back (name);
DoVisitAttribute (object, name);
m_currentPath.pop_back ();
m_currentPath.push_back(name);
DoVisitAttribute(object, name);
m_currentPath.pop_back();
}
void
void
AttributeIterator::StartVisitObject (Ptr<Object> object)
{
m_currentPath.push_back ("$" + object->GetInstanceTypeId ().GetName ());
DoStartVisitObject (object);
m_currentPath.push_back("$" + object->GetInstanceTypeId().GetName());
DoStartVisitObject(object);
}
void
void
AttributeIterator::EndVisitObject (void)
{
m_currentPath.pop_back ();
DoEndVisitObject ();
m_currentPath.pop_back();
DoEndVisitObject();
}
void
AttributeIterator::StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
void
AttributeIterator::StartVisitPointerAttribute (Ptr<Object> object,
std::string name, Ptr<Object> value)
{
m_currentPath.push_back (name);
m_currentPath.push_back ("$" + value->GetInstanceTypeId ().GetName ());
DoStartVisitPointerAttribute (object, name, value);
m_currentPath.push_back(name);
m_currentPath.push_back("$" + value->GetInstanceTypeId().GetName());
DoStartVisitPointerAttribute(object, name, value);
}
void
void
AttributeIterator::EndVisitPointerAttribute (void)
{
m_currentPath.pop_back ();
m_currentPath.pop_back ();
DoEndVisitPointerAttribute ();
m_currentPath.pop_back();
m_currentPath.pop_back();
DoEndVisitPointerAttribute();
}
void
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
void
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object,
std::string name, const ObjectPtrVectorValue &vector)
{
m_currentPath.push_back (name);
DoStartVisitArrayAttribute (object, name, vector);
m_currentPath.push_back(name);
DoStartVisitArrayAttribute(object, name, vector);
}
void
void
AttributeIterator::EndVisitArrayAttribute (void)
{
m_currentPath.pop_back ();
DoEndVisitArrayAttribute ();
m_currentPath.pop_back();
DoEndVisitArrayAttribute();
}
void
AttributeIterator::StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
void
AttributeIterator::StartVisitArrayItem (const ObjectPtrVectorValue &vector,
uint32_t index, Ptr<Object> item)
{
std::ostringstream oss;
oss << index;
m_currentPath.push_back (oss.str ());
m_currentPath.push_back ("$" + item->GetInstanceTypeId ().GetName ());
DoStartVisitArrayItem (vector, index, item);
m_currentPath.push_back(oss.str());
m_currentPath.push_back("$" + item->GetInstanceTypeId().GetName());
DoStartVisitArrayItem(vector, index, item);
}
void
void
AttributeIterator::EndVisitArrayItem (void)
{
m_currentPath.pop_back ();
m_currentPath.pop_back ();
DoEndVisitArrayItem ();
m_currentPath.pop_back();
m_currentPath.pop_back();
DoEndVisitArrayItem();
}
void
AttributeIterator::StartVisitMapAttribute (Ptr<Object> 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<Object> 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> object)
{
if (IsExamined (object))
{
return;
}
if (IsExamined(object))
{
return;
}
TypeId tid;
for (tid = object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ())
for (tid = object->GetInstanceTypeId(); tid.HasParent(); tid
= tid.GetParent())
{
NS_LOG_DEBUG("store " << tid.GetName());
for (uint32_t i = 0; i < tid.GetAttributeN(); ++i)
{
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<const PointerChecker *> (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<Object> ();
if (tmp != 0)
{
struct TypeId::AttributeInformation info = tid.GetAttribute(i);
const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (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<Object> ();
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<const ObjectPtrContainerChecker *> (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<Object> 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);
}
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<const ObjectPtrVectorChecker *> (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<const ObjectPtrMapChecker *> (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 ();
}
Object::AggregateIterator iter = object->GetAggregateIterator();
bool recursiveAggregate = false;
while (iter.HasNext ())
while (iter.HasNext())
{
Ptr<const Object> tmp = iter.Next();
if (IsExamined(tmp))
{
Ptr<const Object> tmp = iter.Next ();
if (IsExamined (tmp))
{
recursiveAggregate = true;
}
recursiveAggregate = true;
}
}
if (!recursiveAggregate)
{
iter = object->GetAggregateIterator();
while (iter.HasNext())
{
iter = object->GetAggregateIterator ();
while (iter.HasNext ())
{
Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
StartVisitObject (tmp);
m_examined.push_back (object);
DoIterate (tmp);
m_examined.pop_back ();
EndVisitObject ();
}
Ptr < Object > tmp = const_cast<Object *> (PeekPointer(iter.Next()));
StartVisitObject ( tmp);
m_examined.push_back(object);
DoIterate(tmp);
m_examined.pop_back();
EndVisitObject();
}
}
}
} // namespace ns3

View File

@@ -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 <vector>
namespace ns3 {
@@ -46,10 +47,14 @@ private:
virtual void DoEndVisitObject (void);
virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
virtual void DoEndVisitPointerAttribute (void);
virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrVectorValue &vector);
virtual void DoEndVisitArrayAttribute (void);
virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
virtual void DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr<Object> item);
virtual void DoEndVisitArrayItem (void);
virtual void DoStartVisitMapAttribute (Ptr<Object> object, std::string name, const ObjectPtrMapValue &map);
virtual void DoEndVisitMapAttribute (void);
virtual void DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr<Object> item);
virtual void DoEndVisitMapItem (void);
void DoIterate (Ptr<Object> object);
bool IsExamined (Ptr<const Object> object);
@@ -60,11 +65,14 @@ private:
void EndVisitObject (void);
void StartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
void EndVisitPointerAttribute (void);
void StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
void StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrVectorValue &vector);
void EndVisitArrayAttribute (void);
void StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
void StartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index, Ptr<Object> item);
void EndVisitArrayItem (void);
void StartVisitMapAttribute (Ptr<Object> object, std::string name, const ObjectPtrMapValue &map);
void EndVisitMapAttribute (void);
void StartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index, Ptr<Object> item);
void EndVisitMapItem (void);
std::vector<Ptr<Object> > m_examined;
std::vector<std::string> m_currentPath;

View File

@@ -16,9 +16,10 @@
* Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "model-node-creator.h"
namespace ns3 {
namespace ns3
{
ModelCreator::ModelCreator ()
{
@@ -28,103 +29,141 @@ void
ModelCreator::Build (GtkTreeStore *treestore)
{
m_treestore = treestore;
m_iters.push_back (0);
m_iters.push_back(0);
//this function will go through all the objects and call on them
//DoStartVisitObject, DoIterate and DoEndVisitObject
Iterate ();
NS_ASSERT (m_iters.size () == 1);
Iterate();
NS_ASSERT(m_iters.size() == 1);
}
void
ModelCreator::Add (ModelNode *node)
{
GtkTreeIter *parent = m_iters.back ();
GtkTreeIter *current = g_new (GtkTreeIter, 1);
gtk_tree_store_append (m_treestore, current, parent);
gtk_tree_store_set (m_treestore, current,
COL_NODE, node, -1);
m_iters.push_back (current);
GtkTreeIter *parent = m_iters.back();
GtkTreeIter *current = g_new(GtkTreeIter, 1);
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::Remove (void)
{
GtkTreeIter *iter = m_iters.back ();
g_free (iter);
m_iters.pop_back ();
GtkTreeIter *iter = m_iters.back();
g_free(iter);
m_iters.pop_back();
}
void
void
ModelCreator::DoVisitAttribute (Ptr<Object> object, std::string name)
{
ModelNode *node = new ModelNode ();
ModelNode *node = new ModelNode();
node->type = ModelNode::NODE_ATTRIBUTE;
node->object = object;
node->name = name;
Add (node);
Remove ();
Add(node);
Remove();
}
void
void
ModelCreator::DoStartVisitObject (Ptr<Object> object)
{
ModelNode *node = new ModelNode ();
ModelNode *node = new ModelNode();
node->type = ModelNode::NODE_OBJECT;
node->object = object;
Add (node);
Add(node);
}
void
void
ModelCreator::DoEndVisitObject (void)
{
Remove ();
Remove();
}
void
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
void
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object,
std::string name, Ptr<Object> value)
{
ModelNode *node = new ModelNode ();
ModelNode *node = new ModelNode();
node->type = ModelNode::NODE_POINTER;
node->object = object;
node->name = name;
Add (node);
Add(node);
}
void
void
ModelCreator::DoEndVisitPointerAttribute (void)
{
Remove ();
Remove();
}
void
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
void
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
const ObjectPtrVectorValue &vector)
{
ModelNode *node = new ModelNode ();
ModelNode *node = new ModelNode();
node->type = ModelNode::NODE_VECTOR;
node->object = object;
node->name = name;
Add (node);
Add(node);
}
void
void
ModelCreator::DoEndVisitArrayAttribute (void)
{
Remove ();
Remove();
}
void
ModelCreator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
void
ModelCreator::DoStartVisitArrayItem (const ObjectPtrVectorValue &vector,
uint32_t index, Ptr<Object> item)
{
GtkTreeIter *parent = m_iters.back ();
GtkTreeIter *current = g_new (GtkTreeIter, 1);
ModelNode *node = new ModelNode ();
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);
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
void
ModelCreator::DoEndVisitArrayItem (void)
{
GtkTreeIter *iter = m_iters.back ();
g_free (iter);
m_iters.pop_back ();
GtkTreeIter *iter = m_iters.back();
g_free(iter);
m_iters.pop_back();
}
void
ModelCreator::DoStartVisitMapAttribute (Ptr<Object> 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<Object> 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

View File

@@ -56,21 +56,45 @@ class ModelCreator : public AttributeIterator
public:
ModelCreator ();
void Build (GtkTreeStore *treestore);
void
Build (GtkTreeStore *treestore);
private:
virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
virtual void DoStartVisitObject (Ptr<Object> object);
virtual void DoEndVisitObject (void);
virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
virtual void DoEndVisitPointerAttribute (void);
virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
const ObjectPtrContainerValue &vector);
virtual void DoEndVisitArrayAttribute (void);
virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector,
uint32_t index, Ptr<Object> item);
virtual void DoEndVisitArrayItem (void);
void Add (ModelNode *node);
void Remove (void);
virtual void
DoVisitAttribute (Ptr<Object> object, std::string name);
virtual void
DoStartVisitObject (Ptr<Object> object);
virtual void
DoEndVisitObject (void);
virtual void
DoStartVisitPointerAttribute (Ptr<Object> object, std::string name,
Ptr<Object> value);
virtual void
DoEndVisitPointerAttribute (void);
virtual void
DoStartVisitArrayAttribute (Ptr<Object> object, std::string name,
const ObjectPtrVectorValue &vector);
virtual void
DoEndVisitArrayAttribute (void);
virtual void
DoStartVisitArrayItem (const ObjectPtrVectorValue &vector, uint32_t index,
Ptr<Object> item);
virtual void
DoEndVisitArrayItem (void);
virtual void
DoStartVisitMapAttribute (Ptr<Object> object, std::string name,
const ObjectPtrMapValue &map);
virtual void
DoEndVisitMapAttribute (void);
virtual void
DoStartVisitMapItem (const ObjectPtrMapValue &vector, uint32_t index,
Ptr<Object> item);
virtual void
DoEndVisitMapItem (void);
void
Add (ModelNode *node);
void
Remove (void);
GtkTreeStore *m_treestore;
std::vector<GtkTreeIter *> m_iters;

View File

@@ -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 @@ public:
private:
void Canonicalize (void);
void DoResolve (std::string path, Ptr<Object> 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> object);
std::string GetResolvedPath (void) const;
virtual void DoOne (Ptr<Object> object, std::string path) = 0;
@@ -403,23 +405,34 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
m_workStack.pop_back ();
}
// attempt to cast to an object vector.
const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
const ObjectPtrVectorChecker *vectorChecker = dynamic_cast<const ObjectPtrVectorChecker *> (PeekPointer (info.checker));
if (vectorChecker != 0)
{
NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath ());
ObjectPtrContainerValue vector;
ObjectPtrVectorValue vector;
root->GetAttribute (item, vector);
m_workStack.push_back (item);
DoArrayResolve (pathLeft, vector);
m_workStack.pop_back ();
}
// attempt to cast to an object map.
const ObjectPtrMapChecker *mapChecker = dynamic_cast<const ObjectPtrMapChecker *> (PeekPointer (info.checker));
if (mapChecker != 0)
{
NS_LOG_DEBUG ("GetAttribute(map)="<<item<<" on path="<<GetResolvedPath ());
ObjectPtrMapValue map;
root->GetAttribute (item, map);
m_workStack.push_back (item);
DoMapResolve (pathLeft, map);
m_workStack.pop_back ();
}
// this could be anything else and we don't know what to do with it.
// So, we just ignore it.
}
}
void
Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector)
Resolver::DoArrayResolve (std::string path, const ObjectPtrVectorValue &vector)
{
NS_ASSERT (path != "");
NS_ASSERT ((path.find ("/")) == 0);
@@ -445,6 +458,34 @@ Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &vecto
}
}
void
Resolver::DoMapResolve (std::string path, const ObjectPtrMapValue &map)
{
NS_ASSERT (path != "");
NS_ASSERT ((path.find ("/")) == 0);
std::string::size_type next = path.find ("/", 1);
if (next == std::string::npos)
{
NS_FATAL_ERROR ("map path includes no index data on path=\""<<path<<"\"");
}
std::string item = path.substr (1, next-1);
std::string pathLeft = path.substr (next, path.size ()-next);
ArrayMatcher matcher = ArrayMatcher (item);
ObjectPtrMapValue::Iterator it;
for (it = map.Begin (); it != map.End (); ++it)
{
if (matcher.Matches ((*it).first))
{
std::ostringstream oss;
oss << (*it).first;
m_workStack.push_back (oss.str ());
DoResolve (pathLeft, (*it).second);
m_workStack.pop_back ();
}
}
}
class ConfigImpl
{

View File

@@ -20,15 +20,15 @@
#ifndef OBJECT_MAP_H
#define OBJECT_MAP_H
#include <vector>
#include <map>
#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 <typename T, typename U>
Ptr<const AttributeAccessor>
@@ -39,23 +39,19 @@ Ptr<const AttributeChecker> MakeObjectMapChecker (void);
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
INDEX (T::*getN)(void) const);
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const);
} // namespace ns3
namespace ns3 {
template <typename T, typename U>
Ptr<const AttributeAccessor>
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<const T *> (object);
@@ -63,18 +59,20 @@ MakeObjectMapAccessor (U T::*memberVector)
{
return false;
}
*n = (obj->*m_memberVector).size ();
*n = (obj->*m_memberMap).size ();
return true;
}
virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) const {
virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const {
const T *obj = static_cast<const T *> (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 +81,16 @@ MakeObjectMapAccessor (U T::*memberVector)
// 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<const AttributeAccessor> (spec, false);
}
template <typename T>
Ptr<const AttributeChecker> MakeObjectMapChecker (void)
{
return MakeObjectPtrContainerChecker<T> ();
return MakeObjectPtrMapChecker<T> ();
}
template <typename T, typename U, typename INDEX>
@@ -100,7 +98,7 @@ Ptr<const AttributeAccessor>
MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
INDEX (T::*getN)(void) const)
{
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
return MakeObjectPtrMapAccessor<T,U,INDEX>(get, getN);
}
template <typename T, typename U, typename INDEX>
@@ -108,7 +106,7 @@ Ptr<const AttributeAccessor>
MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const)
{
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
return MakeObjectPtrMapAccessor<T,U,INDEX>(get, getN);
}

View File

@@ -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 <jaume.nin@cttc.cat>, Mathieu Lacage <mathieu.lacage@gmail.com>
*/
#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<Object>
ObjectPtrMapValue::Get (uint32_t i) const
{
return m_objects.find(i)->second;
}
Ptr<AttributeValue>
ObjectPtrMapValue::Copy (void) const
{
return ns3::Create<ObjectPtrMapValue>(*this);
}
std::string
ObjectPtrMapValue::SerializeToString (Ptr<const AttributeChecker> 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<const AttributeChecker> 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<ObjectPtrMapValue *> (&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<uint32_t, Ptr<Object> >(k, element));
}
return true;
}
bool
ObjectPtrMapAccessor::HasGetter (void) const
{
return true;
}
bool
ObjectPtrMapAccessor::HasSetter (void) const
{
return false;
}
} // name

View File

@@ -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 <mathieu.lacage@gmail.com>
*/
#ifndef OBJECT_PTR_MAP_H
#define OBJECT_PTR_MAP_H
#include <map>
#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<uint32_t, Ptr<Object> >::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<Object> Get (uint32_t i) const;
virtual Ptr<AttributeValue> Copy (void) const;
virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
private:
friend class ObjectPtrMapAccessor;
std::map<uint32_t, Ptr<Object> > m_objects;
};
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrMapAccessor (Ptr<U> (T::*get)(INDEX) const,
INDEX (T::*getN)(void) const);
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrMapAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const);
class ObjectPtrMapChecker : public AttributeChecker
{
public:
virtual TypeId GetItemTypeId (void) const = 0;
};
template <typename T>
Ptr<const AttributeChecker> MakeObjectPtrMapChecker (void);
} // namespace ns3
namespace ns3 {
namespace internal {
template <typename T>
class AnObjectPtrMapChecker : public ObjectPtrMapChecker
{
public:
virtual TypeId GetItemTypeId (void) const {
return T::GetTypeId ();
}
virtual bool Check (const AttributeValue &value) const {
return dynamic_cast<const ObjectPtrMapValue *> (&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<AttributeValue> Create (void) const {
return ns3::Create<ObjectPtrMapValue> ();
}
virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
const ObjectPtrMapValue *src = dynamic_cast<const ObjectPtrMapValue *> (&source);
ObjectPtrMapValue *dst = dynamic_cast<ObjectPtrMapValue *> (&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<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const = 0;
};
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrMapAccessor (Ptr<U> (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<const T *> (object);
if (obj == 0)
{
return false;
}
*n = (obj->*m_getN)();
return true;
}
virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const {
const T *obj = static_cast<const T *> (object);
return (obj->*m_get)(i);
}
Ptr<U> (T::*m_get)(INDEX) const;
INDEX (T::*m_getN)(void) const;
} *spec = new MemberGetters ();
spec->m_get = get;
spec->m_getN = getN;
return Ptr<const AttributeAccessor> (spec, false);
}
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrMapAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const)
{
return MakeObjectPtrMapAccessor (get, getN);
}
template <typename T>
Ptr<const AttributeChecker> MakeObjectPtrMapChecker (void)
{
return Create<internal::AnObjectPtrMapChecker<T> > ();
}
} // namespace ns3
#endif /* OBJECT_PTR_MAP_H */

View File

@@ -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 <mathieu.lacage@gmail.com>
*/
#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<Object>
ObjectPtrVectorValue::Get (uint32_t i) const
{
return m_objects[i];
}
Ptr<AttributeValue>
ObjectPtrVectorValue::Copy (void) const
{
return ns3::Create<ObjectPtrVectorValue> (*this);
}
std::string
ObjectPtrVectorValue::SerializeToString (Ptr<const AttributeChecker> 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<const AttributeChecker> 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<ObjectPtrVectorValue *> (&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<Object> 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

View File

@@ -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 <mathieu.lacage@gmail.com>
*/
#ifndef OBJECT_PTR_VECTOR_H
#define OBJECT_PTR_VECTOR_H
#include <vector>
#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<Ptr<Object> >::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<Object> Get (uint32_t i) const;
virtual Ptr<AttributeValue> Copy (void) const;
virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
private:
friend class ObjectPtrVectorAccessor;
std::vector<Ptr<Object> > m_objects;
};
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
INDEX (T::*getN)(void) const);
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrVectorAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const);
class ObjectPtrVectorChecker : public AttributeChecker
{
public:
virtual TypeId GetItemTypeId (void) const = 0;
};
template <typename T>
Ptr<const AttributeChecker> MakeObjectPtrVectorChecker (void);
} // namespace ns3
namespace ns3 {
namespace internal {
template <typename T>
class AnObjectPtrVectorChecker : public ObjectPtrVectorChecker
{
public:
virtual TypeId GetItemTypeId (void) const {
return T::GetTypeId ();
}
virtual bool Check (const AttributeValue &value) const {
return dynamic_cast<const ObjectPtrVectorValue *> (&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<AttributeValue> Create (void) const {
return ns3::Create<ObjectPtrVectorValue> ();
}
virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
const ObjectPtrVectorValue *src = dynamic_cast<const ObjectPtrVectorValue *> (&source);
ObjectPtrVectorValue *dst = dynamic_cast<ObjectPtrVectorValue *> (&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<Object> DoGet (const ObjectBase *object, uint32_t i) const = 0;
};
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrVectorAccessor (Ptr<U> (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<const T *> (object);
if (obj == 0)
{
return false;
}
*n = (obj->*m_getN)();
return true;
}
virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) const {
const T *obj = static_cast<const T *> (object);
return (obj->*m_get)(i);
}
Ptr<U> (T::*m_get)(INDEX) const;
INDEX (T::*m_getN)(void) const;
} *spec = new MemberGetters ();
spec->m_get = get;
spec->m_getN = getN;
return Ptr<const AttributeAccessor> (spec, false);
}
template <typename T, typename U, typename INDEX>
Ptr<const AttributeAccessor>
MakeObjectPtrVectorAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const)
{
return MakeObjectPtrVectorAccessor (get, getN);
}
template <typename T>
Ptr<const AttributeChecker> MakeObjectPtrVectorChecker (void)
{
return Create<internal::AnObjectPtrVectorChecker<T> > ();
}
} // namespace ns3
#endif /* OBJECT_PTR_VECTOR_H */

View File

@@ -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 <typename T, typename U>
Ptr<const AttributeAccessor>
@@ -55,7 +55,7 @@ template <typename T, typename U>
Ptr<const AttributeAccessor>
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<const T *> (object);
@@ -92,7 +92,7 @@ MakeObjectVectorAccessor (U T::*memberVector)
template <typename T>
Ptr<const AttributeChecker> MakeObjectVectorChecker (void)
{
return MakeObjectPtrContainerChecker<T> ();
return MakeObjectPtrVectorChecker<T> ();
}
template <typename T, typename U, typename INDEX>
@@ -100,7 +100,7 @@ Ptr<const AttributeAccessor>
MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
INDEX (T::*getN)(void) const)
{
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
return MakeObjectPtrVectorAccessor<T,U,INDEX>(get, getN);
}
template <typename T, typename U, typename INDEX>
@@ -108,7 +108,7 @@ Ptr<const AttributeAccessor>
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
Ptr<U> (T::*get)(INDEX) const)
{
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
return MakeObjectPtrVectorAccessor<T,U,INDEX>(get, getN);
}

View File

@@ -135,7 +135,8 @@ def build(bld):
'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',
@@ -229,7 +230,8 @@ def build(bld):
'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',

View File

@@ -24,7 +24,7 @@
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/config-store.h"
//#include "ns3/gtk-config-store.h"
#include "ns3/gtk-config-store.h"
using namespace ns3;

View File

@@ -214,7 +214,7 @@ StaticInformation::DoGather (TypeId tid)
continue;
}
// attempt to cast to an object vector.
const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
const ObjectPtrVectorChecker *vectorChecker = dynamic_cast<const ObjectPtrVectorChecker *> (PeekPointer (info.checker));
if (vectorChecker != 0)
{
TypeId item = vectorChecker->GetItemTypeId ();