summaryrefslogtreecommitdiff
path: root/src/core/model/Document.cpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-22 00:43:40 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-22 00:43:40 +0100
commit33008f1110523ae9c9b9e1d2ca24ed642637c40d (patch)
treed058340aaab51df5a59dc89a8b08b829923074b3 /src/core/model/Document.cpp
parent601d07df6339696bace0f303a69a0a02a39f9eea (diff)
added move semantics do Domain and Document classes.
Diffstat (limited to 'src/core/model/Document.cpp')
-rw-r--r--src/core/model/Document.cpp89
1 files changed, 83 insertions, 6 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index f29af1c..2ae9107 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -335,13 +335,39 @@ void DocumentEntity::setAttributes(const Variant &a)
void DocumentEntity::addStructureNode(Handle<StructureNode> s, const int &i)
{
- invalidateSubInstance();
- fields[i].push_back(s);
- if (s->getParent() != subInst) {
+ // only add the new node if we don't have it already.
+ auto it = fields[i].find(s);
+ if (it == fields[i].end()) {
+ invalidateSubInstance();
+ fields[i].push_back(s);
+ }
+ Handle<Managed> par = s->getParent();
+ if (par != subInst) {
+ // if a previous parent existed, remove the StructureNode from it
+ if (par != nullptr) {
+ if (par->isa(RttiTypes::StructuredEntity)) {
+ par.cast<StructuredEntity>()->removeStructureNode(s);
+ } else {
+ par.cast<AnnotationEntity>()->removeStructureNode(s);
+ }
+ }
s->setParent(subInst);
}
}
+bool DocumentEntity::removeStructureNodeFromField(Handle<StructureNode> s,
+ const int &i)
+{
+ auto it = fields[i].find(s);
+ if (it != fields[i].end()) {
+ invalidateSubInstance();
+ fields[i].erase(it);
+ s->setParent(nullptr);
+ return true;
+ }
+ return false;
+}
+
void DocumentEntity::addStructureNode(Handle<StructureNode> s,
const std::string &fieldName)
{
@@ -357,6 +383,13 @@ void DocumentEntity::addStructureNodes(
}
}
+bool DocumentEntity::removeStructureNodeFromField(
+ Handle<StructureNode> s, const std::string &fieldName)
+{
+ return removeStructureNodeFromField(
+ s, getFieldDescriptorIndex(fieldName, true));
+}
+
void DocumentEntity::addStructureNode(Handle<StructureNode> s,
Handle<FieldDescriptor> fieldDescriptor)
{
@@ -373,6 +406,28 @@ void DocumentEntity::addStructureNodes(
}
}
+bool DocumentEntity::removeStructureNodeFromField(
+ Handle<StructureNode> s, Handle<FieldDescriptor> fieldDescriptor)
+{
+ return removeStructureNodeFromField(
+ s, getFieldDescriptorIndex(fieldDescriptor, true));
+}
+
+bool DocumentEntity::removeStructureNode(Handle<StructureNode> s)
+{
+ for (auto field : fields) {
+ auto it = field.find(s);
+ if (it != field.end()) {
+ invalidateSubInstance();
+ field.erase(it);
+ s->setParent(nullptr);
+ return true;
+ }
+ }
+
+ return false;
+}
+
/* Class StructureNode */
bool StructureNode::doValidate(Logger &logger) const
@@ -558,9 +613,17 @@ bool Document::doValidate(Logger &logger) const
void Document::addAnnotation(Handle<AnnotationEntity> a)
{
- invalidate();
- annotations.push_back(a);
- if (a->getParent() != this) {
+ // only add it if we need to.
+ if (annotations.find(a) == annotations.end()) {
+ invalidate();
+ annotations.push_back(a);
+ }
+ Handle<Managed> par = a->getParent();
+ if (par != this) {
+ if (par != nullptr) {
+ // remove the StructuredClass from the old parent.
+ par.cast<Document>()->removeAnnotation(a);
+ }
a->setParent(this);
}
}
@@ -572,6 +635,20 @@ void Document::addAnnotations(const std::vector<Handle<AnnotationEntity>> &as)
}
}
+
+
+bool Document::removeAnnotation(Handle<AnnotationEntity> a)
+{
+ auto it = annotations.find(a);
+ if (it != annotations.end()) {
+ invalidate();
+ annotations.erase(it);
+ a->setParent(nullptr);
+ return true;
+ }
+ return false;
+}
+
bool Document::hasChild(Handle<StructureNode> s) const
{
Rooted<Managed> parent = s->getParent();