diff --git a/samples/main-component-manager.cc b/samples/main-component-manager.cc deleted file mode 100644 index 506a246e0..000000000 --- a/samples/main-component-manager.cc +++ /dev/null @@ -1,35 +0,0 @@ -#include "ns3/object.h" -#include "ns3/component-manager.h" - -using namespace ns3; - -class AnObject : public Object -{ -public: - static const InterfaceId iid; - static const ClassId cid; - AnObject (int a, double b); -protected: - virtual void DoDispose (void); -}; - -const InterfaceId AnObject::iid = MakeInterfaceId ("AnObject", Object::iid); -const ClassId AnObject::cid = MakeClassId ("AnObject", AnObject::iid); - -AnObject::AnObject (int a, double b) -{} -void -AnObject::DoDispose (void) -{ - // Do your work here. - // chain up - Object::DoDispose (); -} - - -int main (int argc, char *argv[]) -{ - Ptr anObject = ComponentManager::Create (AnObject::cid, AnObject::iid, 10, 20.0); - NS_ASSERT (anObject != 0); - return 0; -} diff --git a/samples/main-object.cc b/samples/main-object.cc deleted file mode 100644 index 5f983c8c7..000000000 --- a/samples/main-object.cc +++ /dev/null @@ -1,118 +0,0 @@ -#include "ns3/object.h" - -using namespace ns3; - -class AnObject : public Object -{ -public: - static const InterfaceId iid; - AnObject (); -protected: - virtual void DoDispose (void); -}; - -const InterfaceId AnObject::iid = MakeInterfaceId ("AnObject", Object::iid); - -AnObject::AnObject () -{} -void -AnObject::DoDispose (void) -{ - // Do your work here. - // chain up - Object::DoDispose (); -} - -class AnotherObject : public Object -{ -public: - static const InterfaceId iid; - AnotherObject (int a); -private: - virtual void DoDispose (void); -}; - -const InterfaceId AnotherObject::iid = MakeInterfaceId ("AnotherObject", Object::iid); - -AnotherObject::AnotherObject (int a) -{ - // enable our interface - SetInterfaceId (AnotherObject::iid); -} -void -AnotherObject::DoDispose (void) -{ - // Do your work here. - // chain up - Object::DoDispose (); -} - - - -class YetAnotherObject : public Object -{ -public: - static const InterfaceId iid; - YetAnotherObject (int a); -private: - virtual void DoDispose (void); -}; - -const InterfaceId YetAnotherObject::iid = MakeInterfaceId ("YetAnotherObject", Object::iid); - -YetAnotherObject::YetAnotherObject (int a) -{ - // enable our interface - SetInterfaceId (YetAnotherObject::iid); - // aggregated directly to another object. - AddInterface (CreateObject ()); -} -void -YetAnotherObject::DoDispose (void) -{ - // Do your work here. - // chain up - Object::DoDispose (); -} - - - -int main (int argc, char *argv[]) -{ - Ptr p; - Ptr anObject; - Ptr anotherObject; - Ptr yetAnotherObject; - - p = CreateObject (); - // p gives you access to AnObject's interface - anObject = p->QueryInterface (AnObject::iid); - NS_ASSERT (anObject != 0); - // p does not give you access to AnotherObject's interface - anotherObject = p->QueryInterface (AnotherObject::iid); - NS_ASSERT (anotherObject == 0); - - anotherObject = CreateObject (1); - // AnotherObject does not give you access to AnObject's interface - anObject = anotherObject->QueryInterface (AnObject::iid); - NS_ASSERT (anObject == 0); - - // aggregate the two objects - p->AddInterface (anotherObject); - // p gives you access to AnObject's interface - anObject = p->QueryInterface (AnObject::iid); - NS_ASSERT (anObject != 0); - // p gives you access to AnotherObject's interface - anotherObject = p->QueryInterface (AnotherObject::iid); - NS_ASSERT (anotherObject != 0); - - - yetAnotherObject = CreateObject (2); - // gives you acess to AnObject interface too. - anObject = yetAnotherObject->QueryInterface (AnObject::iid); - NS_ASSERT (anObject != 0); - - - return 0; -} - diff --git a/samples/main-query-interface.cc b/samples/main-query-interface.cc deleted file mode 100644 index 50b47f3bf..000000000 --- a/samples/main-query-interface.cc +++ /dev/null @@ -1,280 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 University of Washington - * Authors: Tom Henderson, Craig Dowell - * - * 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 - */ - -#include "ns3/log.h" -#include "ns3/object.h" -#include "ns3/component-manager.h" - -using namespace ns3; - -// -// This sample file shows examples of how to use QueryInterface. -// -// QueryInterface is a templated method of class Object, defined in -// src/core/object.h. ns-3 objects that derive from class Object -// can have QueryInterface invoked on them. -// -// QueryInterface is a type-safe way to ask an object, at run-time, -// "Do you support the interface identified by the given InterfaceId?" -// It avoids deprecated techniques of having to downcast pointers to -// an object to ask questions about its type. One or more interfaces -// may be associated with a given object. -// -// QueryInterface is of most use when working with base class -// pointers of objects that may be subclassed. For instance, -// one may have a pointer to a Node, but not know whether it has -// an IPv4 stack. Another example might be to determine whether -// a Node has an EnergyModel, to which calls to decrement energy -// from the node's battery might be made. -// - - -// -// Object is the base class for ns-3 node-related objects used at -// the public API. Object provides reference counting implementations -// and the QueryInterface. -// -// A common design paradigm for an ns-3 node object, such as a Queue, -// is that we provide an abstract base class that inherits from -// Object. This class is assigned an interface ID (iid) and -// contains the basic API for objects in this class and subclasses. -// This base class is specialized to provide implementations of -// the object in question (such as a DropTailQueue). -// -// The design pattern commonly used is known as the "non-virtual -// public interface" pattern, whereby the public API for this -// object is a set of public non-virtual functions that forward -// to private virtual functions. The forwarding functions can -// impose pre- and post-conditions on the forwarding call at -// the base class level. -// -// We'll call this base class "AnInterface" in the example below. -// -// -class AnInterface : public Object -{ -public: - static const InterfaceId iid; - void methodA (void); -private: - virtual void domethodA (void) = 0; -}; - -void -AnInterface::methodA (void) -{ - NS_LOG_FUNCTION; - // pre-dispatch asserts - NS_LOG_LOGIC ("pre-condition"); - domethodA (); - NS_LOG_LOGIC ("post-condition"); - // post-dispatch asserts -} - -// -// The below assignment assigns the InterfaceId of the class AnInterface, -// and declares that the parent iid is that of class Object. -// -const InterfaceId AnInterface::iid = MakeInterfaceId ("AnInterface", Object::iid); - -// -// AnImplementation is an implementation of the abstract base class -// defined above. It provides implementation for the virtual functions -// in the base class. It defines one ClassId for each constructor, -// and can also provide an interface itself (in this example, -// a methodImpl is available) -// -class AnImplementation : public AnInterface -{ -public: - static const InterfaceId iid; - static const ClassId cid; - - AnImplementation (); - void methodImpl (void); -private: - virtual void domethodA (void); -}; - -void -AnImplementation::methodImpl (void) -{ - NS_LOG_FUNCTION; -} - - -AnImplementation::AnImplementation (void) -{ - NS_LOG_FUNCTION; -} - -void -AnImplementation::domethodA () -{ - NS_LOG_FUNCTION; -} - -// -// The below assignment assigns the InterfaceId of the class AnImplementation, -// and declares that the parent iid is that of class Object. -// -const InterfaceId AnImplementation::iid = - MakeInterfaceId ("AnImplementation", AnInterface::iid); - -// -// The next few lines are used by the component manager. They -// state that the component manager can create a new object -// AnImplementation and return an interface corresponding to -// the AnImplementation iid. -// -const ClassId AnImplementation::cid = - MakeClassId - ("AnImplementation", AnImplementation::iid); - - -// -// Extending interfaces -// ================== -// What if AnInterface doesn't provide enough API for your -// object type? -// - if you aren't concerned about backward compatibility and -// don't mind recompiling, you just add new methods to AnInterface -// and recompile. -// - if you want to address backward compatibiliy, or allow part -// of the system to use the old interface, you have to do more. -// You have to declare a new interface with the new functionality. -// - -class AnExtendedInterface : public AnInterface -{ -public: - static const InterfaceId iid; - void methodB (void); -private: - virtual void domethodB (void) = 0; -}; - -const InterfaceId AnExtendedInterface::iid = - MakeInterfaceId ("AnExtendedInterface", AnInterface::iid); - -// -// Then you need provide an implementation for the virtual -// methods. If you are providing a new implementation for -// everything, the answer is straightforward -// - -class ANewImplementation : public AnExtendedInterface -{ -public: - static const InterfaceId iid; - static const ClassId cid; - - ANewImplementation (); - void methodImpl (void); -private: - virtual void domethodA (void) { /* new-implementation-behavior (); */} - virtual void domethodB (void) { /* new-implementation-behavior (); */} -}; - -ANewImplementation::ANewImplementation (void) -{ - // enable our interface - SetInterfaceId (ANewImplementation::iid); -} - -void -ANewImplementation::methodImpl (void) -{ - NS_LOG_FUNCTION; -} - -const InterfaceId ANewImplementation::iid = - MakeInterfaceId ("ANewImplementation", AnExtendedInterface::iid); - -// -// If you want to extend an existing implementation, you can use -// the existing class to instantiate an implementation of its -// methods (hasa) and do the following if you can use stuff from -// the existing class. -// - -class AnExtendedImplementation : public AnExtendedInterface -{ -public: - static const InterfaceId iid; - static const ClassId cid; - - AnExtendedImplementation (); - void methodImpl (void) { /* pImpl->methodImpl (); */ } - void methodExtendedImpl (void); -private: - virtual void domethodA (void) { /* new-implementation-behavior (); */} - virtual void domethodB (void) { /* new-implementation-behavior (); */} - Ptr pImpl; -}; - -AnExtendedImplementation::AnExtendedImplementation (void) -{ - pImpl = CreateObject (); - SetInterfaceId (AnExtendedImplementation::iid); -} - -void -AnExtendedImplementation::methodExtendedImpl (void) -{ - NS_LOG_FUNCTION; -} - -const InterfaceId AnExtendedImplementation::iid = - MakeInterfaceId ("AnExtendedImplementation", AnExtendedInterface::iid); - -// -// Inheriting from an existing implementation (isa) and an extended -// interface is tricky, because of the diamond multiple inheritance -// problem. If the pImpl method above is not desirable, it may -// be that the implementation extension could be aggregated. -// -// The extension will not have access to the base implementation, -// so this design pattern may be more appropriate if the extension -// is very modular (e.g., add an EnergyModel to a wireless interface) -// -// EXAMPLE NOT YET PROVIDED - -int main (int argc, char *argv[]) -{ - - Ptr aBase = ComponentManager::Create - (AnImplementation::cid, AnInterface::iid); - NS_ASSERT (aBase != 0); - - aBase->methodA (); - //aBase->methodImpl (); // XXX won't compile, aBase not right ptr type - - Ptr aBaseImplPtr = - aBase-> QueryInterface (AnImplementation::iid); - aBaseImplPtr->methodImpl (); - aBaseImplPtr->methodA(); - - // Test symmetric property of QueryInterface - Ptr aBase2 = - aBaseImplPtr-> QueryInterface (AnInterface::iid); - aBase2->methodA (); - - return 0; -} diff --git a/src/common/error-model.cc b/src/common/error-model.cc index 946f6c118..8aaf6faad 100644 --- a/src/common/error-model.cc +++ b/src/common/error-model.cc @@ -34,10 +34,14 @@ NS_LOG_COMPONENT_DEFINE ("ErrorModel"); namespace ns3 { static ClassIdDefaultValue g_classIdErrorModelDefaultValue ("ErrorModel", - "Error Model", ErrorModel::iid, "RateErrorModel"); + "Error Model", ErrorModel::iid (), + "RateErrorModel"); -const InterfaceId ErrorModel::iid = - MakeInterfaceId ("ErrorModel", Object::iid); +InterfaceId ErrorModel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("ErrorModel", Object::iid ()); + return iid; +} ErrorModel::ErrorModel () : m_enable (true) @@ -55,8 +59,7 @@ ErrorModel::CreateDefault (void) { NS_LOG_FUNCTION; ClassId classId = g_classIdErrorModelDefaultValue.GetValue (); - Ptr em = ComponentManager::Create (classId, - ErrorModel::iid); + Ptr em = ComponentManager::Create (classId); return em; } @@ -103,12 +106,10 @@ ErrorModel::IsEnabled (void) const // RateErrorModel // -const InterfaceId RateErrorModel::iid = - MakeInterfaceId ("RateErrorModel", ErrorModel::iid); const ClassId RateErrorModel::cid = - MakeClassId ("RateErrorModel", ErrorModel::iid, - RateErrorModel::iid); + MakeClassId ("RateErrorModel", ErrorModel::iid (), + RateErrorModel::iid ()); // Defaults for rate/size static NumericDefaultValue g_defaultRateErrorModelErrorRate @@ -122,6 +123,13 @@ static EnumDefaultValue EU_BIT, "EU_BIT", 0, (void*)0); +InterfaceId RateErrorModel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("RateErrorModel", ErrorModel::iid ()); + return iid; +} + + RateErrorModel::RateErrorModel () : m_unit (g_defaultRateErrorModelErrorUnit.GetValue() ), m_rate (g_defaultRateErrorModelErrorRate.GetValue() ) @@ -232,12 +240,15 @@ RateErrorModel::DoReset (void) // ListErrorModel // -const InterfaceId ListErrorModel::iid = - MakeInterfaceId ("ListErrorModel", ErrorModel::iid); - const ClassId ListErrorModel::cid = - MakeClassId ("ListErrorModel", ErrorModel::iid, - ListErrorModel::iid); + MakeClassId ("ListErrorModel", ErrorModel::iid (), + ListErrorModel::iid ()); + +InterfaceId ListErrorModel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("ListErrorModel", ErrorModel::iid ()); + return iid; +} ListErrorModel::ListErrorModel () { diff --git a/src/common/error-model.h b/src/common/error-model.h index 6c61762e6..3d5df5e50 100644 --- a/src/common/error-model.h +++ b/src/common/error-model.h @@ -67,7 +67,7 @@ class RandomVariable; class ErrorModel : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); /** * A factory method to generate a preconfigured default ErrorModel for use * \return an ErrorModel smart pointer that is the default ErrorModel @@ -137,7 +137,7 @@ enum ErrorUnit class RateErrorModel : public ErrorModel { public: - static const InterfaceId iid; + static InterfaceId iid (void); static const ClassId cid; RateErrorModel (); @@ -204,7 +204,7 @@ private: class ListErrorModel : public ErrorModel { public: - static const InterfaceId iid; + static InterfaceId iid (void); static const ClassId cid; ListErrorModel (); virtual ~ListErrorModel (); diff --git a/src/core/component-manager.cc b/src/core/component-manager.cc index 1c7d2011c..9e81dfe36 100644 --- a/src/core/component-manager.cc +++ b/src/core/component-manager.cc @@ -100,10 +100,10 @@ ComponentManager::LookupByInterfaceId (InterfaceId iid) List *list = Singleton::Get (); for (List::const_iterator i = list->begin (); i != list->end (); i++) { - for (std::vector::const_iterator j = i->m_supportedInterfaces.begin (); + for (std::vector::const_iterator j = i->m_supportedInterfaces.begin (); j != i->m_supportedInterfaces.end (); j++) { - if (*(*j) == iid) + if (*j == iid) { classIdList.push_back (i->m_classId); break; @@ -116,30 +116,30 @@ ComponentManager::LookupByInterfaceId (InterfaceId iid) void ComponentManager::Register (ClassId classId, CallbackBase *callback, - std::vector supportedInterfaces) + std::vector supportedInterfaces) { List *list = Singleton::Get (); struct ClassIdEntry entry = ClassIdEntry (classId); entry.m_callback = callback; bool foundObject = false; - for (std::vector::iterator i = supportedInterfaces.begin (); + for (std::vector::iterator i = supportedInterfaces.begin (); i != supportedInterfaces.end (); i++) { - if (*i == &Object::iid) + if (*i == Object::iid ()) { foundObject = true; } } if (!foundObject) { - supportedInterfaces.push_back (&Object::iid); + supportedInterfaces.push_back (Object::iid ()); } entry.m_supportedInterfaces = supportedInterfaces; list->push_back (entry); } void -RegisterCallback (ClassId classId, CallbackBase *callback, std::vector supportedInterfaces) +RegisterCallback (ClassId classId, CallbackBase *callback, std::vector supportedInterfaces) { return ComponentManager::Register (classId, callback, supportedInterfaces); } @@ -147,12 +147,12 @@ RegisterCallback (ClassId classId, CallbackBase *callback, std::vector classIdList = ComponentManager::LookupByInterfaceId (*m_interfaceId); + std::vector classIdList = ComponentManager::LookupByInterfaceId (m_interfaceId); for (std::vector::const_iterator i = classIdList.begin (); i != classIdList.end (); i++) { @@ -196,7 +196,7 @@ ClassIdDefaultValue::DoParseValue (const std::string &value) std::string ClassIdDefaultValue::DoGetType (void) const { - std::vector classIdList = ComponentManager::LookupByInterfaceId (*m_interfaceId); + std::vector classIdList = ComponentManager::LookupByInterfaceId (m_interfaceId); std::ostringstream oss; oss << "("; for (std::vector::const_iterator i = classIdList.begin (); @@ -234,12 +234,14 @@ namespace { class B : public ns3::Object { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("B", Object::iid ()); + return iid; + } + B (); }; -const ns3::InterfaceId B::iid = MakeInterfaceId ("B", Object::iid); - B::B () {} @@ -251,7 +253,11 @@ public: static const ns3::ClassId cidOneBool; static const ns3::ClassId cidOneUi32; static const ns3::ClassId cidOther; - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("A", Object::iid ()); + return iid; + } + A (); A (bool); @@ -265,10 +271,9 @@ public: int m_ui32; }; -const ns3::ClassId A::cidZero = ns3::MakeClassId ("A", A::iid); -const ns3::ClassId A::cidOneBool = ns3::MakeClassId ("ABool", A::iid); -const ns3::ClassId A::cidOneUi32 = ns3::MakeClassId ("AUi32", A::iid); -const ns3::InterfaceId A::iid = ns3::MakeInterfaceId ("A", Object::iid); +const ns3::ClassId A::cidZero = ns3::MakeClassId ("A", A::iid ()); +const ns3::ClassId A::cidOneBool = ns3::MakeClassId ("ABool", A::iid ()); +const ns3::ClassId A::cidOneUi32 = ns3::MakeClassId ("AUi32", A::iid ()); A::A () : m_zeroInvoked (true), @@ -302,24 +307,31 @@ A::A (uint32_t i) class X : public A { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("X", A::iid ()); + return iid; + } + }; class C : public X { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("C", X::iid ()); + return iid; + } }; class D : public C { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("D", C::iid ()); + return iid; + } static const ns3::ClassId cid; }; -const ns3::InterfaceId X::iid = ns3::MakeInterfaceId ("X", A::iid); -const ns3::InterfaceId C::iid = ns3::MakeInterfaceId ("C", X::iid); -const ns3::InterfaceId D::iid = ns3::MakeInterfaceId ("D", C::iid); -const ns3::ClassId D::cid = ns3::MakeClassId ("D", A::iid, X::iid, C::iid, D::iid); +const ns3::ClassId D::cid = ns3::MakeClassId ("D", A::iid (), X::iid (), C::iid (), D::iid ()); } diff --git a/src/core/component-manager.h b/src/core/component-manager.h index bb239b930..dee19717d 100644 --- a/src/core/component-manager.h +++ b/src/core/component-manager.h @@ -91,7 +91,7 @@ public: * as a supported interface. */ MakeClassId (std::string name, - const InterfaceId &iid); + InterfaceId iid); /** * \param name name of ClassId * \param iid0 interface id @@ -101,8 +101,8 @@ public: * as supported interfaces. */ MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId iid1); + InterfaceId iid0, + InterfaceId iid1); /** * \param name name of ClassId * \param iid0 interface id @@ -113,9 +113,9 @@ public: * and iid2 as supported interfaces. */ MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2); + InterfaceId iid0, + InterfaceId iid1, + InterfaceId iid2); /** * \param name name of ClassId * \param iid0 interface id @@ -127,10 +127,10 @@ public: * iid2, and iid3 as supported interfaces. */ MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2, - const InterfaceId &iid3); + InterfaceId iid0, + InterfaceId iid1, + InterfaceId iid2, + InterfaceId iid3); /** * \param name name of ClassId * \param iid0 interface id @@ -143,15 +143,15 @@ public: * iid2, iid3, and iid4 as supported interfaces. */ MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2, - const InterfaceId &iid3, - const InterfaceId &iid4); + InterfaceId iid0, + InterfaceId iid1, + InterfaceId iid2, + InterfaceId iid3, + InterfaceId iid4); private: typedef ObjectMaker MakerType; static Callback,T1,T2,T3,T4,T5> m_callback; - void Register (const InterfaceId *array [], uint32_t n); + void Register (InterfaceId array [], uint32_t n); }; @@ -345,9 +345,9 @@ public: private: friend void RegisterCallback (ClassId classId, CallbackBase *callback, - std::vector supportedInterfaces); + std::vector supportedInterfaces); static void Register (ClassId classId, CallbackBase *callback, - std::vector supportedInterfaces); + std::vector supportedInterfaces); template m_supportedInterfaces; + std::vector m_supportedInterfaces; }; typedef std::vector List; @@ -386,7 +386,7 @@ public: */ ClassIdDefaultValue (std::string name, std::string help, - const InterfaceId &iid, + InterfaceId iid, std::string defaultValue); /** * \returns the ClassId of the object selected by the user. @@ -410,7 +410,7 @@ private: virtual std::string DoGetDefaultValue (void) const; std::string m_defaultName; std::string m_name; - const InterfaceId *m_interfaceId; + InterfaceId m_interfaceId; }; } // namespace ns3 @@ -473,16 +473,16 @@ struct ObjectMaker { namespace ns3 { void RegisterCallback (ClassId classId, ns3::CallbackBase *callback, - std::vector supportedInterfaces); + std::vector supportedInterfaces); template void -MakeClassId::Register (const InterfaceId *array [], uint32_t n) +MakeClassId::Register (InterfaceId array [], uint32_t n) { - std::vector supportedInterfaces; + std::vector supportedInterfaces; for (uint32_t i = 0; i < n; i++) { supportedInterfaces.push_back (array[i]); @@ -495,63 +495,63 @@ template ::MakeClassId (std::string name) : ClassId (name) { - const InterfaceId *array[] = {}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); + InterfaceId array[] = {}; + Register (array, sizeof (array)/sizeof(InterfaceId)); } template MakeClassId::MakeClassId (std::string name, - const InterfaceId &iid) + InterfaceId iid) : ClassId (name) { - const InterfaceId *array[] = {&iid}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); + InterfaceId array[] = {iid}; + Register (array, sizeof (array)/sizeof(InterfaceId)); } template MakeClassId::MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId iid1) + InterfaceId iid0, + InterfaceId iid1) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); + InterfaceId array[] = {iid0, iid1}; + Register (array, sizeof (array)/sizeof(InterfaceId)); } template MakeClassId::MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2) + InterfaceId iid0, + InterfaceId iid1, + InterfaceId iid2) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1, &iid2}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); + InterfaceId array[] = {iid0, iid1, iid2}; + Register (array, sizeof (array)/sizeof(InterfaceId)); } template MakeClassId::MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2, - const InterfaceId &iid3) + InterfaceId iid0, + InterfaceId iid1, + InterfaceId iid2, + InterfaceId iid3) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1, &iid2, &iid3}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); + InterfaceId array[] = {iid0, iid1, iid2, iid3}; + Register (array, sizeof (array)/sizeof(InterfaceId)); } template MakeClassId::MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2, - const InterfaceId &iid3, - const InterfaceId &iid4) + InterfaceId iid0, + InterfaceId iid1, + InterfaceId iid2, + InterfaceId iid3, + InterfaceId iid4) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1, iid2, &iid3, &iid4}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); + InterfaceId array[] = {iid0, iid1, iid2, iid3, iid4}; + Register (array, sizeof (array)/sizeof(InterfaceId)); } template m_iid; - while (cur != iid && cur != Object::iid) + while (cur != iid && cur != Object::iid ()) { cur = InterfaceId::LookupParent (cur); } @@ -349,7 +354,7 @@ Object::DoCollectSources (std::string path, const TraceContext &context, NS_ASSERT (current != 0); NS_LOG_LOGIC ("collect current=" << current); InterfaceId cur = current->m_iid; - while (cur != Object::iid) + while (cur != Object::iid ()) { std::string name = cur.GetName (); std::string fullpath = path; @@ -404,7 +409,10 @@ namespace { class BaseA : public ns3::Object { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("BaseA", Object::iid ()); + return iid; + } BaseA () {} void BaseGenerateTrace (int16_t v) @@ -424,7 +432,10 @@ public: class DerivedA : public BaseA { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("DerivedA", BaseA::iid ()); + return iid; + } DerivedA (int v) {} void DerivedGenerateTrace (int16_t v) @@ -443,15 +454,13 @@ public: ns3::SVTraceSource m_sourceDerived; }; -const ns3::InterfaceId BaseA::iid = - ns3::MakeInterfaceId ("BaseA", Object::iid); -const ns3::InterfaceId DerivedA::iid = - ns3::MakeInterfaceId ("DerivedA", BaseA::iid);; - class BaseB : public ns3::Object { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("BaseB", Object::iid ()); + return iid; + } BaseB () {} void BaseGenerateTrace (int16_t v) @@ -471,7 +480,10 @@ public: class DerivedB : public BaseB { public: - static const ns3::InterfaceId iid; + static ns3::InterfaceId iid (void) { + static ns3::InterfaceId iid = ns3::MakeInterfaceId ("DerivedB", BaseB::iid ()); + return iid; + } DerivedB (int v) {} void DerivedGenerateTrace (int16_t v) @@ -490,11 +502,6 @@ public: ns3::SVTraceSource m_sourceDerived; }; -const ns3::InterfaceId BaseB::iid = - ns3::MakeInterfaceId ("BaseB", Object::iid); -const ns3::InterfaceId DerivedB::iid = - ns3::MakeInterfaceId ("DerivedB", BaseB::iid);; - } // namespace anonymous namespace ns3 { @@ -547,11 +554,11 @@ ObjectTest::RunTests (void) Ptr baseA = CreateObject (); NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (), baseA); - NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid), 0); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid ()), 0); NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (), 0); baseA = CreateObject (10); NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (), baseA); - NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid), baseA); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid ()), baseA); NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface (), 0); baseA = CreateObject (); diff --git a/src/core/object.h b/src/core/object.h index eb67c70c2..de4bf4eaa 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -98,7 +98,7 @@ MakeInterfaceId (std::string name, const InterfaceId &parent); class Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); Object (); virtual ~Object (); @@ -265,7 +265,7 @@ template Ptr Object::QueryInterface () const { - Ptr found = DoQueryInterface (T::iid); + Ptr found = DoQueryInterface (T::iid ()); if (found != 0) { return Ptr (dynamic_cast (PeekPointer (found))); @@ -289,7 +289,7 @@ template Ptr CreateObject (void) { Ptr p = Ptr (new T (), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -297,7 +297,7 @@ template Ptr CreateObject (T1 a1) { Ptr p = Ptr (new T (a1), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -305,7 +305,7 @@ template Ptr CreateObject (T1 a1, T2 a2) { Ptr p = Ptr (new T (a1, a2), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -313,7 +313,7 @@ template Ptr CreateObject (T1 a1, T2 a2, T3 a3) { Ptr p = Ptr (new T (a1, a2, a3), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -321,7 +321,7 @@ template Ptr CreateObject (T1 a1, T2 a2, T3 a3, T4 a4) { Ptr p = Ptr (new T (a1, a2, a3, a4), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -329,7 +329,7 @@ template CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { Ptr p = Ptr (new T (a1, a2, a3, a4, a5), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -337,7 +337,7 @@ template CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) { Ptr p = Ptr (new T (a1, a2, a3, a4, a5, a6), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } @@ -345,7 +345,7 @@ template CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) { Ptr p = Ptr (new T (a1, a2, a3, a4, a5, a6, a7), false); - p->SetInterfaceId (T::iid); + p->SetInterfaceId (T::iid ()); return p; } diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index 184a4b7b7..ff7ec65c2 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -33,9 +33,15 @@ NS_LOG_COMPONENT_DEFINE ("ArpL3Protocol"); namespace ns3 { -const InterfaceId ArpL3Protocol::iid = MakeInterfaceId ("ArpL3Protocol", Object::iid); const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806; +InterfaceId +ArpL3Protocol::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("ArpL3Protocol", Object::iid ()); + return iid; +} + ArpL3Protocol::ArpL3Protocol (Ptr node) : m_node (node) { diff --git a/src/internet-node/arp-l3-protocol.h b/src/internet-node/arp-l3-protocol.h index 395801834..6bb26181e 100644 --- a/src/internet-node/arp-l3-protocol.h +++ b/src/internet-node/arp-l3-protocol.h @@ -40,7 +40,7 @@ class TraceContext; class ArpL3Protocol : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); static const uint16_t PROT_NUMBER; /** * \brief Constructor diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index e8cff69bf..f4e58215e 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -40,9 +40,15 @@ NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol"); namespace ns3 { -const InterfaceId Ipv4L3Protocol::iid = MakeInterfaceId ("Ipv4L3Protocol", Object::iid); const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800; +InterfaceId +Ipv4L3Protocol::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Ipv4L3Protocol", Object::iid ()); + return iid; +} + Ipv4L3ProtocolTraceContextElement::Ipv4L3ProtocolTraceContextElement () : m_type (TX) { diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index cd912e9f1..5ed445110 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -99,7 +99,7 @@ private: class Ipv4L3Protocol : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); static const uint16_t PROT_NUMBER; Ipv4L3Protocol(Ptr node); diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index e0b63cc18..92cf166ae 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -30,8 +30,6 @@ namespace ns3 { -const InterfaceId Ipv4L4Demux::iid = MakeInterfaceId ("Ipv4L4Demux", Object::iid); - Ipv4L4ProtocolTraceContextElement::Ipv4L4ProtocolTraceContextElement () : m_protocolNumber (0) {} @@ -60,6 +58,12 @@ Ipv4L4ProtocolTraceContextElement::GetTypeName (void) const return "ns3::Ipv4L4ProtocolTraceContextElement"; } +InterfaceId +Ipv4L4Demux::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Ipv4L4Demux", Object::iid ()); + return iid; +} Ipv4L4Demux::Ipv4L4Demux (Ptr node) : m_node (node) diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 6e1208c13..b740b55d7 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -62,7 +62,7 @@ private: class Ipv4L4Demux : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); Ipv4L4Demux (Ptr node); virtual ~Ipv4L4Demux(); diff --git a/src/mobility/grid-topology.cc b/src/mobility/grid-topology.cc index 1e33a70cd..e2471a67b 100644 --- a/src/mobility/grid-topology.cc +++ b/src/mobility/grid-topology.cc @@ -43,8 +43,7 @@ GridTopology::LayoutOneRowFirst (Ptr object, uint32_t i) double x, y; x = m_xMin + m_deltaX * (i % m_n); y = m_yMin + m_deltaY * (i / m_n); - Ptr mobility = ComponentManager::Create (m_positionClassId, - MobilityModel::iid); + Ptr mobility = ComponentManager::Create (m_positionClassId); object->AddInterface (mobility); mobility->SetPosition (Vector (x, y, 0.0)); } @@ -55,8 +54,7 @@ GridTopology::LayoutOneColumnFirst (Ptr object, uint32_t i) double x, y; x = m_xMin + m_deltaX * (i / m_n); y = m_yMin + m_deltaY * (i % m_n); - Ptr mobility = ComponentManager::Create (m_positionClassId, - MobilityModel::iid); + Ptr mobility = ComponentManager::Create (m_positionClassId); object->AddInterface (mobility); mobility->SetPosition (Vector (x, y, 0.0)); } diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index 95ea01cb2..c97f4bdd6 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -22,6 +22,13 @@ namespace ns3 { +InterfaceId +HierarchicalMobilityModel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("HierarchicalMobilityModel", MobilityModel::iid ()); + return iid; +} + HierarchicalMobilityModel::HierarchicalMobilityModel (Ptr child, Ptr parent) : m_child (child), m_parent (parent) diff --git a/src/mobility/hierarchical-mobility-model.h b/src/mobility/hierarchical-mobility-model.h index f864289f5..d719cb6af 100644 --- a/src/mobility/hierarchical-mobility-model.h +++ b/src/mobility/hierarchical-mobility-model.h @@ -33,7 +33,7 @@ namespace ns3 { class HierarchicalMobilityModel : public MobilityModel { public: - static const InterfaceId iid; + static InterfaceId iid (void); /** * \param child the "relative" mobility model diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index 8f48509b8..f95fb1216 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -23,10 +23,15 @@ namespace ns3 { -const InterfaceId MobilityModelNotifier::iid = MakeInterfaceId ("MobilityModelNotifier", Object::iid); const ClassId MobilityModelNotifier::cid = MakeClassId ("MobilityModelNotifier", - MobilityModelNotifier::iid); + MobilityModelNotifier::iid ()); +InterfaceId +MobilityModelNotifier::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("MobilityModelNotifier", Object::iid ()); + return iid; +} MobilityModelNotifier::MobilityModelNotifier () {} diff --git a/src/mobility/mobility-model-notifier.h b/src/mobility/mobility-model-notifier.h index e3616b904..0e9c8e544 100644 --- a/src/mobility/mobility-model-notifier.h +++ b/src/mobility/mobility-model-notifier.h @@ -34,8 +34,8 @@ namespace ns3 { class MobilityModelNotifier : public Object { public: - static const InterfaceId iid; static const ClassId cid; + static InterfaceId iid (void); /** * Create a new position notifier diff --git a/src/mobility/mobility-model.cc b/src/mobility/mobility-model.cc index 643887800..32110f81e 100644 --- a/src/mobility/mobility-model.cc +++ b/src/mobility/mobility-model.cc @@ -23,7 +23,12 @@ namespace ns3 { -const InterfaceId MobilityModel::iid = MakeInterfaceId ("MobilityModel", Object::iid); +InterfaceId +MobilityModel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("MobilityModel", Object::iid ()); + return iid; +} MobilityModel::MobilityModel () {} diff --git a/src/mobility/mobility-model.h b/src/mobility/mobility-model.h index e55b27988..4073641f8 100644 --- a/src/mobility/mobility-model.h +++ b/src/mobility/mobility-model.h @@ -35,7 +35,7 @@ namespace ns3 { class MobilityModel : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); MobilityModel (); virtual ~MobilityModel () = 0; diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index 0f21b6ff3..073831027 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -33,7 +33,7 @@ namespace ns3 { const double RandomDirection2dMobilityModel::PI = 3.14159265358979323846; const ClassId RandomDirection2dMobilityModel::cid = MakeClassId ("RandomDirection2dMobilityModel", - MobilityModel::iid); + MobilityModel::iid ()); static RandomVariableDefaultValue diff --git a/src/mobility/random-position.cc b/src/mobility/random-position.cc index 56ebf36f3..a3b55c7e1 100644 --- a/src/mobility/random-position.cc +++ b/src/mobility/random-position.cc @@ -58,14 +58,19 @@ g_discY ("RandomDiscPositionY", "The y coordinate of the center of the random position disc.", 0.0); -const InterfaceId RandomPosition::iid = MakeInterfaceId ("RandomPosition", Object::iid); +InterfaceId +RandomPosition::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("RandomPosition", Object::iid ()); + return iid; +} const ClassId RandomRectanglePosition::cid = MakeClassId ("RandomRectanglePosition", - RandomPosition::iid); + RandomPosition::iid ()); const ClassId RandomDiscPosition::cid = MakeClassId ("RandomDiscPosition", - RandomPosition::iid); + RandomPosition::iid ()); RandomPosition::RandomPosition () { diff --git a/src/mobility/random-position.h b/src/mobility/random-position.h index 27559844d..bbd7272ea 100644 --- a/src/mobility/random-position.h +++ b/src/mobility/random-position.h @@ -36,7 +36,7 @@ class RandomVariable; class RandomPosition : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); RandomPosition (); virtual ~RandomPosition (); /** diff --git a/src/mobility/random-topology.cc b/src/mobility/random-topology.cc index 64469053b..8f5d39dc7 100644 --- a/src/mobility/random-topology.cc +++ b/src/mobility/random-topology.cc @@ -28,20 +28,19 @@ namespace ns3 { static ClassIdDefaultValue g_position ("RandomTopologyPositionType", "The type of initial random position in a 3d topology.", - RandomPosition::iid, + RandomPosition::iid (), "RandomRectanglePosition"); static ClassIdDefaultValue g_mobility ("RandomTopologyMobilityType", "The type of mobility model attached to an object in a 3d topology.", - MobilityModel::iid, + MobilityModel::iid (), "StaticMobilityModel"); RandomTopology::RandomTopology () : m_mobilityModel (g_mobility.GetValue ()) { - m_positionModel = ComponentManager::Create (g_position.GetValue (), - RandomPosition::iid); + m_positionModel = ComponentManager::Create (g_position.GetValue ()); } RandomTopology::RandomTopology (Ptr positionModel, ClassId mobilityModel) : m_positionModel (positionModel), @@ -67,8 +66,7 @@ RandomTopology::SetPositionModel (Ptr positionModel) void RandomTopology::LayoutOne (Ptr object) { - Ptr mobility = ComponentManager::Create (m_mobilityModel, - MobilityModel::iid); + Ptr mobility = ComponentManager::Create (m_mobilityModel); object->AddInterface (mobility); Vector position = m_positionModel->Get (); mobility->SetPosition (position); diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 342bfb150..992f04235 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -32,7 +32,7 @@ NS_LOG_COMPONENT_DEFINE ("RandomWalk2d"); namespace ns3 { const ClassId RandomWalk2dMobilityModel::cid = - MakeClassId ("RandomWalk2dMobilityModel", RandomWalk2dMobilityModel::iid); + MakeClassId ("RandomWalk2dMobilityModel", RandomWalk2dMobilityModel::iid ()); static EnumDefaultValue diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index be5f43ada..983970411 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -40,18 +40,17 @@ g_pause ("RandomWaypointPause", static ClassIdDefaultValue g_position ("RandomWaypointPosition", "A random position model used to pick the next waypoint position.", - RandomPosition::iid, + RandomPosition::iid (), "RandomRectanglePosition"); const ClassId RandomWaypointMobilityModel::cid = - MakeClassId ("RandomWaypointMobilityModel", MobilityModel::iid); + MakeClassId ("RandomWaypointMobilityModel", MobilityModel::iid ()); RandomWaypointMobilityModelParameters::RandomWaypointMobilityModelParameters () : m_speed (g_speed.GetCopy ()), m_pause (g_pause.GetCopy ()) { - m_position = ComponentManager::Create (g_position.GetValue (), - RandomPosition::iid); + m_position = ComponentManager::Create (g_position.GetValue ()); } RandomWaypointMobilityModelParameters::RandomWaypointMobilityModelParameters (Ptr randomPosition, const RandomVariable &speed, diff --git a/src/mobility/static-mobility-model.cc b/src/mobility/static-mobility-model.cc index 1b7c18775..b8d07c7fd 100644 --- a/src/mobility/static-mobility-model.cc +++ b/src/mobility/static-mobility-model.cc @@ -22,7 +22,7 @@ namespace ns3 { const ClassId StaticMobilityModel::cid = MakeClassId ("StaticMobilityModel", - MobilityModel::iid); + MobilityModel::iid ()); StaticMobilityModel::StaticMobilityModel () {} diff --git a/src/mobility/static-speed-mobility-model.cc b/src/mobility/static-speed-mobility-model.cc index 49e764be1..f758ea430 100644 --- a/src/mobility/static-speed-mobility-model.cc +++ b/src/mobility/static-speed-mobility-model.cc @@ -22,12 +22,14 @@ namespace ns3 { -const InterfaceId StaticSpeedMobilityModel::iid = - MakeInterfaceId ("StaticSpeedMobilityModel", MobilityModel::iid); const ClassId StaticSpeedMobilityModel::cid = MakeClassId ("StaticSpeedMobilityModel", - StaticSpeedMobilityModel::iid); - + StaticSpeedMobilityModel::iid ()); +InterfaceId StaticSpeedMobilityModel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("StaticSpeedMobilityModel", MobilityModel::iid ()); + return iid; +} StaticSpeedMobilityModel::StaticSpeedMobilityModel () {} diff --git a/src/mobility/static-speed-mobility-model.h b/src/mobility/static-speed-mobility-model.h index 81198d735..dd06f9288 100644 --- a/src/mobility/static-speed-mobility-model.h +++ b/src/mobility/static-speed-mobility-model.h @@ -36,8 +36,8 @@ namespace ns3 { class StaticSpeedMobilityModel : public MobilityModel { public: - static const InterfaceId iid; static const ClassId cid; + static InterfaceId iid (void); /** * Create position located at coordinates (0,0,0) with * speed (0,0,0). diff --git a/src/node/channel.cc b/src/node/channel.cc index dd60b06c4..df73fa768 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -24,7 +24,12 @@ NS_LOG_COMPONENT_DEFINE ("Channel"); namespace ns3 { -const InterfaceId Channel::iid = MakeInterfaceId ("Channel", Object::iid); +InterfaceId +Channel::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Channel", Object::iid ()); + return iid; +} Channel::Channel () : m_name("Channel") diff --git a/src/node/channel.h b/src/node/channel.h index 9d3bd7c5c..d5d3402bc 100644 --- a/src/node/channel.h +++ b/src/node/channel.h @@ -35,7 +35,7 @@ class NetDevice; class Channel : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); Channel (); Channel (std::string name); diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index 3e843564d..f0900703d 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -25,7 +25,7 @@ NS_LOG_COMPONENT_DEFINE ("DropTailQueue"); namespace ns3 { const ClassId DropTailQueue::cid = - MakeClassId ("DropTailQueue", Queue::iid); + MakeClassId ("DropTailQueue", Queue::iid ()); DropTailQueue::DropTailQueue () : diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 0e51fdbe0..d3dd8b25c 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -25,7 +25,12 @@ namespace ns3 { -const InterfaceId Ipv4::iid = MakeInterfaceId ("Ipv4", Object::iid); +InterfaceId +Ipv4::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Ipv4", Object::iid ()); + return iid; +} Ipv4::Ipv4 () {} diff --git a/src/node/ipv4.h b/src/node/ipv4.h index a0ece2823..856c2fcc8 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -157,7 +157,7 @@ public: class Ipv4 : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); Ipv4 (); virtual ~Ipv4 (); diff --git a/src/node/net-device.cc b/src/node/net-device.cc index a2142dcdf..9f639360c 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -33,7 +33,11 @@ NS_LOG_COMPONENT_DEFINE ("NetDevice"); namespace ns3 { -const InterfaceId NetDevice::iid = MakeInterfaceId ("NetDevice", Object::iid); +InterfaceId NetDevice::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("NetDevice", Object::iid ()); + return iid; +} NetDevice::NetDevice(Ptr node, const Address& addr) : m_node (node), diff --git a/src/node/net-device.h b/src/node/net-device.h index 0b85d63c8..537c11116 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -60,7 +60,7 @@ class Packet; class NetDevice : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); virtual ~NetDevice(); diff --git a/src/node/node.cc b/src/node/node.cc index 43d2aa977..03d6b08d1 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -29,7 +29,12 @@ namespace ns3{ -const InterfaceId Node::iid = MakeInterfaceId ("Node", Object::iid); +InterfaceId +Node::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Node", Object::iid ()); + return iid; +} NodeNetDeviceIndex::NodeNetDeviceIndex () : m_index (0) diff --git a/src/node/node.h b/src/node/node.h index 24caa9317..ed0c7aaf9 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -96,7 +96,7 @@ private: class Node : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); /** * Must be invoked by subclasses only. diff --git a/src/node/packet-socket-factory.cc b/src/node/packet-socket-factory.cc index 23f5148e2..998de2c34 100644 --- a/src/node/packet-socket-factory.cc +++ b/src/node/packet-socket-factory.cc @@ -24,8 +24,13 @@ namespace ns3 { -const InterfaceId PacketSocketFactory::iid = MakeInterfaceId ("Packet", - SocketFactory::iid); +InterfaceId +PacketSocketFactory::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Packet", + SocketFactory::iid ()); + return iid; +} PacketSocketFactory::PacketSocketFactory () {} diff --git a/src/node/packet-socket-factory.h b/src/node/packet-socket-factory.h index 7d7468052..4963cb50c 100644 --- a/src/node/packet-socket-factory.h +++ b/src/node/packet-socket-factory.h @@ -34,7 +34,7 @@ class Socket; class PacketSocketFactory : public SocketFactory { public: - static const InterfaceId iid; /// Interface identifier + static InterfaceId iid (void); PacketSocketFactory (); diff --git a/src/node/queue.cc b/src/node/queue.cc index 5e3238290..8e463a6fc 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -27,9 +27,8 @@ NS_LOG_COMPONENT_DEFINE ("Queue"); namespace ns3 { -const InterfaceId Queue::iid = MakeInterfaceId ("Queue", Object::iid); static ClassIdDefaultValue g_classIdDefaultValue ("Queue", "Packet Queue", - Queue::iid, "DropTailQueue"); + Queue::iid (), "DropTailQueue"); std::string @@ -97,6 +96,13 @@ QueueTraceType::Print (std::ostream &os) const } } +InterfaceId +Queue::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Queue", Object::iid ()); + return iid; +} + Queue::Queue() : m_nBytes(0), m_nTotalReceivedBytes(0), @@ -275,7 +281,7 @@ Queue::CreateDefault (void) { NS_LOG_FUNCTION; ClassId classId = g_classIdDefaultValue.GetValue (); - Ptr queue = ComponentManager::Create (classId, Queue::iid); + Ptr queue = ComponentManager::Create (classId); return queue; } diff --git a/src/node/queue.h b/src/node/queue.h index 0f5aa277a..781c53f46 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -78,7 +78,7 @@ private: class Queue : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); Queue (); virtual ~Queue (); diff --git a/src/node/socket-factory.cc b/src/node/socket-factory.cc index ba6689f6d..6c8ad867f 100644 --- a/src/node/socket-factory.cc +++ b/src/node/socket-factory.cc @@ -22,7 +22,11 @@ namespace ns3 { -const InterfaceId SocketFactory::iid = MakeInterfaceId ("SocketFactory", Object::iid); +InterfaceId SocketFactory::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("SocketFactory", Object::iid ()); + return iid; +} SocketFactory::SocketFactory () {} diff --git a/src/node/socket-factory.h b/src/node/socket-factory.h index ae999adf3..6cc96ff5d 100644 --- a/src/node/socket-factory.h +++ b/src/node/socket-factory.h @@ -47,7 +47,7 @@ class Socket; class SocketFactory : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); SocketFactory (); diff --git a/src/node/udp.cc b/src/node/udp.cc index a604ea698..c43861963 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -22,7 +22,11 @@ namespace ns3 { -const InterfaceId Udp::iid = MakeInterfaceId ("Udp", SocketFactory::iid); +InterfaceId Udp::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("Udp", SocketFactory::iid ()); + return iid; +} Udp::Udp () {} diff --git a/src/node/udp.h b/src/node/udp.h index d67dce768..aadcb3eb8 100644 --- a/src/node/udp.h +++ b/src/node/udp.h @@ -43,7 +43,7 @@ class Socket; class Udp : public SocketFactory { public: - static const InterfaceId iid; + static InterfaceId iid (void); Udp (); diff --git a/src/routing/global-routing/global-router-interface.cc b/src/routing/global-routing/global-router-interface.cc index d37c98d2d..11dd8375c 100644 --- a/src/routing/global-routing/global-router-interface.cc +++ b/src/routing/global-routing/global-router-interface.cc @@ -431,8 +431,12 @@ std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa) // // --------------------------------------------------------------------------- -const InterfaceId GlobalRouter::iid = - MakeInterfaceId ("GlobalRouter", Object::iid); +InterfaceId +GlobalRouter::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("GlobalRouter", Object::iid ()); + return iid; +} GlobalRouter::GlobalRouter () : m_LSAs() diff --git a/src/routing/global-routing/global-router-interface.h b/src/routing/global-routing/global-router-interface.h index a9517dea9..dd8bf30ef 100644 --- a/src/routing/global-routing/global-router-interface.h +++ b/src/routing/global-routing/global-router-interface.h @@ -560,7 +560,7 @@ public: * * @see Object::QueryInterface () */ - static const InterfaceId iid; + static InterfaceId iid (void); /** * @brief Create a Global Router class diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 3d6231933..56642325f 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -178,7 +178,7 @@ AgentImpl::AgentImpl (Ptr node) m_ipv4 = node->QueryInterface (); NS_ASSERT (m_ipv4); - Ptr socketFactory = node->QueryInterface (Udp::iid); + Ptr socketFactory = node->QueryInterface (Udp::iid ()); m_receiveSocket = socketFactory->CreateSocket (); if (m_receiveSocket->Bind (InetSocketAddress (OLSR_PORT_NUMBER))) diff --git a/src/routing/olsr/olsr-agent.cc b/src/routing/olsr/olsr-agent.cc index 0210eb050..e62285b99 100644 --- a/src/routing/olsr/olsr-agent.cc +++ b/src/routing/olsr/olsr-agent.cc @@ -24,7 +24,14 @@ namespace ns3 { namespace olsr { -const InterfaceId Agent::iid = MakeInterfaceId ("OlsrAgent", Object::iid); -const ClassId Agent::cid = MakeClassId< AgentImpl, Ptr > ("OlsrAgent", Agent::iid); +const ClassId Agent::cid = MakeClassId< AgentImpl, Ptr > ("OlsrAgent", Agent::iid ()); + +InterfaceId +Agent::iid (void) +{ + static InterfaceId iid = MakeInterfaceId ("OlsrAgent", Object::iid ()); + return iid; +} + }} diff --git a/src/routing/olsr/olsr-agent.h b/src/routing/olsr/olsr-agent.h index d918d9368..58c030bdd 100644 --- a/src/routing/olsr/olsr-agent.h +++ b/src/routing/olsr/olsr-agent.h @@ -46,7 +46,7 @@ namespace olsr { class Agent : public Object { public: - static const InterfaceId iid; + static InterfaceId iid (void); static const ClassId cid; /** diff --git a/utils/bench-object.cc b/utils/bench-object.cc deleted file mode 100644 index 171611309..000000000 --- a/utils/bench-object.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include "ns3/object.h" - -using namespace ns3; - -class BaseA : public ns3::Object -{ -public: - static const ns3::InterfaceId iid; - BaseA () - { - SetInterfaceId (BaseA::iid); - } - virtual void Dispose (void) {} -}; - -const ns3::InterfaceId BaseA::iid = -ns3::MakeInterfaceId ("BaseABench", Object::iid); - - - -int main (int argc, char *argv[]) -{ - int nobjects = atoi (argv[1]); - int nswaps = atoi (argv[2]); - - std::vector< Ptr > objlist; - - for (int i = 0; i < nobjects; ++i) - objlist.push_back (CreateObject ()); - - for (int swapCounter = nswaps; swapCounter; --swapCounter) - { - int x1 = swapCounter % nobjects; - int x2 = (swapCounter+1) % nobjects; - Ptr obj1 = objlist[x1]; - Ptr obj2 = objlist[x2]; - objlist[x2] = obj1; - objlist[x1] = obj2; - } -} -