diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-02 19:48:50 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-02 19:48:50 +0100 |
commit | 3c0d819176620f118b04931e8444e03f62577faf (patch) | |
tree | fe1458232d8e33bcd8a09c22ce609a34f83ed252 | |
parent | 51f4788b2b51a21894ae49821abc67c2fab4a68a (diff) |
added copy and move constructors to some classes
-rw-r--r-- | include/class.h | 12 | ||||
-rw-r--r-- | include/classbase.h | 15 | ||||
-rw-r--r-- | src/callable.h | 28 | ||||
-rw-r--r-- | src/function.h | 12 | ||||
-rw-r--r-- | src/method.h | 8 |
5 files changed, 66 insertions, 9 deletions
diff --git a/include/class.h b/include/class.h index 61d5856..851de8d 100644 --- a/include/class.h +++ b/include/class.h @@ -42,7 +42,17 @@ public: */ Class(const char *name) : ClassBase(name) {} - // @todo add copy and move constructor + /** + * Copy constructor + * @param that + */ + Class(const Class<T> &that) : ClassBase(that) {} + + /** + * Move constructor + * @param that + */ + Class(Class<T> &&that) : ClassBase(std::move(that)) {} /** * Destructor diff --git a/include/classbase.h b/include/classbase.h index e664105..baa1624 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -50,20 +50,23 @@ public: /** * Copy constructor * @param that - * - * @todo prefer move */ ClassBase(const ClassBase &that) : - _name(that._name), _type(that._type), _methods(that._methods), - _members(that._members), _entry(nullptr) {} + _name(that._name), + _type(that._type), + _methods(that._methods), + _members(that._members), + _entry(nullptr) {} /** * Move constructor * @param that */ ClassBase(ClassBase &&that) : - _name(std::move(that._name)), _type(that._type), - _methods(std::move(that._methods)), _members(std::move(that._members)), + _name(std::move(that._name)), + _type(that._type), + _methods(std::move(that._methods)), + _members(std::move(that._members)), _entry(that._entry) { // other entry are invalid now (not that it is used..., class objects are diff --git a/src/callable.h b/src/callable.h index 5b32558..9b5cdcd 100644 --- a/src/callable.h +++ b/src/callable.h @@ -49,13 +49,39 @@ public: // @todo find out number of required arguments _required = _argc; } + + /** + * Copy constructor + * @param that + */ + Callable(const Callable &that) : + _ptr(that._ptr), + _return(that._return), + _required(that._required), + _argc(that._argc), + _argv(nullptr) {} + + /** + * Move constructor + * @param that + */ + Callable(Callable &&that) : + _ptr(std::move(that._ptr)), + _return(that._return), + _required(that._required), + _argc(that._argc), + _argv(that._argv) + { + // invalidate other object + that._argv = nullptr; + } /** * Destructor */ virtual ~Callable() { - delete[] _argv; + if (_argv) delete[] _argv; } /** diff --git a/src/function.h b/src/function.h index 40c392f..eabc2e2 100644 --- a/src/function.h +++ b/src/function.h @@ -30,6 +30,18 @@ public: Function(const char *name, native_callback_3 function, const Arguments &arguments = {}) : Callable(name, arguments), _type(3) { _function.f3 = function; } /** + * Copy constructor + * @param that + */ + Function(const Function &that) : Callable(that), _function(that._function), _type(that._type) {} + + /** + * Move constructor + * @param that + */ + Function(Function &&that) : Callable(std::move(that)), _function(that._function), _type(that._type) {} + + /** * Destructor */ virtual ~Function() {} diff --git a/src/method.h b/src/method.h index 8b545b0..f583fc8 100644 --- a/src/method.h +++ b/src/method.h @@ -34,6 +34,13 @@ public: Method(const char *name, int flags, const Arguments &args) : Callable(name, args), _type(4), _flags(flags) { _callback.m0 = nullptr; } /** + * Copy and move constructors + * @param that + */ + Method(const Method &that) : Callable(that), _type(that._type), _flags(that._flags), _callback(that._callback) {} + Method(Method &&that) : Callable(std::move(that)), _type(that._type), _flags(that._flags), _callback(that._callback) {} + + /** * Destructor * @param type * @param callback @@ -86,7 +93,6 @@ private: /** * Access flags (protected, public, abstract, final, private, etc) * @var int - * @todo use this */ int _flags; |