From 60d9d3f9f54fab975c39d4c341f118df90628375 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Mon, 12 Jan 2015 13:42:10 +0100 Subject: normalized NodeVector access in model classes and added some more documentation to model classes. --- src/core/model/Document.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/core/model/Document.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index bed65c9..f591095 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -26,7 +26,8 @@ namespace model { /* Class DocumentEntity */ -int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName) +int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName, + bool enforce) const { const NodeVector &fds = descriptor->getFieldDescriptors(); unsigned int f = 0; @@ -56,21 +57,15 @@ int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName) f++; } } - return -1; -} - -NodeVector &DocumentEntity::getField( - const std::string &fieldName) -{ - int f = getFieldDescriptorIndex(fieldName); - if (f < 0) { + if (enforce) { throw OusiaException("No field for the given name exists!"); + } else { + return -1; } - return fields[f]; } -NodeVector &DocumentEntity::getField( - Handle fieldDescriptor) +int DocumentEntity::getFieldDescriptorIndex( + Handle fieldDescriptor, bool enforce) const { if (fieldDescriptor.isNull()) { throw OusiaException("The given FieldDescriptor handle is null!"); @@ -80,13 +75,18 @@ NodeVector &DocumentEntity::getField( for (auto &fd : fds) { if (fd->getName() == fieldDescriptor->getName() && fd->getFieldType() == fieldDescriptor->getFieldType()) { - return fields[f]; + return f; } f++; } - throw OusiaException( - "The given FieldDescriptor is not specified in the Descriptor of this " - "node."); + if (enforce) { + throw OusiaException( + "The given FieldDescriptor is not specified in the Descriptor of " + "this " + "node."); + } else { + return -1; + } } /* Class Document */ -- cgit v1.2.3