diff --git a/util/geosop/WKBStreamReader.h b/include/geos/io/WKBStreamReader.h similarity index 83% rename from util/geosop/WKBStreamReader.h rename to include/geos/io/WKBStreamReader.h index 65b1f5c5a6..5402ff9324 100644 --- a/util/geosop/WKBStreamReader.h +++ b/include/geos/io/WKBStreamReader.h @@ -16,27 +16,34 @@ #include #include +#include // Forward declarations namespace geos { namespace geom { - class Geometry; class PrecisionModel; } } -class WKBStreamReader { +namespace geos { +namespace io { + +class GEOS_DLL WKBStreamReader { public: WKBStreamReader(std::istream& instr); ~WKBStreamReader(); - geos::geom::Geometry* next(); + std::unique_ptr next(); private: std::istream& instr; - geos::io::WKBReader rdr; + WKBReader rdr; }; +} +} + + diff --git a/util/geosop/WKTFileReader.h b/include/geos/io/WKTFileReader.h similarity index 73% rename from util/geosop/WKTFileReader.h rename to include/geos/io/WKTFileReader.h index a54449957c..9785d6ae6a 100644 --- a/util/geosop/WKTFileReader.h +++ b/include/geos/io/WKTFileReader.h @@ -16,6 +16,7 @@ #include #include +#include // Forward declarations namespace geos { @@ -26,15 +27,20 @@ class PrecisionModel; } } -class WKTFileReader { +namespace geos { +namespace io { + +class GEOS_DLL WKTFileReader { public: WKTFileReader(); ~WKTFileReader(); - std::vector read(std::string fname); + std::vector> read(std::string fname); private: - geos::geom::Geometry* readGeom(std::ifstream& f, geos::io::WKTReader& rdr); + std::unique_ptr readGeom(std::ifstream& f, geos::io::WKTReader& rdr); }; +} +} diff --git a/util/geosop/WKTStreamReader.h b/include/geos/io/WKTStreamReader.h similarity index 82% rename from util/geosop/WKTStreamReader.h rename to include/geos/io/WKTStreamReader.h index 479a3b135d..e9b7d7c8ca 100644 --- a/util/geosop/WKTStreamReader.h +++ b/include/geos/io/WKTStreamReader.h @@ -16,6 +16,7 @@ #include #include +#include // Forward declarations namespace geos { @@ -26,17 +27,22 @@ class PrecisionModel; } } -class WKTStreamReader { +namespace geos { +namespace io { + +class GEOS_DLL WKTStreamReader { public: WKTStreamReader(std::istream& instr); ~WKTStreamReader(); - geos::geom::Geometry* next(); + std::unique_ptr next(); private: std::istream& instr; - geos::io::WKTReader rdr; + WKTReader rdr; }; +} +} diff --git a/util/geosop/WKBStreamReader.cpp b/src/io/WKBStreamReader.cpp similarity index 87% rename from util/geosop/WKBStreamReader.cpp rename to src/io/WKBStreamReader.cpp index 52fc9ea0a3..b705220cb8 100644 --- a/util/geosop/WKBStreamReader.cpp +++ b/src/io/WKBStreamReader.cpp @@ -18,11 +18,13 @@ #include #include #include // for unique_ptr -//#include -#include "WKBStreamReader.h" +#include -using namespace geos::geom; +using geos::geom::Geometry; + +namespace geos { +namespace io { WKBStreamReader::WKBStreamReader(std::istream& p_instr) : instr(p_instr) @@ -39,7 +41,7 @@ WKBStreamReader::~WKBStreamReader() { /* Return: nullptr if at EOF */ -Geometry* +std::unique_ptr WKBStreamReader::next() { std::string line; @@ -49,5 +51,8 @@ WKBStreamReader::next() } std::istringstream hex(line); auto g = rdr.readHEX( hex ); - return g.release(); + return g; +} + +} } diff --git a/util/geosop/WKTFileReader.cpp b/src/io/WKTFileReader.cpp similarity index 81% rename from util/geosop/WKTFileReader.cpp rename to src/io/WKTFileReader.cpp index ac63217381..9a7c1e37c4 100644 --- a/util/geosop/WKTFileReader.cpp +++ b/src/io/WKTFileReader.cpp @@ -20,10 +20,13 @@ #include // for unique_ptr #include -#include "WKTFileReader.h" +#include using namespace geos::geom; +namespace geos { +namespace io { + WKTFileReader::WKTFileReader() { @@ -34,11 +37,11 @@ WKTFileReader::~WKTFileReader() { } /*public*/ -std::vector +std::vector> WKTFileReader::read(std::string fname) { std::ifstream f( fname ); - std::vector geoms; + std::vector> geoms; geos::io::WKTReader rdr; while (true) { @@ -46,7 +49,7 @@ WKTFileReader::read(std::string fname) if (g == nullptr) { break; } - geoms.push_back(g); + geoms.push_back(std::move(g)); } f.close(); @@ -56,13 +59,13 @@ WKTFileReader::read(std::string fname) /* Return: nullptr if at EOF */ -Geometry* +std::unique_ptr WKTFileReader::readGeom(std::ifstream& f, geos::io::WKTReader& rdr) { std::string wkt = ""; - int lParen = 0; - int rParen = 0; + std::string::difference_type lParen = 0; + std::string::difference_type rParen = 0; do { std::string line; std::getline(f, line); @@ -77,5 +80,8 @@ WKTFileReader::readGeom(std::ifstream& f, geos::io::WKTReader& rdr) } while (lParen == 0 || lParen != rParen); auto g = rdr.read( wkt.c_str() ); - return g.release(); + return g; +} + +} } diff --git a/util/geosop/WKTStreamReader.cpp b/src/io/WKTStreamReader.cpp similarity index 91% rename from util/geosop/WKTStreamReader.cpp rename to src/io/WKTStreamReader.cpp index 4649d44523..63e94d1dfa 100644 --- a/util/geosop/WKTStreamReader.cpp +++ b/src/io/WKTStreamReader.cpp @@ -20,10 +20,13 @@ #include // for unique_ptr #include -#include "WKTStreamReader.h" +#include using namespace geos::geom; +namespace geos { +namespace io { + WKTStreamReader::WKTStreamReader(std::istream& p_instr) : instr(p_instr) { @@ -39,7 +42,7 @@ WKTStreamReader::~WKTStreamReader() { /* Return: nullptr if at EOF */ -Geometry* +std::unique_ptr WKTStreamReader::next() { std::string wkt = ""; @@ -60,5 +63,9 @@ WKTStreamReader::next() } while (lParen == 0 || lParen != rParen); auto g = rdr.read( wkt.c_str() ); - return g.release(); + return g; +} + + +} } diff --git a/util/geosop/CMakeLists.txt b/util/geosop/CMakeLists.txt index bc31cc89c5..5833202693 100644 --- a/util/geosop/CMakeLists.txt +++ b/util/geosop/CMakeLists.txt @@ -12,8 +12,7 @@ add_executable(geosop GeosOp.cpp GeomFunction.cpp - WKBStreamReader.cpp - WKTStreamReader.cpp ) + ) target_link_libraries(geosop PRIVATE geos geos_c) diff --git a/util/geosop/GeosOp.cpp b/util/geosop/GeosOp.cpp index 1b8c1e9568..2bdc5fa011 100644 --- a/util/geosop/GeosOp.cpp +++ b/util/geosop/GeosOp.cpp @@ -19,15 +19,15 @@ #include #include #include +#include #include #include +#include #include #include #include -#include "WKTStreamReader.h" -#include "WKBStreamReader.h" #include "GeomFunction.h" #include "GeosOp.h" #include "cxxopts.hpp" @@ -221,7 +221,7 @@ readWKTFile(std::istream& in, int limit) { auto geom = rdr.next(); if (geom == nullptr) break; - geoms.push_back( std::unique_ptr(geom) ); + geoms.push_back(std::move(geom)); count++; } return geoms; @@ -247,7 +247,7 @@ readWKBFile(std::istream& in, int limit) { auto geom = rdr.next(); if (geom == nullptr) break; - geoms.push_back( std::unique_ptr(geom) ); + geoms.push_back(std::move(geom)); count++; } return geoms;