Skip to content

Commit

Permalink
--stdin is now available to both pcpipeline and pcinfo, and if they a…
Browse files Browse the repository at this point in the history
…re set, they are used as the filename
  • Loading branch information
hobu committed Jul 11, 2012
1 parent be7e6ba commit 3450f68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
5 changes: 4 additions & 1 deletion apps/Application.cpp
Expand Up @@ -55,6 +55,7 @@ Application::Application(int argc, char* argv[], const std::string& appName)
, m_argv(argv)
, m_appName(appName)
, m_hardCoreDebug(false)
, m_usestdin(false)
{
return;
}
Expand Down Expand Up @@ -306,10 +307,12 @@ void Application::addBasicSwitchSet()
basic_options->add_options()
("help,h", po::value<bool>(&m_showHelp)->zero_tokens()->implicit_value(true), "produce help message")
("debug,d", po::value<bool>(&m_isDebug)->zero_tokens()->implicit_value(true), "Enable debug mode")
("developer-debug", po::value<bool>(&m_hardCoreDebug)->zero_tokens()->implicit_value(true), "Enable developer debug mode (don't trap segfaults)")
("developer-debug", po::value<bool>(&m_hardCoreDebug)->zero_tokens()->implicit_value(true), "Enable developer debug mode (don't trap exceptions so segfaults are thrown)")
("verbose,v", po::value<boost::uint32_t>(&m_verboseLevel)->default_value(0), "Set verbose message level")
("version", po::value<bool>(&m_showVersion)->zero_tokens()->implicit_value(true), "Show version info")
("timer", po::value<bool>(&m_showTime)->zero_tokens()->implicit_value(true), "Show execution time")
("stdin,s", po::value<bool>(&m_usestdin)->zero_tokens()->implicit_value(true), "Read pipeline XML from stdin")

;

addSwitchSet(basic_options);
Expand Down
5 changes: 5 additions & 0 deletions apps/Application.hpp
Expand Up @@ -103,6 +103,8 @@ class Application
void addSwitchSet(boost::program_options::options_description* options);
void addPositionalSwitch(const char* name, int max_count);



private:
int innerRun();
void parseSwitches();
Expand Down Expand Up @@ -131,6 +133,9 @@ class Application

Application& operator=(const Application&); // not implemented
Application(const Application&); // not implemented

protected:
bool m_usestdin;
};

#endif
18 changes: 3 additions & 15 deletions apps/pcinfo.cpp
Expand Up @@ -69,7 +69,6 @@ class PcInfo : public Application
void dumpMetadata(const Stage&) const;

std::string m_inputFile;
std::string m_outputFile;
bool m_showStats;
bool m_showSchema;
bool m_showStage;
Expand All @@ -86,7 +85,6 @@ class PcInfo : public Application
PcInfo::PcInfo(int argc, char* argv[])
: Application(argc, argv, "pcinfo")
, m_inputFile("")
, m_outputFile("")
, m_showStats(false)
, m_showSchema(false)
, m_showStage(false)
Expand All @@ -101,10 +99,6 @@ PcInfo::PcInfo(int argc, char* argv[])

void PcInfo::validateSwitches()
{
if (m_inputFile == "")
{
throw app_usage_error("input file name required");
}

const bool got_something =
(m_pointNumber != (std::numeric_limits<boost::uint64_t>::max)()) ||
Expand All @@ -129,7 +123,6 @@ void PcInfo::addSwitches()

file_options->add_options()
("input,i", po::value<std::string>(&m_inputFile)->default_value(""), "input file name")
("output,o", po::value<std::string>(&m_outputFile)->default_value(""), "output file name")
;

addSwitchSet(file_options);
Expand Down Expand Up @@ -268,17 +261,12 @@ void PcInfo::dumpMetadata(const Stage& stage) const

int PcInfo::execute()
{
if (m_outputFile != "")
{
m_outputStream = FileUtils::createFile(m_outputFile);
if (!m_outputStream)
{
throw app_runtime_error("cannot open output file: " + m_outputFile);
}
}


Options readerOptions;
{
if (m_usestdin)
m_inputFile = "STDIN";
readerOptions.add<std::string>("filename", m_inputFile);
readerOptions.add<bool>("debug", isDebug());
readerOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
Expand Down
18 changes: 7 additions & 11 deletions apps/pcpipeline.cpp
Expand Up @@ -61,7 +61,6 @@ class PcPipeline : public Application

std::string m_inputFile;
std::string m_pipelineFile;
bool m_usestdin;
bool m_validate;
boost::uint64_t m_numPointsToWrite;
boost::uint64_t m_numSkipPoints;
Expand All @@ -71,7 +70,6 @@ class PcPipeline : public Application
PcPipeline::PcPipeline(int argc, char* argv[])
: Application(argc, argv, "pcpipeline")
, m_inputFile("")
, m_usestdin(false)
, m_validate(false)
, m_numPointsToWrite(0)
, m_numSkipPoints(0)
Expand All @@ -82,7 +80,10 @@ PcPipeline::PcPipeline(int argc, char* argv[])

void PcPipeline::validateSwitches()
{
if (m_inputFile == "" && ! m_usestdin)
if (m_usestdin)
m_inputFile = "STDIN";

if (m_inputFile == "")
{
throw app_usage_error("input file name required");
}
Expand All @@ -98,7 +99,6 @@ void PcPipeline::addSwitches()
file_options->add_options()
("input,i", po::value<std::string>(&m_inputFile)->default_value(""), "input file name")
("pipeline-serialization", po::value<std::string>(&m_pipelineFile)->default_value(""), "")
("stdin,s", po::value<bool>(&m_usestdin)->zero_tokens()->implicit_value(true), "Read pipeline XML from stdin")
("validate", po::value<bool>(&m_validate)->zero_tokens()->implicit_value(true), "Validate the pipeline (including serialization), but do not execute writing of points")
("count", po::value<boost::uint64_t>(&m_numPointsToWrite)->default_value(0), "How many points should we write?")
("skip", po::value<boost::uint64_t>(&m_numSkipPoints)->default_value(0), "How many points should we skip?")
Expand All @@ -112,20 +112,16 @@ void PcPipeline::addSwitches()

int PcPipeline::execute()
{
if (!FileUtils::fileExists(m_inputFile) && !m_usestdin)
if (!FileUtils::fileExists(m_inputFile))
{
throw app_runtime_error("file not found: " + m_inputFile);
}

pdal::PipelineManager manager;

pdal::PipelineReader reader(manager, isDebug(), getVerboseLevel());
bool isWriter(false);

if (!m_usestdin)
isWriter = reader.readPipeline(m_inputFile);
else
isWriter = reader.readPipeline(std::cin);
bool isWriter = reader.readPipeline(m_inputFile);


if (!isWriter)
throw app_runtime_error("pipeline file is not a Writer");
Expand Down

0 comments on commit 3450f68

Please sign in to comment.