diff options
Diffstat (limited to 'src/core/resource/Resource.hpp')
-rw-r--r-- | src/core/resource/Resource.hpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/core/resource/Resource.hpp b/src/core/resource/Resource.hpp index 9df851d..1934029 100644 --- a/src/core/resource/Resource.hpp +++ b/src/core/resource/Resource.hpp @@ -22,15 +22,159 @@ * Contains the Resource class, representing an external resource as well as * further types used for describing resources. * + * @author Benjamin Paaßen (bpassen@techfak.uni-bielefeld.de) */ #ifndef _OUSIA_RESOURCE_HPP_ #define _OUSIA_RESOURCE_HPP_ +#include <map> +#include <memory> +#include <string> + namespace ousia { +// Forward declaration +class ResourceLocator; + +/** + * This enum contains all possible types of includable resources in Ousía. + */ +enum class ResourceType { + /** + * Unknown type. + */ + UNKNOWN, + + /** + * The resource contains a domain description. + */ + DOMAIN_DESC, + + /** + * The resource contains a typesystem description. + */ + TYPESYSTEM, + + /** + * The resource contains a simple document. + */ + DOCUMENT, + /** + * The resource contains style attributes. + */ + ATTRIBUTES, + + /** + * The resource is a stylesheet. + */ + STYLESHEET, + + /** + * The resource contains script (note that the actual scripting language is + * not specified by the resource type). + */ + SCRIPT, + + /** + * Generic data, such as e.g. images. + */ + DATA +}; + +/** + * A Location contains the location of a Resource, e.g. a file path + * on a hard drive. Note that the 'found' flag might be set to false + * indicating that a resource was not found. + */ +class Resource { +private: + /** + * Specifies whether the resource points at a valid location or not. + */ + bool valid; + /** + * Reference pointing at the location + */ + ResourceLocator const *locator; + + /** + * Requested type of the resource. + */ + ResourceType type; + + /** + * This is a fully qualified/canonical path to the resource found or + * in an undefined state (possibly empty) if the 'valid' flag is set + * to 'false'. + */ + std::string location; + +public: + /** + * Default constructor of the Resource class, represents an invalid + * resource. + */ + Resource(); + + /** + * Constructor of the Resource class. + * + * @param valid specifies whether the Resource is valid or not. + * @param locator specifies the resource locator that was used to locate the + * resource. + */ + Resource(bool valid, const ResourceLocator &locator, + ResourceType type, const std::string &location); + + /** + * This calls the 'stream' method of the underlying ResourceLocator that + * found this location and returns a stream containing the data of the + * Resource at this location. + * + * @return a stream containing the data of the Resource at this + * location. This has to be a unique_pointer because the current + * C++11 compiler does not yet support move semantics for + * streams. + */ + std::unique_ptr<std::istream> stream() const; + + /** + * Returns whether this resource is valid or not. + * + * @return true if the resource is valid, false otherwise. + */ + bool isValid() const { return valid; } + + /** + * Returns a reference pointing at the locator that was used to locate this + * resource. + * + * @return the locator used for locating this resource. + */ + const ResourceLocator &getLocator() const { return *locator; } + + /** + * Returns the type of the resource that was requested when the resource was + * located. + * + * @return the type of the resource. + */ + ResourceType getType() const { return type; } + + /** + * Returns a canonical location that can be used in a hash map to identify + * a resource. + */ + const std::string &getLocation() const { return location; } +}; + +/** + * Invalid resource instance. + */ +extern const Resource NullResource; } #endif /* _OUSIA_RESOURCE_HPP_ */ |