summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Stoeckel <astoecke@techfak.uni-bielefeld.de>2015-04-12 23:38:10 +0200
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2016-04-25 22:24:17 +0200
commit57b738e0008ca7ba0a6cf17d746a3ea2e389d20b (patch)
tree443bb01a6ea1b74fd7b6048446bb941cc8367607 /src
parentef213b258cb4dc13bf72be75e5967c4420c3c8d8 (diff)
Switch Variant::objectType from Rooted<Managed> to Owned<Managed> to allow intra-document references.
Diffstat (limited to 'src')
-rw-r--r--src/core/common/Variant.hpp44
1 files 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<Variant>;
using mapType = std::map<std::string, Variant>;
- using objectType = Rooted<Managed>;
+ using objectType = Owned<Managed>;
using cardinalityType = Cardinality;
using rangeType = Range<size_t>;
using functionType = std::shared_ptr<Function>;
@@ -483,10 +483,10 @@ 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 <class T>
- static Variant fromObject(T o)
+ static Variant fromObject(Owned<T> o)
{
Variant res;
res.setObject(o);
@@ -494,6 +494,21 @@ public:
}
/**
+ * 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 <class T>
+ 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
* new Variant instance.
@@ -1104,11 +1119,12 @@ 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 <class T>
- void setObject(T o)
+ void setObject(const Owned<T> &o)
{
destroy();
meta.setType(VariantType::OBJECT);
@@ -1116,6 +1132,21 @@ public:
}
/**
+ * 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 <class T>
+ 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.
*
* @param c is the new cardinality value.
@@ -1204,6 +1235,7 @@ public:
{
return meta.setLocation(location);
}
+
/*
* Output stream operator.
*/