Add an explicit copy constructor. Bug reported by Raj.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 20 Mar 2008 10:25:59 -0700
changeset 2667 2324032b8f90
parent 2666 74742244d863
child 2668 4956586bd798
child 2670 6e5ee56bed72
Add an explicit copy constructor. Bug reported by Raj.
src/core/object.cc
src/core/object.h
--- a/src/core/object.cc	Thu Mar 20 10:14:02 2008 -0700
+++ b/src/core/object.cc	Thu Mar 20 10:25:59 2008 -0700
@@ -64,6 +64,12 @@
 {
   m_next = 0;
 }
+Object::Object (const Object &o)
+  : m_count (1),
+    m_tid (o.m_tid),
+    m_disposed (false),
+    m_next (this)
+{}
 void
 Object::Construct (const AttributeList &attributes)
 {
--- a/src/core/object.h	Thu Mar 20 10:14:02 2008 -0700
+++ b/src/core/object.h	Thu Mar 20 10:25:59 2008 -0700
@@ -102,7 +102,26 @@
    * up to their parent's implementation once they are done.
    */
   virtual void DoDispose (void);
+  /**
+   * \param o the object to copy.
+   *
+   * Allow subclasses to implement a copy constructor.
+   * While it is technically possible to implement a copy
+   * constructor in a subclass, we strongly discourage you
+   * to do so. If you really want to do it anyway, you have
+   * to understand that this copy constructor will _not_
+   * copy aggregated objects. i.e., if your object instance
+   * is already aggregated to another object and if you invoke
+   * this copy constructor, the new object instance will be
+   * a pristine standlone object instance not aggregated to
+   * any other object. It is thus _your_ responsability
+   * as a caller of this method to do what needs to be done
+   * (if it is needed) to ensure that the object stays in a
+   * valid state.
+   */
+  Object (const Object &o);
 private:
+
   template <typename T>
   friend Ptr<T> CreateObject (const AttributeList &attributes);
   template <typename T>
@@ -165,6 +184,26 @@
   Object *m_next;
 };
 
+template <typename T>
+Ptr<T> CopyObject (Ptr<T> o);
+
+template <typename T>
+Ptr<T> CreateObject (const AttributeList &attributes);
+
+template <typename T>
+Ptr<T> 
+CreateObject (std::string n1 = "", Attribute v1 = Attribute (),
+              std::string n2 = "", Attribute v2 = Attribute (),
+              std::string n3 = "", Attribute v3 = Attribute (),
+              std::string n4 = "", Attribute v4 = Attribute (),
+              std::string n5 = "", Attribute v5 = Attribute (),
+              std::string n6 = "", Attribute v6 = Attribute (),
+              std::string n7 = "", Attribute v7 = Attribute (),
+              std::string n8 = "", Attribute v8 = Attribute (),
+              std::string n9 = "", Attribute v9 = Attribute ());
+  
+
+
 } // namespace ns3
 
 namespace ns3 {
@@ -221,7 +260,7 @@
 Ptr<T> CopyObject (Ptr<T> o)
 {
   Ptr<T> p = Ptr<T> (new T (*PeekPointer (o)), false);
-  p->SetTypeId (T::GetTypeId ());
+  NS_ASSERT (p->m_tid == o->m_tid);
   return p;
 }