// Copyright (c) 2014-2021 Thomas Fussell // Copyright (c) 2010-2015 openpyxl // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include #include #include #include #include namespace xlnt { /// /// The manifest keeps track of all files in the OOXML package and /// their type and relationships. /// class XLNT_API manifest { public: /// /// Unregisters all default and override type and all relationships and known parts. /// void clear(); /// /// Returns the path to all internal package parts registered as a source /// or target of a relationship. /// std::vector parts() const; // Relationships /// /// Returns true if the manifest contains a relationship with the given type with part as the source. /// bool has_relationship(const path &source, relationship_type type) const; /// /// Returns true if the manifest contains a relationship with the given type with part as the source. /// bool has_relationship(const path &source, const std::string &rel_id) const; /// /// Returns the relationship with "source" as the source and with a type of "type". /// Throws a key_not_found exception if no such relationship is found. /// class relationship relationship(const path &source, relationship_type type) const; /// /// Returns the relationship with "source" as the source and with an ID of "rel_id". /// Throws a key_not_found exception if no such relationship is found. /// class relationship relationship(const path &source, const std::string &rel_id) const; /// /// Returns all relationship with "source" as the source. /// std::vector relationships(const path &source) const; /// /// Returns all relationships with "source" as the source and with a type of "type". /// std::vector relationships(const path &source, relationship_type type) const; /// /// Returns the canonical path of the chain of relationships by traversing through rels /// and forming the absolute combined path. /// path canonicalize(const std::vector &rels) const; /// /// Registers a new relationship by specifying all of the relationship properties explicitly. /// std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode); /// /// Registers a new relationship already constructed elsewhere. /// std::string register_relationship(const class relationship &rel); /// /// Delete the relationship with the given id from source part. Returns a mapping /// of relationship IDs since IDs are shifted down. For example, if there are three /// relationships for part a.xml like [rId1, rId2, rId3] and rId2 is deleted, the /// resulting map would look like [rId3->rId2]. /// std::unordered_map unregister_relationship(const uri &source, const std::string &rel_id); // Content Types /// /// Given the path to a part, returns the content type of the part as a string. /// std::string content_type(const path &part) const; // Default Content Types /// /// Returns true if a default content type for the extension has been registered. /// bool has_default_type(const std::string &extension) const; /// /// Returns a vector of all extensions with registered default content types. /// std::vector extensions_with_default_types() const; /// /// Returns the registered default content type for parts of the given extension. /// std::string default_type(const std::string &extension) const; /// /// Associates the given extension with the given content type. /// void register_default_type(const std::string &extension, const std::string &type); /// /// Unregisters the default content type for the given extension. /// void unregister_default_type(const std::string &extension); // Override Content Types /// /// Returns true if a content type overriding the default content type has been registered /// for the given part. /// bool has_override_type(const path &part) const; /// /// Returns the override content type registered for the given part. /// Throws key_not_found exception if no override type was found. /// std::string override_type(const path &part) const; /// /// Returns the path of every part in this manifest with an overriden content type. /// std::vector parts_with_overriden_types() const; /// /// Overrides any default type registered for the part's extension with the given content type. /// void register_override_type(const path &part, const std::string &type); /// /// Unregisters the overriding content type of the given part. /// void unregister_override_type(const path &part); bool operator==(const manifest &other) const; private: /// /// Returns the lowest rId for the given part that hasn't already been registered. /// std::string next_relationship_id(const path &part) const; /// /// The map of extensions to default content types. /// std::unordered_map default_content_types_; /// /// The map of package parts to overriding content types. /// std::unordered_map override_content_types_; /// /// The map of package parts to their registered relationships. /// std::unordered_map> relationships_; }; } // namespace xlnt