diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-16 20:47:07 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-16 20:47:07 +0100 |
commit | 4a4e2245730ead7fce354469fe626398520f12b2 (patch) | |
tree | af42dbf2fd9ea87884cd500367c4017293609863 /src/core/model | |
parent | 6de2c8ad9450a8b349161d37ad7cab538324034d (diff) | |
parent | 75eea3bdd846a34c69be3d09f41ff4fae706628e (diff) |
using remote version of simple_book.osml
Diffstat (limited to 'src/core/model')
-rw-r--r-- | src/core/model/Document.cpp | 62 | ||||
-rw-r--r-- | src/core/model/Document.hpp | 155 | ||||
-rw-r--r-- | src/core/model/Domain.cpp | 49 | ||||
-rw-r--r-- | src/core/model/Domain.hpp | 31 |
4 files changed, 249 insertions, 48 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 4e101fc..2fcd20d 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -314,7 +314,7 @@ const NodeVector<StructureNode> &DocumentEntity::getField( return fields[idx]; } -void DocumentEntity::addStructureNode(Handle<StructureNode> s, const int &i) +void DocumentEntity::addStructureNode(Handle<StructureNode> s, const size_t &i) { // only add the new node if we don't have it already. auto it = fields[i].find(s); @@ -419,6 +419,15 @@ Rooted<StructuredEntity> DocumentEntity::createChildStructuredEntity( fieldName, std::move(name))}; } +Rooted<StructuredEntity> DocumentEntity::createChildStructuredEntity( + Handle<StructuredClass> descriptor, const size_t &fieldIdx, + Variant attributes, std::string name) +{ + return Rooted<StructuredEntity>{ + new StructuredEntity(subInst->getManager(), subInst, descriptor, + fieldIdx, std::move(attributes), std::move(name))}; +} + Rooted<DocumentPrimitive> DocumentEntity::createChildDocumentPrimitive( Variant content, const std::string &fieldName) { @@ -426,11 +435,22 @@ Rooted<DocumentPrimitive> DocumentEntity::createChildDocumentPrimitive( subInst->getManager(), subInst, std::move(content), fieldName)}; } +Rooted<DocumentPrimitive> DocumentEntity::createChildDocumentPrimitive( + Variant content, const size_t &fieldIdx) +{ + return Rooted<DocumentPrimitive>{new DocumentPrimitive( + subInst->getManager(), subInst, std::move(content), fieldIdx)}; +} + Rooted<Anchor> DocumentEntity::createChildAnchor(const std::string &fieldName) { return Rooted<Anchor>{ new Anchor(subInst->getManager(), subInst, fieldName)}; } +Rooted<Anchor> DocumentEntity::createChildAnchor(const size_t &fieldIdx) +{ + return Rooted<Anchor>{new Anchor(subInst->getManager(), subInst, fieldIdx)}; +} /* Class StructureNode */ @@ -468,6 +488,19 @@ StructureNode::StructureNode(Manager &mgr, std::string name, } } +StructureNode::StructureNode(Manager &mgr, std::string name, + Handle<Node> parent, const size_t &fieldIdx) + : Node(mgr, std::move(name), parent) +{ + if (parent->isa(&RttiTypes::StructuredEntity)) { + parent.cast<StructuredEntity>()->addStructureNode(this, fieldIdx); + } else if (parent->isa(&RttiTypes::AnnotationEntity)) { + parent.cast<AnnotationEntity>()->addStructureNode(this, fieldIdx); + } else { + throw OusiaException("The proposed parent was no DocumentEntity!"); + } +} + /* Class StructuredEntity */ StructuredEntity::StructuredEntity(Manager &mgr, Handle<Document> doc, @@ -489,8 +522,25 @@ StructuredEntity::StructuredEntity(Manager &mgr, Handle<Node> parent, bool StructuredEntity::doValidate(Logger &logger) const { + bool valid = true; + // check the parent. + if (getDescriptor() == nullptr) { + logger.error("The descriptor is not set!", *this); + valid = false; + } else if (!getDescriptor()->isa(&RttiTypes::StructuredClass)) { + logger.error("The descriptor is not a structure descriptor!", *this); + valid = false; + } else if (transparent && + !getDescriptor().cast<StructuredClass>()->isTransparent()) { + logger.error( + "The entity is marked as transparent but the descriptor " + "does not allow transparency!", + *this); + valid = false; + } + // check the validity as a StructureNode and as a DocumentEntity. - return StructureNode::doValidate(logger) & + return valid & StructureNode::doValidate(logger) & DocumentEntity::doValidate(logger); } @@ -674,6 +724,7 @@ void Document::doResolve(ResolutionState &state) continueResolveCompositum(root, state); } continueResolveReferences(domains, state); + continueResolveReferences(typesystems, state); } bool Document::doValidate(Logger &logger) const @@ -713,11 +764,14 @@ void Document::doReference(Handle<Node> node) if (node->isa(&RttiTypes::Domain)) { referenceDomain(node.cast<Domain>()); } + if (node->isa(&RttiTypes::Typesystem)) { + referenceTypesystem(node.cast<Typesystem>()); + } } RttiSet Document::doGetReferenceTypes() const { - return RttiSet{&RttiTypes::Domain}; + return RttiSet{&RttiTypes::Domain, &RttiTypes::Typesystem}; } Rooted<StructuredEntity> Document::createRootStructuredEntity( @@ -821,4 +875,4 @@ const Rtti AnnotationEntity = .parent(&Node) .composedOf({&StructuredEntity, &DocumentPrimitive, &Anchor}); } -}
\ No newline at end of file +} diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 5f06eb0..6903bb3 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -246,7 +246,7 @@ public: * FieldDescriptor in the Domain description. * @return a NodeVector of all StructuredEntities in that field. */ - const NodeVector<StructureNode> &getField(const size_t& idx ) const; + const NodeVector<StructureNode> &getField(const size_t &idx) const; /** * This adds a StructureNode to the field with the given index. @@ -259,7 +259,7 @@ public: * @param fieldIdx is the index of a field as specified in the * FieldDescriptor in the Domain description. */ - void addStructureNode(Handle<StructureNode> s, const int &fieldIdx); + void addStructureNode(Handle<StructureNode> s, const size_t &fieldIdx); /** * This adds a StructureNode to the field with the given name. * @@ -403,6 +403,23 @@ public: Variant attributes = Variant::mapType{}, const std::string &fieldName = DEFAULT_FIELD_NAME, std::string name = ""); + + /** + * This creates a new StructuredEntity as child of this DocumentEntity. + * + * @param descriptor is the StructuredClass of this StructuredEntity. + * @param attributes is a Map Variant containing attribute fillings for this + * StructuredEntity. It is empty per default. + * @param fieldIdx is the index of the field, where the newly created + * StructuredEntity shall be added to this DocumentEntity. + * @param name is some name for this StructuredEntity that may be used + * for later reference. It is empty per default. + * + * @return the newly created StructuredEntity. + */ + Rooted<StructuredEntity> createChildStructuredEntity( + Handle<StructuredClass> descriptor, const size_t &fieldIdx, + Variant attributes = Variant::mapType{}, std::string name = ""); /* * Creates a new DocumentPrimitive as child of this DocumentEntity. * @@ -416,8 +433,21 @@ public: * @return the newly created DocumentPrimitive. */ Rooted<DocumentPrimitive> createChildDocumentPrimitive( - Variant content = {}, - const std::string &fieldName = DEFAULT_FIELD_NAME); + Variant content, const std::string &fieldName = DEFAULT_FIELD_NAME); + /* + * Creates a new DocumentPrimitive as child of this DocumentEntity. + * + * @param fieldIdx is the index of the field, where the newly created + * StructuredEntity shall be added to this DocumentEntity. + * @param content is a Variant containing the content of this + * DocumentPrimitive. The Type of this Variant is + * specified at the parents Descriptor for the given + * fieldName. + * + * @return the newly created DocumentPrimitive. + */ + Rooted<DocumentPrimitive> createChildDocumentPrimitive( + Variant content, const size_t &fieldIdx); /** * Creates a new Anchor as child of this DocumentEntity. @@ -429,6 +459,16 @@ public: */ Rooted<Anchor> createChildAnchor( const std::string &fieldName = DEFAULT_FIELD_NAME); + + /** + * Creates a new Anchor as child of this DocumentEntity. + * + * @param fieldIdx is the index of the field, where the newly created + * Anchor shall be added to this DocumentEntity. + * + * @return the newly created Anchor. + */ + Rooted<Anchor> createChildAnchor(const size_t &fieldIdx); }; /** @@ -447,6 +487,11 @@ public: */ StructureNode(Manager &mgr, std::string name, Handle<Node> parent, const std::string &fieldName); + /** + * Constructor for a StructureNode in the StructureTree. + */ + StructureNode(Manager &mgr, std::string name, Handle<Node> parent, + const size_t &fieldIdx); /** * Constructor for an empty StructureNode. @@ -465,6 +510,9 @@ public: class StructuredEntity : public StructureNode, public DocumentEntity { friend Document; +private: + bool transparent = false; + protected: bool doValidate(Logger &logger) const override; @@ -494,6 +542,30 @@ public: DocumentEntity(this, descriptor, std::move(attributes)) { } + /** + * Constructor for a StructuredEntity in the Structure Tree. + * + * @param mgr is the Manager instance. + * @param parent is the parent DocumentEntity of this StructuredEntity + * in the DocumentTree. Note that this StructuredEntity + * will automatically register itself as child of this + * parent. + * @param descriptor is the StructuredClass of this StructuredEntity. + * @param fieldIdx is the index of the field in the parent DocumentEntity + * where this StructuredEntity shall be added. + * @param attributes is a Map Variant containing attribute fillings for this + * StructuredEntity. It is empty per default. + * @param name is some name for this StructuredEntity that may be used + * for later reference. It is empty per default. + */ + StructuredEntity(Manager &mgr, Handle<Node> parent, + Handle<StructuredClass> descriptor, const size_t &fieldIdx, + Variant attributes = Variant::mapType{}, + std::string name = "") + : StructureNode(mgr, std::move(name), parent, fieldIdx), + DocumentEntity(this, descriptor, std::move(attributes)) + { + } /** * Constructor for a StructuredEntity at the document root. @@ -530,6 +602,20 @@ public: Handle<StructuredClass> descriptor = nullptr, Variant attributes = Variant::mapType{}, std::string name = ""); + + /** + * Returns true if and only if this element was created using transparency/ + * if and only if this is an implicit element. + * + * @return true if and only if this element was created using transparency. + */ + bool isTransparent() const { return transparent; } + + /** + * @param trans true if and only if this element was created using + * transparency/if and only if this is an implicit element. + */ + void setTransparent(bool trans) { transparent = trans; } }; /** @@ -557,11 +643,31 @@ public: * @param fieldName is the name of the field in the parent DocumentEntity * where this DocumentPrimitive shall be added. */ - DocumentPrimitive(Manager &mgr, Handle<Node> parent, Variant content = {}, + DocumentPrimitive(Manager &mgr, Handle<Node> parent, Variant content, const std::string &fieldName = DEFAULT_FIELD_NAME) : StructureNode(mgr, "", parent, fieldName), content(content) { } + /** + * Constructor for a DocumentPrimitive. + * + * @param mgr is the Manager instance. + * @param parent is the parent DocumentEntity of this DocumentPrimitive + * in the DocumentTree. Note that this DocumentPrimitive + * will automatically register itself as child of this + * parent. + * @param content is a Variant containing the content of this + * DocumentPrimitive. The Type of this Variant is + * specified at the parents Descriptor for the given + * fieldName. + * @param fieldIdx is the index of the field in the parent DocumentEntity + * where this DocumentPrimitive shall be added. + */ + DocumentPrimitive(Manager &mgr, Handle<Node> parent, Variant content, + const size_t &fieldIdx) + : StructureNode(mgr, "", parent, fieldIdx), content(content) + { + } /** * Returns the content of this DocumentPrimitive. @@ -612,6 +718,21 @@ public: : StructureNode(mgr, "", parent, fieldName) { } + /** + * Constructor for Anchor. + * + * @param mgr is the Manager instance. + * @param parent is the parent of this Anchor in the Structure Tree (!), + * not the AnnotationEntity that references this Anchor. + * Note that this Anchor will automatically register itself + * as child of the given parent. + * @param fieldIdx is the index of the field in the parent DocumentEntity + * where this Anchor shall be added. + */ + Anchor(Manager &mgr, Handle<Node> parent, const size_t &fieldIdx) + : StructureNode(mgr, "", parent, fieldIdx) + { + } /** * Returns the AnnotationEntity this Anchor belongs to. @@ -754,6 +875,7 @@ private: Owned<StructuredEntity> root; NodeVector<AnnotationEntity> annotations; NodeVector<Domain> domains; + NodeVector<Typesystem> typesystems; protected: void doResolve(ResolutionState &state) override; @@ -771,7 +893,8 @@ public: Document(Manager &mgr, std::string name) : RootNode(mgr, std::move(name), nullptr), annotations(this), - domains(this) + domains(this), + typesystems(this) { } @@ -891,6 +1014,25 @@ public: } /** + * Adds a Typesystem reference to this Document. + */ + void referenceTypesystem(Handle<Typesystem> d) + { + invalidate(); + typesystems.push_back(d); + } + + /** + * Adds multiple Typesystem references to this Document. + */ + void referenceTypesystems(const std::vector<Handle<Typesystem>> &d) + { + invalidate(); + typesystems.insert(typesystems.end(), d.begin(), d.end()); + } + + + /** * Returns true if and only if the given StructureNode is part of this * document, meaning that there is a path of parent references in the * Structure Tree leading from the given StructureNode to this Document. @@ -914,4 +1056,3 @@ extern const Rtti Anchor; } #endif /* _OUSIA_MODEL_DOCUMENT_HPP_ */ - diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index ac0699e..f6c3956 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -558,7 +558,7 @@ Rooted<FieldDescriptor> Descriptor::getFieldDescriptor( } } -void Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, +bool Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) { // only add it if we need to. @@ -571,37 +571,25 @@ void Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, fd->getFieldType() != FieldDescriptor::FieldType::TREE) { // if so we add the new field before the TREE field. fieldDescriptors.insert(fieldDescriptors.end() - 1, fd); - - // if the new field was from the same domain we warn the user - // because that is bad coding style. - if (fd->getParent() != nullptr && - fd->getParent().cast<Descriptor>()->getParent() == - getParent()) { - logger.warning( - std::string("Field \"") + fd->getName() + - "\" was declared after main field \"" + - fds.back()->getName() + - "\". The order of fields was changed to make the " - "main field the last field.", - *fd); - } + return true; } else { fieldDescriptors.push_back(fd); } } + return false; } -void Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) +bool Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) { - addAndSortFieldDescriptor(fd, logger); if (fd->getParent() == nullptr) { fd->setParent(this); } + return addAndSortFieldDescriptor(fd, logger); } -void Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) +bool Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) { - addAndSortFieldDescriptor(fd, logger); + bool sorted = addAndSortFieldDescriptor(fd, logger); Handle<Managed> par = fd->getParent(); if (par != this) { if (par != nullptr) { @@ -610,9 +598,10 @@ void Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) } fd->setParent(this); } + return sorted; } -void Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) +bool Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) { Rooted<FieldDescriptor> copy; if (fd->isPrimitive()) { @@ -631,7 +620,7 @@ void Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger) copy->addChild(c); } } - addFieldDescriptor(copy, logger); + return addFieldDescriptor(copy, logger); } bool Descriptor::removeFieldDescriptor(Handle<FieldDescriptor> fd) @@ -646,25 +635,27 @@ bool Descriptor::removeFieldDescriptor(Handle<FieldDescriptor> fd) return false; } -Rooted<FieldDescriptor> Descriptor::createPrimitiveFieldDescriptor( - Handle<Type> primitiveType, Logger &logger, - FieldDescriptor::FieldType fieldType, std::string name, bool optional) +std::pair<Rooted<FieldDescriptor>, bool> +Descriptor::createPrimitiveFieldDescriptor(Handle<Type> primitiveType, + Logger &logger, + FieldDescriptor::FieldType fieldType, + std::string name, bool optional) { Rooted<FieldDescriptor> fd{new FieldDescriptor(getManager(), primitiveType, this, fieldType, std::move(name), optional)}; - addFieldDescriptor(fd, logger); - return fd; + bool sorted = addFieldDescriptor(fd, logger); + return std::make_pair(fd, sorted); } -Rooted<FieldDescriptor> Descriptor::createFieldDescriptor( +std::pair<Rooted<FieldDescriptor>, bool> Descriptor::createFieldDescriptor( Logger &logger, FieldDescriptor::FieldType fieldType, std::string name, bool optional) { Rooted<FieldDescriptor> fd{new FieldDescriptor( getManager(), this, fieldType, std::move(name), optional)}; - addFieldDescriptor(fd, logger); - return fd; + bool sorted = addFieldDescriptor(fd, logger); + return std::make_pair(fd, sorted); } /* Class StructuredClass */ diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 350c7ba..476a38c 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -469,7 +469,7 @@ private: Owned<StructType> attributesDescriptor; NodeVector<FieldDescriptor> fieldDescriptors; - void addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); + bool addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); protected: void doResolve(ResolutionState &state) override; @@ -557,8 +557,11 @@ public: * parent of the given FieldDescriptor if it is not set yet. * * @param fd is a FieldDescriptor. + * @return returns true if the given FieldDescriptor was not added at the + * end one place before because a TREE field already existed and + * the TREE field has to be at the end. */ - void addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); + bool addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); /** * Adds the given FieldDescriptor to this Descriptor. This also sets the @@ -566,16 +569,22 @@ public: * already and removes it from the old parent Descriptor. * * @param fd is a FieldDescriptor. + * @return returns true if the given FieldDescriptor was not added at the + * end one place before because a TREE field already existed and + * the TREE field has to be at the end. */ - void moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); + bool moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); /** * Copies a FieldDescriptor that belongs to another Descriptor to this * Descriptor. * * @param fd some FieldDescriptor belonging to another Descriptor. + * @return returns true if the given FieldDescriptor was not added at the + * end one place before because a TREE field already existed and + * the TREE field has to be at the end. */ - void copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); + bool copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger); /** * Removes the given FieldDescriptor from this Descriptor. This also sets @@ -598,9 +607,12 @@ public: * filled in order for an instance of the parent * Descriptor to be valid. * - * @return the newly created FieldDescriptor. + * @return the newly created FieldDescriptor and a bool + * indicating whether the order of FieldDescriptors had + * to be changed for the TREE field to be in the last + * spot. */ - Rooted<FieldDescriptor> createPrimitiveFieldDescriptor( + std::pair<Rooted<FieldDescriptor>, bool> createPrimitiveFieldDescriptor( Handle<Type> primitiveType, Logger &logger, FieldDescriptor::FieldType fieldType = FieldDescriptor::FieldType::TREE, std::string name = "", bool optional = false); @@ -617,9 +629,12 @@ public: * filled in order for an instance of the parent * Descriptor to be valid. * - * @return the newly created FieldDescriptor. + * @return the newly created FieldDescriptor and a bool + * indicating whether the order of FieldDescriptors had + * to be changed for the TREE field to be in the last + * spot. */ - Rooted<FieldDescriptor> createFieldDescriptor( + std::pair<Rooted<FieldDescriptor>, bool> createFieldDescriptor( Logger &logger, FieldDescriptor::FieldType fieldType = FieldDescriptor::FieldType::TREE, std::string name = "", bool optional = false); |