Skip to content

Commit

Permalink
Remove boost from Log code.
Browse files Browse the repository at this point in the history
Remove dead code from GDALUtils.
  • Loading branch information
abellgithub committed May 6, 2015
1 parent 78119ee commit c7152e9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 332 deletions.
25 changes: 3 additions & 22 deletions include/pdal/GDALUtils.hpp
Expand Up @@ -32,8 +32,7 @@
* OF SUCH DAMAGE.
****************************************************************************/

#ifndef INCLUDED_GDALUTILS_HPP
#define INCLUDED_GDALUTILS_HPP
#pragma once

#include <pdal/pdal_internal.hpp>

Expand Down Expand Up @@ -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
23 changes: 5 additions & 18 deletions include/pdal/Log.hpp
Expand Up @@ -32,21 +32,14 @@
* OF SUCH DAMAGE.
****************************************************************************/

#ifndef INCLUDED_LOG_HPP
#define INCLUDED_LOG_HPP
#pragma once

#include <pdal/pdal_internal.hpp>

#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/null.hpp>
#include <pdal/util/FileUtils.hpp>
#include <iosfwd>
#include <memory>

typedef boost::iostreams::null_sink sink;
typedef boost::iostreams::stream<sink> null_stream;


// Adapted from http://drdobbs.com/cpp/201804215

namespace pdal
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -119,25 +109,22 @@ 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;
};

typedef std::shared_ptr<Log> LogPtr;


} // namespace pdal

#endif
1 change: 1 addition & 0 deletions plugins/nitf/io/NitfReader.hpp
Expand Up @@ -34,6 +34,7 @@

#pragma once

#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/restrict.hpp>

#include <las/LasReader.hpp>
Expand Down
56 changes: 2 additions & 54 deletions src/GDALUtils.cpp
Expand Up @@ -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<std::streamsize>(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<std::streamoff>(VSIFTellL/*ftell*/(m_fp));
}


}
} // namespace pdal::gdal
63 changes: 33 additions & 30 deletions src/Log.cpp
Expand Up @@ -33,10 +33,10 @@
****************************************************************************/

#include <pdal/Log.hpp>
#include <boost/algorithm/string.hpp>
#include <pdal/Utils.hpp>

#include <fstream>
#include <ostream>
#include <sstream>

namespace pdal
{
Expand All @@ -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();
}


Expand All @@ -78,8 +72,7 @@ Log::Log(std::string const& leaderString,
, m_leader(leaderString)
{
m_log = v;

m_null_stream.open(sink());
makeNullStream();
}


Expand All @@ -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
1 change: 0 additions & 1 deletion test/unit/CMakeLists.txt
Expand Up @@ -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)
Expand Down

0 comments on commit c7152e9

Please sign in to comment.