summaryrefslogtreecommitdiff
path: root/src/core/model/Document.hpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-20 01:24:11 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-20 01:24:11 +0100
commit20d3e71f26ca884271ed5d372a8459394554c147 (patch)
tree82f4b40e989205dbbbd03b70446ca8b02bf1908f /src/core/model/Document.hpp
parent7c64a0770a4800d80c5a53eea2243c46301f7749 (diff)
finished setter revival in Document classes, hopefully.
Diffstat (limited to 'src/core/model/Document.hpp')
-rw-r--r--src/core/model/Document.hpp94
1 files changed, 79 insertions, 15 deletions
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index d89ade8..4147847 100644
--- a/src/core/model/Document.hpp
+++ b/src/core/model/Document.hpp
@@ -139,8 +139,6 @@ class StructureNode;
*
*/
class DocumentEntity {
- friend StructureNode;
-
private:
/*
* this is a rather dirty method that should not be used in other cases:
@@ -162,6 +160,8 @@ private:
void invalidateSubInstance();
+ void addStructureNode(Handle<StructureNode> s, const int &i);
+
protected:
bool doValidate(Logger &logger) const;
@@ -190,6 +190,13 @@ public:
Rooted<Descriptor> getDescriptor() const { return descriptor; }
/**
+ * Sets the Descriptor for this DocumentEntity.
+ *
+ * @param d is the new Descriptor for this DocumentEntity.
+ */
+ void setDescriptor(Handle<Descriptor> d);
+
+ /**
* Returns a Map Variant adhering to the attribute StructType in the given
* descriptor.
*
@@ -270,6 +277,9 @@ public:
*
* If the name is unknown an exception is thrown.
*
+ * This method also changes the parent of the newly added StructureNode if
+ * it is not set to this DocumentEntity already.
+ *
* @param s is the StructureNode that shall be added.
* @param fieldName is the name of a field as specified in the
* FieldDescriptor in the Domain description.
@@ -285,6 +295,9 @@ public:
*
* If the name is unknown an exception is thrown.
*
+ * This method also changes the parent of each newly added StructureNode if
+ * it is not set to this DocumentEntity already.
+ *
* @param ss are the StructureNodes that shall be added.
* @param fieldName is the name of a field as specified in the
* FieldDescriptor in the Domain description.
@@ -298,6 +311,9 @@ public:
* If the FieldDescriptor does not belong to the Descriptor of this node
* an exception is thrown.
*
+ * This method also changes the parent of the newly added StructureNode if
+ * it is not set to this DocumentEntity already.
+ *
* @param s is the StructureNode that shall be added.
* @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for
* this DocumentEntity.
@@ -312,6 +328,9 @@ public:
* If the FieldDescriptor does not belong to the Descriptor of this node
* an exception is thrown.
*
+ * This method also changes the parent of each newly added StructureNode if
+ * it is not set to this DocumentEntity already.
+ *
* @param ss are the StructureNodes that shall be added.
* @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for
* this DocumentEntity.
@@ -329,18 +348,19 @@ class StructureNode : public Node {
public:
/**
- * Constructor for a StructureNode at the root.
- */
- StructureNode(Manager &mgr, std::string name, Handle<Document> doc)
- : Node(mgr, std::move(name), doc)
- {
- }
-
- /**
* Constructor for a StructureNode in the StructureTree.
*/
StructureNode(Manager &mgr, std::string name, Handle<Node> parent,
const std::string &fieldName);
+
+ /**
+ * Constructor for an empty StructureNode.
+ */
+ StructureNode(Manager &mgr, std::string name = "",
+ Handle<Node> parent = nullptr)
+ : Node(mgr, std::move(name), parent)
+ {
+ }
};
/**
@@ -394,6 +414,23 @@ public:
StructuredEntity(Manager &mgr, Handle<Document> doc,
Handle<StructuredClass> descriptor,
Variant attributes = {}, std::string name = "");
+
+ /**
+ * Constructor for an empty StructuredEntity that is not yet connected.
+ *
+ * @param mgr is the Manager instance.
+ * @param parent is the parent Document of this StructuredEntity. Note
+ * that this StructuredEntity will automatically register
+ * itself as child of 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.
+ */
+ StructuredEntity(Manager &mgr, Handle<Node> parent = nullptr,
+ Handle<StructuredClass> descriptor = nullptr,
+ Variant attributes = {}, std::string name = "");
};
/**
@@ -527,8 +564,8 @@ public:
* @param name is some name for this AnnotationEntity that might be
* used for references later on. It is empty per default.
*/
- AnnotationEntity(Manager &mgr, Handle<Document> parent,
- Handle<AnnotationClass> descriptor,
+ AnnotationEntity(Manager &mgr, Handle<Document> parent = nullptr,
+ Handle<AnnotationClass> descriptor = nullptr,
Handle<Anchor> start = nullptr,
Handle<Anchor> end = nullptr, Variant attributes = {},
std::string name = "");
@@ -565,6 +602,7 @@ public:
*/
void setEnd(Handle<Anchor> e)
{
+ invalidate();
end = acquire(e);
}
};
@@ -575,8 +613,6 @@ public:
* document and the AnnotationEntities that span over Anchors in this Document.
*/
class Document : public Node {
- friend AnnotationEntity;
-
private:
// TODO: Might there be several roots? E.g. metadata?
Owned<StructuredEntity> root;
@@ -589,18 +625,29 @@ protected:
bool doValidate(Logger &logger) const override;
public:
+ /**
+ * This sets up an empty document.
+ *
+ * @param mgr is the Manager instance.
+ * @param name is a name for this Document.
+ */
Document(Manager &mgr, std::string name)
: Node(mgr, std::move(name), nullptr), annotations(this)
{
}
/**
- * Sets the root StructuredEntity of this Document.
+ * 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.
*/
void setRoot(Handle<StructuredEntity> root)
{
invalidate();
this->root = acquire(root);
+ if (root->getParent() != this) {
+ root->setParent(this);
+ }
};
/**
@@ -623,6 +670,23 @@ public:
}
/**
+ * Adds an AnnotationEntity to this document. This also sets the parent
+ * of the given AnnotationEntity if it is not set to this document already.
+ *
+ * @param a is some AnnotationEntity
+ */
+ void addAnnotation(Handle<AnnotationEntity> a);
+
+ /**
+ * Adds multiple AnnotationEntities to this document. This also sets the
+ * parent of each given AnnotationEntity if it is not set to this document
+ * already.
+ *
+ * @param as is a vector of AnnotationEntities.
+ */
+ void addAnnotations(std::vector<Handle<AnnotationEntity>> as);
+
+ /**
* Returns a const reference to the NodeVector of Domains that are used
* within this Document.
*