diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/model/Document.cpp | 46 | ||||
| -rw-r--r-- | src/core/model/Document.hpp | 91 | ||||
| -rw-r--r-- | src/core/model/Domain.cpp | 31 | ||||
| -rw-r--r-- | src/core/model/Domain.hpp | 94 | 
4 files changed, 257 insertions, 5 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 2ae9107..61c384d 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -383,8 +383,8 @@ void DocumentEntity::addStructureNodes(  	}  } -bool DocumentEntity::removeStructureNodeFromField( -    Handle<StructureNode> s, const std::string &fieldName) +bool DocumentEntity::removeStructureNodeFromField(Handle<StructureNode> s, +                                                  const std::string &fieldName)  {  	return removeStructureNodeFromField(  	    s, getFieldDescriptorIndex(fieldName, true)); @@ -428,6 +428,29 @@ bool DocumentEntity::removeStructureNode(Handle<StructureNode> s)  	return false;  } +Rooted<StructuredEntity> DocumentEntity::createChildStructuredEntity( +    Handle<StructuredClass> descriptor, Variant attributes, +    const std::string &fieldName, std::string name) +{ +	return Rooted<StructuredEntity>{new StructuredEntity( +	    subInst->getManager(), subInst, descriptor, std::move(attributes), +	    fieldName, std::move(name))}; +} + +Rooted<DocumentPrimitive> DocumentEntity::createChildDocumentPrimitive( +    Variant content, const std::string &fieldName) +{ +	return Rooted<DocumentPrimitive>{new DocumentPrimitive( +	    subInst->getManager(), subInst, std::move(content), fieldName)}; +} + +Rooted<Anchor> DocumentEntity::createChildAnchor(std::string name, +                                                 const std::string &fieldName) +{ +	return Rooted<Anchor>{ +	    new Anchor(subInst->getManager(), std::move(name), subInst, fieldName)}; +} +  /* Class StructureNode */  bool StructureNode::doValidate(Logger &logger) const @@ -611,6 +634,14 @@ bool Document::doValidate(Logger &logger) const  	return valid & continueValidation(annotations, logger);  } +Rooted<StructuredEntity> Document::createRootStructuredEntity( +    Handle<StructuredClass> descriptor, Variant attributes, std::string name) +{ +	return Rooted<StructuredEntity>{ +	    new StructuredEntity(getManager(), Handle<Document>{this}, descriptor, +	                         attributes, std::move(name))}; +} +  void Document::addAnnotation(Handle<AnnotationEntity> a)  {  	// only add it if we need to. @@ -635,8 +666,6 @@ void Document::addAnnotations(const std::vector<Handle<AnnotationEntity>> &as)  	}  } - -  bool Document::removeAnnotation(Handle<AnnotationEntity> a)  {  	auto it = annotations.find(a); @@ -649,6 +678,15 @@ bool Document::removeAnnotation(Handle<AnnotationEntity> a)  	return false;  } +Rooted<AnnotationEntity> Document::createChildAnnotation( +    Handle<AnnotationClass> descriptor, Handle<Anchor> start, +    Handle<Anchor> end, Variant attributes, std::string name) +{ +	return Rooted<AnnotationEntity>{ +	    new AnnotationEntity(getManager(), this, descriptor, start, end, +	                         attributes, std::move(name))}; +} +  bool Document::hasChild(Handle<StructureNode> s) const  {  	Rooted<Managed> parent = s->getParent(); diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 7357dd2..97bbb60 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -126,6 +126,9 @@ namespace model {  class Document;  class StructureNode; +class StructuredEntity; +class DocumentPrimitive; +class Anchor;  /**   * A DocumentEntity is the common superclass for StructuredEntities and @@ -309,7 +312,6 @@ public:  	 */  	void addStructureNodes(const std::vector<Handle<StructureNode>> &ss,  	                       const std::string &fieldName = ""); -  	/**  	 * This removes a StructureNode from the field with the given name. If an  	 * empty name is given it is assumed that the 'default' FieldDescriptor is @@ -393,6 +395,49 @@ public:  	 *          not found.  	*/  	bool removeStructureNode(Handle<StructureNode> s); + +	/** +	 * 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 fieldName  is the name 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, Variant attributes = {}, +	    const std::string &fieldName = "", std::string name = ""); +	/* +	 * Creates a new DocumentPrimitive as child of 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. +	 * @param fieldName is the name of the field, where the newly created +	 *                  StructuredEntity shall be added to this DocumentEntity. +	 * +	 * @return          the newly created DocumentPrimitive. +	 */ +	Rooted<DocumentPrimitive> createChildDocumentPrimitive( +	    Variant content = {}, const std::string &fieldName = ""); + +	/** +	 * Creates a new Anchor as child of this DocumentEntity. +	 * +	 * @param name      is the Anchor id. +	 * @param fieldName is the name of the field, where the newly created +	 *                  Anchor shall be added to this DocumentEntity. +	 * +	 * @return          the newly created Anchor. +	 */ +	Rooted<Anchor> createChildAnchor(std::string name, +	                                 const std::string &fieldName = "");  };  /** @@ -702,6 +747,17 @@ public:  	}  	/** +	 * This sets up an empty document. +	 * +	 * @param mgr  is the Manager instance. +	 * @param name is a name for this Document. +	 */ +	static Rooted<Document> createEmptyDocument(Manager &mgr, std::string name) +	{ +		return Rooted<Document>{new Document(mgr, std::move(name))}; +	} + +	/**  	 * Sets the root StructuredEntity of this Document. This also sets the  	 * parent of the given StructuredEntity if it is not set to this Document  	 * already. @@ -723,6 +779,21 @@ public:  	Rooted<StructuredEntity> getRoot() const { return root; }  	/** +	 * This creates a new StructuredEntity and adds it as root to this Document. +	 * +	 * @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 name       is some name for this StructuredEntity that may be used +	 *                   for later reference. It is empty per default. +	 * +	 * @return           the newly constructed StructuredEntity. +	 */ +	Rooted<StructuredEntity> createRootStructuredEntity( +	    Handle<StructuredClass> descriptor, Variant attributes = {}, +	    std::string name = ""); + +	/**  	 * Returns a const reference to the NodeVector of AnnotationEntities that  	 * span over Anchors in this Documents structure.  	 * @@ -761,6 +832,24 @@ public:  	 *          Document did not have the given AnnotationEntity as child.  	 */  	bool removeAnnotation(Handle<AnnotationEntity> a); +	/** +	 * Creates a new AnnotationEntity as child of this Document. +	 * +	 * @param descriptor is the AnnotationClass of this AnnotationEntity. +	 * @param start      is the start Anchor of this AnnotationEntity. It has to +	 *                   be part of this Document. +	 * @param end        is the end Anchor of this Annotationentity. It has to +	 *                   be part of this Document. +	 * @param attributes is a Map Variant containing attribute fillings for this +	 *                   AnnotationEntity. It is empty per default. +	 * @param name       is some name for this AnnotationEntity that might be +	 *                   used for references later on. It is empty per default. +	 * +	 * @return           the newly constructed AnnotationEntity. +	 */ +	Rooted<AnnotationEntity> createChildAnnotation( +	    Handle<AnnotationClass> descriptor, Handle<Anchor> start, +	    Handle<Anchor> end, Variant attributes = {}, std::string name = "");  	/**  	 * Returns a const reference to the NodeVector of Domains that are used diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index b425174..c7afd22 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -289,6 +289,20 @@ bool Descriptor::removeFieldDescriptor(Handle<FieldDescriptor> fd)  	return false;  } +Rooted<FieldDescriptor> Descriptor::createPrimitiveFieldDescriptor( +    Handle<Type> primitiveType, std::string name, bool optional) +{ +	return Rooted<FieldDescriptor>{new FieldDescriptor( +	    getManager(), this, primitiveType, std::move(name), optional)}; +} + +Rooted<FieldDescriptor> Descriptor::createFieldDescriptor( +    FieldDescriptor::FieldType fieldType, std::string name, bool optional) +{ +	return Rooted<FieldDescriptor>{new FieldDescriptor( +	    getManager(), this, fieldType, std::move(name), optional)}; +} +  /* Class StructuredClass */  StructuredClass::StructuredClass(Manager &mgr, std::string name, @@ -481,6 +495,16 @@ bool Domain::removeStructuredClass(Handle<StructuredClass> s)  	return false;  } +Rooted<StructuredClass> Domain::createStructuredClass( +    std::string name, const Cardinality &cardinality, +    Handle<StructType> attributesDescriptor, Handle<StructuredClass> superclass, +    bool transparent, bool root) +{ +	return Rooted<StructuredClass>{new StructuredClass( +	    getManager(), std::move(name), this, cardinality, attributesDescriptor, +	    superclass, std::move(transparent), std::move(root))}; +} +  void Domain::addAnnotationClass(Handle<AnnotationClass> a)  {  	// only add it if we need to. @@ -509,6 +533,13 @@ bool Domain::removeAnnotationClass(Handle<AnnotationClass> a)  	}  	return false;  } + +Rooted<AnnotationClass> Domain::createAnnotationClass( +    std::string name, Handle<StructType> attributesDescriptor) +{ +	return Rooted<AnnotationClass>{new AnnotationClass( +	    getManager(), std::move(name), this, attributesDescriptor)}; +}  }  /* Type registrations */ diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 12cb9b3..e40a9f3 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -549,6 +549,41 @@ public:  	bool removeFieldDescriptor(Handle<FieldDescriptor> fd);  	/** +	 * This creates a new primitive FieldDescriptor and adds it to this +	 * Descriptor. +	 * +	 * @param primitiveType is a handle to some Type in some Typesystem of which +	 *                      one instance is allowed to fill this field. +	 * @param name          is the name of this field. +	 * @param optional      should be set to 'false' is this field needs to be +	 *                      filled in order for an instance of the parent +	 *                      Descriptor to be valid. +	 * +	 * @return              the newly created FieldDescriptor. +	 */ +	Rooted<FieldDescriptor> createPrimitiveFieldDescriptor( +	    Handle<Type> primitiveType, std::string name = "", +	    bool optional = false); + +	/** +	 * This creates a new primitive FieldDescriptor and adds it to this +	 * Descriptor. +	 * +	 * @param fieldType     is the FieldType of this FieldDescriptor, either +	 *                      TREE for the main or default structure or SUBTREE +	 *                      for supporting structures. +	 * @param name          is the name of this field. +	 * @param optional      should be set to 'false' is this field needs to be +	 *                      filled in order for an instance of the parent +	 *                      Descriptor to be valid. +	 * +	 * @return              the newly created FieldDescriptor. +	 */ +	Rooted<FieldDescriptor> createFieldDescriptor( +	    FieldDescriptor::FieldType fieldType = FieldDescriptor::FieldType::TREE, +	    std::string name = "", bool optional = false); + +	/**  	 * This tries to construct the shortest possible path of this Descriptor  	 * to the given child Descriptor. As an example consider the book domain  	 * from above. @@ -911,6 +946,18 @@ public:  	}  	/** +	 * Creates a new Domain and returns it. +	 * +	 * @param mgr  is the Manager instance. +	 * @param name is a name for this domain which will be used for later +	 *             references to this Domain. +	 */ +	static Rooted<Domain> createEmptyDomain(Manager &mgr, std::string name) +	{ +		return Rooted<Domain>{new Domain(mgr, std::move(name))}; +	} + +	/**  	 * Returns a const reference to the NodeVector of StructuredClasses that are  	 * part of this Domain.  	 * @@ -941,6 +988,40 @@ public:  	bool removeStructuredClass(Handle<StructuredClass> s);  	/** +	 * This creates a new StructuredClass and appends it to this Domain. +	 * +	 * @param name                 is the name of the StructuredClass. +	 * @param cardinality          specifies how often an element of this type +	 *                             may occur at a specific point in the +	 *                             StructureTree. For example: A document should +	 *                             have at least one author. This is set to * +	 *                             per default, meaning that any number of +	 *                             of instances is valid, including zero. +	 * @param attributesDescriptor is a StructType that specifies the attribute +	 *                             keys as well as value domains for this +	 *                             Descriptor. +	 * @param superclass           references a parent StructuredClass. Please +	 *                             look for more information on inheritance in +	 *                             the class documentation above. The default is +	 *                             a null reference, meaning no super class. +	 *                             The constructor automatically registers this +	 *                             class as a subclass at the super class. +	 * @param transparent          specifies whether this StructuredClass is +	 *                             transparent. For more information on +	 *                             transparency please refer to the class +	 *                             documentation above. The default is false. +	 * @param root                 specifies whether this StructuredClass is +	 *                             allowed to be at the root of a Document. +	 * +	 * @return                     the newly created StructuredClass. +	 */ +	Rooted<StructuredClass> createStructuredClass( +	    std::string name, const Cardinality &cardinality = AnyCardinality, +	    Handle<StructType> attributesDescriptor = nullptr, +	    Handle<StructuredClass> superclass = nullptr, bool transparent = false, +	    bool root = false); + +	/**  	 * Returns a const reference to the NodeVector of AnnotationClasses that are  	 * part of this Domain.  	 * @@ -971,6 +1052,19 @@ public:  	bool removeAnnotationClass(Handle<AnnotationClass> a);  	/** +	 * This creates a new AnnotationClass and appends it to this Domain. +	 * +	 * @param name                 is a name for this AnnotationClass that will +	 *                             be used for later references to this +	 *                             AnnotationClass. +	 * @param attributesDescriptor is a StructType that specifies the attribute +	 *                             keys as well as value domains for this +	 *                             Descriptor. +	 */ +	Rooted<AnnotationClass> createAnnotationClass( +	    std::string name, Handle<StructType> attributesDescriptor = nullptr); + +	/**  	 * Returns a const reference to the NodeVector of TypeSystems that are  	 * references in this Domain.  	 *  | 
