Program Listing for File RDFFileParser.hpp

Return to documentation for file (src/rdf4cpp/parser/RDFFileParser.hpp)

#ifndef RDF4CPP_RDFFILEPARSER_HPP
#define RDF4CPP_RDFFILEPARSER_HPP

#include <cstdio>
#include <rdf4cpp/parser/IStreamQuadIterator.hpp>

namespace rdf4cpp::parser {
struct RDFFileParser {
    using value_type = Quad;
    using state_type = IStreamQuadIterator::state_type;
    using flags_type = IStreamQuadIterator::flags_type;

private:
    std::string file_path_;
    flags_type flags_;
    state_type *state_;

public:
    explicit RDFFileParser(const std::string &file_path,
                           flags_type flags = flags_type::none(),
                           state_type *state = nullptr);

    explicit RDFFileParser(std::string &&file_path,
                           flags_type flags = flags_type::none(),
                           state_type *state = nullptr);

    struct iterator {
        friend struct RDFFileParser;

    private:
        friend bool operator==(const RDFFileParser::iterator &iter, std::default_sentinel_t) noexcept;
        FILE *stream_;
        std::unique_ptr<IStreamQuadIterator> iter_;

        iterator();
        iterator(FILE *&&stream, flags_type flags, state_type *state);

    public:
        ~iterator() noexcept;

        using value_type = IStreamQuadIterator::value_type;
        using reference = IStreamQuadIterator::reference;
        using pointer = IStreamQuadIterator::pointer;
        using difference_type = IStreamQuadIterator::difference_type;
        using iterator_category = IStreamQuadIterator::iterator_category;
        using istream_type = IStreamQuadIterator::istream_type;

        reference operator*() const noexcept;
        pointer operator->() const noexcept;
        iterator &operator++();
        [[nodiscard]] bool operator==(const iterator &other) const noexcept;
        // != gets generated by compiler
    };

    using sentinel = std::default_sentinel_t;

    [[nodiscard]] iterator begin() const;
    [[nodiscard]] sentinel end() const noexcept;
};

[[nodiscard]] bool operator==(const RDFFileParser::iterator &iter, std::default_sentinel_t s) noexcept;
[[nodiscard]] bool operator==(std::default_sentinel_t s, const RDFFileParser::iterator &iter) noexcept;

}  // namespace rdf4cpp::parser

#endif  //RDF4CPP_RDFFILEPARSER_HPP