From 6041324a65cfdb878154af68d74aac2c86372440 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 15 Feb 2015 20:46:21 +0100 Subject: added cardinality type. --- src/core/model/Typesystem.cpp | 21 +++++++++---- src/core/model/Typesystem.hpp | 69 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 7 deletions(-) (limited to 'src/core') 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 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("IntType").parent(&Type); const Rtti DoubleType = RttiBuilder("DoubleType").parent(&Type); const Rtti BoolType = RttiBuilder("BoolType").parent(&Type); +const Rtti CardinalityType = + RttiBuilder("CardinalityType").parent(&Type); const Rtti EnumType = RttiBuilder("EnumType").parent(&Type); const Rtti StructType = RttiBuilder("StructType") .parent(&Type) @@ -858,10 +870,9 @@ const Rtti Constant = RttiBuilder("Constant").parent(&Node); const Rtti Attribute = RttiBuilder("Attribute").parent(&Node); const Rtti Typesystem = RttiBuilder("Typesystem").parent(&RootNode).composedOf( - {&StringType, &IntType, &DoubleType, &BoolType, &EnumType, &StructType, - &Constant}); + {&StringType, &IntType, &DoubleType, &BoolType, &CardinalityType, + &EnumType, &StructType, &Constant}); const Rtti SystemTypesystem = RttiBuilder( "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 @@ -446,6 +446,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 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 getVariantTypes() const override + { + return {VariantType::CARDINALITY}; + } +}; + /** * The EnumType class represents a user defined enumeration type. */ @@ -1401,6 +1450,11 @@ private: */ Handle boolType; + /** + * Reference to the cardinality type. + */ + Handle 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 getBoolType() { return boolType; } + + /** + * Returns the cardinality type. + * + * @return a reference to the CardinalityType instance. + */ + Rooted getCardinalityType() { return cardinalityType; } }; /* RTTI type registrations */ @@ -1468,6 +1529,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. */ @@ -1510,5 +1576,4 @@ extern const Rtti SystemTypesystem; } } -#endif /* _OUSIA_MODEL_TYPESYSTEM_HPP_ */ - +#endif /* _OUSIA_MODEL_TYPESYSTEM_HPP_ */ \ No newline at end of file -- cgit v1.2.3