[Liblas-commits] libpc: lint
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Feb 28 20:29:01 EST 2011
details: http://hg.liblas.orglibpc/rev/22a562433584
changeset: 124:22a562433584
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:25:52 2011 -0800
description:
lint
Subject: libpc: lint
details: http://hg.liblas.orglibpc/rev/29c44b9ce310
changeset: 125:29c44b9ce310
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:26:07 2011 -0800
description:
lint
Subject: libpc: lint
details: http://hg.liblas.orglibpc/rev/8c7ad1775866
changeset: 126:8c7ad1775866
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:26:48 2011 -0800
description:
lint
Subject: libpc: lint
details: http://hg.liblas.orglibpc/rev/e48444de6607
changeset: 127:e48444de6607
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:27:06 2011 -0800
description:
lint
Subject: libpc: increase block size for actual runs
details: http://hg.liblas.orglibpc/rev/19d91aea1a7d
changeset: 128:19d91aea1a7d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:27:32 2011 -0800
description:
increase block size for actual runs
Subject: libpc: typos
details: http://hg.liblas.orglibpc/rev/bbbac2922c70
changeset: 129:bbbac2922c70
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:28:30 2011 -0800
description:
typos
Subject: libpc: adding -i, -o
details: http://hg.liblas.orglibpc/rev/c1b294fbb611
changeset: 130:c1b294fbb611
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Feb 28 17:28:52 2011 -0800
description:
adding -i, -o
diffstat:
.hgignore | 2 +
apps/Application.cpp | 50 +++++++++++++++++-----
apps/Application.hpp | 10 +++-
apps/pc2pc.cpp | 94 +++++++++++++++++++++++++++++++++++-------
src/LasHeaderWriter.cpp | 2 +-
src/MosaicFilter.cpp | 6 +--
src/Utils.cpp | 8 +++
src/Writer.cpp | 2 +-
src/drivers/liblas/reader.cpp | 4 +-
src/drivers/liblas/writer.cpp | 2 +-
10 files changed, 140 insertions(+), 40 deletions(-)
diffs (truncated from 372 to 300 lines):
diff -r 7a0191148d87 -r c1b294fbb611 .hgignore
--- a/.hgignore Mon Feb 28 16:21:04 2011 -0800
+++ b/.hgignore Mon Feb 28 17:28:52 2011 -0800
@@ -16,6 +16,8 @@
# visual studio cruft
Debug/
+Release/
+RelWithDebInfo/
ipch/
*.sln
*.vcxproj
diff -r 7a0191148d87 -r c1b294fbb611 apps/Application.cpp
--- a/apps/Application.cpp Mon Feb 28 16:21:04 2011 -0800
+++ b/apps/Application.cpp Mon Feb 28 17:28:52 2011 -0800
@@ -64,16 +64,24 @@
// parse the command line
parseOptions();
+ // do any user-level sanity checking
+ bool happy = validateOptions();
+ if (!happy)
+ {
+ outputHelp();
+ return 1;
+ }
+
// handle the well-known options
if (hasOption("version"))
{
- outputVersion(std::cout);
+ outputVersion();
return 0;
}
if (hasOption("help"))
{
- outputHelp(std::cout);
+ outputHelp();
return 0;
}
@@ -92,6 +100,20 @@
}
+void Application::usageError(const std::string& err)
+{
+ std::cout << "Usage error: " << err << std::endl;
+ std::cout << std::endl;
+}
+
+
+void Application::runtimeError(const std::string& err)
+{
+ std::cout << "Error: " << err << std::endl;
+ std::cout << std::endl;
+}
+
+
bool Application::hasOption(const std::string& name)
{
return m_variablesMap.count(name) > 0;
@@ -110,29 +132,33 @@
}
-void Application::outputHelp(std::ostream& oss)
+void Application::outputHelp()
{
- outputVersion(oss);
+ outputVersion();
std::vector<po::options_description*>::const_iterator iter;
for (iter = m_options.begin(); iter != m_options.end(); ++iter)
{
const po::options_description* options = *iter;
- oss << *options;
+ std::cout << *options;
}
- oss <<"\nFor more information, see the full documentation for libPC at:\n";
+ std::cout <<"\nFor more information, see the full documentation for libPC at:\n";
- oss << " http://libpc.org/\n";
- oss << "----------------------------------------------------------\n";
+ std::cout << " http://libpc.org/\n";
+ std::cout << "--------------------------------------------------------------------\n";
+ std::cout << std::endl;
+
+ return;
}
-void Application::outputVersion(std::ostream& oss)
+void Application::outputVersion()
{
- oss << "--------------------------------------------------------------------\n";
- oss << " pc2pc (" << libpc::GetFullVersionString() << ")\n";
- oss << "--------------------------------------------------------------------\n";
+ std::cout << "--------------------------------------------------------------------\n";
+ std::cout << "pc2pc (" << libpc::GetFullVersionString() << ")\n";
+ std::cout << "--------------------------------------------------------------------\n";
+ std::cout << std::endl;
}
diff -r 7a0191148d87 -r c1b294fbb611 apps/Application.hpp
--- a/apps/Application.hpp Mon Feb 28 16:21:04 2011 -0800
+++ b/apps/Application.hpp Mon Feb 28 17:28:52 2011 -0800
@@ -65,6 +65,10 @@
// implement this, with calls to addOptionSet()
virtual void addOptions() = 0;
+ // implement this, to do sanity checking of cmd line
+ // return false if the user gave us bad options
+ virtual bool validateOptions() { return true; }
+
// implement this, to do your actual work
virtual int execute() = 0;
@@ -73,11 +77,13 @@
void addOptionSet(boost::program_options::options_description* options);
bool isVerbose() const;
bool hasOption(const std::string& name);
+ void usageError(const std::string&);
+ void runtimeError(const std::string&);
private:
void parseOptions();
- void outputHelp(std::ostream& oss);
- void outputVersion(std::ostream& oss);
+ void outputHelp();
+ void outputVersion();
void addBasicOptionSet();
bool m_isVerbose;
diff -r 7a0191148d87 -r c1b294fbb611 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Mon Feb 28 16:21:04 2011 -0800
+++ b/apps/pc2pc.cpp Mon Feb 28 17:28:52 2011 -0800
@@ -12,25 +12,29 @@
#include <iostream>
-#include "libpc/exceptions.hpp"
-#include "libpc/libpc_config.hpp"
-#include "libpc/Bounds.hpp"
-#include "libpc/Color.hpp"
-#include "libpc/Dimension.hpp"
-#include "libpc/Schema.hpp"
-#include "libpc/CropFilter.hpp"
-#include "libpc/ColorFilter.hpp"
-#include "libpc/MosaicFilter.hpp"
-#include "libpc/FauxReader.hpp"
-#include "libpc/FauxWriter.hpp"
-#include "libpc/LasReader.hpp"
-#include "libpc/LasHeader.hpp"
-#include "libpc/LasWriter.hpp"
-// #include "libpc/LiblasReader.hpp"
+//#include "libpc/exceptions.hpp"
+//#include "libpc/libpc_config.hpp"
+//#include "libpc/Bounds.hpp"
+//#include "libpc/Color.hpp"
+//#include "libpc/Dimension.hpp"
+//#include "libpc/Schema.hpp"
+//#include "libpc/CropFilter.hpp"
+//#include "libpc/ColorFilter.hpp"
+//#include "libpc/MosaicFilter.hpp"
+//#include "libpc/FauxReader.hpp"
+//#include "libpc/FauxWriter.hpp"
+//#include "libpc/LasReader.hpp"
+//#include "libpc/LasHeader.hpp"
+//#include "libpc/LasWriter.hpp"
+
+#include "libpc/../../src/drivers/liblas/writer.hpp"
+#include "libpc/../../src/drivers/liblas/reader.hpp"
+
#include "Application.hpp"
using namespace libpc;
+namespace po = boost::program_options;
class Application_pc2pc : public Application
@@ -38,8 +42,13 @@
public:
Application_pc2pc(int argc, char* argv[]);
int execute();
+
private:
void addOptions();
+ bool validateOptions();
+
+ std::string m_inputFile;
+ std::string m_outputFile;
};
@@ -49,12 +58,62 @@
}
+bool Application_pc2pc::validateOptions()
+{
+ if (!hasOption("input"))
+ {
+ usageError("--input/-i required");
+ return false;
+ }
+
+ if (!hasOption("output"))
+ {
+ usageError("--output/-o required");
+ return false;
+ }
+
+ return true;
+}
+
+
void Application_pc2pc::addOptions()
{
+ po::options_description* file_options = new po::options_description("file options");
+
+ file_options->add_options()
+ ("input,i", po::value<std::string>(&m_inputFile), "input file name")
+ ("output,o", po::value<std::string>(&m_outputFile), "output file name")
+ ;
+
+ addOptionSet(file_options);
}
int Application_pc2pc::execute()
{
+ if (!Utils::fileExists(m_inputFile))
+ {
+ runtimeError("file not found: " + m_inputFile);
+ return 1;
+ }
+
+ std::istream* ifs = Utils::openFile(m_inputFile);
+ LiblasReader reader(*ifs);
+
+ std::ostream* ofs = Utils::createFile(m_outputFile);
+ {
+ const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
+
+ // need to scope the writer, so that's it dtor can use the stream
+ LiblasWriter writer(reader, *ofs);
+
+ //BUG: handle laz writer.setCompressed(false);
+
+ writer.write(numPoints);
+ }
+
+ Utils::closeFile(ofs);
+ Utils::closeFile(ifs);
+
return 0;
}
@@ -68,7 +127,7 @@
-
+#if 0
static void test1()
{
@@ -172,6 +231,9 @@
return 0;
}
+
+#endif
+
#if 0
#include <liblas/liblas.hpp>
diff -r 7a0191148d87 -r c1b294fbb611 src/LasHeaderWriter.cpp
--- a/src/LasHeaderWriter.cpp Mon Feb 28 16:21:04 2011 -0800
+++ b/src/LasHeaderWriter.cpp Mon Feb 28 17:28:52 2011 -0800
@@ -183,7 +183,7 @@
// 3-6. GUID data
uint8_t d16[16] = { 0 };
boost::uuids::uuid g = m_header.GetProjectId();
- memcpy(d16,g.data,26);
+ memcpy(d16,g.data,16);
Utils::write_n(m_ostream, d16, 16);
// 7. Version major
diff -r 7a0191148d87 -r c1b294fbb611 src/MosaicFilter.cpp
--- a/src/MosaicFilter.cpp Mon Feb 28 16:21:04 2011 -0800
+++ b/src/MosaicFilter.cpp Mon Feb 28 17:28:52 2011 -0800
@@ -46,11 +46,7 @@
const Header& prevHeader1 = m_prevStage.getHeader();
const Header& prevHeader2 = m_prevStage2.getHeader();
More information about the Liblas-commits
mailing list