From 9376ae9c73e1c2faadac546a0a0cde26b4a5c676 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 14 Jan 2015 00:06:36 +0100 Subject: Added some more code escaping for XML in documentation. --- src/core/model/Document.hpp | 4 ++++ src/core/model/Domain.hpp | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 2821e8c..357b752 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -379,14 +379,18 @@ public: * the markups "emphasized" and "strong". In HTML like markup languages these * concepts are handeled as structure elements, like this: * + * \code{.xml} * emphasized and strong + * \endcode * * which is neither intuitive nor semantically sound. Therefore we take the * approach of anchoring the Annotation entities in the text like this: * + * \code{.xml} * emphasized and strong * * + * \endcode * * Which signifies that indeed the text "emphasized and" is emphasized, not * the two text exerpts "emphasized" and "and" separately. diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 966060f..a5ea929 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -233,6 +233,7 @@ class Domain; * As an example consider the "paragraph" StructuredClass, which might allow * the actual text content. Here is the according XML: * + * \code{.xml} * * * @@ -242,6 +243,7 @@ class Domain; * * * + * \endcode * * Accordingly the primitiveType field of a FieldDescriptor may only be * defined if the type is set to "PRIMITIVE". If the type is something else @@ -374,9 +376,11 @@ public: * explained as the difference between node attributes and node children. * Consider the XML * + * \code{.xml} * * value * + * \endcode * * key="value" inside the A-node would be an attribute, while value * would be a primitive field. While equivalent in XML the semantics are @@ -486,6 +490,7 @@ typedef RangeSet Cardinality; * defining itself as a viable child in one existing field. Consider the * example of the "heading" domain from the header documentation again: * + * \code{.xml} * * * @@ -503,6 +508,7 @@ typedef RangeSet Cardinality; * * * + * \endcode * * The "parent" construct allows to "invade" another domain. * @@ -516,19 +522,23 @@ typedef RangeSet Cardinality; * If we go back to our example a user would (without transparency) have to * explicitly declare: * + * \code{.xml} * *
* Text. *
*
+ * \endcode * * But in our mind the document - + * + * \code{.xml} * *
* Text. *
*
+ * \endcode * * Is already sufficiently specific. We can infer that a paragraph should be * wrapped around "Text.". Therefore we set the 'transparent' flag of the -- cgit v1.2.3 From b65781e2158a362025741a405fcaa7e54f4b7733 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 14 Jan 2015 00:09:55 +0100 Subject: Removed parent mechanism in object graph representation. This is only a relevant concept for the parsed XML language. It can be fully expressed by FieldDescriptors and their children in the object graph. --- src/core/model/Domain.cpp | 91 ++++++++++++++++++++++++++--------------------- src/core/model/Domain.hpp | 29 --------------- 2 files changed, 51 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 1fb057e..d664809 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -47,7 +47,7 @@ std::vector> Descriptor::pathTo( return path; } -static bool pathEquals(const Descriptor& a, const Descriptor& b) +static bool pathEquals(const Descriptor &a, const Descriptor &b) { // We assume that two Descriptors are equal if their names and domain names // are equal. @@ -59,57 +59,68 @@ static bool pathEquals(const Descriptor& a, const Descriptor& b) return aDom->getName() == bDom->getName(); } -//TODO: isa-handling. bool Descriptor::continuePath(Handle target, std::vector> &path) const { - // look if our current node is reachable using the parent references - for (auto &pfd : target->getParents()) { - Handle p = pfd->getParent().cast(); - if (pathEquals(*this, *p)) { - // if we have made the connection, stop the search. - path.push_back(pfd); - return true; - } - // look for transparent intermediate nodes. - if (!p->isa(RttiTypes::StructuredClass)) { - continue; - } - Handle pc = p.cast(); - if (pc->transparent) { - // recursion - std::vector> cPath = path; - if (continuePath(pc, cPath)) { - path = std::move(cPath); - path.push_back(pc); - path.push_back(pfd); - return true; - } - } - } + bool found = false; // use recursive depth-first search from the top to reach the given child - for (auto &fd : fieldDescriptors) { - for (auto &c : fd->getChildren()) { - if (pathEquals(*c, *target)) { - // if we have made the connection, stop the search. - path.push_back(fd); - return true; + if (fieldDescriptors.size() > 0) { + for (auto &fd : fieldDescriptors) { + for (auto &c : fd->getChildren()) { + if (pathEquals(*c, *target)) { + // if we have made the connection, stop the search. + path.push_back(fd); + return true; + } + // look for transparent intermediate nodes. + if (c->transparent) { + // copy the path. + std::vector> cPath = path; + cPath.push_back(fd); + cPath.push_back(c); + // recursion. + if (c->continuePath(target, cPath) && + (!found || path.size() > cPath.size())) { + // look if this path is better than the current optimum. + path = std::move(cPath); + found = true; + } + } } - // look for transparent intermediate nodes. - if (c->transparent) { + } + } else { + // if this is a StructuredClass and if it did not formulate own + // fieldDescriptors (overriding the parent), we can also use the + // (inheritance-wise) parent + if (isa(RttiTypes::StructuredClass)) { + const StructuredClass *tis = + static_cast(this); + if (!tis->getIsA().isNull()) { // copy the path. std::vector> cPath = path; - cPath.push_back(fd); - cPath.push_back(c); - // recursion. - if (c->continuePath(target, cPath)) { + if (tis->getIsA()->continuePath(target, cPath) && + (found || path.size() > cPath.size())) { + // look if this path is better than the current optimum. path = std::move(cPath); - return true; + found = true; } } } } - return false; + // either way we can try to find the targets parent (inheritance-wise) + // instead of the target itself. + if (!target->getIsA().isNull()) { + // copy the path. + std::vector> cPath = path; + if (continuePath(target->getIsA(), cPath) && + (!found || path.size() > cPath.size())) { + // look if this path is better than the current optimum. + path = std::move(cPath); + found = true; + } + } + // return if we found something. + return found; } /* Class Domain */ diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index a5ea929..bae980a 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -558,7 +558,6 @@ class StructuredClass : public Descriptor { private: const Cardinality cardinality; Owned isa; - NodeVector parents; public: const bool transparent; @@ -599,7 +598,6 @@ public: : Descriptor(mgr, std::move(name), domain, attributesDescriptor), cardinality(cardinality), isa(acquire(isa)), - parents(this), transparent(transparent), root(root) { @@ -620,33 +618,6 @@ public: * hierarchy (!). */ Rooted getIsA() const { return isa; } - - /** - * Returns a const reference to the NodeVector of FieldDescriptors that - * should allow an instance of this StructuredClass as child in the - * Structure Tree. This enables you to "invade" other domains as described - * in the StructuredClass documentation. - * - * @return a const reference to the NodeVector of FieldDescriptors that - * should allow an instance of this StructuredClass as child in the - * Structure Tree. - */ - const NodeVector &getParents() const { return parents; } - - /** - * Adds a FieldDescriptor that should allow an instance of this - * StructuredClass as a child in the Structure Tree. - */ - void addParent(Handle p) { parents.push_back(p); } - - /** - * Adds multiple FieldDescriptors that should allow an instance of this - * StructuredClass as a child in the Structure Tree. - */ - void addParents(const std::vector> &ps) - { - parents.insert(parents.end(), ps.begin(), ps.end()); - } }; /** -- cgit v1.2.3