refactor ObjectVector generic code into a separate file and introduce ObjectMap.
--HG-- rename : src/core/model/object-vector.cc => src/core/model/object-ptr-container.cc rename : src/core/model/object-vector.h => src/core/model/object-ptr-container.h
This commit is contained in:
1 parent
df84d10e69
commit
b537e38434
10 files changed
+481
-247
No files matched your search
@@ -20,7 +20,7 @@
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/pointer.h"
|
||||
#include "ns3/object-vector.h"
|
||||
#include "ns3/object-ptr-container.h"
|
||||
#include "ns3/string.h"
|
||||
#include <fstream>
|
||||
|
||||
@@ -109,7 +109,7 @@ AttributeIterator::DoEndVisitPointerAttribute (void)
|
||||
{
|
||||
}
|
||||
void
|
||||
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
|
||||
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
|
||||
{
|
||||
}
|
||||
void
|
||||
@@ -117,7 +117,7 @@ AttributeIterator::DoEndVisitArrayAttribute (void)
|
||||
{
|
||||
}
|
||||
void
|
||||
AttributeIterator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
|
||||
AttributeIterator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
|
||||
{
|
||||
}
|
||||
void
|
||||
@@ -160,7 +160,7 @@ AttributeIterator::EndVisitPointerAttribute (void)
|
||||
DoEndVisitPointerAttribute ();
|
||||
}
|
||||
void
|
||||
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
|
||||
AttributeIterator::StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector)
|
||||
{
|
||||
m_currentPath.push_back (name);
|
||||
DoStartVisitArrayAttribute (object, name, vector);
|
||||
@@ -173,7 +173,7 @@ AttributeIterator::EndVisitArrayAttribute (void)
|
||||
}
|
||||
|
||||
void
|
||||
AttributeIterator::StartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
|
||||
AttributeIterator::StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << index;
|
||||
@@ -223,11 +223,11 @@ AttributeIterator::DoIterate (Ptr<Object> object)
|
||||
continue;
|
||||
}
|
||||
// attempt to cast to an object vector.
|
||||
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (info.checker));
|
||||
const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
|
||||
if (vectorChecker != 0)
|
||||
{
|
||||
NS_LOG_DEBUG ("vector attribute " << info.name);
|
||||
ObjectVectorValue vector;
|
||||
ObjectPtrContainerValue vector;
|
||||
object->GetAttribute (info.name, vector);
|
||||
StartVisitArrayAttribute (object, info.name, vector);
|
||||
for (uint32_t j = 0; j < vector.GetN (); ++j)
|
||||
|
||||
@@ -21,12 +21,11 @@
|
||||
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/object-ptr-container.h"
|
||||
#include <vector>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class ObjectVectorValue;
|
||||
|
||||
/**
|
||||
* \ingroup configstore
|
||||
*
|
||||
@@ -47,9 +46,9 @@ 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 ObjectVectorValue &vector);
|
||||
virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
|
||||
virtual void DoEndVisitArrayAttribute (void);
|
||||
virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item);
|
||||
virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
|
||||
virtual void DoEndVisitArrayItem (void);
|
||||
|
||||
void DoIterate (Ptr<Object> object);
|
||||
@@ -61,9 +60,9 @@ 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 ObjectVectorValue &vector);
|
||||
void StartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectPtrContainerValue &vector);
|
||||
void EndVisitArrayAttribute (void);
|
||||
void StartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item);
|
||||
void StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr<Object> item);
|
||||
void EndVisitArrayItem (void);
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "singleton.h"
|
||||
#include "object.h"
|
||||
#include "global-value.h"
|
||||
#include "object-vector.h"
|
||||
#include "object-ptr-container.h"
|
||||
#include "names.h"
|
||||
#include "pointer.h"
|
||||
#include "log.h"
|
||||
@@ -226,7 +226,7 @@ public:
|
||||
private:
|
||||
void Canonicalize (void);
|
||||
void DoResolve (std::string path, Ptr<Object> root);
|
||||
void DoArrayResolve (std::string path, const ObjectVectorValue &vector);
|
||||
void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
|
||||
void DoResolveOne (Ptr<Object> object);
|
||||
std::string GetResolvedPath (void) const;
|
||||
virtual void DoOne (Ptr<Object> object, std::string path) = 0;
|
||||
@@ -403,11 +403,11 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
|
||||
m_workStack.pop_back ();
|
||||
}
|
||||
// attempt to cast to an object vector.
|
||||
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (info.checker));
|
||||
const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
|
||||
if (vectorChecker != 0)
|
||||
{
|
||||
NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath ());
|
||||
ObjectVectorValue vector;
|
||||
ObjectPtrContainerValue vector;
|
||||
root->GetAttribute (item, vector);
|
||||
m_workStack.push_back (item);
|
||||
DoArrayResolve (pathLeft, vector);
|
||||
@@ -419,7 +419,7 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
|
||||
}
|
||||
|
||||
void
|
||||
Resolver::DoArrayResolve (std::string path, const ObjectVectorValue &vector)
|
||||
Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector)
|
||||
{
|
||||
NS_ASSERT (path != "");
|
||||
NS_ASSERT ((path.find ("/")) == 0);
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/* -*- 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_MAP_H
|
||||
#define OBJECT_MAP_H
|
||||
|
||||
#include <vector>
|
||||
#include "object.h"
|
||||
#include "ptr.h"
|
||||
#include "attribute.h"
|
||||
#include "object-ptr-container.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
typedef ObjectPtrContainerValue ObjectMapValue;
|
||||
|
||||
template <typename T, typename U>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectMapAccessor (U T::*memberContainer);
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectMapChecker (void);
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectVectorAccessor (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,
|
||||
Ptr<U> (T::*get)(INDEX) const);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T, typename U>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectMapAccessor (U T::*memberVector)
|
||||
{
|
||||
struct MemberStdContainer : public ObjectPtrContainerAccessor
|
||||
{
|
||||
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_memberVector).size ();
|
||||
return true;
|
||||
}
|
||||
virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i) 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 ();
|
||||
uint32_t k = 0;
|
||||
for (typename U::const_iterator j = begin; j != end; j++, k++)
|
||||
{
|
||||
if (k == i)
|
||||
{
|
||||
return (*j).second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
NS_ASSERT (false);
|
||||
// quiet compiler.
|
||||
return 0;
|
||||
}
|
||||
U T::*m_memberVector;
|
||||
} *spec = new MemberStdContainer ();
|
||||
spec->m_memberVector = memberVector;
|
||||
return Ptr<const AttributeAccessor> (spec, false);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectMapChecker (void)
|
||||
{
|
||||
return MakeObjectPtrContainerChecker<T> ();
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
|
||||
INDEX (T::*getN)(void) const)
|
||||
{
|
||||
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
|
||||
Ptr<U> (T::*get)(INDEX) const)
|
||||
{
|
||||
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* OBJECT_MAP_H */
|
||||
@@ -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-container.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
ObjectPtrContainerValue::ObjectPtrContainerValue ()
|
||||
{
|
||||
}
|
||||
|
||||
ObjectPtrContainerValue::Iterator
|
||||
ObjectPtrContainerValue::Begin (void) const
|
||||
{
|
||||
return m_objects.begin ();
|
||||
}
|
||||
ObjectPtrContainerValue::Iterator
|
||||
ObjectPtrContainerValue::End (void) const
|
||||
{
|
||||
return m_objects.end ();
|
||||
}
|
||||
uint32_t
|
||||
ObjectPtrContainerValue::GetN (void) const
|
||||
{
|
||||
return m_objects.size ();
|
||||
}
|
||||
Ptr<Object>
|
||||
ObjectPtrContainerValue::Get (uint32_t i) const
|
||||
{
|
||||
return m_objects[i];
|
||||
}
|
||||
|
||||
Ptr<AttributeValue>
|
||||
ObjectPtrContainerValue::Copy (void) const
|
||||
{
|
||||
return ns3::Create<ObjectPtrContainerValue> (*this);
|
||||
}
|
||||
std::string
|
||||
ObjectPtrContainerValue::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
|
||||
ObjectPtrContainerValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
|
||||
{
|
||||
NS_FATAL_ERROR ("cannot deserialize a vector of object pointers.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ObjectPtrContainerAccessor::Set (ObjectBase * object, const AttributeValue & value) const
|
||||
{
|
||||
// not allowed.
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
ObjectPtrContainerAccessor::Get (const ObjectBase * object, AttributeValue &value) const
|
||||
{
|
||||
ObjectPtrContainerValue *v = dynamic_cast<ObjectPtrContainerValue *> (&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
|
||||
ObjectPtrContainerAccessor::HasGetter (void) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
ObjectPtrContainerAccessor::HasSetter (void) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} // name
|
||||
@@ -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_CONTAINER_H
|
||||
#define OBJECT_PTR_CONTAINER_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 ObjectPtrContainerValue : public AttributeValue
|
||||
{
|
||||
public:
|
||||
typedef std::vector<Ptr<Object> >::const_iterator Iterator;
|
||||
|
||||
ObjectPtrContainerValue ();
|
||||
|
||||
/**
|
||||
* \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 ObjectPtrContainerAccessor;
|
||||
std::vector<Ptr<Object> > m_objects;
|
||||
};
|
||||
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectPtrContainerAccessor (Ptr<U> (T::*get)(INDEX) const,
|
||||
INDEX (T::*getN)(void) const);
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectPtrContainerAccessor (INDEX (T::*getN)(void) const,
|
||||
Ptr<U> (T::*get)(INDEX) const);
|
||||
|
||||
class ObjectPtrContainerChecker : public AttributeChecker
|
||||
{
|
||||
public:
|
||||
virtual TypeId GetItemTypeId (void) const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectPtrContainerChecker (void);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename T>
|
||||
class AnObjectPtrContainerChecker : public ObjectPtrContainerChecker
|
||||
{
|
||||
public:
|
||||
virtual TypeId GetItemTypeId (void) const {
|
||||
return T::GetTypeId ();
|
||||
}
|
||||
virtual bool Check (const AttributeValue &value) const {
|
||||
return dynamic_cast<const ObjectPtrContainerValue *> (&value) != 0;
|
||||
}
|
||||
virtual std::string GetValueTypeName (void) const {
|
||||
return "ns3::ObjectPtrContainerValue";
|
||||
}
|
||||
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<ObjectPtrContainerValue> ();
|
||||
}
|
||||
virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
|
||||
const ObjectPtrContainerValue *src = dynamic_cast<const ObjectPtrContainerValue *> (&source);
|
||||
ObjectPtrContainerValue *dst = dynamic_cast<ObjectPtrContainerValue *> (&destination);
|
||||
if (src == 0 || dst == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*dst = *src;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
||||
class ObjectPtrContainerAccessor : 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>
|
||||
MakeObjectPtrContainerAccessor (Ptr<U> (T::*get)(INDEX) const,
|
||||
INDEX (T::*getN)(void) const)
|
||||
{
|
||||
struct MemberGetters : public ObjectPtrContainerAccessor
|
||||
{
|
||||
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>
|
||||
MakeObjectPtrContainerAccessor (INDEX (T::*getN)(void) const,
|
||||
Ptr<U> (T::*get)(INDEX) const)
|
||||
{
|
||||
return MakeObjectPtrContainerAccessor (get, getN);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectPtrContainerChecker (void)
|
||||
{
|
||||
return Create<internal::AnObjectPtrContainerChecker<T> > ();
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* OBJECT_PTR_CONTAINER_H */
|
||||
@@ -1,95 +0,0 @@
|
||||
#include "object-vector.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
ObjectVectorValue::ObjectVectorValue ()
|
||||
{
|
||||
}
|
||||
|
||||
ObjectVectorValue::Iterator
|
||||
ObjectVectorValue::Begin (void) const
|
||||
{
|
||||
return m_objects.begin ();
|
||||
}
|
||||
ObjectVectorValue::Iterator
|
||||
ObjectVectorValue::End (void) const
|
||||
{
|
||||
return m_objects.end ();
|
||||
}
|
||||
uint32_t
|
||||
ObjectVectorValue::GetN (void) const
|
||||
{
|
||||
return m_objects.size ();
|
||||
}
|
||||
Ptr<Object>
|
||||
ObjectVectorValue::Get (uint32_t i) const
|
||||
{
|
||||
return m_objects[i];
|
||||
}
|
||||
|
||||
Ptr<AttributeValue>
|
||||
ObjectVectorValue::Copy (void) const
|
||||
{
|
||||
return ns3::Create<ObjectVectorValue> (*this);
|
||||
}
|
||||
std::string
|
||||
ObjectVectorValue::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
|
||||
ObjectVectorValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
|
||||
{
|
||||
NS_FATAL_ERROR ("cannot deserialize a vector of object pointers.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ObjectVectorAccessor::Set (ObjectBase * object, const AttributeValue & value) const
|
||||
{
|
||||
// not allowed.
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
ObjectVectorAccessor::Get (const ObjectBase * object, AttributeValue &value) const
|
||||
{
|
||||
ObjectVectorValue *v = dynamic_cast<ObjectVectorValue *> (&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
|
||||
ObjectVectorAccessor::HasGetter (void) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
ObjectVectorAccessor::HasSetter (void) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} // name
|
||||
+36
-132
@@ -1,3 +1,22 @@
|
||||
/* -*- 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_VECTOR_H
|
||||
#define OBJECT_VECTOR_H
|
||||
|
||||
@@ -5,54 +24,18 @@
|
||||
#include "object.h"
|
||||
#include "ptr.h"
|
||||
#include "attribute.h"
|
||||
#include "object-ptr-container.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 ObjectVectorValue : public AttributeValue
|
||||
{
|
||||
public:
|
||||
typedef std::vector<Ptr<Object> >::const_iterator Iterator;
|
||||
|
||||
ObjectVectorValue ();
|
||||
|
||||
/**
|
||||
* \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 ObjectVectorAccessor;
|
||||
std::vector<Ptr<Object> > m_objects;
|
||||
};
|
||||
typedef ObjectPtrContainerValue ObjectVectorValue;
|
||||
|
||||
template <typename T, typename U>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectVectorAccessor (U T::*memberVector);
|
||||
MakeObjectVectorAccessor (U T::*memberContainer);
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectVectorChecker (void);
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
@@ -64,75 +47,15 @@ Ptr<const AttributeAccessor>
|
||||
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
|
||||
Ptr<U> (T::*get)(INDEX) const);
|
||||
|
||||
class ObjectVectorChecker : public AttributeChecker
|
||||
{
|
||||
public:
|
||||
virtual TypeId GetItemTypeId (void) const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectVectorChecker (void);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename T>
|
||||
class AnObjectVectorChecker : public ObjectVectorChecker
|
||||
{
|
||||
public:
|
||||
virtual TypeId GetItemTypeId (void) const {
|
||||
return T::GetTypeId ();
|
||||
}
|
||||
virtual bool Check (const AttributeValue &value) const {
|
||||
return dynamic_cast<const ObjectVectorValue *> (&value) != 0;
|
||||
}
|
||||
virtual std::string GetValueTypeName (void) const {
|
||||
return "ns3::ObjectVectorValue";
|
||||
}
|
||||
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<ObjectVectorValue> ();
|
||||
}
|
||||
virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const {
|
||||
const ObjectVectorValue *src = dynamic_cast<const ObjectVectorValue *> (&source);
|
||||
ObjectVectorValue *dst = dynamic_cast<ObjectVectorValue *> (&destination);
|
||||
if (src == 0 || dst == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*dst = *src;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
||||
class ObjectVectorAccessor : 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>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectVectorAccessor (U T::*memberVector)
|
||||
{
|
||||
struct MemberStdContainer : public ObjectVectorAccessor
|
||||
struct MemberStdContainer : public ObjectPtrContainerAccessor
|
||||
{
|
||||
virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
|
||||
const T *obj = dynamic_cast<const T *> (object);
|
||||
@@ -166,47 +89,28 @@ MakeObjectVectorAccessor (U T::*memberVector)
|
||||
return Ptr<const AttributeAccessor> (spec, false);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectVectorChecker (void)
|
||||
{
|
||||
return MakeObjectPtrContainerChecker<T> ();
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
|
||||
INDEX (T::*getN)(void) const)
|
||||
INDEX (T::*getN)(void) const)
|
||||
{
|
||||
struct MemberGetters : public ObjectVectorAccessor
|
||||
{
|
||||
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);
|
||||
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename INDEX>
|
||||
Ptr<const AttributeAccessor>
|
||||
MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
|
||||
Ptr<U> (T::*get)(INDEX) const)
|
||||
Ptr<U> (T::*get)(INDEX) const)
|
||||
{
|
||||
return MakeObjectVectorAccessor (get, getN);
|
||||
return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Ptr<const AttributeChecker> MakeObjectVectorChecker (void)
|
||||
{
|
||||
return Create<internal::AnObjectVectorChecker<T> > ();
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
+3
-1
@@ -137,7 +137,7 @@ def build(bld):
|
||||
'model/int64x64.cc',
|
||||
'model/string.cc',
|
||||
'model/pointer.cc',
|
||||
'model/object-vector.cc',
|
||||
'model/object-ptr-container.cc',
|
||||
'model/object-factory.cc',
|
||||
'model/global-value.cc',
|
||||
'model/trace-source-accessor.cc',
|
||||
@@ -231,7 +231,9 @@ def build(bld):
|
||||
'model/traced-value.h',
|
||||
'model/trace-source-accessor.h',
|
||||
'model/config.h',
|
||||
'model/object-ptr-container.h',
|
||||
'model/object-vector.h',
|
||||
'model/object-map.h',
|
||||
'model/deprecated.h',
|
||||
'model/abort.h',
|
||||
'model/names.h',
|
||||
|
||||
Reference in new issue
Block a user