add const version of CopyObject
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 18 Apr 2008 14:35:10 -0700
changeset 2924 70a02c24d5eb
parent 2923 dbbe74916235
child 2925 7149e19cada4
add const version of CopyObject
src/core/object.h
--- a/src/core/object.h	Thu Apr 17 16:24:43 2008 -0700
+++ b/src/core/object.h	Fri Apr 18 14:35:10 2008 -0700
@@ -137,6 +137,8 @@
   friend Ptr<T> CreateObject (const AttributeList &attributes);
   template <typename T>
   friend Ptr<T> CopyObject (Ptr<T> object);
+  template <typename T>
+  friend Ptr<T> CopyObject (Ptr<const T> object);
 
   friend class ObjectFactory;
 
@@ -203,8 +205,11 @@
  * and returns the new instance.
  */
 template <typename T>
+Ptr<T> CopyObject (Ptr<const T> object);
+template <typename T>
 Ptr<T> CopyObject (Ptr<T> object);
 
+
 /**
  * \param attributes a list of attributes to set on the 
  *        object during construction.
@@ -314,6 +319,14 @@
   return p;
 }
 
+template <typename T>
+Ptr<T> CopyObject (Ptr<const T> object)
+{
+  Ptr<T> p = Ptr<T> (new T (*PeekPointer (object)), false);
+  NS_ASSERT (p->m_tid == object->m_tid);
+  return p;
+}
+
 
 template <typename T>
 Ptr<T> CreateObject (const AttributeList &attributes)