diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-09 17:30:06 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-09 17:30:06 +0100 |
commit | eb864f65356468a023abe9462a1aa5805d3ee5ef (patch) | |
tree | 6ddd44cd0e6b3621aa0b1d4fdf7d4bc4c53991c1 /src | |
parent | 85a4bb306a648964ddbf166e88e3263ace293768 (diff) | |
parent | fbaad57be8ddf3f90eb13551cc7eb18674b3efa2 (diff) |
Merge branch 'master' of somweyr.de:ousia
Diffstat (limited to 'src')
-rw-r--r-- | src/core/model/Domain.cpp | 11 | ||||
-rw-r--r-- | src/core/model/Domain.hpp | 10 | ||||
-rw-r--r-- | src/plugins/xml/XmlParser.cpp | 31 |
3 files changed, 44 insertions, 8 deletions
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 20a9d42..806b9b8 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -265,6 +265,17 @@ ssize_t Descriptor::getFieldDescriptorIndex(Handle<FieldDescriptor> fd) const return -1; } +Rooted<FieldDescriptor> Descriptor::getFieldDescriptor( + const std::string &name) const +{ + for (auto &fd : getFieldDescriptors()) { + if (fd->getName() == name) { + return fd; + } + } + return nullptr; +} + void Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd) { // only add it if we need to. diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index db3b9e6..24199b1 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -515,6 +515,16 @@ public: * FieldDescriptor is not registered at this Descriptor. */ ssize_t getFieldDescriptorIndex(Handle<FieldDescriptor> fd) const; + /** + * Returns the FieldDescriptor with the given name. + * + * @param name the name of a FieldDescriptor. + + * @return the FieldDescriptor with the given name or a nullptr if no + * such FieldDescriptor was found. + */ + Rooted<FieldDescriptor> getFieldDescriptor( + const std::string &name = DEFAULT_FIELD_NAME) const; /** * This returns true if this Descriptor has a FieldDescriptor with the diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index 6d77138..c46d9de 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -132,6 +132,7 @@ public: // try to find a FieldDescriptor for the given tag if we are not in a // field already. + // TODO: Consider fields of transparent classes if (!inField && parent != nullptr && parent->getDescriptor()->hasField(name())) { Rooted<DocumentField> field{new DocumentField( @@ -151,17 +152,37 @@ public: std::string("\"") + name() + "\" could not be resolved.", location()); } + std::string name; auto it = args.find("name"); if (it != args.end()) { name = it->second.asString(); args.erase(it); } + Rooted<StructuredEntity> entity; if (parentNode->isa(&RttiTypes::Document)) { entity = parentNode.cast<Document>()->createRootStructuredEntity( strct, args, name); } else { + // calculate a path if transparent entities are needed in between. + auto path = parent->getDescriptor()->pathTo(strct); + if (path.empty()) { + throw LoggableException( + std::string("An instance of \"") + strct->getName() + + "\" is not allowed as child of an instance of \"" + + parent->getDescriptor()->getName() + "\"", + location()); + } + + // create all transparent entities until the last field. + for (size_t p = 1; p < path.size() - 1; p = p + 2) { + parent = static_cast<DocumentEntity *>( + parent->createChildStructuredEntity( + path[p].cast<StructuredClass>(), + Variant::mapType{}, path[p - 1]->getName(), + "").get()); + } entity = parent->createChildStructuredEntity(strct, args, fieldName, name); } @@ -184,15 +205,9 @@ public: preamble(parentNode, fieldName, parent, inField); // retrieve the correct FieldDescriptor. + // TODO: Consider fields of transparent classes Rooted<Descriptor> desc = parent->getDescriptor(); - Rooted<FieldDescriptor> field = nullptr; - // TODO: Use more convenient mechanism once possible. - for (auto &fd : desc->getFieldDescriptors()) { - if (fd->getName() == fieldName) { - field = fd; - break; - } - } + Rooted<FieldDescriptor> field = desc->getFieldDescriptor(fieldName); if (field == nullptr) { logger().error( std::string("Can't handle data because no field with name \"") + |