summaryrefslogtreecommitdiff
path: root/src/core/model
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-16 18:47:38 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-16 18:47:38 +0100
commit585ebd4afab08434f4dadd46085bf7822c7188c1 (patch)
treed482aa0ed3c77a8e1472abc049e3412f26601325 /src/core/model
parent9556bd8ac1374daf01700e18e4a025c02b5d3857 (diff)
added creation methods that reference fields by index instead of name.
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/Document.cpp54
-rw-r--r--src/core/model/Document.hpp134
2 files changed, 179 insertions, 9 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index 4e101fc..76835a1 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);
}
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index 5f06eb0..57a4b1a 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.
@@ -913,5 +1034,4 @@ extern const Rtti Anchor;
}
}
-#endif /* _OUSIA_MODEL_DOCUMENT_HPP_ */
-
+#endif /* _OUSIA_MODEL_DOCUMENT_HPP_ */ \ No newline at end of file