diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-04 20:20:02 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-04 20:20:02 +0100 |
commit | fce5cce5fdc7bd265eb023dfc0fc1accbe5a796e (patch) | |
tree | c745b76fc01ff7fa8c38c5810682c8878ade1fc1 /src/core/model/Document.cpp | |
parent | e76f58e912bd6661ba755d27da97bebf711f06ad (diff) |
set non-empty default field name.
Diffstat (limited to 'src/core/model/Document.cpp')
-rw-r--r-- | src/core/model/Document.cpp | 28 |
1 files changed, 6 insertions, 22 deletions
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<FieldDescriptor> &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 + "\""); |