summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-02 15:11:34 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-02 15:11:34 +0100
commit66e9838c47b58810cb0bb6c67c32fb119eb50797 (patch)
treecb2fff77f6e45e41708e33c8c10c9cb7f206364e /src/core
parent19d1eeba6ad3637e0e108fe177874b5509a7988b (diff)
Importing files works now
Diffstat (limited to 'src/core')
-rw-r--r--src/core/model/Document.cpp14
-rw-r--r--src/core/model/Document.hpp10
-rw-r--r--src/core/model/Domain.cpp14
-rw-r--r--src/core/model/Domain.hpp8
-rw-r--r--src/core/model/Project.cpp18
-rw-r--r--src/core/model/Project.hpp11
-rw-r--r--src/core/model/RootNode.cpp10
-rw-r--r--src/core/model/RootNode.hpp21
-rw-r--r--src/core/model/Typesystem.cpp14
-rw-r--r--src/core/model/Typesystem.hpp8
-rw-r--r--src/core/resource/ResourceRequest.cpp14
11 files changed, 103 insertions, 39 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index f452695..8c87cfe 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -653,6 +653,18 @@ bool Document::doValidate(Logger &logger) const
return valid & continueValidation(annotations, logger);
}
+void Document::doReference(Handle<Node> node)
+{
+ if (node->isa(RttiTypes::Domain)) {
+ referenceDomain(node.cast<Domain>());
+ }
+}
+
+RttiSet Document::doGetReferenceTypes() const
+{
+ return RttiSet{&RttiTypes::Domain};
+}
+
Rooted<StructuredEntity> Document::createRootStructuredEntity(
Handle<StructuredClass> descriptor, Variant attributes, std::string name)
{
@@ -723,7 +735,7 @@ bool Document::hasChild(Handle<StructureNode> s) const
/* Type registrations */
namespace RttiTypes {
const Rtti Document = RttiBuilder<ousia::Document>("Document")
- .parent(&Node)
+ .parent(&RootNode)
.composedOf({&AnnotationEntity, &StructuredEntity});
const Rtti StructureNode =
RttiBuilder<ousia::StructureNode>("StructureNode").parent(&Node);
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index dcb8966..ad8cbca 100644
--- a/src/core/model/Document.hpp
+++ b/src/core/model/Document.hpp
@@ -115,6 +115,7 @@
#include "Node.hpp"
#include "Domain.hpp"
+#include "RootNode.hpp"
#include "Typesystem.hpp"
namespace ousia {
@@ -719,17 +720,18 @@ public:
* Graph. It also references the domains that have been used within this
* document and the AnnotationEntities that span over Anchors in this Document.
*/
-class Document : public Node {
+class Document : public RootNode {
private:
// TODO: Might there be several roots? E.g. metadata?
Owned<StructuredEntity> root;
NodeVector<AnnotationEntity> annotations;
NodeVector<Domain> domains;
- void doResolve(ResolutionState &state) override;
-
protected:
+ void doResolve(ResolutionState &state) override;
bool doValidate(Logger &logger) const override;
+ void doReference(Handle<Node> node) override;
+ RttiSet doGetReferenceTypes() const override;
public:
/**
@@ -739,7 +741,7 @@ public:
* @param name is a name for this Document.
*/
Document(Manager &mgr, std::string name)
- : Node(mgr, std::move(name), nullptr), annotations(this)
+ : RootNode(mgr, std::move(name), nullptr), annotations(this)
{
}
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp
index 360aa83..ef505dd 100644
--- a/src/core/model/Domain.cpp
+++ b/src/core/model/Domain.cpp
@@ -469,6 +469,18 @@ bool Domain::doValidate(Logger &logger) const
continueValidationCheckDuplicates(typesystems, logger);
}
+void Domain::doReference(Handle<Node> node)
+{
+ if (node->isa(RttiTypes::Domain)) {
+ referenceTypesystem(node.cast<Typesystem>());
+ }
+}
+
+RttiSet Domain::doGetReferenceTypes() const
+{
+ return RttiSet{&RttiTypes::Domain};
+}
+
void Domain::addStructuredClass(Handle<StructuredClass> s)
{
// only add it if we need to.
@@ -559,7 +571,7 @@ const Rtti StructuredClass =
const Rtti AnnotationClass =
RttiBuilder<ousia::AnnotationClass>("AnnotationClass").parent(&Descriptor);
const Rtti Domain = RttiBuilder<ousia::Domain>("Domain")
- .parent(&Node)
+ .parent(&RootNode)
.composedOf({&StructuredClass, &AnnotationClass});
}
}
diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp
index 7704d36..6648551 100644
--- a/src/core/model/Domain.hpp
+++ b/src/core/model/Domain.hpp
@@ -206,6 +206,7 @@
#include <core/RangeSet.hpp>
#include "Node.hpp"
+#include "RootNode.hpp"
#include "Typesystem.hpp"
namespace ousia {
@@ -879,7 +880,7 @@ public:
* are part of this domain. TODO: Do we want to be able to restrict Annotations
* to certain Structures?
*/
-class Domain : public Node {
+class Domain : public RootNode {
friend StructuredClass;
friend AnnotationClass;
@@ -890,8 +891,9 @@ private:
protected:
void doResolve(ResolutionState &state) override;
-
bool doValidate(Logger &logger) const override;
+ void doReference(Handle<Node> node) override;
+ RttiSet doGetReferenceTypes() const override;
public:
/**
@@ -903,7 +905,7 @@ public:
* references to this Domain.
*/
Domain(Manager &mgr, std::string name = "")
- : Node(mgr, std::move(name), nullptr),
+ : RootNode(mgr, std::move(name), nullptr),
structuredClasses(this),
annotationClasses(this),
typesystems(this)
diff --git a/src/core/model/Project.cpp b/src/core/model/Project.cpp
index b355969..31530f3 100644
--- a/src/core/model/Project.cpp
+++ b/src/core/model/Project.cpp
@@ -26,7 +26,7 @@
namespace ousia {
Project::Project(Manager &mgr)
- : Node(mgr),
+ : RootNode(mgr),
systemTypesystem(acquire(new SystemTypesystem(mgr))),
documents(this)
{
@@ -41,6 +41,16 @@ void Project::doResolve(ResolutionState &state){
continueResolveComposita(documents, documents.getIndex(), state);
}
+void Project::doReference(Handle<Node> node) {
+ if (node->isa(RttiTypes::Document)) {
+ referenceDocument(node.cast<Document>());
+ }
+}
+
+RttiSet Project::doGetReferenceTypes() const {
+ return RttiSet{&RttiTypes::Document};
+}
+
Rooted<SystemTypesystem> Project::getSystemTypesystem()
{
return systemTypesystem;
@@ -55,7 +65,7 @@ Rooted<Typesystem> Project::createTypesystem(const std::string &name)
Rooted<Document> Project::createDocument(const std::string &name)
{
Rooted<Document> document{new Document(getManager(), name)};
- addDocument(document);
+ referenceDocument(document);
return document;
}
@@ -64,7 +74,7 @@ Rooted<Domain> Project::createDomain(const std::string &name)
return Rooted<Domain>{new Domain(getManager(), systemTypesystem, name)};
}
-void Project::addDocument(Handle<Document> document)
+void Project::referenceDocument(Handle<Document> document)
{
invalidate();
documents.push_back(document);
@@ -74,7 +84,7 @@ const NodeVector<Document> &Project::getDocuments() const { return documents; }
namespace RttiTypes {
const Rtti Project = RttiBuilder<ousia::Project>("Project")
- .parent(&Node)
+ .parent(&RootNode)
.composedOf(&Document)
.composedOf(&SystemTypesystem);
}
diff --git a/src/core/model/Project.hpp b/src/core/model/Project.hpp
index 9b81058..480609c 100644
--- a/src/core/model/Project.hpp
+++ b/src/core/model/Project.hpp
@@ -28,13 +28,14 @@
#ifndef _OUSIA_PROJECT_HPP_
#define _OUSIA_PROJECT_HPP_
-#include "Node.hpp"
+#include <core/common/Rtti.hpp>
+
+#include "RootNode.hpp"
namespace ousia {
// Forward declarations
class Logger;
-class Rtti;
class Registry;
class SystemTypesystem;
class Typesystem;
@@ -46,7 +47,7 @@ class Domain;
* documents are stored. It also contains an instance of the SystemTypesystem
* and allows for simple creation of new Typesystem and Domain instances.
*/
-class Project : public Node {
+class Project : public RootNode {
private:
/**
* Private instance of the system typesystem which is distributed as a
@@ -62,6 +63,8 @@ private:
protected:
bool doValidate(Logger &loger) const override;
void doResolve(ResolutionState &state) override;
+ void doReference(Handle<Node> node) override;
+ RttiSet doGetReferenceTypes() const override;
public:
/**
@@ -108,7 +111,7 @@ public:
*
* @param document is the document that should be added to the project.
*/
- void addDocument(Handle<Document> document);
+ void referenceDocument(Handle<Document> document);
/**
* Returns all documents of this project.
diff --git a/src/core/model/RootNode.cpp b/src/core/model/RootNode.cpp
index fa05c36..821c50c 100644
--- a/src/core/model/RootNode.cpp
+++ b/src/core/model/RootNode.cpp
@@ -22,17 +22,17 @@
namespace ousia {
-void RootNode::import(Handle<Node> node)
+void RootNode::reference(Handle<Node> node)
{
- if (!node->type().isOneOf(doGetImportTypes())) {
+ if (!node->type().isOneOf(getReferenceTypes())) {
throw OusiaException(
std::string("Node with type ") + node->type().name +
- std::string(" cannot be imported in a ") + type().name);
+ std::string(" cannot be referenced in a ") + type().name);
}
- doImport(node);
+ doReference(node);
}
-RttiSet RootNode::getImportTypes() { return doGetImportTypes(); }
+RttiSet RootNode::getReferenceTypes() const { return doGetReferenceTypes(); }
namespace RttiTypes {
const Rtti RootNode = RttiBuilder<ousia::RootNode>("RootNode").parent(&Node);
diff --git a/src/core/model/RootNode.hpp b/src/core/model/RootNode.hpp
index 1ed72f1..173a6e4 100644
--- a/src/core/model/RootNode.hpp
+++ b/src/core/model/RootNode.hpp
@@ -28,6 +28,9 @@
#ifndef _OUSIA_ROOT_NODE_HPP_
#define _OUSIA_ROOT_NODE_HPP_
+#include <core/managed/Managed.hpp>
+#include <core/common/Rtti.hpp>
+
#include "Node.hpp"
namespace ousia {
@@ -43,16 +46,16 @@ protected:
* Imports the given node. The node was checked to be one of the supported
* types.
*
- * @param node is the node that should be imported.
+ * @param node is the node that should be referenced.
*/
- virtual void doImport(Handle<Node> node) = 0;
+ virtual void doReference(Handle<Node> node) = 0;
/**
- * Should return a set of types that can be imported by this Node.
+ * Should return a set of types that can be referenced by this Node.
*
- * @return a set of Node types that may be imported by this Node.
+ * @return a set of Node types that may be referenced by this Node.
*/
- virtual RttiSet doGetImportTypes() = 0;
+ virtual RttiSet doGetReferenceTypes() const = 0;
public:
using Node::Node;
@@ -63,14 +66,14 @@ public:
*
* @param node is the node that should be imported.
*/
- void import(Handle<Node> node);
+ void reference(Handle<Node> node);
/**
- * Returns a set of types that can be imported by this Node.
+ * Returns a set of types that can be referenced by this Node.
*
- * @return a set of types that can be imported.
+ * @return a set of types that can be referenced.
*/
- RttiSet getImportTypes();
+ RttiSet getReferenceTypes() const;
};
namespace RttiTypes {
diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp
index dc6df63..1711129 100644
--- a/src/core/model/Typesystem.cpp
+++ b/src/core/model/Typesystem.cpp
@@ -633,6 +633,18 @@ bool Typesystem::doValidate(Logger &logger) const
continueValidationCheckDuplicates(types, logger);
}
+void Typesystem::doReference(Handle<Node> node)
+{
+ if (node->isa(RttiTypes::Typesystem)) {
+ referenceTypesystem(node.cast<Typesystem>());
+ }
+}
+
+RttiSet Typesystem::doGetReferenceTypes() const
+{
+ return RttiSet{&RttiTypes::Typesystem};
+}
+
Rooted<StructType> Typesystem::createStructType(const std::string &name)
{
Rooted<StructType> structType{new StructType(getManager(), name, this)};
@@ -688,7 +700,7 @@ const Rtti UnknownType =
const Rtti Constant = RttiBuilder<ousia::Constant>("Constant").parent(&Node);
const Rtti Attribute = RttiBuilder<ousia::Attribute>("Attribute").parent(&Node);
const Rtti Typesystem =
- RttiBuilder<ousia::Typesystem>("Typesystem").parent(&Node).composedOf(
+ RttiBuilder<ousia::Typesystem>("Typesystem").parent(&RootNode).composedOf(
{&StringType, &IntType, &DoubleType, &BoolType, &EnumType, &StructType,
&Constant});
const Rtti SystemTypesystem = RttiBuilder<ousia::SystemTypesystem>(
diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp
index 9d85d80..b14ff62 100644
--- a/src/core/model/Typesystem.hpp
+++ b/src/core/model/Typesystem.hpp
@@ -38,6 +38,7 @@
#include <core/common/Variant.hpp>
#include "Node.hpp"
+#include "RootNode.hpp"
namespace ousia {
@@ -1025,7 +1026,7 @@ public:
/**
* The Typesystem class represents a collection of types and constants.
*/
-class Typesystem : public Node {
+class Typesystem : public RootNode {
private:
/**
* List containing all types.
@@ -1044,8 +1045,9 @@ private:
protected:
void doResolve(ResolutionState &state) override;
-
bool doValidate(Logger &logger) const override;
+ void doReference(Handle<Node> node) override;
+ RttiSet doGetReferenceTypes() const override;
public:
/**
@@ -1055,7 +1057,7 @@ public:
* @param name is the name of the typesystem.
*/
Typesystem(Manager &mgr, std::string name)
- : Node(mgr, std::move(name)),
+ : RootNode(mgr, std::move(name)),
types(this),
constants(this),
typesystems(this)
diff --git a/src/core/resource/ResourceRequest.cpp b/src/core/resource/ResourceRequest.cpp
index f820bc3..41aec75 100644
--- a/src/core/resource/ResourceRequest.cpp
+++ b/src/core/resource/ResourceRequest.cpp
@@ -146,6 +146,12 @@ bool ResourceRequest::deduce(Registry &registry, Logger &logger)
{
bool ok = true;
+ // Make sure the given file name is not empty
+ if (path.empty()) {
+ logger.error("Filename may not be empty");
+ return false;
+ }
+
// Try to deduce the mimetype if none was given
if (mimetype.empty()) {
mimetype = registry.getMimetypeForFilename(path);
@@ -206,10 +212,10 @@ bool ResourceRequest::deduce(Registry &registry, Logger &logger)
if (resourceType != ResourceType::UNKNOWN) {
supportedTypes = limitSupportedTypes(resourceType, supportedTypes);
if (supportedTypes.empty()) {
- logger.error(
- std::string("File of type \"") + mimetype +
- std::string("\" cannot be included with relationship ") +
- Resource::getResourceTypeName(resourceType));
+ logger.error(std::string("Resource of type \"") + mimetype +
+ std::string("\" and relationship \"") +
+ Resource::getResourceTypeName(resourceType) +
+ std::string("\" cannot be included here"));
ok = false;
}
} else {