--- a/src/core/component-manager.h Fri May 25 18:51:04 2007 +0200
+++ b/src/core/component-manager.h Fri May 25 21:27:58 2007 +0200
@@ -31,13 +31,20 @@
#include "empty.h"
#include "default-value.h"
+namespace {
+ // anonymous namespace for implementation code.
+template <typename T, typename T1 = ns3::empty, typename T2 = ns3::empty,
+ typename T3 = ns3::empty, typename T4 = ns3::empty, typename T5 = ns3::empty>
+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 @@
uint32_t m_classId;
};
-template <typename T, typename T1 = empty, typename T2 = empty>
-class MakeClassId;
+/**
+ * \brief a class used to create ClassIds
+ *
+ *
+ */
+template <typename T, typename T1 = empty, typename T2 = empty,
+ typename T3 = empty, typename T4 = empty, typename T5 = empty>
+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<T,T1,T2,T3,T4,T5> MakerType;
+ static Callback<Ptr<Object>,T1,T2,T3,T4,T5> m_callback;
+ void Register (const InterfaceId *array [], uint32_t n);
+};
/**
@@ -129,6 +220,49 @@
template <typename T1, typename T2>
static Ptr<Object> 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 <typename T1, typename T2, typename T3>
+ static Ptr<Object> 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 <typename T1, typename T2, typename T3, typename T4>
+ static Ptr<Object> 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 <typename T1, typename T2, typename T3, typename T4, typename T5>
+ static Ptr<Object> 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 @@
template <typename T>
static Ptr<T> 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 <typename T, typename T1>
static Ptr<T> 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 <typename T, typename T1, typename T2>
static Ptr<T> 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 <typename T, typename T1, typename T2, typename T3>
+ static Ptr<T> 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 <typename T, typename T1, typename T2, typename T3, typename T4>
+ static Ptr<T> 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 <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+ static Ptr<T> Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4, T5);
+
private:
friend void RegisterCallback (ClassId classId, CallbackBase *callback,
std::vector<const InterfaceId *> supportedInterfaces);
@@ -170,15 +373,43 @@
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 @@
namespace {
- // anonymous namespace for implementation code.
-template <typename T, typename T1 = ns3::empty, typename T2 = ns3::empty>
-struct ObjectMaker;
template <typename T>
-struct ObjectMaker<T,ns3::empty,ns3::empty> {
+struct ObjectMaker<T,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> {
static ns3::Ptr<ns3::Object>
MakeObject (void) {
return ns3::MakeNewObject<T> ();
@@ -206,7 +434,7 @@
};
template <typename T, typename T1>
-struct ObjectMaker<T,T1,ns3::empty> {
+struct ObjectMaker<T,T1,ns3::empty,ns3::empty,ns3::empty,ns3::empty> {
static ns3::Ptr<ns3::Object>
MakeObject (T1 a1) {
return ns3::MakeNewObject<T> (a1);
@@ -214,13 +442,39 @@
};
template <typename T, typename T1, typename T2>
-struct ObjectMaker {
+struct ObjectMaker<T,T1,T2,ns3::empty,ns3::empty,ns3::empty> {
static ns3::Ptr<ns3::Object>
MakeObject (T1 a1, T2 a2) {
return ns3::MakeNewObject<T> (a1, a2);
}
};
+template <typename T, typename T1, typename T2, typename T3>
+struct ObjectMaker<T,T1,T2,T3,ns3::empty,ns3::empty> {
+ static ns3::Ptr<ns3::Object>
+ MakeObject (T1 a1, T2 a2, T3 a3) {
+ return ns3::MakeNewObject<T> (a1, a2, a3);
+ }
+};
+
+template <typename T, typename T1, typename T2, typename T3,
+ typename T4>
+struct ObjectMaker<T,T1,T2,T3,T4,ns3::empty> {
+ static ns3::Ptr<ns3::Object>
+ MakeObject (T1 a1, T2 a2, T3 a3, T4 a4) {
+ return ns3::MakeNewObject<T> (a1, a2, a3, a4);
+ }
+};
+
+template <typename T, typename T1, typename T2, typename T3,
+ typename T4, typename T5>
+struct ObjectMaker {
+ static ns3::Ptr<ns3::Object>
+ MakeObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
+ return ns3::MakeNewObject<T> (a1, a2, a3, a4, a5);
+ }
+};
+
} // anonymous namespace
namespace ns3 {
@@ -229,64 +483,88 @@
std::vector<const InterfaceId *> supportedInterfaces);
-template <typename T, typename T1, typename T2>
-class MakeClassId : public ClassId
+
+template <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+void
+MakeClassId<T,T1,T2,T3,T4,T5>::Register (const InterfaceId *array [], uint32_t n)
+{
+ std::vector<const InterfaceId *> supportedInterfaces;
+ for (uint32_t i = 0; i < n; i++)
+ {
+ supportedInterfaces.push_back (array[i]);
+ }
+ RegisterCallback (*this, &m_callback, supportedInterfaces);
+}
+
+template <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+MakeClassId<T,T1,T2,T3,T4,T5>::MakeClassId (std::string name)
+ : ClassId (name)
+{
+ const InterfaceId *array[] = {};
+ Register (array, sizeof (array)/sizeof(InterfaceId *));
+}
+template <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+MakeClassId<T,T1,T2,T3,T4,T5>::MakeClassId (std::string name,
+ const InterfaceId &iid)
+ : ClassId (name)
+{
+ const InterfaceId *array[] = {&iid};
+ Register (array, sizeof (array)/sizeof(InterfaceId *));
+}
+template <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+MakeClassId<T,T1,T2,T3,T4,T5>::MakeClassId (std::string name,
+ const InterfaceId &iid0,
+ const InterfaceId iid1)
+ : ClassId (name)
{
-private:
- typedef ObjectMaker<T,T1,T2> MakerType;
- static Callback<Ptr<Object>,T1,T2> m_callback;
- void Register (const InterfaceId *array [], uint32_t n) {
- std::vector<const InterfaceId *> 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 *));
- }
-};
+ const InterfaceId *array[] = {&iid0, &iid1};
+ Register (array, sizeof (array)/sizeof(InterfaceId *));
+}
+template <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+MakeClassId<T,T1,T2,T3,T4,T5>::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 <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+MakeClassId<T,T1,T2,T3,T4,T5>::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 <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+MakeClassId<T,T1,T2,T3,T4,T5>::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 <typename T, typename T1, typename T2>
-Callback<Ptr<Object>,T1,T2> MakeClassId<T,T1,T2>::m_callback = MakeCallback (&MakeClassId::MakerType::MakeObject);
+template <typename T, typename T1, typename T2,
+ typename T3, typename T4, typename T5>
+Callback<Ptr<Object>,T1,T2,T3,T4,T5> MakeClassId<T,T1,T2,T3,T4,T5>::m_callback =
+ MakeCallback (&MakeClassId::MakerType::MakeObject);
@@ -323,6 +601,31 @@
return callback (a1, a2);
}
+template <typename T1, typename T2, typename T3>
+Ptr<Object>
+ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3)
+{
+ Callback<Ptr<Object>,T1,T2,T3> callback = DoGetCallback<T1,T2,T3,empty,empty> (classId);
+ return callback (a1, a2, a3);
+}
+
+template <typename T1, typename T2, typename T3, typename T4>
+Ptr<Object>
+ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4)
+{
+ Callback<Ptr<Object>,T1,T2,T3,T4> callback = DoGetCallback<T1,T2,T3,T4,empty> (classId);
+ return callback (a1, a2, a3, a4);
+}
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+Ptr<Object>
+ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+{
+ Callback<Ptr<Object>,T1,T2,T3,T4,T5> callback = DoGetCallback<T1,T2,T3,T4,T5> (classId);
+ return callback (a1, a2, a3, a4, a5);
+}
+
+
template <typename T>
Ptr<T>
ComponentManager::Create (ClassId classId, InterfaceId iid)
@@ -350,6 +653,34 @@
return i;
}
+
+template <typename T, typename T1, typename T2, typename T3>
+Ptr<T>
+ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3)
+{
+ Ptr<Object> obj = Create (classId, a1, a2, a3);
+ Ptr<T> i = obj->QueryInterface<T> (iid);
+ return i;
+}
+
+template <typename T, typename T1, typename T2, typename T3, typename T4>
+Ptr<T>
+ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4)
+{
+ Ptr<Object> obj = Create (classId, a1, a2, a3, a4);
+ Ptr<T> i = obj->QueryInterface<T> (iid);
+ return i;
+}
+
+template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+Ptr<T>
+ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+{
+ Ptr<Object> obj = Create (classId, a1, a2, a3, a4, a5);
+ Ptr<T> i = obj->QueryInterface<T> (iid);
+ return i;
+}
+
} // namespace ns3
#endif /* NS_COMPONENT_MANAGER_H */