summaryrefslogtreecommitdiff
path: root/src/core/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/Document.cpp9
-rw-r--r--src/core/model/Ontology.cpp48
-rw-r--r--src/core/model/Ontology.hpp17
3 files changed, 39 insertions, 35 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index 894330b..411a755 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -93,7 +93,8 @@ bool DocumentEntity::doValidate(Logger &logger) const
* gather all fields of superclasses as well, that have not been
* overridden in the subclasses.
*/
- NodeVector<FieldDescriptor> fieldDescs = descriptor->getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fieldDescs =
+ descriptor->getFieldDescriptors();
// iterate over every field
for (unsigned int f = 0; f < fields.size(); f++) {
// we have a special check for primitive fields.
@@ -137,9 +138,9 @@ bool DocumentEntity::doValidate(Logger &logger) const
std::unordered_set<StructuredClass *> childClasses;
{
- NodeVector<StructuredClass> tmp =
+ ManagedVector<StructuredClass> tmp =
fieldDescs[f]->getChildrenWithSubclasses();
- for (auto s : tmp) {
+ for (const auto &s : tmp) {
childClasses.insert(s.get());
}
}
@@ -999,4 +1000,4 @@ const Rtti AnnotationEntity =
.parent(&Node)
.composedOf({&StructuredEntity, &DocumentPrimitive, &Anchor});
}
-} \ No newline at end of file
+}
diff --git a/src/core/model/Ontology.cpp b/src/core/model/Ontology.cpp
index d63c5e7..89710d3 100644
--- a/src/core/model/Ontology.cpp
+++ b/src/core/model/Ontology.cpp
@@ -67,7 +67,7 @@ static NodeVector<Node> pathTo(const Node *start, Logger &logger,
if (start->isa(&RttiTypes::Descriptor)) {
const Descriptor *desc = static_cast<const Descriptor *>(start);
// initially put every field descriptor on the queue.
- NodeVector<FieldDescriptor> fields = desc->getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fields = desc->getFieldDescriptors();
for (auto fd : fields) {
if (fd == target) {
@@ -115,7 +115,7 @@ static NodeVector<Node> pathTo(const Node *start, Logger &logger,
static_cast<const StructuredClass *>(current->node);
// look through all fields.
- NodeVector<FieldDescriptor> fields = strct->getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fields = strct->getFieldDescriptors();
for (auto fd : fields) {
// if we found our target, break off the search in this branch.
if (fd == target) {
@@ -182,9 +182,9 @@ struct CollectState {
* TODO: @Benjmin Documentation!
*/
template <typename F>
-static NodeVector<Node> collect(const Node *start, F match)
+static ManagedVector<Node> collect(const Node *start, F match)
{
- NodeVector<Node> res;
+ ManagedVector<Node> res;
// Queue and set for breadth-first search of the document graph
std::queue<CollectState> q;
@@ -205,7 +205,7 @@ static NodeVector<Node> collect(const Node *start, F match)
Rooted<Descriptor> strct{static_cast<Descriptor *>(state.n)};
// look through all fields.
- NodeVector<FieldDescriptor> fields = strct->getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fields = strct->getFieldDescriptors();
for (auto fd : fields) {
// Store all matching items
if (match(fd, state.depth)) {
@@ -403,7 +403,7 @@ bool FieldDescriptor::doValidate(Logger &logger) const
static void gatherSubclasses(
std::unordered_set<const StructuredClass *> &visited,
- NodeVector<StructuredClass> &res, Handle<StructuredClass> strct)
+ ManagedVector<StructuredClass> &res, Handle<StructuredClass> strct)
{
// this check is to prevent cycles.
if (!visited.insert(strct.get()).second) {
@@ -419,10 +419,11 @@ static void gatherSubclasses(
}
}
-NodeVector<StructuredClass> FieldDescriptor::getChildrenWithSubclasses() const
+ManagedVector<StructuredClass> FieldDescriptor::getChildrenWithSubclasses()
+ const
{
std::unordered_set<const StructuredClass *> visited;
- NodeVector<StructuredClass> res;
+ ManagedVector<StructuredClass> res;
for (auto c : children) {
res.push_back(c);
gatherSubclasses(visited, res, c);
@@ -455,10 +456,11 @@ NodeVector<Node> FieldDescriptor::pathTo(Handle<FieldDescriptor> field,
bool success = false;
return ousia::pathTo(this, logger, field, success);
}
-NodeVector<FieldDescriptor> FieldDescriptor::getDefaultFields() const
+
+ManagedVector<FieldDescriptor> FieldDescriptor::getDefaultFields() const
{
// TODO: In principle a cast would be nicer here, but for now we copy.
- NodeVector<Node> nodes = collect(this, [](Handle<Node> n, size_t depth) {
+ ManagedVector<Node> nodes = collect(this, [](Handle<Node> n, size_t depth) {
if (!n->isa(&RttiTypes::FieldDescriptor)) {
return false;
}
@@ -466,7 +468,7 @@ NodeVector<FieldDescriptor> FieldDescriptor::getDefaultFields() const
return f->getFieldType() == FieldDescriptor::FieldType::TREE &&
f->isPrimitive();
});
- NodeVector<FieldDescriptor> res;
+ ManagedVector<FieldDescriptor> res;
for (auto n : nodes) {
res.push_back(n.cast<FieldDescriptor>());
}
@@ -584,10 +586,10 @@ std::pair<NodeVector<Node>, bool> Descriptor::pathTo(
return std::make_pair(path, success);
}
-NodeVector<FieldDescriptor> Descriptor::getDefaultFields() const
+ManagedVector<FieldDescriptor> Descriptor::getDefaultFields() const
{
// TODO: In principle a cast would be nicer here, but for now we copy.
- NodeVector<Node> nodes = collect(this, [](Handle<Node> n, size_t depth) {
+ ManagedVector<Node> nodes = collect(this, [](Handle<Node> n, size_t depth) {
if (!n->isa(&RttiTypes::FieldDescriptor)) {
return false;
}
@@ -595,7 +597,7 @@ NodeVector<FieldDescriptor> Descriptor::getDefaultFields() const
return f->getFieldType() == FieldDescriptor::FieldType::TREE &&
f->isPrimitive();
});
- NodeVector<FieldDescriptor> res;
+ ManagedVector<FieldDescriptor> res;
for (auto n : nodes) {
res.push_back(n.cast<FieldDescriptor>());
}
@@ -605,7 +607,7 @@ NodeVector<FieldDescriptor> Descriptor::getDefaultFields() const
NodeVector<StructuredClass> Descriptor::getPermittedChildren() const
{
// TODO: In principle a cast would be nicer here, but for now we copy.
- NodeVector<Node> nodes = collect(this, [](Handle<Node> n, size_t depth) {
+ ManagedVector<Node> nodes = collect(this, [](Handle<Node> n, size_t depth) {
return n->isa(&RttiTypes::StructuredClass);
});
NodeVector<StructuredClass> res;
@@ -615,7 +617,7 @@ NodeVector<StructuredClass> Descriptor::getPermittedChildren() const
return res;
}
-static ssize_t getFieldDescriptorIndex(const NodeVector<FieldDescriptor> &fds,
+static ssize_t getFieldDescriptorIndex(const ManagedVector<FieldDescriptor> &fds,
const std::string &name)
{
if (fds.empty()) {
@@ -644,7 +646,7 @@ static ssize_t getFieldDescriptorIndex(const NodeVector<FieldDescriptor> &fds,
ssize_t Descriptor::getFieldDescriptorIndex(const std::string &name) const
{
- NodeVector<FieldDescriptor> fds = getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fds = getFieldDescriptors();
return ousia::getFieldDescriptorIndex(fds, name);
}
@@ -663,7 +665,7 @@ ssize_t Descriptor::getFieldDescriptorIndex(Handle<FieldDescriptor> fd) const
Rooted<FieldDescriptor> Descriptor::getFieldDescriptor(
const std::string &name) const
{
- NodeVector<FieldDescriptor> fds = getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fds = getFieldDescriptors();
ssize_t idx = ousia::getFieldDescriptorIndex(fds, name);
if (idx != -1) {
return fds[idx];
@@ -673,7 +675,7 @@ Rooted<FieldDescriptor> Descriptor::getFieldDescriptor(
Rooted<FieldDescriptor> Descriptor::getFieldDescriptor(size_t idx) const
{
- NodeVector<FieldDescriptor> fds = getFieldDescriptors();
+ ManagedVector<FieldDescriptor> fds = getFieldDescriptors();
if (idx < fds.size()) {
return fds[idx];
}
@@ -925,7 +927,7 @@ void StructuredClass::removeSubclass(Handle<StructuredClass> sc, Logger &logger)
}
Rooted<FieldDescriptor> StructuredClass::gatherFieldDescriptors(
- NodeVector<FieldDescriptor> &current,
+ ManagedVector<FieldDescriptor> &current,
std::unordered_set<const StructuredClass *> &visited,
std::set<std::string> &overriddenFields, bool hasTREE) const
{
@@ -934,7 +936,7 @@ Rooted<FieldDescriptor> StructuredClass::gatherFieldDescriptors(
return nullptr;
}
Rooted<FieldDescriptor> mainField;
- NodeVector<FieldDescriptor> tmp;
+ ManagedVector<FieldDescriptor> tmp;
// first gather the non-overridden fields.
for (auto f : Descriptor::getFieldDescriptors()) {
if (overriddenFields.insert(f->getName()).second) {
@@ -965,10 +967,10 @@ Rooted<FieldDescriptor> StructuredClass::gatherFieldDescriptors(
return mainField;
}
-NodeVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const
+ManagedVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const
{
// in this case we return a NodeVector of Rooted entries without owner.
- NodeVector<FieldDescriptor> vec;
+ ManagedVector<FieldDescriptor> vec;
std::unordered_set<const StructuredClass *> visited;
std::set<std::string> overriddenFields;
Rooted<FieldDescriptor> mainField =
diff --git a/src/core/model/Ontology.hpp b/src/core/model/Ontology.hpp
index 3ef3b65..2533b9d 100644
--- a/src/core/model/Ontology.hpp
+++ b/src/core/model/Ontology.hpp
@@ -300,7 +300,7 @@ public:
* the Structure Tree of instances of this field including subclasses of
* children, which are allowed directly.
*/
- NodeVector<StructuredClass> getChildrenWithSubclasses() const;
+ ManagedVector<StructuredClass> getChildrenWithSubclasses() const;
/**
* Adds a StructuredClass whose instances shall be allowed as children in
@@ -449,7 +449,7 @@ public:
* @return a vector of all TREE fields that are allowed as structure tree
* children of an instance of this Descriptor.
*/
- NodeVector<FieldDescriptor> getDefaultFields() const;
+ ManagedVector<FieldDescriptor> getDefaultFields() const;
/**
* Returns the name of this FieldDescriptor or the default field name
@@ -643,9 +643,10 @@ public:
*
* @return the NodeVector of all FieldDescriptors of this Descriptor.
*/
- virtual NodeVector<FieldDescriptor> getFieldDescriptors() const
+ virtual ManagedVector<FieldDescriptor> getFieldDescriptors() const
{
- return fieldDescriptors;
+ return ManagedVector<FieldDescriptor>(const_cast<Descriptor*>(this), fieldDescriptors.begin(),
+ fieldDescriptors.end());
}
/**
@@ -856,7 +857,7 @@ public:
* @return a vector of all TREE fields that are allowed as structure tree
* children of an instance of this Descriptor.
*/
- NodeVector<FieldDescriptor> getDefaultFields() const;
+ ManagedVector<FieldDescriptor> getDefaultFields() const;
/**
* Returns a vector of all StructuredClasses that are allowed as children
@@ -1035,7 +1036,7 @@ private:
* Helper method for getFieldDescriptors.
*/
Rooted<FieldDescriptor> gatherFieldDescriptors(
- NodeVector<FieldDescriptor> &current,
+ ManagedVector<FieldDescriptor> &current,
std::unordered_set<const StructuredClass *> &visited,
std::set<std::string> &overriddenFields, bool hasTREE) const;
@@ -1170,7 +1171,7 @@ public:
*
* @return a NodeVector of all FieldDescriptors of this StructuredClass.
*/
- NodeVector<FieldDescriptor> getFieldDescriptors() const override;
+ ManagedVector<FieldDescriptor> getFieldDescriptors() const override;
bool isTransparent() const { return transparent; }
@@ -1483,4 +1484,4 @@ extern const Rtti Ontology;
}
}
-#endif /* _OUSIA_MODEL_ONTOLOGY_HPP_ */ \ No newline at end of file
+#endif /* _OUSIA_MODEL_ONTOLOGY_HPP_ */