From 9216a4eb4e2af997444cb7b7c3e4938b91edc4d9 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sat, 14 Feb 2015 00:09:14 +0100 Subject: added DocumentEntity::getField with direct indexation. --- src/core/model/Document.cpp | 15 +++++++++++++-- src/core/model/Document.hpp | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index b38f2c0..a2ba5cf 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -306,6 +306,18 @@ const NodeVector &DocumentEntity::getField( return fields[enforceGetFieldDescriptorIndex(descriptor, fieldDescriptor)]; } +const NodeVector &DocumentEntity::getField( + const size_t &idx) const +{ + if (idx >= fields.size()) { + throw OusiaException(std::string("Descriptor \"") + + descriptor->getName() + + "\" does not have enough fields for index \"" + + std::to_string(idx) + "\"."); + } + return fields[idx]; +} + void DocumentEntity::addStructureNode(Handle s, const int &i) { // only add the new node if we don't have it already. @@ -813,5 +825,4 @@ const Rtti AnnotationEntity = .parent(&Node) .composedOf({&StructuredEntity, &DocumentPrimitive, &Anchor}); } -} - +} \ No newline at end of file diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index bffd397..5f06eb0 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -236,6 +236,18 @@ public: const NodeVector &getField( Handle fieldDescriptor) const; + /** + * This returns the vector of entities containing all members of the field + * with the given index. + * + * If the index is out of bounds an exception is thrown. + * + * @param idx is the index of a field as specified in the + * FieldDescriptor in the Domain description. + * @return a NodeVector of all StructuredEntities in that field. + */ + const NodeVector &getField(const size_t& idx ) const; + /** * This adds a StructureNode to the field with the given index. * -- cgit v1.2.3