diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-11 13:23:26 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-11 13:23:26 +0100 |
commit | 7df5f30494b7da283164717dea9098c8d9dca77a (patch) | |
tree | 8d967f3c47fc905b08ee7039b7549253f969703f /src | |
parent | 3d6d42333a49e0a33a8cc4e1b8f890905a435a83 (diff) |
Renamed RttiBase to RttiType
Diffstat (limited to 'src')
-rw-r--r-- | src/core/common/Rtti.cpp | 28 | ||||
-rw-r--r-- | src/core/common/Rtti.hpp | 108 | ||||
-rw-r--r-- | src/core/common/Variant.hpp | 9 | ||||
-rw-r--r-- | src/core/common/VariantConverter.hpp | 4 | ||||
-rw-r--r-- | src/core/managed/Managed.cpp | 6 | ||||
-rw-r--r-- | src/core/managed/Managed.hpp | 20 | ||||
-rw-r--r-- | src/core/managed/Manager.cpp | 4 | ||||
-rw-r--r-- | src/core/model/Node.cpp | 12 | ||||
-rw-r--r-- | src/core/model/Node.hpp | 4 | ||||
-rw-r--r-- | src/core/parser/Scope.cpp | 2 | ||||
-rw-r--r-- | src/core/parser/Scope.hpp | 2 |
11 files changed, 103 insertions, 96 deletions
diff --git a/src/core/common/Rtti.cpp b/src/core/common/Rtti.cpp index feabe05..7ee3c45 100644 --- a/src/core/common/Rtti.cpp +++ b/src/core/common/Rtti.cpp @@ -22,18 +22,18 @@ namespace ousia { /* Class RttiStore */ -std::unordered_map<std::type_index, const RttiBase *> &RttiStore::table() +std::unordered_map<std::type_index, const RttiType *> &RttiStore::table() { - static std::unordered_map<std::type_index, const RttiBase *> table; + static std::unordered_map<std::type_index, const RttiType *> table; return table; } -void RttiStore::store(const std::type_info &native, const RttiBase *rtti) +void RttiStore::store(const std::type_info &native, const RttiType *rtti) { table().emplace(std::type_index{native}, rtti); } -const RttiBase &RttiStore::lookup(const std::type_info &native) +const RttiType &RttiStore::lookup(const std::type_info &native) { const auto &tbl = table(); auto it = tbl.find(std::type_index{native}); @@ -44,9 +44,9 @@ const RttiBase &RttiStore::lookup(const std::type_info &native) } } -/* Class RttiBase */ +/* Class RttiType */ -void RttiBase::initialize() const +void RttiType::initialize() const { // Only run this function exactly once -- directly set the initialized flag // to prevent unwanted recursion @@ -56,12 +56,12 @@ void RttiBase::initialize() const // Insert the parent types of the parent types and the composite types // of the parents { - std::unordered_set<const RttiBase *> origParents = parents; - for (const RttiBase *parent : origParents) { + std::unordered_set<const RttiType *> origParents = parents; + for (const RttiType *parent : origParents) { parent->initialize(); parents.insert(parent->parents.begin(), parent->parents.end()); } - for (const RttiBase *parent : parents) { + for (const RttiType *parent : parents) { parent->initialize(); compositeTypes.insert(parent->compositeTypes.begin(), parent->compositeTypes.end()); @@ -72,9 +72,9 @@ void RttiBase::initialize() const // Insert the composite types of the composite types and the parents // of each composite type { - std::unordered_set<const RttiBase *> origCompositeTypes = + std::unordered_set<const RttiType *> origCompositeTypes = compositeTypes; - for (const RttiBase *compositeType : origCompositeTypes) { + for (const RttiType *compositeType : origCompositeTypes) { compositeType->initialize(); compositeTypes.insert(compositeType->compositeTypes.begin(), compositeType->compositeTypes.end()); @@ -85,13 +85,13 @@ void RttiBase::initialize() const } } -bool RttiBase::isa(const RttiBase &other) const +bool RttiType::isa(const RttiType &other) const { initialize(); return parents.count(&other) > 0; } -bool RttiBase::composedOf(const RttiBase &other) const +bool RttiType::composedOf(const RttiType &other) const { initialize(); return compositeTypes.count(&other) > 0; @@ -99,6 +99,6 @@ bool RttiBase::composedOf(const RttiBase &other) const /* Constant initialization */ -const RttiBase RttiTypes::None; +const RttiType RttiTypes::None; } diff --git a/src/core/common/Rtti.hpp b/src/core/common/Rtti.hpp index f2d4c27..aa161d6 100644 --- a/src/core/common/Rtti.hpp +++ b/src/core/common/Rtti.hpp @@ -72,7 +72,7 @@ namespace ousia { -class RttiBase; +class RttiType; /** * Helper class used to globally store and access the runtime type information. @@ -83,11 +83,11 @@ private: * Function used internally to access the static map storing all registered * native types and their corresponding type information. */ - static std::unordered_map<std::type_index, const RttiBase *> &table(); + static std::unordered_map<std::type_index, const RttiType *> &table(); public: /** - * Registers the given pointer to the RttiBase class in the RTTI table. Does + * Registers the given pointer to the RttiType class in the RTTI table. Does * not override information for already registered types. * * @param native is a reference at the native type information provided @@ -95,27 +95,27 @@ public: * @param rtti is a pointer pointing at the type information that should be * stored for this type. */ - static void store(const std::type_info &native, const RttiBase *rtti); + static void store(const std::type_info &native, const RttiType *rtti); /** * Looks up the type information stored for the given native type * information. */ - static const RttiBase &lookup(const std::type_info &native); + static const RttiType &lookup(const std::type_info &native); }; /** * The RttiBuilder class is used to conveniently build new instances of the Rtti - * or the RttiBase class. It follows the "Builder" pattern and allows to create - * the properties of the RttiBase class by chaining method calls. The RttiBase + * 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 RttiBuilder { public: /** - * Type describing a set of RttiBase pointers. + * Type describing a set of RttiType pointers. */ - using RttiBaseSet = std::unordered_set<const RttiBase *>; + using RttiTypeSet = std::unordered_set<const RttiType *>; /** * Contains the human readable name of the type for which the type @@ -126,22 +126,22 @@ public: /** * Set containing references to all parent types. */ - RttiBaseSet parentTypes; + RttiTypeSet parentTypes; /** * Set containing references to all composite types. */ - RttiBaseSet compositeTypes; + RttiTypeSet compositeTypes; /** * Default constructor, initializes the name of the type described by the - * RttiBaseSet with "unknown". + * RttiTypeSet with "unknown". */ RttiBuilder() : currentName("unknown"){}; /** * Default constructor, initializes the name of the type described by the - * RttiBaseSet with the given name. + * RttiTypeSet with the given name. * * @param name is the initial name of the type described by the type * builder. @@ -170,7 +170,7 @@ public: * @return a reference to the current RttiBuilder reference to allow method * chaining. */ - RttiBuilder &parent(const RttiBase *p) + RttiBuilder &parent(const RttiType *p) { parentTypes.insert(p); return *this; @@ -184,7 +184,7 @@ public: * @return a reference to the current RttiBuilder reference to allow method * chaining. */ - RttiBuilder &parent(const RttiBase &p) + RttiBuilder &parent(const RttiType &p) { parentTypes.insert(&p); return *this; @@ -198,7 +198,7 @@ public: * @return a reference to the current RttiBuilder reference to allow method * chaining. */ - RttiBuilder &parent(const RttiBaseSet &p) + RttiBuilder &parent(const RttiTypeSet &p) { parentTypes.insert(p.begin(), p.end()); return *this; @@ -213,7 +213,7 @@ public: * @return a reference to the current RttiBuilder reference to allow method * chaining. */ - RttiBuilder &composedOf(const RttiBase *p) + RttiBuilder &composedOf(const RttiType *p) { compositeTypes.insert(p); return *this; @@ -228,7 +228,7 @@ public: * @return a reference to the current RttiBuilder reference to allow method * chaining. */ - RttiBuilder &composedOf(const RttiBase &p) + RttiBuilder &composedOf(const RttiType &p) { compositeTypes.insert(&p); return *this; @@ -243,7 +243,7 @@ public: * @return a reference to the current RttiBuilder reference to allow method * chaining. */ - RttiBuilder &composedOf(const RttiBaseSet &p) + RttiBuilder &composedOf(const RttiTypeSet &p) { compositeTypes.insert(p.begin(), p.end()); return *this; @@ -251,13 +251,13 @@ public: }; /** - * 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. Use the Rtti class for - * convenient registration of type information. + * The RttiType 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. Use the + * RttiType class for convenient registration of type information. */ -class RttiBase { +class RttiType { private: /** * Set to true if once the parents and the composite types list have been @@ -269,13 +269,13 @@ private: /** * Set containing references to all parent types, including their parents. */ - mutable std::unordered_set<const RttiBase *> parents; + mutable std::unordered_set<const RttiType *> parents; /** * Set containing references to all types this type is a composition of, * including all composite types of the original composite types. */ - mutable std::unordered_set<const RttiBase *> compositeTypes; + mutable std::unordered_set<const RttiType *> compositeTypes; /** * Adds the parent types of the original parents and the composite types of @@ -293,10 +293,10 @@ public: * Default constructor. Creates a Rtti instance with name "unknown" * and no parents. */ - RttiBase() : name("unknown") {} + RttiType() : name("unknown") {} /** - * Creates a new RttiBase instance and registers it in the global type + * 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. * @@ -307,11 +307,11 @@ public: * @param compositeTypes is a list of types of which instances of this type * are composited (consist of). */ - RttiBase(std::string name, const std::type_info &native, - std::unordered_set<const RttiBase *> parents = - std::unordered_set<const RttiBase *>{}, - std::unordered_set<const RttiBase *> compositeTypes = - std::unordered_set<const RttiBase *>{}) + RttiType(std::string name, const std::type_info &native, + std::unordered_set<const RttiType *> parents = + std::unordered_set<const RttiType *>{}, + std::unordered_set<const RttiType *> compositeTypes = + std::unordered_set<const RttiType *>{}) : initialized(false), parents(std::move(parents)), compositeTypes(compositeTypes), @@ -321,13 +321,13 @@ public: } /** - * Creates a new RttiBase instance and registers it in the global type + * Creates a new RttiType instance and registers it in the global type * table. Use the Rtti class for more convenient registration of type * information. * * @param builder is the builder instance containing the Rtti data. */ - RttiBase(const std::type_info &native, const RttiBuilder &builder) + RttiType(const std::type_info &native, const RttiBuilder &builder) : initialized(false), parents(builder.parentTypes), compositeTypes(builder.compositeTypes), @@ -343,7 +343,7 @@ public: * @param other is the other type for which the relation to this type * should be checked. */ - bool isa(const RttiBase &other) const; + bool isa(const RttiType &other) const; /** * Returns true if an instance of this type may have references to the other @@ -353,7 +353,7 @@ public: * @param other is the other type for which should be checked whether this * type is directly or indirectly composed of it. */ - bool composedOf(const RttiBase &other) const; + bool composedOf(const RttiType &other) const; }; /** @@ -365,7 +365,7 @@ public: * @tparam T is the class for which the type information should be registered. */ template <class T> -class Rtti : public RttiBase { +class Rtti : public RttiType { public: /** * Creates a new Rtti instance and registers it in the global type table. @@ -375,11 +375,11 @@ public: * @param compositeTypes is a list of types of which instances of this type * are composited (consist of). */ - Rtti(std::string name, const std::unordered_set<const RttiBase *> &parents = - std::unordered_set<const RttiBase *>{}, - std::unordered_set<const RttiBase *> compositeTypes = - std::unordered_set<const RttiBase *>{}) - : RttiBase(name, typeid(T), std::move(parents), + Rtti(std::string name, const std::unordered_set<const RttiType *> &parents = + std::unordered_set<const RttiType *>{}, + std::unordered_set<const RttiType *> compositeTypes = + std::unordered_set<const RttiType *>{}) + : RttiType(name, typeid(T), std::move(parents), std::move(compositeTypes)) { } @@ -391,7 +391,7 @@ public: * @param builder is the RttiBuilder instance containing the data from which * the Rtti information should be copied. */ - Rtti(const RttiBuilder &builder) : RttiBase(typeid(T), builder){}; + Rtti(const RttiBuilder &builder) : RttiType(typeid(T), builder){}; }; /** @@ -403,7 +403,7 @@ public: * @tparam T is the C++ type for which the type information should be returned. */ template <typename T> -inline const RttiBase &typeOf() +inline const RttiType &typeOf() { return RttiStore::lookup(typeid(T)); } @@ -419,7 +419,7 @@ inline const RttiBase &typeOf() * returned. */ template <typename T> -inline const RttiBase &typeOf(const T &obj) +inline const RttiType &typeOf(const T &obj) { return RttiStore::lookup(typeid(obj)); } @@ -428,37 +428,37 @@ namespace RttiTypes { /** * Type of no particular type. */ -extern const RttiBase None; +extern const RttiType None; /** * Bool type for use by the Variant::rttiType method. */ -extern const RttiBase Bool; +extern const RttiType Bool; /** * Integer type for use by the Variant::rttiType method. */ -extern const RttiBase Int; +extern const RttiType Int; /** * Double type for use by the Variant::rttiType method. */ -extern const RttiBase Double; +extern const RttiType Double; /** * String type for use by the Variant::rttiType method. */ -extern const RttiBase String; +extern const RttiType String; /** * Array type for use by the Variant::rttiType method. */ -extern const RttiBase Array; +extern const RttiType Array; /** * Function type for use by the Variant::rttiType method. */ -extern const RttiBase Function; +extern const RttiType Function; } } diff --git a/src/core/common/Variant.hpp b/src/core/common/Variant.hpp index 9f6ec7a..98ee49b 100644 --- a/src/core/common/Variant.hpp +++ b/src/core/common/Variant.hpp @@ -48,7 +48,7 @@ namespace ousia { // Forward declarations class Function; -class RttiBase; +class RttiType; /** * Enum containing the possible types a variant may have. @@ -856,6 +856,13 @@ public: } /** + * Returns the current Rtti type descriptor of the Variant. + * + * @return the Rtti type descriptor. Either one of RttiTypes::Int, + * RttiTypes::Bool, RttiTypes::Double, RttiTypes:: + */ + + /** * Returns the name of the given variant type as C-style string. */ static const char *getTypeName(VariantType type); diff --git a/src/core/common/VariantConverter.hpp b/src/core/common/VariantConverter.hpp index e5014bd..22ead7a 100644 --- a/src/core/common/VariantConverter.hpp +++ b/src/core/common/VariantConverter.hpp @@ -23,7 +23,7 @@ namespace ousia { // Forward declaration class Logger; -class RttiBase; +class RttiType; class Variant; enum class VariantType : int16_t; @@ -111,7 +111,7 @@ public: static bool toString(Variant &var, Logger &logger, Mode mode = Mode::SAFE); static bool convert(Variant &var, VariantType requestedType, - const RttiBase &rttiType, Logger &logger, + const RttiType &rttiType, Logger &logger, Mode mode = Mode::SAFE); static bool convert(Variant &var, VariantType requestedType, diff --git a/src/core/managed/Managed.cpp b/src/core/managed/Managed.cpp index 1342fec..d9f3a86 100644 --- a/src/core/managed/Managed.cpp +++ b/src/core/managed/Managed.cpp @@ -77,11 +77,11 @@ bool Managed::unregisterEvent(EventType type, EventHandler handler, bool Managed::triggerEvent(Event &ev) { return mgr.triggerEvent(this, ev); } -const RttiBase &Managed::type() const { return typeOf(*this); } +const RttiType &Managed::type() const { return typeOf(*this); } -bool Managed::isa(const RttiBase &t) const { return type().isa(t); } +bool Managed::isa(const RttiType &t) const { return type().isa(t); } -bool Managed::composedOf(const RttiBase &t) const +bool Managed::composedOf(const RttiType &t) const { return type().composedOf(t); } diff --git a/src/core/managed/Managed.hpp b/src/core/managed/Managed.hpp index f7eaa48..8ad609f 100644 --- a/src/core/managed/Managed.hpp +++ b/src/core/managed/Managed.hpp @@ -41,7 +41,7 @@ class Rooted; template <class T> class Owned; -class RttiBase; +class RttiType; // TODO: Implement clone, getReferenced and getReferencing @@ -190,32 +190,32 @@ public: /* RTTI methods */ /** - * Returns the RttiBase instance registered for instances of the type of + * Returns the RttiType instance registered for instances of the type of * this Managed instance. * - * @return a reference to the registered RttiBase for this particular + * @return a reference to the registered RttiType for this particular * Managed class. */ - const RttiBase &type() const; + const RttiType &type() const; /** * Returns true if this Managed instance is of the type described by the - * given RttiBase instance. + * given RttiType instance. * - * @param true if the RttiBase registered for this particular Managed + * @param true if the RttiType registered for this particular Managed * class is of the given type or one of the registered parent types is of * the given type. */ - bool isa(const RttiBase &t) const; + bool isa(const RttiType &t) const; /** * Returns true if this Managed instance may contain instances of the type - * described by the given RttiBase instance. + * described by the given RttiType instance. * - * @param true if the RttiBase registered for this particular Managed class + * @param true if the RttiType registered for this particular Managed class * may contain instance of the given type. */ - bool composedOf(const RttiBase &t) const; + bool composedOf(const RttiType &t) const; }; /** diff --git a/src/core/managed/Manager.cpp b/src/core/managed/Manager.cpp index 3950ce2..c6b162b 100644 --- a/src/core/managed/Manager.cpp +++ b/src/core/managed/Manager.cpp @@ -593,7 +593,7 @@ void Manager::exportGraphviz(const char *filename) : std::vector<EventHandlerDescriptor>{}; // Read type information and Node name (if available) - const RttiBase &type = objectPtr->type(); + const RttiType &type = objectPtr->type(); const std::string &typeName = type.name; std::string name = ""; if (type.isa(RttiTypes::Node)) { @@ -661,7 +661,7 @@ void Manager::exportGraphviz(const char *filename) while (edgeCount > 0) { // Get the type of the target element uintptr_t pTar = reinterpret_cast<uintptr_t>(e.first); - const RttiBase &typeTar = e.first->type(); + const RttiType &typeTar = e.first->type(); // Get some information about the edge std::string port = ""; diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index 5d8bbeb..284f323 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -64,7 +64,7 @@ public: /** * Type of the node that was requested for resolution. */ - const RttiBase &type; + const RttiType &type; /** * Tracks all nodes that have already been visited. @@ -87,7 +87,7 @@ public: * @param type is the type of the node that should be resolved. */ SharedResolutionState(const std::vector<std::string> &path, - const RttiBase &type) + const RttiType &type) : path(path), type(type) { } @@ -184,9 +184,9 @@ public: * * @return true if the type matches, false otherwise. */ - bool typeMatches(const RttiBase &type) { return type.isa(shared.type); } + bool typeMatches(const RttiType &type) { return type.isa(shared.type); } - bool canContainType(const RttiBase &type) + bool canContainType(const RttiType &type) { return type.composedOf(shared.type); } @@ -328,7 +328,7 @@ bool Node::continueResolveReference(Handle<Node> h, ResolutionState &state) } std::vector<ResolutionResult> Node::resolve( - const std::vector<std::string> &path, const RttiBase &type) + const std::vector<std::string> &path, const RttiType &type) { // Create the state variables SharedResolutionState sharedState(path, type); @@ -344,7 +344,7 @@ std::vector<ResolutionResult> Node::resolve( } std::vector<ResolutionResult> Node::resolve(const std::string &name, - const RttiBase &type) + const RttiType &type) { // Place the name in a vector and call the corresponding resolve function return resolve(std::vector<std::string>{name}, type); diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index 6001dc2..54a1497 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -351,7 +351,7 @@ public: * the resolved elements. */ std::vector<ResolutionResult> resolve(const std::vector<std::string> &path, - const RttiBase &type); + const RttiType &type); /** * Function which resolves a single name to a list of possible nodes @@ -363,7 +363,7 @@ public: * the resolved elements. */ std::vector<ResolutionResult> resolve(const std::string &name, - const RttiBase &type); + const RttiType &type); }; /** diff --git a/src/core/parser/Scope.cpp b/src/core/parser/Scope.cpp index f452ce8..c73b908 100644 --- a/src/core/parser/Scope.cpp +++ b/src/core/parser/Scope.cpp @@ -24,7 +24,7 @@ namespace ousia { namespace parser { Rooted<Node> Scope::resolve(const std::vector<std::string> &path, - const RttiBase &type, Logger &logger) + const RttiType &type, Logger &logger) { // Go up the stack and try to resolve the for (auto it = nodes.rbegin(); it != nodes.rend(); it++) { diff --git a/src/core/parser/Scope.hpp b/src/core/parser/Scope.hpp index d015371..01a8ea7 100644 --- a/src/core/parser/Scope.hpp +++ b/src/core/parser/Scope.hpp @@ -153,7 +153,7 @@ public: * found. */ Rooted<Node> resolve(const std::vector<std::string> &path, - const RttiBase &type, Logger &logger); + const RttiType &type, Logger &logger); }; /* Class ScopedScope -- inline declaration of some methods */ |