diff options
-rw-r--r-- | src/core/model/Typesystem.cpp | 21 | ||||
-rw-r--r-- | src/core/model/Typesystem.hpp | 69 | ||||
-rw-r--r-- | test/core/model/TypesystemTest.cpp | 2 |
3 files changed, 85 insertions, 7 deletions
diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index b34687e..506bd31 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -169,6 +169,14 @@ bool StringType::doBuild(Variant &data, Logger &logger, return VariantConverter::toString(data, logger); } +/* Class CardinalityType */ + +bool CardinalityType::doBuild(Variant &data, Logger &logger, + const MagicCallback &magicCallback) const +{ + return VariantConverter::toCardinality(data, logger); +} + /* Class EnumType */ EnumType::EnumType(Manager &mgr, std::string name, Handle<Typesystem> system) @@ -829,12 +837,14 @@ SystemTypesystem::SystemTypesystem(Manager &mgr) stringType(new StringType(mgr, this)), intType(new IntType(mgr, this)), doubleType(new DoubleType(mgr, this)), - boolType(new BoolType(mgr, this)) + boolType(new BoolType(mgr, this)), + cardinalityType(new CardinalityType(mgr, this)) { addType(stringType); addType(intType); addType(doubleType); addType(boolType); + addType(cardinalityType); } /* RTTI type registrations */ @@ -847,6 +857,8 @@ const Rtti IntType = RttiBuilder<ousia::IntType>("IntType").parent(&Type); const Rtti DoubleType = RttiBuilder<ousia::DoubleType>("DoubleType").parent(&Type); const Rtti BoolType = RttiBuilder<ousia::BoolType>("BoolType").parent(&Type); +const Rtti CardinalityType = + RttiBuilder<ousia::CardinalityType>("CardinalityType").parent(&Type); const Rtti EnumType = RttiBuilder<ousia::EnumType>("EnumType").parent(&Type); const Rtti StructType = RttiBuilder<ousia::StructType>("StructType") .parent(&Type) @@ -858,10 +870,9 @@ const Rtti Constant = RttiBuilder<ousia::Constant>("Constant").parent(&Node); const Rtti Attribute = RttiBuilder<ousia::Attribute>("Attribute").parent(&Node); const Rtti Typesystem = RttiBuilder<ousia::Typesystem>("Typesystem").parent(&RootNode).composedOf( - {&StringType, &IntType, &DoubleType, &BoolType, &EnumType, &StructType, - &Constant}); + {&StringType, &IntType, &DoubleType, &BoolType, &CardinalityType, + &EnumType, &StructType, &Constant}); const Rtti SystemTypesystem = RttiBuilder<ousia::SystemTypesystem>( "SystemTypesystem").parent(&Typesystem); } -} - +}
\ No newline at end of file diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index 9f9470e..ca4f206 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -447,6 +447,55 @@ public: }; /** + * The CardinalityType class represents the cardinality type. There should be + * exactly one instance of this class available in a preloaded type system. + */ +class CardinalityType : public Type { +protected: + /** + * Expects the given variant to be a cardinality or a single int. + * + * @param data is a variant containing the data that should be checked. + * @param logger is the Logger instance into which errors should be written. + * @return true if the conversion was successful, false otherwise. + */ + bool doBuild(Variant &data, Logger &logger, + const MagicCallback &magicCallback) const override; + +public: + /** + * Constructor of the CardinalityType class. Only one instance of + *CardinalityType should + * exist per project graph. + * + * @param mgr is the Manager instance to be used for the Node. + * @param name is the name of the type. + * @param system is a reference to the parent Typesystem instance. + */ + CardinalityType(Manager &mgr, Handle<Typesystem> system) + : Type(mgr, "cardinality", system, true) + { + } + + /** + * Creates a variant with the cardinality value "any". + * + * @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}; + } +}; + +/** * The EnumType class represents a user defined enumeration type. */ class EnumType : public Type { @@ -1401,6 +1450,11 @@ private: */ Handle<BoolType> boolType; + /** + * Reference to the cardinality type. + */ + Handle<CardinalityType> cardinalityType; + public: /** * Creates the SystemTypesystem containing all basic types (string, int, @@ -1438,6 +1492,13 @@ public: * @return a reference to the primitive BoolType instance. */ Rooted<BoolType> getBoolType() { return boolType; } + + /** + * Returns the cardinality type. + * + * @return a reference to the CardinalityType instance. + */ + Rooted<CardinalityType> getCardinalityType() { return cardinalityType; } }; /* RTTI type registrations */ @@ -1469,6 +1530,11 @@ extern const Rtti DoubleType; extern const Rtti BoolType; /** + * Type information for the CardinalityType class. + */ +extern const Rtti CardinalityType; + +/** * Type information for the EnumType class. */ extern const Rtti EnumType; @@ -1510,5 +1576,4 @@ extern const Rtti SystemTypesystem; } } -#endif /* _OUSIA_MODEL_TYPESYSTEM_HPP_ */ - +#endif /* _OUSIA_MODEL_TYPESYSTEM_HPP_ */
\ No newline at end of file diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp index 9b5872c..ae6f11f 100644 --- a/test/core/model/TypesystemTest.cpp +++ b/test/core/model/TypesystemTest.cpp @@ -961,6 +961,7 @@ TEST(Typesystem, rtti) ASSERT_TRUE(typesystem->composedOf(&RttiTypes::IntType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::DoubleType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::BoolType)); + ASSERT_TRUE(typesystem->composedOf(&RttiTypes::CardinalityType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::EnumType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::StructType)); ASSERT_FALSE(typesystem->composedOf(&RttiTypes::ArrayType)); @@ -982,6 +983,7 @@ TEST(SystemTypesystem, rtti) ASSERT_TRUE(typesystem->composedOf(&RttiTypes::IntType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::DoubleType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::BoolType)); + ASSERT_TRUE(typesystem->composedOf(&RttiTypes::CardinalityType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::EnumType)); ASSERT_TRUE(typesystem->composedOf(&RttiTypes::StructType)); ASSERT_FALSE(typesystem->composedOf(&RttiTypes::ArrayType)); |