From 8ff05a11e6fbab7ed5e029f06152b2860e6f229b Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 2 Jan 2015 12:09:40 +0100 Subject: Added SystemTypesystem class, autoformat --- src/core/model/Typesystem.cpp | 38 ++++++++++++++++------ src/core/model/Typesystem.hpp | 73 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 9 deletions(-) (limited to 'src') 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::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 &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 ArrayType{"ArrayType", {&Type}}; const Rtti UnknownType{"UnknownType", {&Type}}; const Rtti Constant{"Constant", {&Node}}; const Rtti Typesystem{"Typesystem", {&Node}}; +const Rtti 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 &getConstants() const { return constants; } + + static Rooted 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; + + /** + * Reference to the string type. + */ + Handle intType; + + /** + * Reference to the double type. + */ + Handle doubleType; + + /** + * Reference to the bool type. + */ + Handle 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 getStringType() { return stringType; } + + /** + * Returns the primitive integer type. + * + * @return a reference to the primitive IntType instance. + */ + Rooted getIntType() { return intType; } + + /** + * Returns the primitive double type. + * + * @return a reference to the primitive DoubleType instance. + */ + Rooted getDoubleType() { return doubleType; } + + /** + * Returns the primitive boolean type. + * + * @return a reference to the primitive BoolType instance. + */ + Rooted getBoolType() { return boolType; } }; } @@ -895,6 +962,12 @@ extern const Rtti Constant; * Type information for the Typesystem class. */ extern const Rtti Typesystem; + +/** + * Type information for the SystemTypesystem class. + */ +extern const Rtti SystemTypesystem; + } } -- cgit v1.2.3