Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ find_package(highway REQUIRED)
find_package(dice-hash REQUIRED)
find_package(dice-sparse-map REQUIRED)
find_package(dice-template-library REQUIRED)
find_package(libxml2 REQUIRED)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/rdf4cpp/version.hpp)

Expand Down Expand Up @@ -130,6 +131,7 @@ add_library(rdf4cpp
src/rdf4cpp/namespaces/RDF.cpp
src/rdf4cpp/parser/IStreamQuadIterator.cpp
src/rdf4cpp/parser/RDFFileParser.cpp
src/rdf4cpp/parser/XMLParser.cpp
src/rdf4cpp/query/QuadPattern.cpp
src/rdf4cpp/query/Solution.cpp
src/rdf4cpp/query/TriplePattern.cpp
Expand Down Expand Up @@ -177,6 +179,7 @@ target_link_libraries(rdf4cpp
OpenSSL::Crypto
uni-algo::uni-algo
highway::highway
LibXml2::LibXml2
)

set_target_properties(rdf4cpp PROPERTIES
Expand Down
2 changes: 2 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def requirements(self):
self.requires("dice-hash/0.4.11", transitive_headers=True)
self.requires("dice-sparse-map/0.2.9", transitive_headers=True)
self.requires("dice-template-library/1.13.0", transitive_headers=True)
self.requires("libxml2/2.14.5")
self.requires("zlib/1.3.1", force=True)

if self.options.with_test_deps:
self.test_requires("doctest/2.4.11")
Expand Down
4 changes: 4 additions & 0 deletions src/rdf4cpp/IRIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,9 @@ IRIFactoryError IRIFactory::set_base(std::string_view b) noexcept {
base_parts_cache = IRIView{base}.all_parts();
return IRIFactoryError::Ok;
}
void IRIFactory::set_base_unchecked(std::string_view b) noexcept {
base = b;
base_parts_cache = IRIView{base}.all_parts();
}

} // namespace rdf4cpp
6 changes: 6 additions & 0 deletions src/rdf4cpp/IRIFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ struct IRIFactory {
* @return
*/
[[nodiscard]] IRIFactoryError set_base(std::string_view b) noexcept;
/**
* Changes the base IRI. Skips validating the new base IRI.
* @param b
* @return
*/
void set_base_unchecked(std::string_view b) noexcept;

/**
* validates the given IRI and creates it in the given node storage, if valid.
Expand Down
550 changes: 550 additions & 0 deletions src/rdf4cpp/parser/XMLParser.cpp

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions src/rdf4cpp/parser/XMLParser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef RDF4CPP_XMLPARSER_HPP
#define RDF4CPP_XMLPARSER_HPP

#include <iterator>
#include <memory>

#include <rdf4cpp/Expected.hpp>

#include <rdf4cpp/Quad.hpp>

#include <rdf4cpp/parser/ParsingError.hpp>
#include <rdf4cpp/parser/ParsingFlags.hpp>
#include <rdf4cpp/parser/ParsingState.hpp>
#include <rdf4cpp/IRIFactory.hpp>

namespace rdf4cpp::parser {
struct XMLQuadIterator {
using flags_type = ParsingFlags;
using state_type = ParsingState;
using ok_type = Quad;
using error_type = ParsingError;

using value_type = nonstd::expected<ok_type, error_type>;
using reference = value_type const &;
using pointer = value_type const *;
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;
using istream_type = std::istream;

/**
* Identical semantics to fread.
* Uses stream to read at most count elements of size element_size into buffer.
*
* @param buffer pointer to buffer with at least count elements of size elem_size
* @param elem_size sizeof each element
* @param count number of elements to read
* @param stream pointer to any object.
* @return number of elements read
*/
using ReadFunc = size_t (*)(void *buffer, size_t elem_size, size_t count, void *stream);

/**
* Identical semantics to ferror.
*
* @param stream pointer to any object
* @return nonzero value if there is an error in stream, zero value otherwise
*/
using ErrorFunc = int (*)(void *stream);

/**
* Identical semantics to feof.
*
*
* @param stream pointer to any object
* @return nonzero value if there is an error in stream, zero value otherwise
*/
using EOFFunc = int (*)(void *stream);

private:
struct Impl;

std::unique_ptr<Impl> impl_;
std::optional<nonstd::expected<ok_type, error_type>> cur_;

public:
XMLQuadIterator(void *stream, ReadFunc read, ErrorFunc error, EOFFunc eof);
explicit XMLQuadIterator(std::istream& stream);

XMLQuadIterator(XMLQuadIterator&&) noexcept = delete;
XMLQuadIterator& operator=(XMLQuadIterator&&) noexcept = delete;

XMLQuadIterator(XMLQuadIterator const &) = delete;
XMLQuadIterator& operator=(XMLQuadIterator const &) = delete;

~XMLQuadIterator() noexcept;

reference operator*() const noexcept;
pointer operator->() const noexcept;
XMLQuadIterator &operator++();

bool operator==(std::default_sentinel_t) const noexcept;
};
}

#endif //RDF4CPP_XMLPARSER_H
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ target_link_libraries(tests_Serialization
)
add_test(NAME tests_Serialization COMMAND tests_Serialization)

add_executable(tests_XMLParser parser/tests_XMLParser.cpp)
target_link_libraries(tests_XMLParser
doctest::doctest
rdf4cpp
)
add_test(NAME tests_XMLParser COMMAND tests_XMLParser)

if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/test_swdf/swdf.nt")
file(DOWNLOAD "https://files.tentris.dev/swdf.zip" "${CMAKE_CURRENT_BINARY_DIR}/test_swdf/swdf.zip")
execute_process(COMMAND unzip "${CMAKE_CURRENT_BINARY_DIR}/test_swdf/swdf.zip" -d "${CMAKE_CURRENT_BINARY_DIR}/test_swdf")
Expand Down
Loading
Loading