diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-18 18:22:14 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-18 18:22:14 +0100 |
commit | a30e627ffccf36384689295ce54af32e38ef5ef8 (patch) | |
tree | ffd03045f2f292da9d9f2d684d166093abaf7a21 /src | |
parent | 1ebaaf08c0bc7de704a3c2a423f572c54c4a069b (diff) |
Droped Rtti<T> class, using RttiType instead
Diffstat (limited to 'src')
-rw-r--r-- | src/core/XML.cpp | 10 | ||||
-rw-r--r-- | src/core/XML.hpp | 6 | ||||
-rw-r--r-- | src/core/common/Rtti.cpp | 10 | ||||
-rw-r--r-- | src/core/common/Rtti.hpp | 176 | ||||
-rw-r--r-- | src/core/common/RttiBuilder.cpp (renamed from src/core/common/TypedRttiBuilder.cpp) | 2 | ||||
-rw-r--r-- | src/core/common/RttiBuilder.hpp | 206 | ||||
-rw-r--r-- | src/core/common/TypedRttiBuilder.hpp | 171 | ||||
-rw-r--r-- | src/core/model/Document.cpp | 32 | ||||
-rw-r--r-- | src/core/model/Document.hpp | 14 | ||||
-rw-r--r-- | src/core/model/Domain.cpp | 22 | ||||
-rw-r--r-- | src/core/model/Domain.hpp | 10 | ||||
-rw-r--r-- | src/core/model/Node.cpp | 7 | ||||
-rw-r--r-- | src/core/model/Node.hpp | 2 | ||||
-rw-r--r-- | src/core/model/Typesystem.cpp | 40 | ||||
-rw-r--r-- | src/core/model/Typesystem.hpp | 28 |
15 files changed, 370 insertions, 366 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp index 9b621a6..b8ee11d 100644 --- a/src/core/XML.cpp +++ b/src/core/XML.cpp @@ -19,7 +19,7 @@ #include <sstream> #include <core/common/Rtti.hpp> -#include <core/common/TypedRttiBuilder.hpp> +#include <core/common/RttiBuilder.hpp> #include "XML.hpp" @@ -118,15 +118,15 @@ void Text::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty) namespace RttiTypes { - const Rtti<xml::Node> XMLNode = RttiBuilder("XMLNode"); - const Rtti<xml::Element> XMLElement = - TypedRttiBuilder<xml::Element>("XMLElement") + const RttiType XMLNode = RttiBuilder<xml::Node>("XMLNode"); + const RttiType XMLElement = + RttiBuilder<xml::Element>("XMLElement") .parent(&XMLNode) .composedOf(&XMLNode) .property("name", {RttiTypes::String, {[](const xml::Element *obj) { return Variant::fromString(obj->name); }}}); - const Rtti<xml::Text> XMLText = RttiBuilder("XMLText").parent(&XMLNode); + const RttiType XMLText = RttiBuilder<xml::Text>("XMLText").parent(&XMLNode); } } diff --git a/src/core/XML.hpp b/src/core/XML.hpp index 5e2542b..aee59a1 100644 --- a/src/core/XML.hpp +++ b/src/core/XML.hpp @@ -173,9 +173,9 @@ public: } namespace RttiTypes { -extern const Rtti<xml::Node> XMLNode; -extern const Rtti<xml::Element> XMLElement; -extern const Rtti<xml::Text> XMLText; +extern const RttiType XMLNode; +extern const RttiType XMLElement; +extern const RttiType XMLText; } } #endif diff --git a/src/core/common/Rtti.cpp b/src/core/common/Rtti.cpp index 6809911..ad77973 100644 --- a/src/core/common/Rtti.cpp +++ b/src/core/common/Rtti.cpp @@ -45,9 +45,9 @@ const RttiType &RttiStore::lookup(const std::type_info &native) } } -/* Class RttiBuilder */ +/* Class RttiBuilderBase */ -RttiBuilder &RttiBuilder::genericMethod(const std::string name, +RttiBuilderBase &RttiBuilderBase::genericMethod(const std::string &name, std::shared_ptr<Function> function) { if (!methods.emplace(name, function).second) { @@ -58,8 +58,8 @@ RttiBuilder &RttiBuilder::genericMethod(const std::string name, return *this; } -RttiBuilder &RttiBuilder::genericProperty( - const std::string name, std::shared_ptr<PropertyDescriptor> property) +RttiBuilderBase &RttiBuilderBase::genericProperty( + const std::string &name, std::shared_ptr<PropertyDescriptor> property) { if (!properties.emplace(name, property).second) { throw OusiaException(std::string("Property with name \"") + name + @@ -174,7 +174,7 @@ bool RttiType::hasProperty(const std::string &name) const /* Constant initialization */ namespace RttiTypes { -const RttiType None{"unknown"}; +const RttiType None{"none"}; const RttiType Nullptr{"nullptr"}; const RttiType Bool{"bool"}; const RttiType Int{"int"}; diff --git a/src/core/common/Rtti.hpp b/src/core/common/Rtti.hpp index 3549474..6b6eff0 100644 --- a/src/core/common/Rtti.hpp +++ b/src/core/common/Rtti.hpp @@ -34,7 +34,7 @@ * this would create a significant overhead. * * <b>How to use:</b> The Rtti class allows to attach information to a certain - * C++ class. To do so, create a global constant of the type Rtti<T> in the + * C++ class. To do so, create a global constant of the type RttiType in the * source file associated with the type declaration, where T is the type you * want to register. As the type must only be registered once, you must not * declare the variable as "static" in the header file (this would register it @@ -50,12 +50,18 @@ * // Only needed if the type needs to be accessed * // from other compilation units! * namespace RttiTypes { - * extern const Rtti<MyT> MyT; + * extern const RttiType MyT; * } * \endcode * In the source file: * \code{.cpp} - * const Rtti<MyT> RttiTypes::MyT{"MyT", {&RttiTypes::MyOtherT}, [...]}; + * #include <core/common/RttiBuilder.hpp> + * + * // [...] + * + * namespace RttiTypes { + * const RttiType MyT = RttiBuilder<ousia::MyT>("MyT"); + * } * \endcode * * @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de) @@ -125,14 +131,23 @@ public: }; /** - * The RttiBuilder class is used to conveniently build new instances of the Rtti - * or the RttiType class. It follows the "Builder" pattern and allows to create + * The RttiBuilderBase class is used to build new instances of the Rtti or the + * RttiType class. It follows the "Builder" pattern and allows to create * the properties of the RttiType class by chaining method calls. The RttiType - * and Rtti class can be constructed from the RttiBuilder instance. + * class can be constructed from the RttiBuilderBase instance. Use the + * RttiBuilder class for a more convenient, templated version that does not + * require the native C++ type in the constructor and allows for more convenient + * definition of methods and properties. */ -class RttiBuilder { +class RttiBuilderBase { public: /** + * Reference at the native type for which the Rtti information is currently + * being built by the RttiBuilder. + */ + const std::type_info &native; + + /** * Contains the human readable name of the type for which the type * information is being built. */ @@ -161,27 +176,34 @@ public: /** * Default constructor, initializes the name of the type described by the * RttiTypeSet with "unknown". + * + * @param native is the native C++ type information for which the type + * information is being built. */ - RttiBuilder() : currentName("unknown"){}; + RttiBuilderBase(const std::type_info &native) + : native(native), currentName("unknown"){}; /** * Default constructor, initializes the name of the type described by the * RttiTypeSet with the given name. * + * @param native is the native C++ type information for which the type + * information is being built. * @param name is the initial name of the type described by the type * builder. */ - RttiBuilder(std::string name) : currentName(std::move(name)){}; + RttiBuilderBase(const std::type_info &native, std::string name) + : native(native), currentName(std::move(name)){}; /** * Sets the human readable name of the type information being built to the * given string. * * @param s is the name to which the name should be set. - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &name(const std::string &s) + RttiBuilderBase &name(const std::string &s) { currentName = s; return *this; @@ -189,13 +211,13 @@ public: /** * Adds the given type descriptor as "parent" of the type information that - * is being built by this RttiBuilder instance. + * is being built by this RttiBuilderBase instance. * * @param p is the pointer to the type descriptor that should be added. - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &parent(const RttiType *p) + RttiBuilderBase &parent(const RttiType *p) { parentTypes.insert(p); return *this; @@ -203,43 +225,43 @@ public: /** * Adds the given type descriptors as "parent" of the type information that - * is being built by this RttiBuilder instance. + * is being built by this RttiBuilderBase instance. * - * @param p is a - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @param p is the pointer to the type descriptor that should be added. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &parent(const RttiTypeSet &p) + RttiBuilderBase &parent(const RttiTypeSet &p) { parentTypes.insert(p.begin(), p.end()); return *this; } /** - * Marks the current type being built by this RttiBuilder instance as being - * a composition of the given other type. + * Marks the current type being built by this RttiBuilderBase instance as + * being a composition of the given other type. * * @param p is the pointer to the type descriptor that should be added as * composition type. - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &composedOf(const RttiType *p) + RttiBuilderBase &composedOf(const RttiType *p) { compositeTypes.insert(p); return *this; } /** - * Marks the current type being built by this RttiBuilder instance as being - * a composition of the given other types. + * Marks the current type being built by this RttiBuilderBase instance as + * being a composition of the given other types. * * @param p is the pointer to the type descriptor that should be added as * composition type. - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &composedOf(const RttiTypeSet &p) + RttiBuilderBase &composedOf(const RttiTypeSet &p) { compositeTypes.insert(p.begin(), p.end()); return *this; @@ -252,11 +274,11 @@ public: * @param name is the name of the method. Names must be unique for one * RttiType instance. If the name is not unique, an exception is thrown. * @param function is the function that should be registered. - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &genericMethod(const std::string name, - std::shared_ptr<Function> function); + RttiBuilderBase &genericMethod(const std::string &name, + std::shared_ptr<Function> function); /** * Registers a generic (no particular C++ type given) property descriptor @@ -265,11 +287,11 @@ public: * @param name is the name of the property. Names must be unique for one * RttiType instance. If the property is not unique, an exception is thrown. * @param property is the property that should be registered. - * @return a reference to the current RttiBuilder reference to allow method - * chaining. + * @return a reference to the current RttiBuilderBase instance to allow + * method chaining. */ - RttiBuilder &genericProperty(const std::string name, - std::shared_ptr<PropertyDescriptor> property); + RttiBuilderBase &genericProperty( + const std::string &name, std::shared_ptr<PropertyDescriptor> property); }; /** @@ -315,33 +337,11 @@ private: */ void initialize() const; -protected: +public: /** - * Creates a new RttiType instance and registers it in the global type - * table. Use the Rtti and the RttiBuilder class for more convenient - * registration of type information. - * - * @param name is the name of the type. - * @param native is a reference at the native type information provided by - * the compiler. - * @param parents is a list of parent types. - * @param compositeTypes is a list of types of which instances of this type - * are composited (consist of). - */ - RttiType(std::string name, const std::type_info &native, - RttiTypeSet parents = RttiTypeSet{}, - RttiTypeSet compositeTypes = RttiTypeSet{}, - RttiMethodMap methods = RttiMethodMap{}, - RttiPropertyMap properties = RttiPropertyMap{}) - : initialized(false), - parents(std::move(parents)), - compositeTypes(compositeTypes), - methods(std::move(methods)), - properties(std::move(properties)), - name(std::move(name)) - { - RttiStore::store(native, this); - } + * Human readable name associated with the type. + */ + const std::string name; /** * Creates a new RttiType instance and registers it in the global type @@ -350,7 +350,7 @@ protected: * * @param builder is the builder instance containing the Rtti data. */ - RttiType(const std::type_info &native, const RttiBuilder &builder) + RttiType(const RttiBuilderBase &builder) : initialized(false), parents(std::move(builder.parentTypes)), compositeTypes(std::move(builder.compositeTypes)), @@ -358,15 +358,9 @@ protected: properties(std::move(builder.properties)), name(std::move(builder.currentName)) { - RttiStore::store(native, this); + RttiStore::store(builder.native, this); } -public: - /** - * Human readable name associated with the type. - */ - const std::string name; - /** * Default constructor. Creates a Rtti instance with name "unknown" * and no parents. @@ -405,7 +399,7 @@ public: * @return a mapping between method name and shared pointers of the * registered function. */ - const RttiMethodMap& getMethods() const; + const RttiMethodMap &getMethods() const; /** * Returns all properties that are registered for this type (and the parent @@ -415,7 +409,7 @@ public: * @return a mapping between property name and the shared pointers of the * registered properties. */ - const RttiPropertyMap& getProperties() const; + const RttiPropertyMap &getProperties() const; /** * Searches for a method with the given name. Returns a shared pointer to @@ -433,7 +427,8 @@ public: * @param name is the name of the property that should be looked up. * @return a shared pointer pointing at the property with the given name */ - std::shared_ptr<PropertyDescriptor> getProperty(const std::string &name) const; + std::shared_ptr<PropertyDescriptor> getProperty( + const std::string &name) const; /** * Returns true if a method with the given name is registered for this type. @@ -451,35 +446,6 @@ public: * @return true if a property with this name exists, false otherwise. */ bool hasProperty(const std::string &name) const; - -}; - -/** - * The Rtti class allows for attaching data to native types that can be accessed - * at runtime. This type information can e.g. be retrieved using the "type" - * method of the Managed class. This system is used for attaching human - * readable names, parent types and script engine functionality. - * - * @tparam T is the class for which the type information should be registered. - */ -template <class T> -class Rtti : public RttiType { -public: - /** - * Creates a new Rtti instance and registers it in the global type table. - * - * @param name is the name of the type. - */ - Rtti(std::string name) : RttiType(name, typeid(T)) {} - - /** - * Creates a new Rtti instance from the data stored in the given builder - * instance and registers it in the global type table. - * - * @param builder is the RttiBuilder instance containing the data from which - * the Rtti information should be copied. - */ - Rtti(const RttiBuilder &builder) : RttiType(typeid(T), builder){}; }; /** diff --git a/src/core/common/TypedRttiBuilder.cpp b/src/core/common/RttiBuilder.cpp index ea836e0..ca048e1 100644 --- a/src/core/common/TypedRttiBuilder.cpp +++ b/src/core/common/RttiBuilder.cpp @@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "TypedRttiBuilder.hpp" +#include "RttiBuilder.hpp" namespace ousia { diff --git a/src/core/common/RttiBuilder.hpp b/src/core/common/RttiBuilder.hpp new file mode 100644 index 0000000..4b27058 --- /dev/null +++ b/src/core/common/RttiBuilder.hpp @@ -0,0 +1,206 @@ +/* + Ousía + Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file RttiBuilder.hpp + * + * Defines a more convenient version of the RttiBuilder. + * + * @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de) + */ + +#ifndef _OUSIA_RTTI_BUILDER_HPP_ +#define _OUSIA_RTTI_BUILDER_HPP_ + +#include "Argument.hpp" +#include "Rtti.hpp" +#include "Function.hpp" +#include "Property.hpp" + +namespace ousia { + +/** + * The RttiBuilder class is a more convenient version of the RttiBuilderBase + * class which allows simple definition of new methods and properties. + * + * @tparam T is the C++ class for which the type is being built. + */ +template <class T> +class RttiBuilder : public RttiBuilderBase { +public: + /** + * Default constructor, initializes the name of the type described by the + * RttiTypeSet with "unknown". + */ + RttiBuilder() : RttiBuilderBase(typeid(T)){}; + + /** + * Default constructor, initializes the name of the type described by the + * RttiTypeSet with the given name. + * + * @param name is the initial name of the type described by the type + * builder. + */ + RttiBuilder(std::string name) : RttiBuilderBase(typeid(T), name){}; + + /** + * Sets the human readable name of the type information being built to the + * given string. + * + * @param s is the name to which the name should be set. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &name(const std::string &s) + { + RttiBuilderBase::name(s); + return *this; + } + + /** + * Adds the given type descriptor as "parent" of the type information that + * is being built by this RttiBuilder instance. + * + * @param p is the pointer to the type descriptor that should be added. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &parent(const RttiType *p) + { + RttiBuilderBase::parent(p); + return *this; + } + + /** + * Adds the given type descriptors as "parent" of the type information that + * is being built by this RttiBuilder instance. + * + * @param p is the pointer to the type descriptor that should be added. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &parent(const RttiTypeSet &p) + { + RttiBuilderBase::parent(p); + return *this; + } + + /** + * Marks the current type being built by this RttiBuilder instance as being + * a composition of the given other type. + * + * @param p is the pointer to the type descriptor that should be added as + * composition type. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &composedOf(const RttiType *p) + { + RttiBuilderBase::composedOf(p); + return *this; + } + + /** + * Marks the current type being built by this RttiBuilder instance as being + * a composition of the given other types. + * + * @param p is the pointer to the type descriptor that should be added as + * composition type. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &composedOf(const RttiTypeSet &p) + { + RttiBuilderBase::composedOf(p); + return *this; + } + + /** + * Registers a generic (no particular C++ type given) method for this RTTI + * type descriptor. + * + * @param name is the name of the method. Names must be unique for one + * RttiType instance. If the name is not unique, an exception is thrown. + * @param function is the function that should be registered. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &genericMethod(const std::string &name, + std::shared_ptr<Function> function) + { + RttiBuilderBase::genericMethod(name, function); + return *this; + } + + /** + * Registers a generic (no particular C++ type given) property descriptor + * for this RTTI type descriptor. + * + * @param name is the name of the property. Names must be unique for one + * RttiType instance. If the property is not unique, an exception is thrown. + * @param property is the property that should be registered. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &genericProperty( + const std::string &name, std::shared_ptr<PropertyDescriptor> property) + { + RttiBuilderBase::genericProperty(name, property); + return *this; + } + + /** + * Registers a method for this RTTI type descriptor. + * + * @param name is the name of the method. Names must be unique for one + * RttiType instance. If the name is not unique, an exception is thrown. + * @param method is the function that should be registered. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &method(const std::string name, const Method<T> &method) + { + return genericMethod(name, std::make_shared<Method<T>>(method)); + } + + /** + * Registers a method for this RTTI type descriptor. + * + * @param name is the name of the method. Names must be unique for one + * RttiType instance. If the name is not unique, an exception is thrown. + * @param method is the function that should be registered. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &method(const std::string name, + const typename Method<T>::Callback &method) + { + return genericMethod(name, std::make_shared<Method<T>>(method)); + } + + /** + * Registers a property for this RTTI type descriptor. + * + * @param name is the name of the property. Names must be unique for one + * RttiType instance. If the property is not unique, an exception is thrown. + * @param property is the property that should be registered. + * @return a reference to the current RttiBuilder to allow method chaining. + */ + RttiBuilder<T> &property(const std::string name, + const Property<T> &property) + { + RttiBuilderBase::genericProperty( + name, std::make_shared<Property<T>>(property)); + return *this; + } +}; +} + +#endif /* _OUSIA_RTTI_BUILDER_HPP_ */ + diff --git a/src/core/common/TypedRttiBuilder.hpp b/src/core/common/TypedRttiBuilder.hpp deleted file mode 100644 index e390b38..0000000 --- a/src/core/common/TypedRttiBuilder.hpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - Ousía - Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** - * @file TypedRttiBuilder.hpp - * - * Defines a more convenient version of the RttiBuilder. - * - * @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de) - */ - -#ifndef _OUSIA_TYPED_RTTI_BUILDER_HPP_ -#define _OUSIA_TYPED_RTTI_BUILDER_HPP_ - -#include "Argument.hpp" -#include "Rtti.hpp" -#include "Function.hpp" -#include "Property.hpp" - -namespace ousia { - -/** - * The TypedRttiBuilder class is a more convenient version of the RttiBuilder - * class which allows simple definition of new methods and properties. - * - * @tparam T is the C++ class for which the type is being built. - */ -template <class T> -class TypedRttiBuilder : public RttiBuilder { -public: - using RttiBuilder::RttiBuilder; - - /** - * Sets the human readable name of the type information being built to the - * given string. - * - * @param s is the name to which the name should be set. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &name(const std::string &s) - { - RttiBuilder::name(s); - return *this; - } - - /** - * Adds the given type descriptor as "parent" of the type information that - * is being built by this RttiBuilder instance. - * - * @param p is the pointer to the type descriptor that should be added. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &parent(const RttiType *p) - { - RttiBuilder::parent(p); - return *this; - } - - /** - * Adds the given type descriptors as "parent" of the type information that - * is being built by this RttiBuilder instance. - * - * @param p is a - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &parent(const RttiTypeSet &p) - { - RttiBuilder::parent(p); - return *this; - } - - /** - * Marks the current type being built by this RttiBuilder instance as being - * a composition of the given other type. - * - * @param p is the pointer to the type descriptor that should be added as - * composition type. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &composedOf(const RttiType *p) - { - RttiBuilder::composedOf(p); - return *this; - } - - /** - * Marks the current type being built by this RttiBuilder instance as being - * a composition of the given other types. - * - * @param p is the pointer to the type descriptor that should be added as - * composition type. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &composedOf(const RttiTypeSet &p) - { - RttiBuilder::composedOf(p); - return *this; - } - - /** - * Registers a method for this RTTI type descriptor. - * - * @param name is the name of the method. Names must be unique for one - * RttiType instance. If the name is not unique, an exception is thrown. - * @param method is the function that should be registered. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &method(const std::string name, const Method<T> &method) - { - RttiBuilder::genericMethod(name, std::make_shared<Method<T>>(method)); - return *this; - } - - /** - * Registers a method for this RTTI type descriptor. - * - * @param name is the name of the method. Names must be unique for one - * RttiType instance. If the name is not unique, an exception is thrown. - * @param method is the function that should be registered. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &method(const std::string name, - const typename Method<T>::Callback &method) - { - RttiBuilder::genericMethod(name, std::make_shared<Method<T>>(method)); - return *this; - } - - /** - * Registers a property for this RTTI type descriptor. - * - * @param name is the name of the property. Names must be unique for one - * RttiType instance. If the property is not unique, an exception is thrown. - * @param property is the property that should be registered. - * @return a reference to the current TypedRttiBuilder reference to allow - * method chaining. - */ - TypedRttiBuilder<T> &property(const std::string name, - const Property<T> &property) - { - RttiBuilder::genericProperty(name, - std::make_shared<Property<T>>(property)); - return *this; - } -}; -} - -#endif /* _OUSIA_TYPED_RTTI_BUILDER_HPP_ */ - diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 5f0ad4c..f817845 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -22,7 +22,7 @@ #include <set> #include <core/common/Exceptions.hpp> -#include <core/common/Rtti.hpp> +#include <core/common/RttiBuilder.hpp> namespace ousia { namespace model { @@ -347,20 +347,24 @@ bool Document::hasChild(Handle<StructureNode> s) const /* Type registrations */ namespace RttiTypes { -const Rtti<model::Document> Document = - RttiBuilder("Document").parent(&Node).composedOf( +const RttiType Document = + RttiBuilder<model::Document>("Document").parent(&Node).composedOf( {&AnnotationEntity, &StructuredEntity}); -const Rtti<model::StructureNode> StructureNode = - RttiBuilder("StructureNode").parent(&Node); -const Rtti<model::StructuredEntity> StructuredEntity = - RttiBuilder("StructuredEntity").parent(&StructureNode).composedOf( - {&StructuredEntity, &DocumentPrimitive, &Anchor}); -const Rtti<model::DocumentPrimitive> DocumentPrimitive = - RttiBuilder("DocumentPrimitive").parent(&StructureNode); -const Rtti<model::Anchor> Anchor = RttiBuilder("Anchor").parent(&StructureNode); -const Rtti<model::AnnotationEntity> AnnotationEntity = - RttiBuilder("AnnotationEntity").parent(&Node).composedOf( - {&StructuredEntity, &DocumentPrimitive, &Anchor}); +const RttiType StructureNode = + RttiBuilder<model::StructureNode>("StructureNode").parent(&Node); +const RttiType StructuredEntity = + RttiBuilder<model::StructuredEntity>("StructuredEntity") + .parent(&StructureNode) + .composedOf({&StructuredEntity, &DocumentPrimitive, &Anchor}); +const RttiType DocumentPrimitive = + RttiBuilder<model::DocumentPrimitive>("DocumentPrimitive") + .parent(&StructureNode); +const RttiType Anchor = + RttiBuilder<model::Anchor>("Anchor").parent(&StructureNode); +const RttiType AnnotationEntity = + RttiBuilder<model::AnnotationEntity>("AnnotationEntity") + .parent(&Node) + .composedOf({&StructuredEntity, &DocumentPrimitive, &Anchor}); } } diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 9410d17..d9729c3 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -641,13 +641,13 @@ public: } namespace RttiTypes { -extern const Rtti<model::Document> Document; -extern const Rtti<model::DocumentEntity> DocumentEntity; -extern const Rtti<model::AnnotationEntity> AnnotationEntity; -extern const Rtti<model::StructureNode> StructureNode; -extern const Rtti<model::StructuredEntity> StructuredEntity; -extern const Rtti<model::DocumentPrimitive> DocumentPrimitive; -extern const Rtti<model::Anchor> Anchor; +extern const RttiType Document; +extern const RttiType DocumentEntity; +extern const RttiType AnnotationEntity; +extern const RttiType StructureNode; +extern const RttiType StructuredEntity; +extern const RttiType DocumentPrimitive; +extern const RttiType Anchor; } } diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 9a0ed0d..6f50b1c 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -18,7 +18,7 @@ #include <set> -#include <core/common/Rtti.hpp> +#include <core/common/RttiBuilder.hpp> #include <core/common/Exceptions.hpp> #include "Domain.hpp" @@ -279,17 +279,17 @@ void Domain::addAnnotationClass(Handle<AnnotationClass> a) /* Type registrations */ namespace RttiTypes { -const Rtti<model::FieldDescriptor> FieldDescriptor = - RttiBuilder("FieldDescriptor").parent(&Node); -const Rtti<model::Descriptor> Descriptor = - RttiBuilder("Descriptor").parent(&Node); -const Rtti<model::StructuredClass> StructuredClass = - RttiBuilder("StructuredClass").parent(&Descriptor).composedOf( +const RttiType FieldDescriptor = + RttiBuilder<model::FieldDescriptor>("FieldDescriptor").parent(&Node); +const RttiType Descriptor = + RttiBuilder<model::Descriptor>("Descriptor").parent(&Node); +const RttiType StructuredClass = + RttiBuilder<model::StructuredClass>("StructuredClass").parent(&Descriptor).composedOf( &FieldDescriptor); -const Rtti<model::AnnotationClass> AnnotationClass = - RttiBuilder("AnnotationClass").parent(&Descriptor); -const Rtti<model::Domain> Domain = - RttiBuilder("Domain").parent(&Node).composedOf( +const RttiType AnnotationClass = + RttiBuilder<model::AnnotationClass>("AnnotationClass").parent(&Descriptor); +const RttiType Domain = + RttiBuilder<model::Domain>("Domain").parent(&Node).composedOf( {&StructuredClass, &AnnotationClass}); } } diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index d1ba44f..b192c11 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -769,11 +769,11 @@ public: namespace RttiTypes { -extern const Rtti<model::FieldDescriptor> FieldDescriptor; -extern const Rtti<model::Descriptor> Descriptor; -extern const Rtti<model::StructuredClass> StructuredClass; -extern const Rtti<model::AnnotationClass> AnnotationClass; -extern const Rtti<model::Domain> Domain; +extern const RttiType FieldDescriptor; +extern const RttiType Descriptor; +extern const RttiType StructuredClass; +extern const RttiType AnnotationClass; +extern const RttiType Domain; } } diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index bd023e1..be13d42 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -21,8 +21,7 @@ #include <core/common/Exceptions.hpp> #include <core/common/Logger.hpp> -#include <core/common/Rtti.hpp> -#include <core/common/TypedRttiBuilder.hpp> +#include <core/common/RttiBuilder.hpp> #include <core/common/Utils.hpp> #include "Node.hpp" @@ -438,8 +437,8 @@ bool Node::validate(Logger &logger) const /* RTTI type registrations */ namespace RttiTypes { -const Rtti<ousia::Node> Node = - TypedRttiBuilder<ousia::Node>("Node") +const RttiType Node = + RttiBuilder<ousia::Node>("Node") .property("name", {RttiTypes::String, {[](const ousia::Node *obj) { return Variant::fromString(obj->getName()); diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index 0168a3e..79f38b8 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -575,7 +575,7 @@ namespace RttiTypes { /** * Typeinformation for the base "Node" class. */ -extern const Rtti<Node> Node; +extern const RttiType Node; } } diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index 13bb38c..2be564d 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -18,7 +18,7 @@ #include "Typesystem.hpp" -#include <core/common/Rtti.hpp> +#include <core/common/RttiBuilder.hpp> #include <core/common/Utils.hpp> #include <core/common/VariantConverter.hpp> @@ -560,27 +560,27 @@ SystemTypesystem::SystemTypesystem(Manager &mgr) /* RTTI type registrations */ namespace RttiTypes { -const Rtti<model::Type> Type = RttiBuilder("Type").parent(&Node); -const Rtti<model::StringType> StringType = - RttiBuilder("StringType").parent(&Type); -const Rtti<model::IntType> IntType = RttiBuilder("IntType").parent(&Type); -const Rtti<model::DoubleType> DoubleType = - RttiBuilder("DoubleType").parent(&Type); -const Rtti<model::BoolType> BoolType = RttiBuilder("BoolType").parent(&Type); -const Rtti<model::EnumType> EnumType = RttiBuilder("EnumType").parent(&Type); -const Rtti<model::StructType> StructType = - RttiBuilder("StructType").parent(&Type).composedOf(&Attribute); -const Rtti<model::ArrayType> ArrayType = RttiBuilder("ArrayType").parent(&Type); -const Rtti<model::UnknownType> UnknownType = - RttiBuilder("UnknownType").parent(&Type); -const Rtti<model::Constant> Constant = RttiBuilder("Constant").parent(&Node); -const Rtti<model::Attribute> Attribute = RttiBuilder("Attribute").parent(&Node); -const Rtti<model::Typesystem> Typesystem = - RttiBuilder("Typesystem").parent(&Node).composedOf( +const RttiType Type = RttiBuilder<model::Type>("Type").parent(&Node); +const RttiType StringType = + RttiBuilder<model::StringType>("StringType").parent(&Type); +const RttiType IntType = RttiBuilder<model::IntType>("IntType").parent(&Type); +const RttiType DoubleType = + RttiBuilder<model::DoubleType>("DoubleType").parent(&Type); +const RttiType BoolType = RttiBuilder<model::BoolType>("BoolType").parent(&Type); +const RttiType EnumType = RttiBuilder<model::EnumType>("EnumType").parent(&Type); +const RttiType StructType = + RttiBuilder<model::StructType>("StructType").parent(&Type).composedOf(&Attribute); +const RttiType ArrayType = RttiBuilder<model::ArrayType>("ArrayType").parent(&Type); +const RttiType UnknownType = + RttiBuilder<model::UnknownType>("UnknownType").parent(&Type); +const RttiType Constant = RttiBuilder<model::Constant>("Constant").parent(&Node); +const RttiType Attribute = RttiBuilder<model::Attribute>("Attribute").parent(&Node); +const RttiType Typesystem = + RttiBuilder<model::Typesystem>("Typesystem").parent(&Node).composedOf( {&StringType, &IntType, &DoubleType, &BoolType, &EnumType, &StructType, &Constant}); -const Rtti<model::SystemTypesystem> SystemTypesystem = - RttiBuilder("SystemTypesystem").parent(&Typesystem); +const RttiType SystemTypesystem = + RttiBuilder<model::SystemTypesystem> ("SystemTypesystem").parent(&Typesystem); } } diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index a4a679d..1b54a07 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -1097,67 +1097,67 @@ namespace RttiTypes { /** * Type information for the Type class. */ -extern const Rtti<model::Type> Type; +extern const RttiType Type; /** * Type information for the StringType class. */ -extern const Rtti<model::StringType> StringType; +extern const RttiType StringType; /** * Type information for the IntType class. */ -extern const Rtti<model::IntType> IntType; +extern const RttiType IntType; /** * Type information for the DoubleType class. */ -extern const Rtti<model::DoubleType> DoubleType; +extern const RttiType DoubleType; /** * Type information for the BoolType class. */ -extern const Rtti<model::BoolType> BoolType; +extern const RttiType BoolType; /** * Type information for the EnumType class. */ -extern const Rtti<model::EnumType> EnumType; +extern const RttiType EnumType; /** * Type information for the StructType class. */ -extern const Rtti<model::StructType> StructType; +extern const RttiType StructType; /** * Type information for the ArrayType class. */ -extern const Rtti<model::ArrayType> ArrayType; +extern const RttiType ArrayType; /** * Type information for the UnknownType class. */ -extern const Rtti<model::UnknownType> UnknownType; +extern const RttiType UnknownType; /** * Type information for the Constant class. */ -extern const Rtti<model::Constant> Constant; +extern const RttiType Constant; /** - * Type information for the Constant class. + * Type information for the Attribute class. */ -extern const Rtti<model::Attribute> Attribute; +extern const RttiType Attribute; /** * Type information for the Typesystem class. */ -extern const Rtti<model::Typesystem> Typesystem; +extern const RttiType Typesystem; /** * Type information for the SystemTypesystem class. */ -extern const Rtti<model::SystemTypesystem> SystemTypesystem; +extern const RttiType SystemTypesystem; } } |