diff options
| author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-15 21:56:04 +0100 | 
|---|---|---|
| committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-15 21:56:04 +0100 | 
| commit | d2f99e4b43ed93ef0fa8e138e0c3afc79775b77c (patch) | |
| tree | 8e7cdb894b7036b3ca01499ee9432d2e62930477 /src/core/model | |
| parent | 40f7df390f00f85c17bd0e6527ec4ba19cbce4fc (diff) | |
| parent | 4f2872d9968aec93bebff90d1238347c8a364949 (diff) | |
Merge branch 'master' of somweyr.de:ousia
Diffstat (limited to 'src/core/model')
| -rw-r--r-- | src/core/model/Node.cpp | 2 | ||||
| -rw-r--r-- | src/core/model/Typesystem.cpp | 60 | ||||
| -rw-r--r-- | src/core/model/Typesystem.hpp | 163 | 
3 files changed, 26 insertions, 199 deletions
diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index 39ee2e4..ce15cad 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -448,7 +448,7 @@ bool Node::doValidate(Logger &logger) const { return true; }  bool Node::validateName(Logger &logger) const  { -	if (!Utils::isIdentifier(name)) { +	if (!Utils::isIdentifierOrEmpty(name)) {  		logger.error(type()->name + std::string(" name \"") + name +  		                 std::string("\" is not a valid identifier"),  		             this); diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index 506bd31..df2b9fb 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -21,7 +21,6 @@  #include <core/common/RttiBuilder.hpp>  #include <core/common/Utils.hpp>  #include <core/common/VariantConverter.hpp> -#include <core/common/VariantReader.hpp>  namespace ousia { @@ -68,65 +67,6 @@ bool Type::build(Variant &data, Logger &logger) const  	return build(data, logger, NullMagicCallback);  } -std::pair<bool, Variant> Type::read(CharReader &reader, Logger &logger, -                                    const std::unordered_set<char> &delims) -{ -	// try all variant types of this type and use the first successful one. -	Variant v; -	bool success = false; -	for (auto t : getVariantTypes()) { -		auto res = VariantReader::parseTyped(t, reader, logger, delims); -		if (res.first) { -			v = res.second; -			success = true; -			break; -		} -	} - -	if (!success) { -		return std::make_pair(false, Variant{}); -	} -	if (!build(v, logger)) { -		return std::make_pair(false, Variant{}); -	} -	return std::make_pair(true, v); -} - -std::pair<bool, Variant> Type::read(const std::string &str, Logger &logger, -                                    SourceId sourceId, size_t offs) -{ -	// try all variant types of this type and use the first successful one. -	Variant v; -	bool success = false; -	std::vector<LoggerFork> forks; -	auto vts = getVariantTypes(); -	for (auto vt : vts) { -		forks.emplace_back(logger.fork()); -		auto res = -		    VariantReader::parseTyped(vt, str, forks.back(), sourceId, offs); -		if (res.first) { -			v = res.second; -			success = true; -			forks.back().commit(); -			break; -		} -	} - -	if (!success) { -		logger.error("Could not read data with any of the possible types:"); -		for (size_t t = 0; t < forks.size(); t++) { -			logger.note(std::string(Variant::getTypeName(vts[t])) + ":", -			            SourceLocation{}, MessageMode::NO_CONTEXT); -			forks[t].commit(); -		} -		return std::make_pair(false, Variant{}); -	} -	if (!build(v, logger)) { -		return std::make_pair(false, Variant{}); -	} -	return std::make_pair(true, v); -} -  bool Type::doCheckIsa(Handle<const Type> type) const { return false; }  bool Type::checkIsa(Handle<const Type> type) const diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index ca4f206..8079578 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -59,7 +59,27 @@ class SystemTypesystem;   */  class Type : public Node {  public: -	enum class MagicCallbackResult { NOT_FOUND, FOUND_INVALID, FOUND_VALID }; +	/** +	 * Enum describing the result of the MagicCallback. +	 */ +	enum class MagicCallbackResult { +		/** +		 * A magic value with the given name could not be resolved. +		 */ +		NOT_FOUND, + +		/** +		 * A magic value with the given name could be resolved, but is of the +		 * wrong type. +		 */ +		FOUND_INVALID, + +		/** +		 * A magic value with the given name could be resolved and is of the +		 * correct type. +		 */ +		FOUND_VALID +	};  	/**  	 * Callback function called when a variant with "magic" value is reached. @@ -70,7 +90,9 @@ public:  	 * to which the value of the looked up constant should be written.  	 * @param type is a const pointer at the type. TODO: Replace this with a  	 * "ConstHandle". -	 * @return true if a constant was found, false otherwise. +	 * @return a MagicCallbackResult describing whether the magic value could +	 * not be resolved, could be resolved but is of the wrong type or could be +	 * resolved and is of the correct type.  	 */  	using MagicCallback =  	    std::function<MagicCallbackResult(Variant &data, const Type *type)>; @@ -169,32 +191,6 @@ public:  	bool build(Variant &data, Logger &logger) const;  	/** -	 * Tries to parse an instance of this type from the given stream. -	 * -	 * @param reader is a reference to the CharReader instance which is -	 * the source for the character data. The reader will be positioned -	 * at the end of the type instance (or the delimiting character). -	 * @param delims is a set of characters which will terminate the typed -	 * instance if the according parser uses delimiting characters. -	 * These characters are not included in the result. May not be nullptr. -	 */ -	std::pair<bool, Variant> read(CharReader &reader, Logger &logger, -	                              const std::unordered_set<char> &delims = {}); - -	/** -	 * Tries to parse an instance of this type from the given string. -	 * -	 * @param str is the string from which the value should be read. -	 * @param sourceId is an optional descriptor of the source file from which -	 * the element is being read. -	 * @param offs is the by offset in the source file at which the string -	 * starts. -	 */ -	std::pair<bool, Variant> read(const std::string &str, Logger &logger, -	                              SourceId sourceId = InvalidSourceId, -	                              size_t offs = 0); - -	/**  	 * Returns true if and only if the given Variant adheres to this Type. In  	 * essence this just calls the build method on a copy of the input Variant.  	 * @@ -230,23 +226,6 @@ 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> getVariantTypes() const = 0;  };  /** @@ -287,16 +266,6 @@ 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> getVariantTypes() const override -	{ -		return {VariantType::STRING}; -	}  };  /** @@ -336,16 +305,6 @@ public:  	 * @return the integer value zero.  	 */  	Variant create() const override { return Variant{0}; } - -	/** -	 * Returns the Int VariantType. -	 * -	 * @return the Int VariantType. -	 */ -	std::vector<VariantType> getVariantTypes() const override -	{ -		return {VariantType::INT}; -	}  };  /** @@ -385,16 +344,6 @@ 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> getVariantTypes() const override -	{ -		return {VariantType::DOUBLE}; -	}  };  /** @@ -434,16 +383,6 @@ 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> getVariantTypes() const override -	{ -		return {VariantType::BOOL}; -	}  };  /** @@ -483,16 +422,6 @@ public:  	 * @return a Variant with the cardinality value "any".  	 */  	Variant create() const override { return Variant{Cardinality::any()}; } - -	/** -	 * Returns the cardinality VariantType. -	 * -	 * @return the cardinality VariantType. -	 */ -	std::vector<VariantType> getVariantTypes() const override -	{ -		return {VariantType::CARDINALITY}; -	}  };  /** @@ -609,16 +538,6 @@ 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> getVariantTypes() const override -	{ -		return {VariantType::INT, VariantType::STRING}; -	}  };  /** @@ -1054,15 +973,6 @@ 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> getVariantTypes() const override -	{ -		return {VariantType::MAP}; -	}  };  /** @@ -1128,15 +1038,6 @@ public:  	 * @return Rooted reference pointing at the innerType.  	 */  	Rooted<Type> getInnerType() { return innerType; } -	/** -	 * Returns the array VariantType. -	 * -	 * @return the array VariantType. -	 */ -	std::vector<VariantType> getVariantTypes() const override -	{ -		return {VariantType::ARRAY}; -	}  };  /** @@ -1175,20 +1076,6 @@ 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> getVariantTypes() const override -	{ -		return {VariantType::BOOL,   VariantType::INT, -		        VariantType::DOUBLE, VariantType::ARRAY, -		        VariantType::MAP,    VariantType::CARDINALITY, -		        VariantType::OBJECT, VariantType::STRING}; -	}  };  /** @@ -1576,4 +1463,4 @@ extern const Rtti SystemTypesystem;  }  } -#endif /* _OUSIA_MODEL_TYPESYSTEM_HPP_ */
\ No newline at end of file +#endif /* _OUSIA_MODEL_TYPESYSTEM_HPP_ */  | 
