From 4358b2fd7189449e608434968b15fca32e6ec160 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 25 May 2007 10:32:34 +0200 Subject: [PATCH] port ComponentManager to Object from Interface --- src/core/component-manager.cc | 31 ++++++++++---------- src/core/component-manager.h | 46 ++++++++++++++--------------- src/core/object.cc | 54 +++++++++++++++++------------------ src/core/object.h | 34 +++++++++++----------- 4 files changed, 83 insertions(+), 82 deletions(-) diff --git a/src/core/component-manager.cc b/src/core/component-manager.cc index 497a39264..130bc0b9d 100644 --- a/src/core/component-manager.cc +++ b/src/core/component-manager.cc @@ -49,10 +49,10 @@ bool operator == (const ClassId &a, const ClassId &b) return a.m_classId == b.m_classId; } -Ptr +Ptr ComponentManager::Create (ClassId classId) { - Callback > callback = DoGetCallback (classId); + Callback > callback = DoGetCallback (classId); return callback (); } @@ -91,26 +91,27 @@ ComponentManager::Register (std::string name, CallbackBase *callback) #ifdef RUN_SELF_TESTS #include "test.h" -#include "interface.h" +#include "object.h" namespace { -class B : public ns3::Interface +class B : public ns3::Object { public: static const ns3::InterfaceId iid; B (); }; -const ns3::InterfaceId B::iid ("IB"); +const ns3::InterfaceId B::iid = MakeInterfaceId ("B", Object::iid); B::B () - : Interface (B::iid) -{} +{ + SetInterfaceId (B::iid); +} -class A : public ns3::Interface +class A : public ns3::Object { public: static const ns3::ClassId cidZero; @@ -133,36 +134,36 @@ public: const ns3::ClassId A::cidZero = ns3::ComponentManager::RegisterConstructor ("A"); const ns3::ClassId A::cidOneBool = ns3::ComponentManager::RegisterConstructor ("ABool"); const ns3::ClassId A::cidOneUi32 = ns3::ComponentManager::RegisterConstructor ("AUi32"); -const ns3::InterfaceId A::iid ("IA"); +const ns3::InterfaceId A::iid = MakeInterfaceId ("A", Object::iid); A::A () - : Interface (A::iid), - m_zeroInvoked (true), + : m_zeroInvoked (true), m_oneBoolInvoked (false), m_oneUi32Invoked (false) { + SetInterfaceId (A::iid); ns3::Ptr b = ns3::MakeNewObject (); AddInterface (b); } A::A (bool bo) - : Interface (A::iid), - m_zeroInvoked (false), + : m_zeroInvoked (false), m_oneBoolInvoked (true), m_oneUi32Invoked (false), m_bool (bo) { + SetInterfaceId (A::iid); ns3::Ptr b = ns3::MakeNewObject (); AddInterface (b); } A::A (uint32_t i) - : Interface (A::iid), - m_zeroInvoked (false), + : m_zeroInvoked (false), m_oneBoolInvoked (false), m_oneUi32Invoked (true), m_ui32 (i) { + SetInterfaceId (A::iid); ns3::Ptr b = ns3::MakeNewObject (); AddInterface (b); } diff --git a/src/core/component-manager.h b/src/core/component-manager.h index f69648d16..dc7f2f5ad 100644 --- a/src/core/component-manager.h +++ b/src/core/component-manager.h @@ -25,7 +25,7 @@ #include #include #include "callback.h" -#include "interface.h" +#include "object.h" #include "fatal-error.h" #include "ptr.h" @@ -83,7 +83,7 @@ public: * Create an instance of the object identified by its * ClassId. This method invokes the default constructor. */ - static Ptr Create (ClassId classId); + static Ptr Create (ClassId classId); /** * \param classId class id of the constructor to invoke. @@ -94,7 +94,7 @@ public: * ClassId. */ template - static Ptr Create (ClassId classId, T1 a1); + static Ptr Create (ClassId classId, T1 a1); /** * \param classId class id of the constructor to invoke. @@ -106,7 +106,7 @@ public: * ClassId. */ template - static Ptr Create (ClassId classId, T1 a1, T2 a2); + static Ptr Create (ClassId classId, T1 a1, T2 a2); /** * \param classId class id of the constructor to invoke. @@ -134,7 +134,7 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback > callback = + static Callback > callback = MakeCallback (&ComponentManager::MakeObjectZero); return ComponentManager::Register (name, &callback); } @@ -147,7 +147,7 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback ,T1> callback = MakeCallback (&ComponentManager::MakeObjectOne); + static Callback ,T1> callback = MakeCallback (&ComponentManager::MakeObjectOne); return ComponentManager::Register (name, &callback); } @@ -159,7 +159,7 @@ public: template static ClassId RegisterConstructor (std::string name) { - static Callback,T1,T2> callback = MakeCallback (&ComponentManager::MakeObjectTwo); + static Callback,T1,T2> callback = MakeCallback (&ComponentManager::MakeObjectTwo); return ComponentManager::Register (name, &callback); } private: @@ -168,16 +168,16 @@ private: template - static Callback,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId); + static Callback,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId); template - static Ptr MakeObjectZero (void); + static Ptr MakeObjectZero (void); template - static Ptr MakeObjectOne (T1 a1); + static Ptr MakeObjectOne (T1 a1); template - static Ptr MakeObjectTwo (T1 a1, T2 a2); + static Ptr MakeObjectTwo (T1 a1, T2 a2); typedef std::vector > List; static List *GetList (void); @@ -192,7 +192,7 @@ namespace ns3 { template -Callback,T1,T2,T3,T4,T5> +Callback,T1,T2,T3,T4,T5> ComponentManager::DoGetCallback (ClassId classId) { CallbackBase *callback = Lookup (classId); @@ -200,25 +200,25 @@ ComponentManager::DoGetCallback (ClassId classId) { NS_FATAL_ERROR ("Invalid Class Id."); } - Callback, T1,T2,T3,T4,T5> reference; + Callback, T1,T2,T3,T4,T5> reference; reference.Assign (*callback); return reference; } template -Ptr +Ptr ComponentManager::Create (ClassId classId, T1 a1) { - Callback, T1> callback = DoGetCallback (classId); + Callback, T1> callback = DoGetCallback (classId); return callback (a1); } template -Ptr +Ptr ComponentManager::Create (ClassId classId, T1 a1, T2 a2) { - Callback , T1,T2> callback = DoGetCallback (classId); + Callback , T1,T2> callback = DoGetCallback (classId); return callback (a1, a2); } @@ -226,7 +226,7 @@ template Ptr ComponentManager::Create (ClassId classId, InterfaceId iid) { - Ptr obj = Create (classId); + Ptr obj = Create (classId); Ptr i = obj->QueryInterface (iid); return i; } @@ -235,7 +235,7 @@ template Ptr ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1) { - Ptr obj = Create (classId, a1); + Ptr obj = Create (classId, a1); Ptr i = obj->QueryInterface (iid); return i; } @@ -244,26 +244,26 @@ template Ptr ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2) { - Ptr obj = Create (classId, a1, a2); + Ptr obj = Create (classId, a1, a2); Ptr i = obj->QueryInterface (iid); return i; } template -Ptr +Ptr ComponentManager::MakeObjectZero (void) { return MakeNewObject (); } template -Ptr +Ptr ComponentManager::MakeObjectOne (T1 a1) { return MakeNewObject (a1); } template -Ptr +Ptr ComponentManager::MakeObjectTwo (T1 a1, T2 a2) { return MakeNewObject (a1, a2); diff --git a/src/core/object.cc b/src/core/object.cc index 26cbabf8c..aee9e7473 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -54,50 +54,50 @@ IidTree::LookupParent (uint32_t child) namespace ns3 { -MyInterfaceId::MyInterfaceId (uint32_t iid) +InterfaceId::InterfaceId (uint32_t iid) : m_iid (iid) {} -MyInterfaceId::~MyInterfaceId () +InterfaceId::~InterfaceId () {} -MyInterfaceId -MyInterfaceId::LookupByName (std::string name) +InterfaceId +InterfaceId::LookupByName (std::string name) { - return MyInterfaceId (Singleton::Get ()->LookupByName (name)); + return InterfaceId (Singleton::Get ()->LookupByName (name)); } -MyInterfaceId -MyInterfaceId::LookupParent (MyInterfaceId iid) +InterfaceId +InterfaceId::LookupParent (InterfaceId iid) { return Singleton::Get ()->LookupParent (iid.m_iid); } -bool operator == (const MyInterfaceId &a, const MyInterfaceId &b) +bool operator == (const InterfaceId &a, const InterfaceId &b) { return a.m_iid == b.m_iid; } -bool operator != (const MyInterfaceId &a, const MyInterfaceId &b) +bool operator != (const InterfaceId &a, const InterfaceId &b) { return a.m_iid != b.m_iid; } -MyInterfaceId -MakeInterfaceId (std::string name, const MyInterfaceId &parent) +InterfaceId +MakeInterfaceId (std::string name, const InterfaceId &parent) { - MyInterfaceId iid = Singleton::Get ()->Allocate (name); + InterfaceId iid = Singleton::Get ()->Allocate (name); Singleton::Get ()->SetParent (iid.m_iid, &parent.m_iid); return iid; } -MyInterfaceId +InterfaceId MakeObjectInterfaceId (void) { - MyInterfaceId iid = Singleton::Get ()->Allocate ("Object"); + InterfaceId iid = Singleton::Get ()->Allocate ("Object"); Singleton::Get ()->SetParent (iid.m_iid, &iid.m_iid); return iid; } -const MyInterfaceId Object::iid = MakeObjectInterfaceId (); +const InterfaceId Object::iid = MakeObjectInterfaceId (); Object::Object () @@ -110,16 +110,16 @@ Object::~Object () m_next = 0; } Ptr -Object::DoQueryInterface (MyInterfaceId iid) +Object::DoQueryInterface (InterfaceId iid) { NS_ASSERT (Check ()); Object *currentObject = this; do { NS_ASSERT (currentObject != 0); - MyInterfaceId cur = currentObject->m_iid; + InterfaceId cur = currentObject->m_iid; while (cur != iid && cur != Object::iid) { - cur = MyInterfaceId::LookupParent (cur); + cur = InterfaceId::LookupParent (cur); } if (cur == iid) { @@ -155,7 +155,7 @@ Object::AddInterface (Ptr o) } void -Object::SetInterfaceId (MyInterfaceId iid) +Object::SetInterfaceId (InterfaceId iid) { NS_ASSERT (Check ()); m_iid = iid; @@ -212,7 +212,7 @@ namespace { class BaseA : public ns3::Object { public: - static const ns3::MyInterfaceId iid; + static const ns3::InterfaceId iid; BaseA () { SetInterfaceId (BaseA::iid); @@ -223,7 +223,7 @@ public: class DerivedA : public BaseA { public: - static const ns3::MyInterfaceId iid; + static const ns3::InterfaceId iid; DerivedA (int v) { SetInterfaceId (DerivedA::iid); @@ -233,15 +233,15 @@ public: } }; -const ns3::MyInterfaceId BaseA::iid = +const ns3::InterfaceId BaseA::iid = ns3::MakeInterfaceId ("BaseA", Object::iid); -const ns3::MyInterfaceId DerivedA::iid = +const ns3::InterfaceId DerivedA::iid = ns3::MakeInterfaceId ("DerivedA", BaseA::iid);; class BaseB : public ns3::Object { public: - static const ns3::MyInterfaceId iid; + static const ns3::InterfaceId iid; BaseB () { SetInterfaceId (BaseB::iid); @@ -252,7 +252,7 @@ public: class DerivedB : public BaseB { public: - static const ns3::MyInterfaceId iid; + static const ns3::InterfaceId iid; DerivedB (int v) { SetInterfaceId (DerivedB::iid); @@ -262,9 +262,9 @@ public: } }; -const ns3::MyInterfaceId BaseB::iid = +const ns3::InterfaceId BaseB::iid = ns3::MakeInterfaceId ("BaseB", Object::iid); -const ns3::MyInterfaceId DerivedB::iid = +const ns3::InterfaceId DerivedB::iid = ns3::MakeInterfaceId ("DerivedB", BaseB::iid);; } // namespace anonymous diff --git a/src/core/object.h b/src/core/object.h index aa051cf1c..559520486 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -27,46 +27,46 @@ namespace ns3 { -class MyInterfaceId +class InterfaceId { public: - static MyInterfaceId LookupByName (std::string name); - static MyInterfaceId LookupParent (MyInterfaceId iid); - ~MyInterfaceId (); + static InterfaceId LookupByName (std::string name); + static InterfaceId LookupParent (InterfaceId iid); + ~InterfaceId (); private: - MyInterfaceId (uint32_t iid); - friend MyInterfaceId MakeInterfaceId (std::string name, const MyInterfaceId &parent); - friend MyInterfaceId MakeObjectInterfaceId (void); - friend bool operator == (const MyInterfaceId &a, const MyInterfaceId &b); - friend bool operator != (const MyInterfaceId &a, const MyInterfaceId &b); + InterfaceId (uint32_t iid); + friend InterfaceId MakeInterfaceId (std::string name, const InterfaceId &parent); + friend InterfaceId MakeObjectInterfaceId (void); + friend bool operator == (const InterfaceId &a, const InterfaceId &b); + friend bool operator != (const InterfaceId &a, const InterfaceId &b); uint32_t m_iid; }; -MyInterfaceId -MakeInterfaceId (std::string name, const MyInterfaceId &parent); +InterfaceId +MakeInterfaceId (std::string name, const InterfaceId &parent); class Object { public: - static const MyInterfaceId iid; + static const InterfaceId iid; Object (); virtual ~Object (); inline void Ref (void) const; inline void Unref (void) const; template - Ptr QueryInterface (MyInterfaceId iid); + Ptr QueryInterface (InterfaceId iid); void Dispose (void); void AddInterface (Ptr other); protected: - void SetInterfaceId (MyInterfaceId iid); + void SetInterfaceId (InterfaceId iid); virtual void DoDispose (void); private: - Ptr DoQueryInterface (MyInterfaceId iid); + Ptr DoQueryInterface (InterfaceId iid); bool Check (void) const; void MaybeDelete (void) const; mutable uint32_t m_count; - MyInterfaceId m_iid; + InterfaceId m_iid; Object *m_next; }; @@ -92,7 +92,7 @@ Object::Unref (void) const template Ptr -Object::QueryInterface (MyInterfaceId iid) +Object::QueryInterface (InterfaceId iid) { Ptr found = DoQueryInterface (iid); if (found != 0)