diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-02 12:09:40 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2015-01-02 12:09:40 +0100 |
commit | 8ff05a11e6fbab7ed5e029f06152b2860e6f229b (patch) | |
tree | 9c9e978a5a37137ec7d48ed1bfbed42b0e892b2e /src/core/model | |
parent | 87d3ddb6fdaa13fa7dad05867420a41409f0c094 (diff) |
Added SystemTypesystem class, autoformat
Diffstat (limited to 'src/core/model')
-rw-r--r-- | src/core/model/Typesystem.cpp | 38 | ||||
-rw-r--r-- | src/core/model/Typesystem.hpp | 73 |
2 files changed, 102 insertions, 9 deletions
diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index 58afd27..9fbecd6 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -54,8 +54,8 @@ bool StringType::doBuild(Variant &data, Logger &logger) const data = data.toString().c_str(); // Log conversions as these may be potentially unwanted - logger.note(std::string("Implicit conversion from ") + - oldName + " to string."); + logger.note(std::string("Implicit conversion from ") + oldName + + " to string."); } return true; } @@ -138,7 +138,8 @@ Rooted<EnumType> EnumType::createValidated( // uniqueness and insert them into the internal values map for (size_t i = 0; i < values.size(); i++) { if (!Utils::isIdentifier(values[i])) { - logger.error(std::string("\"") + values[i] + "\" is no valid identifier."); + logger.error(std::string("\"") + values[i] + + "\" is no valid identifier."); } if (!(unique_values.insert(std::make_pair(values[i], i))).second) { @@ -216,9 +217,9 @@ bool StructType::insertDefaults(Variant &data, const std::vector<bool> &set, } else { ok = false; arr[a] = attributes[a]->getType()->create(); - logger.error(std::string("No value given for mandatory attribute \"") + - attributes[a]->getName() + - std::string("\"")); + logger.error( + std::string("No value given for mandatory attribute \"") + + attributes[a]->getName() + std::string("\"")); } } } @@ -307,7 +308,9 @@ bool StructType::buildFromArrayOrMap(Variant &data, Logger &logger, return buildFromMap(data, logger, trim); } throw LoggableException( - std::string("Expected array or map for building a struct type, but got ") + data.getTypeName()); + std::string( + "Expected array or map for building a struct type, but got ") + + data.getTypeName()); } bool StructType::doBuild(Variant &data, Logger &logger) const @@ -405,7 +408,8 @@ ssize_t StructType::indexOf(const std::string &name) const bool ArrayType::doBuild(Variant &data, Logger &logger) const { if (!data.isArray()) { - throw LoggableException(std::string("Expected array, but got ") + data.getTypeName()); + throw LoggableException(std::string("Expected array, but got ") + + data.getTypeName()); } bool res = true; for (auto &v : data.asArray()) { @@ -415,8 +419,22 @@ bool ArrayType::doBuild(Variant &data, Logger &logger) const } return res; } -} +/* Class SystemTypesystem */ + +SystemTypesystem::SystemTypesystem(Manager &mgr) + : Typesystem(mgr, "system"), + stringType(new StringType(mgr, this)), + intType(new IntType(mgr, this)), + doubleType(new DoubleType(mgr, this)), + boolType(new BoolType(mgr, this)) +{ + addType(stringType); + addType(intType); + addType(doubleType); + addType(boolType); +} +} /* RTTI type registrations */ namespace RttiTypes { @@ -431,6 +449,8 @@ const Rtti<model::ArrayType> ArrayType{"ArrayType", {&Type}}; const Rtti<model::UnknownType> UnknownType{"UnknownType", {&Type}}; const Rtti<model::Constant> Constant{"Constant", {&Node}}; const Rtti<model::Typesystem> Typesystem{"Typesystem", {&Node}}; +const Rtti<model::SystemTypesystem> SystemTypesystem{"SystemTypesystem", + {&Typesystem}}; } } diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index cc29d4c..3a91895 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -835,6 +835,73 @@ public: * @return NodeVector containing all registered constants. */ const NodeVector<Constant> &getConstants() const { return constants; } + + static Rooted<Typesystem> createSystemTypesystem(Manager &mgr); +}; + +/** + * The SystemTypesystem class represents the typesystem defining the primitive + * types. There should be exactly one SystemTypesystem instance in each project. + */ +class SystemTypesystem : public Typesystem { +private: + /** + * Reference to the string type. + */ + Handle<StringType> stringType; + + /** + * Reference to the string type. + */ + Handle<IntType> intType; + + /** + * Reference to the double type. + */ + Handle<DoubleType> doubleType; + + /** + * Reference to the bool type. + */ + Handle<BoolType> boolType; + +public: + /** + * Creates the SystemTypesystem containing all basic types (string, int, + * double, bool). + * + * @param mgr is the Manager instance which manages the new Typesystem + * instance. + */ + SystemTypesystem(Manager &mgr); + + /** + * Returns the primitive string type. + * + * @return a reference to the primitive StringType instance. + */ + Rooted<StringType> getStringType() { return stringType; } + + /** + * Returns the primitive integer type. + * + * @return a reference to the primitive IntType instance. + */ + Rooted<IntType> getIntType() { return intType; } + + /** + * Returns the primitive double type. + * + * @return a reference to the primitive DoubleType instance. + */ + Rooted<DoubleType> getDoubleType() { return doubleType; } + + /** + * Returns the primitive boolean type. + * + * @return a reference to the primitive BoolType instance. + */ + Rooted<BoolType> getBoolType() { return boolType; } }; } @@ -895,6 +962,12 @@ extern const Rtti<model::Constant> Constant; * Type information for the Typesystem class. */ extern const Rtti<model::Typesystem> Typesystem; + +/** + * Type information for the SystemTypesystem class. + */ +extern const Rtti<model::SystemTypesystem> SystemTypesystem; + } } |