From b537e38434535a02c286c4cfcd7b005e4e1a3e6f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 10 Aug 2011 11:48:19 -0400 Subject: [PATCH] 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 --- src/config-store/model/attribute-iterator.cc | 14 +- src/config-store/model/attribute-iterator.h | 11 +- src/core/model/config.cc | 10 +- src/core/model/object-map.h | 118 ++++++++++++ src/core/model/object-ptr-container.cc | 114 +++++++++++ src/core/model/object-ptr-container.h | 192 +++++++++++++++++++ src/core/model/object-vector.cc | 95 --------- src/core/model/object-vector.h | 168 ++++------------ src/core/wscript | 4 +- utils/print-introspected-doxygen.cc | 2 +- 10 files changed, 481 insertions(+), 247 deletions(-) create mode 100644 src/core/model/object-map.h create mode 100644 src/core/model/object-ptr-container.cc create mode 100644 src/core/model/object-ptr-container.h delete mode 100644 src/core/model/object-vector.cc diff --git a/src/config-store/model/attribute-iterator.cc b/src/config-store/model/attribute-iterator.cc index fe6d634d6..f0559c5f3 100644 --- a/src/config-store/model/attribute-iterator.cc +++ b/src/config-store/model/attribute-iterator.cc @@ -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 @@ -109,7 +109,7 @@ AttributeIterator::DoEndVisitPointerAttribute (void) { } void -AttributeIterator::DoStartVisitArrayAttribute (Ptr object, std::string name, const ObjectVectorValue &vector) +AttributeIterator::DoStartVisitArrayAttribute (Ptr 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 item) +AttributeIterator::DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item) { } void @@ -160,7 +160,7 @@ AttributeIterator::EndVisitPointerAttribute (void) DoEndVisitPointerAttribute (); } void -AttributeIterator::StartVisitArrayAttribute (Ptr object, std::string name, const ObjectVectorValue &vector) +AttributeIterator::StartVisitArrayAttribute (Ptr 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 item) +AttributeIterator::StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item) { std::ostringstream oss; oss << index; @@ -223,11 +223,11 @@ AttributeIterator::DoIterate (Ptr object) continue; } // attempt to cast to an object vector. - const ObjectVectorChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); + const ObjectPtrContainerChecker *vectorChecker = dynamic_cast (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) diff --git a/src/config-store/model/attribute-iterator.h b/src/config-store/model/attribute-iterator.h index fe6e4ebe2..5821651a8 100644 --- a/src/config-store/model/attribute-iterator.h +++ b/src/config-store/model/attribute-iterator.h @@ -21,12 +21,11 @@ #include "ns3/ptr.h" #include "ns3/object.h" +#include "ns3/object-ptr-container.h" #include namespace ns3 { -class ObjectVectorValue; - /** * \ingroup configstore * @@ -47,9 +46,9 @@ private: 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 ObjectVectorValue &vector); + virtual void DoStartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector); virtual void DoEndVisitArrayAttribute (void); - virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr item); + virtual void DoStartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item); virtual void DoEndVisitArrayItem (void); void DoIterate (Ptr object); @@ -61,9 +60,9 @@ private: void EndVisitObject (void); void StartVisitPointerAttribute (Ptr object, std::string name, Ptr value); void EndVisitPointerAttribute (void); - void StartVisitArrayAttribute (Ptr object, std::string name, const ObjectVectorValue &vector); + void StartVisitArrayAttribute (Ptr object, std::string name, const ObjectPtrContainerValue &vector); void EndVisitArrayAttribute (void); - void StartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr item); + void StartVisitArrayItem (const ObjectPtrContainerValue &vector, uint32_t index, Ptr item); void EndVisitArrayItem (void); diff --git a/src/core/model/config.cc b/src/core/model/config.cc index 6b9a4df0a..89ba1d364 100644 --- a/src/core/model/config.cc +++ b/src/core/model/config.cc @@ -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 root); - void DoArrayResolve (std::string path, const ObjectVectorValue &vector); + void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector); void DoResolveOne (Ptr object); std::string GetResolvedPath (void) const; virtual void DoOne (Ptr object, std::string path) = 0; @@ -403,11 +403,11 @@ Resolver::DoResolve (std::string path, Ptr root) m_workStack.pop_back (); } // attempt to cast to an object vector. - const ObjectVectorChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); + const ObjectPtrContainerChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); if (vectorChecker != 0) { NS_LOG_DEBUG ("GetAttribute(vector)="< + */ +#ifndef OBJECT_MAP_H +#define OBJECT_MAP_H + +#include +#include "object.h" +#include "ptr.h" +#include "attribute.h" +#include "object-ptr-container.h" + +namespace ns3 { + +typedef ObjectPtrContainerValue ObjectMapValue; + +template +Ptr +MakeObjectMapAccessor (U T::*memberContainer); + +template +Ptr MakeObjectMapChecker (void); + +template +Ptr +MakeObjectVectorAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const); + +template +Ptr +MakeObjectVectorAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const); + +} // namespace ns3 + +namespace ns3 { + +template +Ptr +MakeObjectMapAccessor (U T::*memberVector) +{ + struct MemberStdContainer : public ObjectPtrContainerAccessor + { + virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const { + const T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + *n = (obj->*m_memberVector).size (); + return true; + } + virtual Ptr DoGet (const ObjectBase *object, uint32_t i) 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 (); + 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 (spec, false); +} + +template +Ptr MakeObjectMapChecker (void) +{ + return MakeObjectPtrContainerChecker (); +} + +template +Ptr +MakeObjectMapAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const) +{ + return MakeObjectPtrContainerAccessor(get, getN); +} + +template +Ptr +MakeObjectMapAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const) +{ + return MakeObjectPtrContainerAccessor(get, getN); +} + + + +} // namespace ns3 + +#endif /* OBJECT_MAP_H */ diff --git a/src/core/model/object-ptr-container.cc b/src/core/model/object-ptr-container.cc new file mode 100644 index 000000000..e8660f4ae --- /dev/null +++ b/src/core/model/object-ptr-container.cc @@ -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-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 +ObjectPtrContainerValue::Get (uint32_t i) const +{ + return m_objects[i]; +} + +Ptr +ObjectPtrContainerValue::Copy (void) const +{ + return ns3::Create (*this); +} +std::string +ObjectPtrContainerValue::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 +ObjectPtrContainerValue::DeserializeFromString (std::string value, Ptr 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 (&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 +ObjectPtrContainerAccessor::HasGetter (void) const +{ + return true; +} +bool +ObjectPtrContainerAccessor::HasSetter (void) const +{ + return false; +} + +} // name diff --git a/src/core/model/object-ptr-container.h b/src/core/model/object-ptr-container.h new file mode 100644 index 000000000..c16944539 --- /dev/null +++ b/src/core/model/object-ptr-container.h @@ -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_CONTAINER_H +#define OBJECT_PTR_CONTAINER_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 ObjectPtrContainerValue : public AttributeValue +{ +public: + typedef std::vector >::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 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 ObjectPtrContainerAccessor; + std::vector > m_objects; +}; + + +template +Ptr +MakeObjectPtrContainerAccessor (Ptr (T::*get)(INDEX) const, + INDEX (T::*getN)(void) const); + +template +Ptr +MakeObjectPtrContainerAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const); + +class ObjectPtrContainerChecker : public AttributeChecker +{ +public: + virtual TypeId GetItemTypeId (void) const = 0; +}; + +template +Ptr MakeObjectPtrContainerChecker (void); + +} // namespace ns3 + +namespace ns3 { + +namespace internal { + +template +class AnObjectPtrContainerChecker : public ObjectPtrContainerChecker +{ +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::ObjectPtrContainerValue"; + } + 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 ObjectPtrContainerValue *src = dynamic_cast (&source); + ObjectPtrContainerValue *dst = dynamic_cast (&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 DoGet (const ObjectBase *object, uint32_t i) const = 0; +}; + +template +Ptr +MakeObjectPtrContainerAccessor (Ptr (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 (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 +MakeObjectPtrContainerAccessor (INDEX (T::*getN)(void) const, + Ptr (T::*get)(INDEX) const) +{ + return MakeObjectPtrContainerAccessor (get, getN); +} + +template +Ptr MakeObjectPtrContainerChecker (void) +{ + return Create > (); +} + + +} // namespace ns3 + +#endif /* OBJECT_PTR_CONTAINER_H */ diff --git a/src/core/model/object-vector.cc b/src/core/model/object-vector.cc deleted file mode 100644 index b2693ac44..000000000 --- a/src/core/model/object-vector.cc +++ /dev/null @@ -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 -ObjectVectorValue::Get (uint32_t i) const -{ - return m_objects[i]; -} - -Ptr -ObjectVectorValue::Copy (void) const -{ - return ns3::Create (*this); -} -std::string -ObjectVectorValue::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 -ObjectVectorValue::DeserializeFromString (std::string value, Ptr 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 (&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 -ObjectVectorAccessor::HasGetter (void) const -{ - return true; -} -bool -ObjectVectorAccessor::HasSetter (void) const -{ - return false; -} - -} // name diff --git a/src/core/model/object-vector.h b/src/core/model/object-vector.h index c41a546da..953c21545 100644 --- a/src/core/model/object-vector.h +++ b/src/core/model/object-vector.h @@ -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 + */ #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 >::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 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 ObjectVectorAccessor; - std::vector > m_objects; -}; +typedef ObjectPtrContainerValue ObjectVectorValue; template Ptr -MakeObjectVectorAccessor (U T::*memberVector); +MakeObjectVectorAccessor (U T::*memberContainer); + +template +Ptr MakeObjectVectorChecker (void); template Ptr @@ -64,75 +47,15 @@ Ptr MakeObjectVectorAccessor (INDEX (T::*getN)(void) const, Ptr (T::*get)(INDEX) const); -class ObjectVectorChecker : public AttributeChecker -{ -public: - virtual TypeId GetItemTypeId (void) const = 0; -}; - -template -Ptr MakeObjectVectorChecker (void); - } // namespace ns3 namespace ns3 { -namespace internal { - -template -class AnObjectVectorChecker : public ObjectVectorChecker -{ -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::ObjectVectorValue"; - } - 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 ObjectVectorValue *src = dynamic_cast (&source); - ObjectVectorValue *dst = dynamic_cast (&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 DoGet (const ObjectBase *object, uint32_t i) const = 0; -}; - template Ptr 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 (object); @@ -166,47 +89,28 @@ MakeObjectVectorAccessor (U T::*memberVector) return Ptr (spec, false); } +template +Ptr MakeObjectVectorChecker (void) +{ + return MakeObjectPtrContainerChecker (); +} + template Ptr MakeObjectVectorAccessor (Ptr (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 (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); + return MakeObjectPtrContainerAccessor(get, getN); } template Ptr MakeObjectVectorAccessor (INDEX (T::*getN)(void) const, - Ptr (T::*get)(INDEX) const) + Ptr (T::*get)(INDEX) const) { - return MakeObjectVectorAccessor (get, getN); + return MakeObjectPtrContainerAccessor(get, getN); } -template -Ptr MakeObjectVectorChecker (void) -{ - return Create > (); -} } // namespace ns3 diff --git a/src/core/wscript b/src/core/wscript index 0cbf8c5ba..74e8afe51 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -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', diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index 5c80fe566..16fd992d3 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -184,7 +184,7 @@ StaticInformation::DoGather (TypeId tid) continue; } // attempt to cast to an object vector. - const ObjectVectorChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); + const ObjectPtrContainerChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); if (vectorChecker != 0) { TypeId item = vectorChecker->GetItemTypeId ();