diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-01 18:04:08 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2015-01-01 18:04:08 +0100 |
commit | 1640daaa6d736f20012d4f10a5d3321394eef490 (patch) | |
tree | 19772be42ac55cafeade41e992ab7a59e287fee4 /src/core/common | |
parent | f42b36bd1f7d27c2bd8f2684a562edab6e3ccc06 (diff) |
Treat Magic type like a string -- only the "isMagic" and "asMagic" methods can distinguish between the two.
Diffstat (limited to 'src/core/common')
-rw-r--r-- | src/core/common/Variant.cpp | 3 | ||||
-rw-r--r-- | src/core/common/Variant.hpp | 41 |
2 files changed, 23 insertions, 21 deletions
diff --git a/src/core/common/Variant.cpp b/src/core/common/Variant.cpp index bc55377..e216aa1 100644 --- a/src/core/common/Variant.cpp +++ b/src/core/common/Variant.cpp @@ -51,8 +51,9 @@ const char *Variant::getTypeName(Type type) case Type::DOUBLE: return "double"; case Type::STRING: - case Type::MAGIC: return "string"; + case Type::MAGIC: + return "magic"; case Type::ARRAY: return "array"; case Type::MAP: diff --git a/src/core/common/Variant.hpp b/src/core/common/Variant.hpp index 596a429..9c061c1 100644 --- a/src/core/common/Variant.hpp +++ b/src/core/common/Variant.hpp @@ -572,27 +572,16 @@ public: */ const stringType &asString() const { - if (isMagic()) { - return asObj<stringType>(Type::MAGIC); - } else { - return asObj<stringType>(Type::STRING); - } + return asObj<stringType>(Type::STRING); } /** - * Returns a reference to the string value. Performs no type conversion. + * Returns a reference to the string value. Performs no type conversion. * Throws an exception if the underlying type is not a string. * * @return the string value as reference. */ - stringType &asString() - { - if (isMagic()) { - return asObj<stringType>(Type::MAGIC); - } else { - return asObj<stringType>(Type::STRING); - } - } + stringType &asString() { return asObj<stringType>(Type::STRING); } /** * Returns a const reference to the magic string value. Performs no type @@ -603,11 +592,14 @@ public: */ const stringType &asMagic() const { - return asObj<stringType>(Type::MAGIC); + if (type == Type::MAGIC) { + return asObj<stringType>(Type::STRING); + } + throw TypeException{getType(), Type::MAGIC}; } /** - * Returns a reference to the magic string value. Performs no type + * Returns a reference to the magic string value. Performs no type * conversion. Throws an exception if the underlying type is not a magic * string. * @@ -615,7 +607,10 @@ public: */ stringType &asMagic() { - return asObj<stringType>(Type::MAGIC); + if (type == Type::MAGIC) { + return asObj<stringType>(Type::STRING); + } + throw TypeException{getType(), Type::MAGIC}; } /** @@ -775,7 +770,7 @@ public: */ void setString(const char *s) { - if (isString() || isMagic()) { + if (isString()) { type = Type::STRING; asString().assign(s); } else { @@ -792,7 +787,7 @@ public: */ void setMagic(const char *s) { - if (isString() || isMagic()) { + if (isString()) { type = Type::MAGIC; asString().assign(s); } else { @@ -851,7 +846,13 @@ public: * * @return the current type of the Variant. */ - Type getType() const { return type; } + Type getType() const + { + if (isMagic()) { + return Type::STRING; + } + return type; + } /** * Returns the name of the given variant type as C-style string. |