diff --git a/src/core/component-manager.h b/src/core/component-manager.h index 4fd784404..26b685c26 100644 --- a/src/core/component-manager.h +++ b/src/core/component-manager.h @@ -31,13 +31,20 @@ #include "empty.h" #include "default-value.h" +namespace { + // anonymous namespace for implementation code. +template +struct ObjectMaker; +} + namespace ns3 { /** * \brief Unique Identifier for class constructors. * * Instances of this type must be allocated through - * the ns3::Ns3UnknownManager::RegisterConstructor methods + * the ns3::MakeClassId class. */ class ClassId { @@ -61,8 +68,92 @@ private: uint32_t m_classId; }; -template -class MakeClassId; +/** + * \brief a class used to create ClassIds + * + * + */ +template +class MakeClassId : public ClassId +{ +public: + /** + * \param name name of ClassId + * + * Create a ClassId with specified name. + */ + MakeClassId (std::string name); + /** + * \param name name of ClassId + * \param iid interface id + * + * Create a ClassId with specified name. Register iid + * as a supported interface. + */ + MakeClassId (std::string name, + const InterfaceId &iid); + /** + * \param name name of ClassId + * \param iid0 interface id + * \param iid1 interface id + * + * Create a ClassId with specified name. Register iid0 and iid1 + * as supported interfaces. + */ + MakeClassId (std::string name, + const InterfaceId &iid0, + const InterfaceId iid1); + /** + * \param name name of ClassId + * \param iid0 interface id + * \param iid1 interface id + * \param iid2 interface id + * + * Create a ClassId with specified name. Register iid0, iid1 + * and iid2 as supported interfaces. + */ + MakeClassId (std::string name, + const InterfaceId &iid0, + const InterfaceId &iid1, + const InterfaceId &iid2); + /** + * \param name name of ClassId + * \param iid0 interface id + * \param iid1 interface id + * \param iid2 interface id + * \param iid3 interface id + * + * Create a ClassId with specified name. Register iid0, iid1 + * iid2, and iid3 as supported interfaces. + */ + MakeClassId (std::string name, + const InterfaceId &iid0, + const InterfaceId &iid1, + const InterfaceId &iid2, + const InterfaceId &iid3); + /** + * \param name name of ClassId + * \param iid0 interface id + * \param iid1 interface id + * \param iid2 interface id + * \param iid3 interface id + * \param iid4 interface id + * + * Create a ClassId with specified name. Register iid0, iid1 + * 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); +private: + typedef ObjectMaker MakerType; + static Callback,T1,T2,T3,T4,T5> m_callback; + void Register (const InterfaceId *array [], uint32_t n); +}; /** @@ -129,6 +220,49 @@ public: template static Ptr Create (ClassId classId, T1 a1, T2 a2); + + /** + * \param classId class id of the constructor to invoke. + * \param a1 first argument to pass to the constructor. + * \param a2 second argument to pass to the constructor. + * \param a3 third argument to pass to the constructor. + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId. + */ + template + static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3); + + /** + * \param classId class id of the constructor to invoke. + * \param a1 first argument to pass to the constructor. + * \param a2 second argument to pass to the constructor. + * \param a3 third argument to pass to the constructor. + * \param a4 fourth argument to pass to the constructor. + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId. + */ + template + static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4); + + /** + * \param classId class id of the constructor to invoke. + * \param a1 first argument to pass to the constructor. + * \param a2 second argument to pass to the constructor. + * \param a3 third argument to pass to the constructor. + * \param a4 fourth argument to pass to the constructor. + * \param a5 fifth argument to pass to the constructor. + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId. + */ + template + static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + /** * \param classId class id of the constructor to invoke. * \param iid interface id to query for @@ -141,12 +275,81 @@ public: template static Ptr Create (ClassId classId, InterfaceId iid); + /** + * \param classId class id of the constructor to invoke. + * \param iid interface id to query for + * \param a1 first argument to pass to constructor + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId, call QueryInterface on it, and return the + * result. + */ template static Ptr Create (ClassId classId, InterfaceId iid, T1 a1); + /** + * \param classId class id of the constructor to invoke. + * \param iid interface id to query for + * \param a1 first argument to pass to constructor + * \param a2 second argument to pass to constructor + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId, call QueryInterface on it, and return the + * result. + */ template static Ptr Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2); + /** + * \param classId class id of the constructor to invoke. + * \param iid interface id to query for + * \param a1 first argument to pass to constructor + * \param a2 second argument to pass to constructor + * \param a3 third argument to pass to constructor + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId, call QueryInterface on it, and return the + * result. + */ + template + static Ptr Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3); + + /** + * \param classId class id of the constructor to invoke. + * \param iid interface id to query for + * \param a1 first argument to pass to constructor + * \param a2 second argument to pass to constructor + * \param a3 third argument to pass to constructor + * \param a4 fourth argument to pass to constructor + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId, call QueryInterface on it, and return the + * result. + */ + template + static Ptr Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4); + + /** + * \param classId class id of the constructor to invoke. + * \param iid interface id to query for + * \param a1 first argument to pass to constructor + * \param a2 second argument to pass to constructor + * \param a3 third argument to pass to constructor + * \param a4 fourth argument to pass to constructor + * \param a5 fifth argument to pass to constructor + * \return a pointer to the instance created. + * + * Create an instance of the object identified by its + * ClassId, call QueryInterface on it, and return the + * result. + */ + template + static Ptr Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4, T5); + private: friend void RegisterCallback (ClassId classId, CallbackBase *callback, std::vector supportedInterfaces); @@ -170,15 +373,43 @@ private: static CallbackBase *Lookup (ClassId classId); }; +/** + * \brief a DefaultValue class to handle ClassIds + * + * This class provides the necessary glue to allow + * the Bind function and the command-line arguments + * to control the type of an object to create. + */ class ClassIdDefaultValue : public DefaultValueBase { public: + /** + * \param name the name of this default value. + * \param help the help text associated to this default value + * \param iid the interface id which all objects created + * through this "default value" must support. + * \param defaultValue the name of the object to create + * by default. + */ ClassIdDefaultValue (std::string name, std::string help, const InterfaceId &iid, std::string defaultValue); + /** + * \returns the ClassId of the object selected by the user. + */ ClassId GetValue (void) const; + /** + * \param classId the new ClassId selected. + * + * Override the currently-selected value. + */ void SetValue (ClassId classId); + /** + * \param name the new object selected. + * + * Override the currently-selected value. + */ void SetValue (std::string name); private: virtual bool DoParseValue (const std::string &value); @@ -193,12 +424,9 @@ private: namespace { - // anonymous namespace for implementation code. -template -struct ObjectMaker; template -struct ObjectMaker { +struct ObjectMaker { static ns3::Ptr MakeObject (void) { return ns3::MakeNewObject (); @@ -206,7 +434,7 @@ struct ObjectMaker { }; template -struct ObjectMaker { +struct ObjectMaker { static ns3::Ptr MakeObject (T1 a1) { return ns3::MakeNewObject (a1); @@ -214,13 +442,39 @@ struct ObjectMaker { }; template -struct ObjectMaker { +struct ObjectMaker { static ns3::Ptr MakeObject (T1 a1, T2 a2) { return ns3::MakeNewObject (a1, a2); } }; +template +struct ObjectMaker { + static ns3::Ptr + MakeObject (T1 a1, T2 a2, T3 a3) { + return ns3::MakeNewObject (a1, a2, a3); + } +}; + +template +struct ObjectMaker { + static ns3::Ptr + MakeObject (T1 a1, T2 a2, T3 a3, T4 a4) { + return ns3::MakeNewObject (a1, a2, a3, a4); + } +}; + +template +struct ObjectMaker { + static ns3::Ptr + MakeObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { + return ns3::MakeNewObject (a1, a2, a3, a4, a5); + } +}; + } // anonymous namespace namespace ns3 { @@ -229,64 +483,88 @@ void RegisterCallback (ClassId classId, ns3::CallbackBase *callback, std::vector supportedInterfaces); -template -class MakeClassId : public ClassId -{ -private: - typedef ObjectMaker MakerType; - static Callback,T1,T2> m_callback; - void Register (const InterfaceId *array [], uint32_t n) { - std::vector supportedInterfaces; - for (uint32_t i = 0; i < n; i++) - { - supportedInterfaces.push_back (array[i]); - } - RegisterCallback (*this, &m_callback, supportedInterfaces); - } -public: - MakeClassId (std::string name) : ClassId (name) { - const InterfaceId *array[] = {}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); - } - MakeClassId (std::string name, - const InterfaceId &iid) : ClassId (name) { - const InterfaceId *array[] = {&iid}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); - } - MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId iid1) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); - } - MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1, &iid2}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); - } - MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2, - const InterfaceId &iid3) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1, &iid2, &iid3}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); - } - MakeClassId (std::string name, - const InterfaceId &iid0, - const InterfaceId &iid1, - const InterfaceId &iid2, - const InterfaceId &iid3, - const InterfaceId &iid4) : ClassId (name) { - const InterfaceId *array[] = {&iid0, &iid1, iid2, &iid3, &iid4}; - Register (array, sizeof (array)/sizeof(InterfaceId *)); - } -}; -template -Callback,T1,T2> MakeClassId::m_callback = MakeCallback (&MakeClassId::MakerType::MakeObject); +template +void +MakeClassId::Register (const InterfaceId *array [], uint32_t n) +{ + std::vector supportedInterfaces; + for (uint32_t i = 0; i < n; i++) + { + supportedInterfaces.push_back (array[i]); + } + RegisterCallback (*this, &m_callback, supportedInterfaces); +} + +template +MakeClassId::MakeClassId (std::string name) + : ClassId (name) +{ + const InterfaceId *array[] = {}; + Register (array, sizeof (array)/sizeof(InterfaceId *)); +} +template +MakeClassId::MakeClassId (std::string name, + const InterfaceId &iid) + : ClassId (name) +{ + const InterfaceId *array[] = {&iid}; + Register (array, sizeof (array)/sizeof(InterfaceId *)); +} +template +MakeClassId::MakeClassId (std::string name, + const InterfaceId &iid0, + const InterfaceId iid1) + : ClassId (name) +{ + const 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) + : ClassId (name) +{ + const 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) + : ClassId (name) +{ + const 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) + : ClassId (name) +{ + const InterfaceId *array[] = {&iid0, &iid1, iid2, &iid3, &iid4}; + Register (array, sizeof (array)/sizeof(InterfaceId *)); +} + +template +Callback,T1,T2,T3,T4,T5> MakeClassId::m_callback = + MakeCallback (&MakeClassId::MakerType::MakeObject); @@ -323,6 +601,31 @@ ComponentManager::Create (ClassId classId, T1 a1, T2 a2) return callback (a1, a2); } +template +Ptr +ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3) +{ + Callback,T1,T2,T3> callback = DoGetCallback (classId); + return callback (a1, a2, a3); +} + +template +Ptr +ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4) +{ + Callback,T1,T2,T3,T4> callback = DoGetCallback (classId); + return callback (a1, a2, a3, a4); +} + +template +Ptr +ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + Callback,T1,T2,T3,T4,T5> callback = DoGetCallback (classId); + return callback (a1, a2, a3, a4, a5); +} + + template Ptr ComponentManager::Create (ClassId classId, InterfaceId iid) @@ -350,6 +653,34 @@ ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2) return i; } + +template +Ptr +ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3) +{ + Ptr obj = Create (classId, a1, a2, a3); + Ptr i = obj->QueryInterface (iid); + return i; +} + +template +Ptr +ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4) +{ + Ptr obj = Create (classId, a1, a2, a3, a4); + Ptr i = obj->QueryInterface (iid); + return i; +} + +template +Ptr +ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + Ptr obj = Create (classId, a1, a2, a3, a4, a5); + Ptr i = obj->QueryInterface (iid); + return i; +} + } // namespace ns3 #endif /* NS_COMPONENT_MANAGER_H */