diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 15:11:46 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 15:11:46 +0100 |
commit | 200952ad4004f6ee5527598622505adbe84df8af (patch) | |
tree | a4fb92a86730c771e36abf421835ab01861ef41c /include | |
parent | 59cfe935248918c1151b300eb19496b76ed579a9 (diff) |
implemented cloning of objects
Diffstat (limited to 'include')
-rw-r--r-- | include/class.h | 14 | ||||
-rw-r--r-- | include/classbase.h | 27 | ||||
-rw-r--r-- | include/interface.h | 11 |
3 files changed, 52 insertions, 0 deletions
diff --git a/include/class.h b/include/class.h index 8bfcad4..7d82441 100644 --- a/include/class.h +++ b/include/class.h @@ -139,6 +139,20 @@ private: } /** + * Construct a clone + * @param orig + * @return Base + */ + virtual Base *clone(Base *orig) override + { + // cast to the original object + T *t = (T *)orig; + + // construct a new base by calling the copy constructor + return new T(*t); + } + + /** * Namespaces have access to the private base class */ friend class Namespace; diff --git a/include/classbase.h b/include/classbase.h index e23c579..a380840 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -98,12 +98,39 @@ public: // done return result; } + + /** + * Construct a clone of the object + * @param orig + * @param value + * @return Base + */ + Base* clone(Base *orig, const struct _zend_object_value &value) + { + // construct the base + auto *result = clone(orig); + if (!result) return nullptr; + + // assign the zend object to it + // @todo fix this +// result->assign(value); + + // done + return result; + } /** * Construct a new instance of the object * @return Base */ virtual Base* construct() = 0; + + /** + * Create a clone of an object + * @param orig + * @return Base + */ + virtual Base *clone(Base *orig) = 0; /** * Initialize the class, given its name diff --git a/include/interface.h b/include/interface.h index f276d6f..b3031e9 100644 --- a/include/interface.h +++ b/include/interface.h @@ -50,6 +50,17 @@ private: } /** + * Construct a clone of the object + * @param orig + * @return Base + */ + virtual Base* clone(Base *orig) override + { + // this does not occur for interfaces + return nullptr; + } + + /** * Namespaces have access to the private base class */ friend class Namespace; |