diff --git a/apps/Application.cpp b/apps/Application.cpp index 7e08041e40..a187199c4b 100644 --- a/apps/Application.cpp +++ b/apps/Application.cpp @@ -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; } @@ -306,10 +307,12 @@ void Application::addBasicSwitchSet() basic_options->add_options() ("help,h", po::value(&m_showHelp)->zero_tokens()->implicit_value(true), "produce help message") ("debug,d", po::value(&m_isDebug)->zero_tokens()->implicit_value(true), "Enable debug mode") - ("developer-debug", po::value(&m_hardCoreDebug)->zero_tokens()->implicit_value(true), "Enable developer debug mode (don't trap segfaults)") + ("developer-debug", po::value(&m_hardCoreDebug)->zero_tokens()->implicit_value(true), "Enable developer debug mode (don't trap exceptions so segfaults are thrown)") ("verbose,v", po::value(&m_verboseLevel)->default_value(0), "Set verbose message level") ("version", po::value(&m_showVersion)->zero_tokens()->implicit_value(true), "Show version info") ("timer", po::value(&m_showTime)->zero_tokens()->implicit_value(true), "Show execution time") + ("stdin,s", po::value(&m_usestdin)->zero_tokens()->implicit_value(true), "Read pipeline XML from stdin") + ; addSwitchSet(basic_options); diff --git a/apps/Application.hpp b/apps/Application.hpp index 9e47548036..220f15b409 100644 --- a/apps/Application.hpp +++ b/apps/Application.hpp @@ -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(); @@ -131,6 +133,9 @@ class Application Application& operator=(const Application&); // not implemented Application(const Application&); // not implemented + +protected: + bool m_usestdin; }; #endif diff --git a/apps/pcinfo.cpp b/apps/pcinfo.cpp index 35586f3663..17662d1e35 100644 --- a/apps/pcinfo.cpp +++ b/apps/pcinfo.cpp @@ -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; @@ -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) @@ -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::max)()) || @@ -129,7 +123,6 @@ void PcInfo::addSwitches() file_options->add_options() ("input,i", po::value(&m_inputFile)->default_value(""), "input file name") - ("output,o", po::value(&m_outputFile)->default_value(""), "output file name") ; addSwitchSet(file_options); @@ -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("filename", m_inputFile); readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); diff --git a/apps/pcpipeline.cpp b/apps/pcpipeline.cpp index 7617d79b03..d1a3e248e1 100644 --- a/apps/pcpipeline.cpp +++ b/apps/pcpipeline.cpp @@ -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; @@ -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) @@ -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"); } @@ -98,7 +99,6 @@ void PcPipeline::addSwitches() file_options->add_options() ("input,i", po::value(&m_inputFile)->default_value(""), "input file name") ("pipeline-serialization", po::value(&m_pipelineFile)->default_value(""), "") - ("stdin,s", po::value(&m_usestdin)->zero_tokens()->implicit_value(true), "Read pipeline XML from stdin") ("validate", po::value(&m_validate)->zero_tokens()->implicit_value(true), "Validate the pipeline (including serialization), but do not execute writing of points") ("count", po::value(&m_numPointsToWrite)->default_value(0), "How many points should we write?") ("skip", po::value(&m_numSkipPoints)->default_value(0), "How many points should we skip?") @@ -112,7 +112,7 @@ 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); } @@ -120,12 +120,8 @@ int PcPipeline::execute() 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");