diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-13 11:34:43 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-13 11:34:43 +0100 |
commit | 591d73e356ecad5218e7e9b746fbe6837126bf05 (patch) | |
tree | 9e7acb490e2ed0a7a1fbc935fa1e80a812cdec8b /src/core/model | |
parent | 4c8cf263e280bd1e59241b7a783d61e6621a2c5e (diff) |
added Type::getVariantType()
Diffstat (limited to 'src/core/model')
-rw-r--r-- | src/core/model/Typesystem.hpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index 8e3a3bc..d20a9af 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -203,6 +203,23 @@ public: { return this->getParent().cast<Typesystem>(); } + + /** + * Returns the VariantTypes whose instances are proper input for building an + * instance of this type. + * More specifically: Every returned VariantType T should be such that: + * If a string s can be parsed according to T to a Variant v then the call + * build(v, logger) should only fail (return false) if the variant content + * does not adhere to the specific type specification. But it should be a + * properly typed input for build. + * The order of the types returned by this function determines the order in + * which a parser should try to interpret an input string s. + * + * @return the VariantTypes that arethe basis for parsing an instance of + *this + * type. + */ + virtual std::vector<VariantType> getVariantType() const = 0; }; /** @@ -243,6 +260,16 @@ public: * @return a variant containing an empty string. */ Variant create() const override { return Variant{""}; } + + /** + * Returns the String VariantType. + * + * @return the String VariantType. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::STRING}; + } }; /** @@ -282,6 +309,16 @@ public: * @return the integer value zero. */ Variant create() const override { return Variant{0}; } + + /** + * Returns the Int VariantType. + * + * @return the Int VariantType. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::INT}; + } }; /** @@ -321,6 +358,16 @@ public: * @return the double value zero. */ Variant create() const override { return Variant{0.0}; } + + /** + * Returns the Double VariantType. + * + * @return the Double VariantType. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::DOUBLE}; + } }; /** @@ -360,6 +407,16 @@ public: * @return a Variant with the boolean value false. */ Variant create() const override { return Variant{false}; } + + /** + * Returns the bool VariantType. + * + * @return the bool VariantType. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::BOOL}; + } }; /** @@ -476,6 +533,16 @@ public: * name. Throws a LoggableException if the string does not exist. */ Ordinal valueOf(const std::string &name) const; + + /** + * Returns the int and string VariantTypes. + * + * @return the int and string VariantTypes. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::INT, VariantType::STRING}; + } }; /** @@ -911,6 +978,15 @@ public: * @return true if the requested attribute name exists, false otherwise. */ bool hasAttribute(const std::string &name) const; + /** + * Returns the array and map VariantTypes. + * + * @return the array and map VariantTypes. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::ARRAY, VariantType::MAP}; + } }; /** @@ -976,6 +1052,15 @@ public: * @return Rooted reference pointing at the innerType. */ Rooted<Type> getInnerType() { return innerType; } + /** + * Returns the array VariantType. + * + * @return the array VariantType. + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::ARRAY}; + } }; /** @@ -1014,6 +1099,20 @@ public: * @return a Variant instance with nullptr value. */ Variant create() const override; + /** + * Returns all parseable VariantTypes (bool, int, double, array, map, + *cardinality, object, string). + * + * @return all parseable VariantTypes (bool, int, double, array, map, + *cardinality, object, string). + */ + std::vector<VariantType> getVariantType() const override + { + return {VariantType::BOOL, VariantType::INT, + VariantType::DOUBLE, VariantType::ARRAY, + VariantType::MAP, VariantType::CARDINALITY, + VariantType::OBJECT, VariantType::STRING}; + } }; /** |