From c7152e9e0c7131240786d5adaef6ebd86c8a046e Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Tue, 5 May 2015 21:10:08 -0500 Subject: [PATCH] Remove boost from Log code. Remove dead code from GDALUtils. --- include/pdal/GDALUtils.hpp | 25 +--- include/pdal/Log.hpp | 23 +--- plugins/nitf/io/NitfReader.hpp | 1 + src/GDALUtils.cpp | 56 +-------- src/Log.cpp | 63 +++++----- test/unit/CMakeLists.txt | 1 - test/unit/GDALUtilsTest.cpp | 207 --------------------------------- 7 files changed, 44 insertions(+), 332 deletions(-) delete mode 100644 test/unit/GDALUtilsTest.cpp diff --git a/include/pdal/GDALUtils.hpp b/include/pdal/GDALUtils.hpp index fd0d028417..ace329b5c3 100644 --- a/include/pdal/GDALUtils.hpp +++ b/include/pdal/GDALUtils.hpp @@ -32,8 +32,7 @@ * OF SUCH DAMAGE. ****************************************************************************/ -#ifndef INCLUDED_GDALUTILS_HPP -#define INCLUDED_GDALUTILS_HPP +#pragma once #include @@ -85,24 +84,6 @@ class PDAL_DLL ErrorHandler pdal::LogPtr m_log; }; -class PDAL_DLL VSILFileBuffer -{ -public: - typedef boost::iostreams::seekable_device_tag category; - typedef char char_type; - - VSILFileBuffer(VSILFILE* fp); - - std::streamsize read(char* s, std::streamsize n); - std::streamsize write(const char* s, std::streamsize n); - std::streampos seek(boost::iostreams::stream_offset off, std::ios_base::seekdir way); - -private: - VSILFILE* m_fp; -}; - - -} -} // namespace pdal::gdal +} // namespace gdal +} // namespace pdal -#endif diff --git a/include/pdal/Log.hpp b/include/pdal/Log.hpp index 3ac3c1f2c0..f44442784b 100644 --- a/include/pdal/Log.hpp +++ b/include/pdal/Log.hpp @@ -32,21 +32,14 @@ * OF SUCH DAMAGE. ****************************************************************************/ -#ifndef INCLUDED_LOG_HPP -#define INCLUDED_LOG_HPP +#pragma once #include -#include -#include #include #include #include -typedef boost::iostreams::null_sink sink; -typedef boost::iostreams::stream null_stream; - - // Adapted from http://drdobbs.com/cpp/201804215 namespace pdal @@ -59,8 +52,6 @@ class PDAL_DLL Log { public: - /** @name Constructors - */ /// Constructs a pdal::Log instance. /// @param leaderString A string to presage all log entries with /// @param outputName A filename or one of 'stdout', 'stdlog', or 'stderr' @@ -110,7 +101,6 @@ class PDAL_DLL Log /// @param level logging level to request /// If the logging level asked for with /// pdal::Log::get is less than the logging level of the pdal::Log instance - /// an ostream with a boost::iostreams::null_sink is returned. std::ostream& get(LogLevel::Enum level = LogLevel::Info); /// Sets the floating point precision @@ -119,17 +109,16 @@ class PDAL_DLL Log /// Clears the floating point precision settings of the streams void clearFloat(); - /** @name private attributes - */ - protected: - std::ostream* m_log; - null_stream m_null_stream; + std::ostream *m_log; + std::ostream *m_nullStream; private: Log(const Log&); Log& operator =(const Log&); + void makeNullStream(); + LogLevel::Enum m_level; bool m_deleteStreamOnCleanup; std::string m_leader; @@ -137,7 +126,5 @@ class PDAL_DLL Log typedef std::shared_ptr LogPtr; - } // namespace pdal -#endif diff --git a/plugins/nitf/io/NitfReader.hpp b/plugins/nitf/io/NitfReader.hpp index 84acdeeccb..ed5076578e 100644 --- a/plugins/nitf/io/NitfReader.hpp +++ b/plugins/nitf/io/NitfReader.hpp @@ -34,6 +34,7 @@ #pragma once +#include #include #include diff --git a/src/GDALUtils.cpp b/src/GDALUtils.cpp index 402ec745bd..432a81389d 100644 --- a/src/GDALUtils.cpp +++ b/src/GDALUtils.cpp @@ -102,58 +102,6 @@ ErrorHandler::~ErrorHandler() CPLPopErrorHandler(); } -VSILFileBuffer::VSILFileBuffer(VSILFILE* fp) - : m_fp(fp) -{} +} // namespace gdal +} // namespace pdal - -std::streamsize VSILFileBuffer::read(char* s, std::streamsize n) -{ - // Read up to n characters from the underlying data source - // into the buffer s, returning the number of characters - // read; return -1 to indicate EOF - size_t result = VSIFReadL/*fread*/(s, 1, (size_t)n, m_fp); - if (result == 0) - return -1; - return result; -} - - -std::streamsize VSILFileBuffer::write(const char* s, std::streamsize n) -{ - // Write up to n characters from the buffer - // s to the output sequence, returning the - // number of characters written - size_t result = VSIFWriteL/*fwrite*/(s, 1, (size_t)n, m_fp); - if (static_cast(result) != n) - return -1; - return result; -} - - -std::streampos VSILFileBuffer::seek(boost::iostreams::stream_offset off, std::ios_base::seekdir way) -{ - // Advances the read/write head by off characters, - // returning the new position, where the offset is - // calculated from: - // - the start of the sequence if way == ios_base::beg - // - the current position if way == ios_base::cur - // - the end of the sequence if way == ios_base::end - - int myway = 0; - if (way == std::ios_base::beg) myway = SEEK_SET; - else if (way == std::ios_base::cur) myway = SEEK_CUR; - else if (way == std::ios_base::end) myway = SEEK_END; - - long myoff = (long)off; - int result = VSIFSeekL/*fseek*/(m_fp, myoff, myway); - if (result != 0) - { - return -1; - } - return static_cast(VSIFTellL/*ftell*/(m_fp)); -} - - -} -} // namespace pdal::gdal diff --git a/src/Log.cpp b/src/Log.cpp index 437e1e3d0b..0ee8fb7d3f 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -33,10 +33,10 @@ ****************************************************************************/ #include -#include +#include +#include #include -#include namespace pdal { @@ -49,25 +49,19 @@ Log::Log(std::string const& leaderString, , m_deleteStreamOnCleanup(false) , m_leader(leaderString) { - if (boost::iequals(outputName, "stdlog")) - { + + if (Utils::iequals(outputName, "stdlog")) m_log = &std::clog; - } - else if (boost::iequals(outputName, "stderr")) - { + else if (Utils::iequals(outputName, "stderr")) m_log = &std::cerr; - } - else if (boost::iequals(outputName, "stdout")) - { + else if (Utils::iequals(outputName, "stdout")) m_log = &std::cout; - } else { m_log = FileUtils::createFile(outputName); m_deleteStreamOnCleanup = true; } - - m_null_stream.open(sink()); + makeNullStream(); } @@ -78,8 +72,7 @@ Log::Log(std::string const& leaderString, , m_leader(leaderString) { m_log = v; - - m_null_stream.open(sink()); + makeNullStream(); } @@ -91,56 +84,66 @@ Log::~Log() m_log->flush(); delete m_log; } + delete m_nullStream; +} + - m_log = 0; +void Log::makeNullStream() +{ +#ifdef _WIN32 + std::string nullFilename = "nul"; +#else + std::string nullFilename = "/dev/null"; +#endif + + m_nullStream = new std::ofstream(nullFilename); } + void Log::floatPrecision(int level) { m_log->setf(std::ios_base::fixed, std::ios_base::floatfield); m_log->precision(level); } + void Log::clearFloat() { m_log->unsetf(std::ios_base::fixed); m_log->unsetf(std::ios_base::floatfield); } + std::ostream& Log::get(LogLevel::Enum level) { if (level <= m_level) { - *m_log << "(" << m_leader << " "<< getLevelString(level) <<": " << level << "): "; - *m_log << std::string(level < Debug ? 0 : level - Debug, '\t'); + *m_log << "(" << m_leader << " "<< getLevelString(level) <<": " << + level << "): " << + std::string(level < Debug ? 0 : level - Debug, '\t'); return *m_log; } - else - { - return m_null_stream; - } + return *m_nullStream; } + std::string Log::getLevelString(LogLevel::Enum level) const { - std::ostringstream output; - switch (level) { case Error: - output << "Error"; + return "Error"; break; case Warning: - output << "Warning"; + return "Warning"; break; case Info: - output << "Info"; + return "Info"; break; default: - output << "Debug"; + return "Debug"; } - - return output.str(); } + } // namespace diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 10438347b0..b34ef9c470 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -52,7 +52,6 @@ PDAL_ADD_TEST(pdal_bounds_test FILES BoundsTest.cpp) PDAL_ADD_TEST(pdal_config_test FILES ConfigTest.cpp) PDAL_ADD_TEST(pdal_environment_test FILES EnvironmentTest.cpp) PDAL_ADD_TEST(pdal_file_utils_test FILES FileUtilsTest.cpp) -PDAL_ADD_TEST(pdal_gdal_utils_test FILES GDALUtilsTest.cpp) PDAL_ADD_TEST(pdal_georeference_test FILES GeoreferenceTest.cpp) PDAL_ADD_TEST(pdal_log_test FILES LogTest.cpp) PDAL_ADD_TEST(pdal_metadata_test FILES MetadataTest.cpp) diff --git a/test/unit/GDALUtilsTest.cpp b/test/unit/GDALUtilsTest.cpp deleted file mode 100644 index 0df94c57f6..0000000000 --- a/test/unit/GDALUtilsTest.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/****************************************************************************** -* Copyright (c) 2011, Michael P. Gerlek (mpg@flaxen.com) -* -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following -* conditions are met: -* -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided -* with the distribution. -* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the -* names of its contributors may be used to endorse or promote -* products derived from this software without specific prior -* written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -* OF SUCH DAMAGE. -****************************************************************************/ - -//#include "UnitTest.hpp" -#include - -#include -#include -#include "Support.hpp" - -#ifdef PDAL_COMPILER_MSVC -# pragma warning(push) -# pragma warning(disable: 4512) // assignment operator could not be generated -#endif -#include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(pop) -#endif - -using namespace pdal; - -TEST(GDALUtilsTest, test_wrapped_vsifile_read) -{ - const int FILESIZE = 10000; // size of file to use - const int NUMREPS = 10000; // number of points to check - - const std::string tempfile = Support::datapath("vsilfile_test.dat"); - - FileUtils::deleteFile(tempfile); - - srand(17); - - // compute the "true" values, and store into test file - uint8_t truth[FILESIZE]; - { - FILE* fp = fopen(tempfile.c_str(), "wb"); - for (int i=0; i i(fp); - - for (int reps=0; reps full_stream(vsi_file); - - // and make a subset view - io::restriction > restricted_dev(full_stream, 10, 20); - io::stream > > restricted_str(restricted_dev); - - std::istream& str(restricted_str); - - // seek to a random spot and read a point - str.seekg(5, std::iostream::beg); - - uint8_t c; - - str.read((char*)&c, 1); - EXPECT_TRUE(c == 15); - - str.read((char*)&c, 1); - EXPECT_TRUE(c == 16); - - str.seekg(4, std::iostream::cur); - str.read((char*)&c, 1); - EXPECT_TRUE(c == 21); - - str.seekg(-5, std::iostream::end); - str.read((char*)&c, 1); - EXPECT_TRUE(c == 25); - - restricted_str.close(); - restricted_dev.close(); - full_stream.close(); - - VSIFCloseL/*fclose*/(vsi_file); - - FileUtils::deleteFile(tempfile); -}