[Liblas-commits]
hg: promote file open/create up into the factories, so others (l...
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Jan 11 12:26:46 EST 2011
details: http://hg.liblas.orghg/rev/636ed44b8a27
changeset: 2727:636ed44b8a27
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Jan 11 09:26:27 2011 -0800
description:
promote file open/create up into the factories, so others (like swig) can use them
Subject: hg: pull-merge
details: http://hg.liblas.orghg/rev/02902673a24d
changeset: 2728:02902673a24d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Jan 11 09:26:42 2011 -0800
description:
pull-merge
diffstat:
apps/las2las.cpp | 51 ++-------------------------------------------
apps/laskernel.cpp | 2 +-
include/liblas/factory.hpp | 9 ++++++++
src/factory.cpp | 39 +++++++++++++++++++++++++++++++++++
src/version.cpp | 2 +-
5 files changed, 53 insertions(+), 50 deletions(-)
diffs (211 lines):
diff -r ceefaf235fb1 -r 02902673a24d apps/las2las.cpp
--- a/apps/las2las.cpp Tue Jan 11 08:56:43 2011 -0800
+++ b/apps/las2las.cpp Tue Jan 11 09:26:42 2011 -0800
@@ -16,14 +16,6 @@
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
-//#define USE_BOOST_IO
-#ifdef USE_BOOST_IO
-#include <ostream>
-#include <boost/iostreams/device/file.hpp>
-#include <boost/iostreams/stream.hpp>
-#include <boost/iostreams/stream_buffer.hpp>
-#endif
-
namespace po = boost::program_options;
using namespace liblas;
@@ -33,44 +25,11 @@
typedef boost::shared_ptr<liblas::CoordinateSummary> SummaryPtr;
-static std::ostream* FileCreate(std::string const& filename)
-{
-#ifdef USE_BOOST_IO
- namespace io = boost::iostreams;
- io::stream<io::file_sink>* ofs = new io::stream<io::file_sink>();
- ofs->open(filename.c_str(), std::ios::out | std::ios::binary);
- if (ofs->is_open() == false) return NULL;
- return ofs;
-#else
- std::ofstream* ofs = new std::ofstream();
- ofs->open(filename.c_str(), std::ios::out | std::ios::binary);
- if (ofs->is_open() == false) return NULL;
- return ofs;
-#endif
-}
-
-static std::istream* FileOpen(std::string const& filename)
-{
-#ifdef USE_BOOST_IO
- namespace io = boost::iostreams;
- io::stream<io::file_source>* ifs = new io::stream<io::file_source>();
- ifs->open(filename.c_str(), std::ios::in | std::ios::binary);
- if (ifs->is_open() == false) return NULL;
- return ifs;
-#else
- std::ifstream* ifs = new std::ifstream();
- ifs->open(filename.c_str(), std::ios::in | std::ios::binary);
- if (ifs->is_open() == false) return NULL;
- return ifs;
-#endif
-}
-
-
WriterPtr start_writer( std::ostream*& ofs,
std::string const& output,
liblas::Header const& header)
{
- ofs = FileCreate(output);
+ ofs = WriterFactory::FileCreate(output);
if (!ofs)
{
std::ostringstream oss;
@@ -80,7 +39,6 @@
WriterPtr writer( new liblas::Writer(*ofs, header));
return writer;
-
}
bool process( std::istream& ifs,
@@ -93,9 +51,6 @@
bool verbose,
bool min_offset)
{
-
-
-
liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs);
SummaryPtr summary(new::liblas::CoordinateSummary);
@@ -336,7 +291,7 @@
if (verbose)
std::cout << "Opening " << input << " to fetch Header" << std::endl;
- std::istream* ifs = FileOpen(input);
+ std::istream* ifs = ReaderFactory::FileOpen(input);
if (!ifs)
{
std::cerr << "Cannot open " << input << " for read. Exiting..." << std::endl;
@@ -410,7 +365,7 @@
break;
}
- std::istream* ifs = FileOpen(input);
+ std::istream* ifs = ReaderFactory::FileOpen(input);
if (!ifs)
{
std::cerr << "Cannot open " << input << " for read. Exiting..." << std::endl;
diff -r ceefaf235fb1 -r 02902673a24d apps/laskernel.cpp
--- a/apps/laskernel.cpp Tue Jan 11 08:56:43 2011 -0800
+++ b/apps/laskernel.cpp Tue Jan 11 09:26:42 2011 -0800
@@ -41,7 +41,7 @@
std::vector<char> data;
if (infile->good()){
size = infile->tellg();
- data.resize(size);
+ data.resize(static_cast<std::vector<char>::size_type>(size));
// data = new char [size];
infile->seekg (0, std::ios::beg);
infile->read (&data.front(), size);
diff -r ceefaf235fb1 -r 02902673a24d include/liblas/factory.hpp
--- a/include/liblas/factory.hpp Tue Jan 11 08:56:43 2011 -0800
+++ b/include/liblas/factory.hpp Tue Jan 11 09:26:42 2011 -0800
@@ -69,6 +69,10 @@
Reader CreateCached(std::istream& stream, boost::uint32_t cache_size);
Reader CreateWithStream(std::istream& stream);
+ // help function to create an input stream
+ // returns NULL if failed to open
+ static std::istream* FileOpen(std::string const& filename);
+
/// Destructor.
/// @exception nothrow
~ReaderFactory() {};
@@ -104,6 +108,11 @@
// returns Unknown, unless we find a .laz or .las extension
static FileType InferFileTypeFromExtension(const std::string&);
+
+ // help function to create an output stream
+ // returns NULL if failed to open
+ static std::ostream* WriterFactory::FileCreate(std::string const& filename);
+
private:
};
diff -r ceefaf235fb1 -r 02902673a24d src/factory.cpp
--- a/src/factory.cpp Tue Jan 11 08:56:43 2011 -0800
+++ b/src/factory.cpp Tue Jan 11 09:26:42 2011 -0800
@@ -51,6 +51,14 @@
// boost
#include <boost/cstdint.hpp>
+//#define USE_BOOST_IO
+#ifdef USE_BOOST_IO
+#include <ostream>
+#include <boost/iostreams/device/file.hpp>
+#include <boost/iostreams/stream.hpp>
+#include <boost/iostreams/stream_buffer.hpp>
+#endif
+
// std
#include <stdexcept>
#include <fstream>
@@ -97,6 +105,21 @@
return liblas::Reader(r);
}
+std::istream* ReaderFactory::FileOpen(std::string const& filename)
+{
+#ifdef USE_BOOST_IO
+ namespace io = boost::iostreams;
+ io::stream<io::file_source>* ifs = new io::stream<io::file_source>();
+ ifs->open(filename.c_str(), std::ios::in | std::ios::binary);
+ if (ifs->is_open() == false) return NULL;
+ return ifs;
+#else
+ std::ifstream* ifs = new std::ifstream();
+ ifs->open(filename.c_str(), std::ios::in | std::ios::binary);
+ if (ifs->is_open() == false) return NULL;
+ return ifs;
+#endif
+}
Writer WriterFactory::CreateWithImpl(WriterIPtr w)
{
@@ -153,4 +176,20 @@
return FileType_Unknown;
}
+std::ostream* WriterFactory::FileCreate(std::string const& filename)
+{
+#ifdef USE_BOOST_IO
+ namespace io = boost::iostreams;
+ io::stream<io::file_sink>* ofs = new io::stream<io::file_sink>();
+ ofs->open(filename.c_str(), std::ios::out | std::ios::binary);
+ if (ofs->is_open() == false) return NULL;
+ return ofs;
+#else
+ std::ofstream* ofs = new std::ofstream();
+ ofs->open(filename.c_str(), std::ios::out | std::ios::binary);
+ if (ofs->is_open() == false) return NULL;
+ return ofs;
+#endif
+}
+
} // namespace liblas
diff -r ceefaf235fb1 -r 02902673a24d src/version.cpp
--- a/src/version.cpp Tue Jan 11 08:56:43 2011 -0800
+++ b/src/version.cpp Tue Jan 11 09:26:42 2011 -0800
@@ -107,7 +107,7 @@
#endif
#ifdef HAVE_LASZIP
- os << " LasZip "
+ os << " LASzip "
<< LASZIP_VERSION_MAJOR << "."
<< LASZIP_VERSION_MINOR << "."
<< LASZIP_VERSION_REVISION;
More information about the Liblas-commits
mailing list