本文整理汇总了C++中osmium::io::Reader::read方法的典型用法代码示例。如果您正苦于以下问题:C++ Reader::read方法的具体用法?C++ Reader::read怎么用?C++ Reader::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osmium::io::Reader
的用法示例。
在下文中一共展示了Reader::read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
osmium::memory::Buffer read() {
osmium::memory::Buffer buffer = m_reader.read();
if (buffer) {
if (m_with_areas) {
std::vector<osmium::memory::Buffer> area_buffers;
osmium::apply(buffer, m_location_handler, m_collector.handler([&area_buffers](osmium::memory::Buffer&& area_buffer) {
area_buffers.push_back(std::move(area_buffer));
}));
for (const osmium::memory::Buffer& b : area_buffers) {
buffer.add_buffer(b);
buffer.commit();
}
} else if (m_entities & (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way)) {
osmium::apply(buffer, m_location_handler);
}
}
return buffer;
}
示例2: MockParser
TEST_CASE("Test Reader using MockParser") {
std::string fail_in;
osmium::io::detail::ParserFactory::instance().register_parser(
osmium::io::file_format::xml,
[&](osmium::io::detail::parser_arguments& args) {
return std::unique_ptr<osmium::io::detail::Parser>(new MockParser(args, fail_in));
});
SECTION("no failure") {
fail_in = "";
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
auto header = reader.header();
REQUIRE(reader.read());
REQUIRE_FALSE(reader.read());
REQUIRE(reader.eof());
reader.close();
}
SECTION("throw in header") {
fail_in = "header";
try {
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
reader.header();
} catch (const std::runtime_error& e) {
REQUIRE(std::string{e.what()} == "error in header");
}
}
示例3: MockParser
std::string fail_in;
osmium::io::detail::ParserFactory::instance().register_parser(
osmium::io::file_format::xml,
[&](osmium::io::detail::future_string_queue_type& input_queue,
osmium::io::detail::future_buffer_queue_type& output_queue,
std::promise<osmium::io::Header>& header_promise,
osmium::osm_entity_bits::type read_which_entities) {
return std::unique_ptr<osmium::io::detail::Parser>(new MockParser(input_queue, output_queue, header_promise, read_which_entities, fail_in));
});
SECTION("no failure") {
fail_in = "";
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
auto header = reader.header();
REQUIRE(reader.read());
REQUIRE(!reader.read());
REQUIRE(reader.eof());
reader.close();
}
SECTION("throw in header") {
fail_in = "header";
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
reader.header();
} catch (std::runtime_error& e) {
REQUIRE(std::string{e.what()} == "error in header");
}
}
示例4: MockCompressor
TEST_CASE("Write with mock compressor") {
std::string fail_in;
osmium::io::CompressionFactory::instance().register_compression(osmium::io::file_compression::gzip,
[&](int, osmium::io::fsync) { return new MockCompressor(fail_in); },
[](int) { return nullptr; },
[](const char*, size_t) { return nullptr; }
);
osmium::io::Header header;
header.set("generator", "test_writer_with_mock_compression.cpp");
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
osmium::memory::Buffer buffer = reader.read();
REQUIRE(buffer);
REQUIRE(buffer.committed() > 0);
REQUIRE(buffer.select<osmium::OSMObject>().size() > 0);
SECTION("fail on construction") {
fail_in = "constructor";
REQUIRE_THROWS_AS([&](){
osmium::io::Writer writer("test-writer-mock-fail-on-construction.osm.gz", header, osmium::io::overwrite::allow);
writer(std::move(buffer));
writer.close();
}(), const std::logic_error&);
}