a pretty simple wrapper around TypeId+Parameters: ObjectFactory
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 08 Feb 2008 02:22:04 +0100
changeset 2395 ffd1c96afe4b
parent 2394 bc7abfdb0748
child 2396 6b87484eb086
a pretty simple wrapper around TypeId+Parameters: ObjectFactory
src/core/object-factory.cc
src/core/object-factory.h
src/core/wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/object-factory.cc	Fri Feb 08 02:22:04 2008 +0100
@@ -0,0 +1,44 @@
+#include "object-factory.h"
+#include <sstream>
+
+namespace ns3 {
+
+ObjectFactory::ObjectFactory ()
+{}
+
+void 
+ObjectFactory::SetTypeId (TypeId tid)
+{
+  m_tid = tid;
+}
+void 
+ObjectFactory::SetTypeId (std::string tid)
+{
+  m_tid = TypeId::LookupByName (tid);
+}
+void 
+ObjectFactory::Set (std::string name, PValue value)
+{
+  m_parameters.SetWithTid (m_tid, name, value);
+}
+
+void 
+ObjectFactory::Set (std::string name, std::string value)
+{
+  m_parameters.SetWithTid (m_tid, name, value);
+}
+
+TypeId 
+ObjectFactory::GetTypeId (void) const
+{
+  return m_tid;
+}
+
+Ptr<Object> 
+ObjectFactory::Create (void) const
+{
+  Ptr<Object> object = m_tid.CreateObject (m_parameters);
+  return object;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/object-factory.h	Fri Feb 08 02:22:04 2008 +0100
@@ -0,0 +1,30 @@
+#ifndef OBJECT_FACTORY_H
+#define OBJECT_FACTORY_H
+
+#include "value.h"
+#include "object.h"
+
+namespace ns3 {
+
+class ObjectFactory
+{
+public:
+  ObjectFactory ();
+
+  void SetTypeId (TypeId tid);
+  void SetTypeId (std::string tid);
+  void Set (std::string name, PValue value);
+  void Set (std::string name, std::string value);
+
+  TypeId GetTypeId (void) const;
+
+  Ptr<Object> Create (void) const;
+
+private:
+  TypeId m_tid;
+  Parameters m_parameters;
+};
+
+} // namespace ns3
+
+#endif /* OBJECT_FACTORY_H */
--- a/src/core/wscript	Fri Feb 08 02:21:23 2008 +0100
+++ b/src/core/wscript	Fri Feb 08 02:22:04 2008 +0100
@@ -60,6 +60,7 @@
         'uint-value.cc',
         'enum-value.cc',
         'fp-value.cc',
+        'object-factory.cc',
         ]
 
     if sys.platform == 'win32':
@@ -110,5 +111,6 @@
         'uint-value.h',
         'fp-value.h',
         'enum-value.h',
+        'object-factory.h',
         ]