From dd0ae959feee26d407ebe4fac8d3f010ed2e4706 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 27 Feb 2008 19:35:37 +0100 Subject: [PATCH] re-organize the code to avoid link-time errors due to duplicate symbols. --- src/core/attribute.h | 159 +++++++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 74 deletions(-) diff --git a/src/core/attribute.h b/src/core/attribute.h index 07dca9919..ca67f1819 100644 --- a/src/core/attribute.h +++ b/src/core/attribute.h @@ -156,21 +156,25 @@ public: virtual bool DeserializeFromString (std::string value, Ptr checker); }; +} // namespace ns3 + /******************************************************** * Store the content of a Ptr in a AttributeValue ********************************************************/ +namespace { + template -class PtrValue : public PtrValueBase +class PtrValue : public ns3::PtrValueBase { public: - PtrValue (Ptr pointer) + PtrValue (ns3::Ptr pointer) : m_pointer (pointer) {} - virtual ObjectBase *PeekObjectBase (void) const { + virtual ns3::ObjectBase *PeekObjectBase (void) const { return PeekPointer (m_pointer); } - virtual bool SetObjectBase (ObjectBase *object) { + virtual bool SetObjectBase (ns3::ObjectBase *object) { T *ptr = dynamic_cast (object); if (ptr == 0) { @@ -179,18 +183,90 @@ public: m_pointer = ptr; return true; } - virtual Attribute Copy (void) const { - return Attribute::Create > (*this); + virtual ns3::Attribute Copy (void) const { + return ns3::Attribute::Create > (*this); } private: - Ptr m_pointer; + ns3::Ptr m_pointer; }; +template +class APtrChecker : public ns3::PtrChecker +{ + virtual bool Check (ns3::Attribute val) const { + const ns3::PtrValueBase *value = val.DynCast (); + if (value == 0) + { + return false; + } + if (value->PeekObjectBase () == 0) + { + return true; + } + T *ptr = dynamic_cast (value->PeekObjectBase ()); + if (ptr == 0) + { + return false; + } + return true; + } +}; + +/******************************************************** + * The Accessor associated to + * PtrValue + ********************************************************/ + +template +class PtrAccessor : public ns3::AttributeAccessor +{ +public: + virtual ~PtrAccessor () {} + virtual bool Set (ns3::ObjectBase * object, ns3::Attribute val) const { + T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + const ns3::PtrValueBase *value = val.DynCast (); + if (value == 0) + { + return false; + } + ns3::Ptr ptr = dynamic_cast (value->PeekObjectBase ()); + if (ptr == 0) + { + return false; + } + DoSet (obj, ptr); + return true; + } + virtual bool Get (const ns3::ObjectBase * object, ns3::Attribute val) const { + const T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + ns3::PtrValueBase *value = val.DynCast (); + if (value == 0) + { + return false; + } + return value->SetObjectBase (PeekPointer (DoGet (obj))); + } +private: + virtual void DoSet (T *object, ns3::Ptr value) const = 0; + virtual ns3::Ptr DoGet (const T *object) const = 0; +}; + +} // anonymous namespace + /******************************************************** * The implementation of the Attribute * class template methods. ********************************************************/ +namespace ns3 { template Attribute @@ -233,52 +309,6 @@ Attribute::operator Ptr () return obj; } -/******************************************************** - * The Accessor associated to - * PtrValue - ********************************************************/ - -template -class PtrAccessor : public AttributeAccessor -{ -public: - virtual ~PtrAccessor () {} - virtual bool Set (ObjectBase * object, Attribute val) const { - T *obj = dynamic_cast (object); - if (obj == 0) - { - return false; - } - const PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - Ptr ptr = dynamic_cast (value->PeekObjectBase ()); - if (ptr == 0) - { - return false; - } - DoSet (obj, ptr); - return true; - } - virtual bool Get (const ObjectBase * object, Attribute val) const { - const T *obj = dynamic_cast (object); - if (obj == 0) - { - return false; - } - PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - return value->SetObjectBase (PeekPointer (DoGet (obj))); - } -private: - virtual void DoSet (T *object, Ptr value) const = 0; - virtual Ptr DoGet (const T *object) const = 0; -}; template @@ -345,31 +375,12 @@ MakePtrAccessor (Ptr (T::*getter) (void) const) return Ptr (spec, false); } + template Ptr MakePtrChecker (void) { - struct APtrChecker : public PtrChecker - { - virtual bool Check (Attribute val) const { - const PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - if (value->PeekObjectBase () == 0) - { - return true; - } - T *ptr = dynamic_cast (value->PeekObjectBase ()); - if (ptr == 0) - { - return false; - } - return true; - } - } *checker = new APtrChecker (); - return Ptr (checker, false); + return Create > (); } template