From e8f21fa4ca283cca44c35f36482e9afa71146e49 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 16 Apr 2015 01:08:50 +0200 Subject: Added ManagedVariant type which is a Managed object containing a variant. This functionality is used for storing Variants in the Managed data store. --- src/core/common/Variant.cpp | 13 +++++++++++- src/core/common/Variant.hpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/core/common/Variant.cpp b/src/core/common/Variant.cpp index 280cba5..e3be395 100644 --- a/src/core/common/Variant.cpp +++ b/src/core/common/Variant.cpp @@ -22,11 +22,12 @@ #include "Location.hpp" #include "Logger.hpp" +#include "Rtti.hpp" +#include "RttiBuilder.hpp" #include "Utils.hpp" #include "Variant.hpp" #include "VariantConverter.hpp" #include "VariantWriter.hpp" -#include "Rtti.hpp" namespace ousia { @@ -188,6 +189,11 @@ Variant::cardinalityType Variant::toCardinality() const return res.asCardinality(); } +Rooted Variant::toManaged(Manager &mgr) const +{ + return Rooted(new ManagedVariant(mgr, *this)); +} + /* Type management */ const Rtti *Variant::getRtti() const @@ -306,5 +312,10 @@ bool operator!=(const Variant &lhs, const Variant &rhs) { return !(lhs == rhs); } + +namespace RttiTypes { +const Rtti ManagedVariant = RttiBuilder("Variant"); +} + } diff --git a/src/core/common/Variant.hpp b/src/core/common/Variant.hpp index 7cdec24..14ec006 100644 --- a/src/core/common/Variant.hpp +++ b/src/core/common/Variant.hpp @@ -52,6 +52,7 @@ namespace ousia { class Function; class Rtti; class SourceLocation; +class ManagedVariant; /** * Enum containing the possible types a variant may have. @@ -1005,6 +1006,15 @@ public: */ cardinalityType toCardinality() const; + /** + * Returns the Variant as a new ManagedVariant instance. + * + * @param mgr is the Manager instance the returned variant should belong to. + * @return a new ManagedVariant instance containing the value of this + * Variant instance. + */ + Rooted toManaged(Manager &mgr) const; + /** * Sets the variant to null. */ @@ -1318,6 +1328,38 @@ public: friend bool operator!=(const Variant &lhs, const Variant &rhs); }; +/** + * The ManagedVariant class allows to store a variant as a Managed object. This + * class is used to store Variants as the data of "Managed" objects. + * + * TODO: Eventually Managed objects should support storing Variants as "data" + * directly. Yet is hard to get the dependencies right... + */ +class ManagedVariant : public Managed { +public: + /** + * Variant value of the ManagedVariant class. + */ + Variant v; + + /** + * Creates a new ManagedVariant instance, the variant is initialized to + * null. + * + * @param mgr is the Manager the ManagedVariant belongs to. + */ + ManagedVariant(Manager &mgr) : Managed(mgr){}; + + /** + * Create a new ManagedVariant instance and initializes it with the given + * variant value. + * + * @param mgr is the Manager the ManagedVariant belongs to. + * @param v is the initial value for the Variant. + */ + ManagedVariant(Manager &mgr, const Variant &v) : Managed(mgr), v(v){}; +}; + /* Static Assertions */ // Make sure VariantData has a length of 8 bytes @@ -1327,6 +1369,12 @@ static_assert(sizeof(VariantMetadata) == 8, // Make sure VariantData has a length of 16 bytes static_assert(sizeof(Variant) == 16, "Variant should have a length of 16 bytes"); + +/* RttiTypes */ + +namespace RttiTypes { +extern const Rtti ManagedVariant; +} } #endif /* _OUSIA_VARIANT_HPP_ */ -- cgit v1.2.3