diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-11 13:52:03 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-11 13:52:03 +0100 |
commit | e6a7bbd753cba97f7bda154341d93d3f1241d2c4 (patch) | |
tree | 88a44443b78e8d962e617365ed6443f8c6b0b979 /src/core | |
parent | 287bc06f77ff5e60884c1709844c5830ff7a70ce (diff) |
Added getRttiType function to the Variant class
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/common/Variant.cpp | 31 | ||||
-rw-r--r-- | src/core/common/Variant.hpp | 5 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/core/common/Variant.cpp b/src/core/common/Variant.cpp index c5c7b80..44a77d8 100644 --- a/src/core/common/Variant.cpp +++ b/src/core/common/Variant.cpp @@ -25,6 +25,7 @@ #include "Variant.hpp" #include "VariantConverter.hpp" #include "VariantWriter.hpp" +#include "Rtti.hpp" namespace ousia { @@ -69,6 +70,8 @@ const char *Variant::getTypeName(VariantType type) return "unknown"; } +/* Conversion functions */ + Variant::boolType Variant::toBool() const { ExceptionLogger logger; @@ -101,6 +104,34 @@ Variant::stringType Variant::toString(bool escape) const return res.asString(); } +/* Type management */ + +const RttiType& Variant::getRttiType() const +{ + switch (type) { + case VariantType::NULLPTR: + return RttiTypes::Nullptr; + case VariantType::BOOL: + return RttiTypes::Bool; + case VariantType::INT: + return RttiTypes::Int; + case VariantType::DOUBLE: + return RttiTypes::Double; + case VariantType::STRING: + case VariantType::MAGIC: + return RttiTypes::String; + case VariantType::ARRAY: + return RttiTypes::Array; + case VariantType::MAP: + return RttiTypes::Map; + case VariantType::FUNCTION: + return RttiTypes::Function; + case VariantType::OBJECT: + return asObject()->type(); + } + return RttiTypes::None; +} + /* Output stream operators */ std::ostream &operator<<(std::ostream &os, const Variant &v) diff --git a/src/core/common/Variant.hpp b/src/core/common/Variant.hpp index 98ee49b..da88449 100644 --- a/src/core/common/Variant.hpp +++ b/src/core/common/Variant.hpp @@ -859,8 +859,11 @@ public: * Returns the current Rtti type descriptor of the Variant. * * @return the Rtti type descriptor. Either one of RttiTypes::Int, - * RttiTypes::Bool, RttiTypes::Double, RttiTypes:: + * RttiTypes::Bool, RttiTypes::Double, RttiTypes::String, RttiTypes::Array + * or RttiTypes::Function or -- in case an object is stored inside the + * variant -- the RttiType of that object. */ + const RttiType& getRttiType() const; /** * Returns the name of the given variant type as C-style string. |