From fce5cce5fdc7bd265eb023dfc0fc1accbe5a796e Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 4 Feb 2015 20:20:02 +0100 Subject: set non-empty default field name. --- src/core/model/Document.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'src/core/model/Document.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 8c87cfe..f27da1d 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -34,31 +34,15 @@ int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName, const NodeVector &fds = descriptor->getFieldDescriptors(); unsigned int f = 0; - // look if we have an empty name. - if (fieldName == "") { - // in that case we look for a default field. - // First: Do we only have one field? - if (fds.size() == 1) { - // if so we return that one. + // otherwise we return the FieldDescriptor with the correct name (if + // such a descriptor exists). + for (auto &fd : fds) { + if (fd->getName() == fieldName) { return f; } - // Second: Do we have a TREE field? - for (auto &fd : fds) { - if (fd->getFieldType() == FieldDescriptor::FieldType::TREE) { - return f; - } - f++; - } - } else { - // otherwise we return the FieldDescriptor with the correct name (if - // such a descriptor exists). - for (auto &fd : fds) { - if (fd->getName() == fieldName) { - return f; - } - f++; - } + f++; } + if (enforce) { throw OusiaException(std::string("\"") + descriptor->getName() + "\" has no field with name \"" + fieldName + "\""); -- cgit v1.2.3