From 57b738e0008ca7ba0a6cf17d746a3ea2e389d20b Mon Sep 17 00:00:00 2001 From: Andreas Stoeckel Date: Sun, 12 Apr 2015 23:38:10 +0200 Subject: Switch Variant::objectType from Rooted to Owned to allow intra-document references. --- src/core/common/Variant.hpp | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/core/common/Variant.hpp b/src/core/common/Variant.hpp index df72fca..9a201c7 100644 --- a/src/core/common/Variant.hpp +++ b/src/core/common/Variant.hpp @@ -239,7 +239,7 @@ public: using stringType = std::string; using arrayType = std::vector; using mapType = std::map; - using objectType = Rooted; + using objectType = Owned; using cardinalityType = Cardinality; using rangeType = Range; using functionType = std::shared_ptr; @@ -483,16 +483,31 @@ public: /** * Named constructor for object values. * - * @param o is an object that can be converted to a Rooted handle. + * @param o is an owned handle that should be copied. */ template - static Variant fromObject(T o) + static Variant fromObject(Owned o) { Variant res; res.setObject(o); return res; } + /** + * Named constructor for object values. + * + * @param o is an object that can be converted to an Owned handle. + * @param owner is the owner of the object handle. If nullptr is given, the + * Owned handle will behave like a Rooted handle. + */ + template + static Variant fromObject(T o, Managed *owner = nullptr) + { + Variant res; + res.setObject(o, owner); + return res; + } + /** * Constructor for cardinality values. The given cardinality is copied and *managed by the @@ -1104,17 +1119,33 @@ public: } /** - * Sets the variant to the given managed object. The variant is equivalent - * to a Rooted handle. + * Sets the variant to the given owned handle. + * + * @param o is the owned handle that should be copied. */ template - void setObject(T o) + void setObject(const Owned &o) { destroy(); meta.setType(VariantType::OBJECT); ptrVal = new objectType(o); } + /** + * Sets the variant to the given object and an optional owner. + * + * @param o is an object that can be converted to a Handle. + * @param owner is an optional owner of o. The object is guaranteed to live + * as long as the owner is alive. + */ + template + void setObject(T o, Managed *owner = nullptr) + { + destroy(); + meta.setType(VariantType::OBJECT); + ptrVal = new objectType(o, owner); + } + /** * Sets the variant to the given cardinality value. * @@ -1204,6 +1235,7 @@ public: { return meta.setLocation(location); } + /* * Output stream operator. */ -- cgit v1.2.3