summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/model/Document.cpp20
-rw-r--r--src/core/model/Document.hpp33
2 files changed, 18 insertions, 35 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index 854e717..e5d0755 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -57,20 +57,22 @@ int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName)
return -1;
}
-void DocumentEntity::getField(NodeVector<StructuredEntity> &res,
- const std::string &fieldName)
+NodeVector<StructuredEntity> &DocumentEntity::getField(
+ const std::string &fieldName)
{
int f = getFieldDescriptorIndex(fieldName);
if (f < 0) {
- NodeVector<StructuredEntity> empty{this};
- res = NodeVector<StructuredEntity>(this);
+ throw OusiaException("No field for the given name exists!");
}
- res = fields[f];
+ return fields[f];
}
NodeVector<StructuredEntity> &DocumentEntity::getField(
- Rooted<FieldDescriptor> fieldDescriptor)
+ Handle<FieldDescriptor> fieldDescriptor)
{
+ if(fieldDescriptor.isNull()){
+ throw OusiaException("The given FieldDescriptor handle is null!");
+ }
const NodeVector<FieldDescriptor> &fds = descriptor->getFieldDescriptors();
int f = 0;
for (auto &fd : fds) {
@@ -155,8 +157,7 @@ Rooted<StructuredEntity> StructuredEntity::buildEntity(
return {nullptr};
}
// append the new entity to the right field.
- NodeVector<StructuredEntity> field(parent);
- parent->getField(field, fieldName);
+ NodeVector<StructuredEntity>& field = parent->getField(fieldName);
field.push_back(entity);
// and return it.
@@ -179,8 +180,7 @@ Rooted<DocumentPrimitive> DocumentPrimitive::buildEntity(
return {nullptr};
}
// append the new entity to the right field.
- NodeVector<StructuredEntity> field(parent);
- parent->getField(field, fieldName);
+ NodeVector<StructuredEntity>& field = parent->getField(fieldName);
field.push_back(entity);
// and return it.
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index 6ca1a30..fabdcaf 100644
--- a/src/core/model/Document.hpp
+++ b/src/core/model/Document.hpp
@@ -156,12 +156,6 @@ public:
Variant getAttributes() const { return attributes; }
/**
- * This allows a direct manipulation of the internal data structure of a
- * DocumentEntity and is not recommended. TODO: Delete this?
- */
- std::vector<NodeVector<StructuredEntity>> &getFields() { return fields; }
-
- /**
* This returns true if there is a FieldDescriptor in the Descriptor for
* this DocumentEntity which has the given name. If an empty name is
* given it is assumed that the 'default' FieldDescriptor is referenced,
@@ -180,29 +174,18 @@ public:
/**
* This returns the vector of entities containing all members of the field
- * for which the FieldDescriptor has the specified name. If an empty name is
- * given it is assumed that the 'default' FieldDescriptor is referenced,
- * where 'default' means either:
+ * with the given name. If an empty name is given it is assumed that the
+ * 'default' FieldDescriptor is referenced, where 'default' means either:
* 1.) The only TREE typed FieldDescriptor (if present) or
* 2.) the only FieldDescriptor (if only one is specified).
*
- * Note that the output of this method might well be ambigous: If no
- * FieldDescriptor matches the given name an empty NodeVector is
- * returned. This is also the case, however, if there are no members for an
- * existing field. Therefore it is recommended to additionally check the
- * output of "hasField" or use the version of this method with
- * a FieldDescriptor as input.
+ * If the name is unknown an exception is thrown.
*
- * @param fieldName is the name of the field as specified in the
+ * @param fieldName is the name of a field as specified in the
* FieldDescriptor in the Domain description.
- * @param res is a NodeVector reference where the result will be
- * stored. After using this method the reference will
- * either refer to all StructuredEntities in that field. If
- * the field is unknown or if no members exist in that
- * field yet, the NodeVector will be empty.
+ * @return a NodeVector of all StructuredEntities in that field.
*/
- void getField(NodeVector<StructuredEntity> &res,
- const std::string &fieldName = "");
+ NodeVector<StructuredEntity> &getField(const std::string &fieldName = "");
/**
* This returns the vector of entities containing all members of the field
@@ -216,7 +199,7 @@ public:
* @return a NodeVector of all StructuredEntities in that field.
*/
NodeVector<StructuredEntity> &getField(
- Rooted<FieldDescriptor> fieldDescriptor);
+ Handle<FieldDescriptor> fieldDescriptor);
};
/**
@@ -407,7 +390,7 @@ public:
{
}
- void setRoot(Handle<StructuredEntity> root) { root = acquire(root); };
+ void setRoot(Handle<StructuredEntity> root) { this->root = acquire(root); };
Rooted<StructuredEntity> getRoot() const { return root; }
};