summaryrefslogtreecommitdiff
path: root/src/core/model
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 14:55:49 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 14:55:49 +0100
commitac61fe02b333c4928fb79e309c3aa065117aea7e (patch)
tree9db9a9474c8f5c8a8d2fbd6bd7901db56fe46ecf /src/core/model
parentf44dac145adabb580cc36b31079ae963bf59b096 (diff)
Removed Typesystem read code again -- using ParseGenericString insteads. It occured to me, that this was the way this problem was once meant to be solved.
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/Typesystem.cpp60
-rw-r--r--src/core/model/Typesystem.hpp151
2 files changed, 24 insertions, 187 deletions
diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp
index b34687e..fb99f87 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 9d22c0b..53fb0df 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 = std::unordered_set<char>{});
-
- /**
- * 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};
- }
};
/**
@@ -560,16 +499,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};
- }
};
/**
@@ -1005,15 +934,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};
- }
};
/**
@@ -1079,15 +999,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};
- }
};
/**
@@ -1126,20 +1037,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};
- }
};
/**