Program Listing for File IRIFactory.hpp¶
↰ Return to documentation for file (src/rdf4cpp/IRIFactory.hpp)
#ifndef RDF4CPP_IRIFACTORY_HPP
#define RDF4CPP_IRIFACTORY_HPP
#include <string>
#include <string_view>
#include <boost/container/flat_map.hpp>
#include <rdf4cpp/IRI.hpp>
#include <rdf4cpp/Expected.hpp>
#include <rdf4cpp/IRIView.hpp>
namespace rdf4cpp {
struct IRIFactory {
using prefix_map_type = boost::container::flat_map<std::string, std::string, std::less<>>;
private:
prefix_map_type prefixes;
std::string base;
IRIView::AllParts base_parts_cache;
public:
constexpr static std::string_view default_base = "http://example.org/";
explicit IRIFactory(std::string_view base = default_base);
explicit IRIFactory(prefix_map_type &&prefixes, std::string_view base = default_base);
IRIFactory(IRIFactory &&) noexcept = default;
IRIFactory &operator=(IRIFactory &&) noexcept = default;
// provide only const iterators to ensure that no key/values will be changed
using const_iterator = prefix_map_type::const_iterator;
using const_reverse_iterator = prefix_map_type::const_reverse_iterator;
[[nodiscard]] const_iterator begin() const noexcept { return prefixes.begin(); }
[[nodiscard]] const_iterator end() const noexcept { return prefixes.end(); }
[[nodiscard]] const_reverse_iterator rbegin() const noexcept { return prefixes.rbegin(); }
[[nodiscard]] const_reverse_iterator rend() const noexcept { return prefixes.rend(); }
[[nodiscard]] nonstd::expected<IRI, IRIFactoryError> from_relative(std::string_view rel, storage::DynNodeStoragePtr node_storage = storage::default_node_storage) const noexcept;
[[nodiscard]] nonstd::expected<IRI, IRIFactoryError> from_maybe_relative(std::string_view rel, storage::DynNodeStoragePtr node_storage = storage::default_node_storage) const noexcept;
[[nodiscard]] nonstd::expected<IRI, IRIFactoryError> from_prefix(std::string_view prefix, std::string_view local, storage::DynNodeStoragePtr node_storage = storage::default_node_storage) const;
[[nodiscard]] IRIFactoryError assign_prefix(std::string_view prefix, std::string_view expanded);
void assign_prefix_unchecked(std::string_view prefix, std::string_view expanded);
void clear_prefix(std::string_view prefix);
[[nodiscard]] std::string_view get_base() const noexcept;
[[nodiscard]] IRIFactoryError set_base(std::string_view b) noexcept;
void set_base_unchecked(std::string_view b) noexcept;
[[nodiscard]] static nonstd::expected<IRI, IRIFactoryError> create_and_validate(std::string_view iri, storage::DynNodeStoragePtr node_storage = storage::default_node_storage) noexcept;
};
} // namespace rdf4cpp
#endif //RDF4CPP_IRIFACTORY_HPP