diff --git a/include/data.h b/include/data.h index 772d35f..0029c53 100644 --- a/include/data.h +++ b/include/data.h @@ -31,7 +31,7 @@ class Data /** * All managed values that should be cleaned up upon destruction */ - std::list> _managed_values; + std::list> _managed_values; /** * All modifiers @@ -52,9 +52,14 @@ class Data Data(const Variant::Value &value); /** - * Deleted copy constructor + * Copy constructor */ - Data(const Data &that) = delete; + Data(const Data &that) + : _variables(that._variables), + _managed_values(that._managed_values), + _modifiers(that._modifiers) + { + } /** * Move constructor @@ -90,6 +95,7 @@ class Data * @return Data Same object for chaining */ Data &assignManaged(const std::string &name, Value *value); + Data &assignManaged(const std::string &name, std::shared_ptr &value); /** * Assign a callback diff --git a/src/data.cpp b/src/data.cpp index 4258602..534dc35 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -148,6 +148,9 @@ Data &Data::assignValue(const std::string &name, Value *value) */ Data &Data::assignManaged(const std::string &name, Value *value) { + // assigning nullptr's doesn't make sense.. + if (!value) return *this; + // append variable _variables[name] = value; @@ -158,6 +161,27 @@ Data &Data::assignManaged(const std::string &name, Value *value) return *this; } +/** + * Assign data that is managed by a unique pointer and keep managing it + * @param name Name of the variable + * @param value A unique pointer to a VariantValue + * @return Data Same object for chaining + */ +Data &Data::assignManaged(const std::string &name, std::shared_ptr &value) +{ + // assigning empty shared pointer doesn't make sense + if (!value) return *this; + + // append variable + _variables[name] = value.get(); + + // make it managed + _managed_values.emplace_back(value); + + // allow chaining + return *this; +} + /** * Assign a callback * @param name Name of the variable