From 33b5b737313e6d1409c60da77db26f1f00b91b57 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 16 Jan 2015 22:47:06 +0100 Subject: wip copy --- src/core/model/Typesystem.cpp | 11 +++++ src/core/model/Typesystem.hpp | 95 ++++++++++++++++++++++--------------------- src/plugins/xml/XmlParser.cpp | 18 ++++---- 3 files changed, 70 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index 76743e1..c2f8a9c 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -340,6 +340,17 @@ Rooted StructType::createValidated( collectedAttributes, attributeNames); } +Rooted StructType::getParentStructure() const +{ + return parentStructure; +} + +void StructType::setParentStructure(Handle parentStructure) +{ + invalidate(); + this->parentStructure = acquire(parentStructure); +} + Variant StructType::create() const { Variant::arrayType arr; diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index 890ae82..42c2591 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -438,17 +438,17 @@ private: * Reference to the parent structure type (or nullptr if the struct type is * not derived from any other struct type). */ - const Owned parentStructure; + Owned parentStructure; /** * Vector containing references to all attribute descriptors. */ - const NodeVector attributes; + NodeVector attributes; /** * Map storing the attribute names. */ - const std::map attributeNames; + std::map attributeNames; /** * Resolves an attribute key string of the form "#idx" to the corresponding @@ -528,29 +528,6 @@ private: */ bool buildFromArrayOrMap(Variant &data, Logger &logger, bool trim) const; - /** - * Private constructor of the StructType class, creates a new instance - * without performing any validity checks. - * - * @param mgr is the underlying Manager instance. - * @param name is the name of the EnumType instance. Should be a valid - * identifier. - * @param system is a reference to the parent Typesystem instance. - * @param parentStructure is a reference to the StructType this type is - * derived from, may be nullptr. - * @param attributes is a vector containing the struct type attributes. - */ - StructType(Manager &mgr, std::string name, Handle system, - Handle parentStructure, - NodeVector attributes, - std::map attributeNames) - : Type(mgr, std::move(name), system, false), - parentStructure(acquire(parentStructure)), - attributes(this, std::move(attributes)), - attributeNames(std::move(attributeNames)) - { - } - protected: /** * Converts the given variant to the representation of the structure type. @@ -567,26 +544,60 @@ protected: */ bool doBuild(Variant &data, Logger &logger) const override; + /** + * Checks the struct descriptor for being valid. + * + * @param logger is a reference to the logger to which error messages should + * be logged. + * @param visited is used internally for recursion avoidance. + */ + bool doValidate(Logger &logger, std::set &visited) const override; + public: /** - * Creates a new instance of the StructType class and checks the given - * parameters for validity. + * Private constructor of the StructType class, creates a new instance + * without performing any validity checks. * * @param mgr is the underlying Manager instance. * @param name is the name of the EnumType instance. Should be a valid * identifier. * @param system is a reference to the parent Typesystem instance. - * @param parentStructure is a reference to the StructType this type is - * derived from, may be nullptr. - * @param attributes is a vector containing the struct type attributes. - * The attributes are checked for validity (their names must be a valid - * identifiers) and uniqueness (each value must exist exactly once). - * @param logger is the Logger instance into which errors should be written. */ - static Rooted createValidated( - Manager &mgr, std::string name, Handle system, - Handle parentStructure, NodeVector attributes, - Logger &logger); + StructType(Manager &mgr, std::string name, Handle system) + : Type(mgr, std::move(name), system, false), attributes(this) + { + } + + /** + * Returns a handle pointing at the parent type. + * + * @return a rooted handle pointing at the parent type or nullptr, if this + * struct type has no parent. + */ + Rooted getParentStructure() const; + + /** + * Sets the parent structure (the structure this once derives from). + * + * @param parentStructure is the new parent structure. + */ + void setParentStructure(Handle parentStructure); + + /** + * Adds an attribute. Throws an exception if the name of the attribute is + * not unique. + * + * @param attribute is the attribute descriptor that should be added to the + * internal attribute list. + */ + void addAttribute(Handle attribute); + + /** + * Adds a complete list of attributes to the typesystem. + * + * @param attributes is the list with typesystems that should be added. + */ + void addAttributes(const NodeVector &attributes); /** * Creates a Variant containing a valid representation of a data instance of @@ -618,14 +629,6 @@ public: */ bool cast(Variant &data, Logger &logger) const; - /** - * Returns a handle pointing at the parent type. - * - * @return a rooted handle pointing at the parent type or nullptr, if this - * struct type has no parent. - */ - Rooted getParentStructure() const { return parentStructure; } - /** * Returns a reference at the list containing all attributes. * diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index 9d1aba4..ced61ee 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -60,7 +60,11 @@ public: scope().push(new model::Typesystem(manager(), args["name"].asString())); } - void end() override { scope().pop(); } + void end() override + { + scope().performDeferredResolution(logger()); + scope().pop(); + } static Handler *create(const HandlerData &handlerData) { @@ -83,13 +87,11 @@ public: this->parent = args["parent"].asString(); } - void end() override - { + void end() override { + } - void child(std::shared_ptr handler) - { - } + void child(std::shared_ptr handler) {} static Handler *create(const HandlerData &handlerData) { @@ -105,8 +107,8 @@ public: void start(Variant::mapType &args) override { -/* this->name = args["name"].asString(); - this->type = args["parent"].asString();*/ + /* this->name = args["name"].asString(); + this->type = args["parent"].asString();*/ } void end() override {} -- cgit v1.2.3