From cb4ea8c945650fc680faa9844bc0b24a2d66b50c Mon Sep 17 00:00:00 2001 From: Bradley J Chambers Date: Thu, 12 Feb 2015 17:06:09 -0500 Subject: [PATCH] move from naked Stage pointers to shared_ptr --- apps/pdal.cpp | 2 +- include/pdal/KernelSupport.hpp | 4 +- include/pdal/PipelineManager.hpp | 14 +- include/pdal/PipelineReader.hpp | 8 +- include/pdal/Stage.hpp | 13 +- include/pdal/StageRunner.hpp | 4 +- include/pdal/Writer.hpp | 10 +- kernels/delta/DeltaKernel.cpp | 4 +- kernels/diff/DiffKernel.cpp | 4 +- kernels/info/InfoKernel.cpp | 2 +- kernels/info/InfoKernel.hpp | 6 +- kernels/pipeline/PipelineKernel.cpp | 2 +- kernels/random/RandomKernel.cpp | 9 +- kernels/sort/SortKernel.cpp | 23 ++-- kernels/sort/SortKernel.hpp | 2 +- kernels/translate/TranslateKernel.cpp | 47 ++++--- kernels/translate/TranslateKernel.hpp | 4 +- plugins/cpd/kernel/Cpd.cpp | 14 +- plugins/cpd/test/CpdKernelTest.cpp | 6 +- plugins/hexbin/test/HexbinFilterTest.cpp | 6 +- plugins/nitf/test/NitfReaderTest.cpp | 10 +- plugins/nitf/test/NitfWriterTest.cpp | 6 +- plugins/pcl/kernel/GroundKernel.cpp | 17 ++- plugins/pcl/kernel/GroundKernel.hpp | 2 +- plugins/pcl/kernel/PCLKernel.cpp | 23 ++-- plugins/pcl/kernel/PCLKernel.hpp | 2 +- plugins/pcl/kernel/SmoothKernel.cpp | 25 ++-- plugins/pcl/kernel/SmoothKernel.hpp | 2 +- plugins/pcl/kernel/ViewKernel.cpp | 15 +-- plugins/pcl/kernel/ViewKernel.hpp | 2 +- plugins/pcl/test/PCLBlockFilterTest.cpp | 19 +-- plugins/python/test/PredicateFilterTest.cpp | 94 +++++++------- .../python/test/ProgrammableFilterTest.cpp | 26 ++-- src/Kernel.cpp | 8 +- src/KernelSupport.cpp | 8 +- src/PipelineManager.cpp | 25 ++-- src/PipelineReader.cpp | 27 ++-- src/PipelineWriter.cpp | 2 +- src/Stage.cpp | 12 +- src/StageFactory.cpp | 31 ++--- test/unit/LogTest.cpp | 28 ++-- test/unit/OptionsTest.cpp | 6 +- test/unit/PipelineManagerTest.cpp | 4 +- test/unit/SpatialReferenceTest.cpp | 66 +++++----- test/unit/StageTester.hpp | 16 +-- test/unit/apps/pc2pcTest.cpp | 18 +-- test/unit/filters/ChipperTest.cpp | 40 +++--- test/unit/filters/ColorizationFilterTest.cpp | 14 +- test/unit/filters/CropFilterTest.cpp | 38 +++--- test/unit/filters/DecimationFilterTest.cpp | 6 +- test/unit/filters/FerryFilterTest.cpp | 8 +- test/unit/filters/RangeFilterTest.cpp | 42 +++--- test/unit/filters/SortFilterTest.cpp | 12 +- test/unit/filters/SplitterTest.cpp | 18 +-- test/unit/filters/StatsFilterTest.cpp | 52 ++++---- .../unit/filters/TransformationFilterTest.cpp | 6 +- test/unit/io/bpf/BPFTest.cpp | 8 +- test/unit/io/buffer/BufferTest.cpp | 23 ++-- test/unit/io/faux/FauxReaderTest.cpp | 41 +++--- test/unit/io/las/LasReaderTest.cpp | 84 ++++++------ test/unit/io/las/LasWriterTest.cpp | 122 +++++++++--------- test/unit/io/qfit/QFITReaderTest.cpp | 19 ++- test/unit/io/sbet/SbetReaderTest.cpp | 16 +-- test/unit/io/sbet/SbetWriterTest.cpp | 27 ++-- 64 files changed, 604 insertions(+), 650 deletions(-) diff --git a/apps/pdal.cpp b/apps/pdal.cpp index 4ad0c3165b..e5f6978a17 100644 --- a/apps/pdal.cpp +++ b/apps/pdal.cpp @@ -142,7 +142,7 @@ void outputDrivers() void outputOptions(std::string const& n) { StageFactory f(false); - std::unique_ptr s = f.createStage(n); + std::shared_ptr s(f.createStage(n)); if (!s) { diff --git a/include/pdal/KernelSupport.hpp b/include/pdal/KernelSupport.hpp index 2cdc8c1db1..0d12a3f9d4 100644 --- a/include/pdal/KernelSupport.hpp +++ b/include/pdal/KernelSupport.hpp @@ -67,11 +67,11 @@ class PDAL_DLL KernelSupport { public: // makes a reader/stage, from just the filename and some other options - static Stage* makeReader(const std::string& filename); + static std::shared_ptr makeReader(const std::string& filename); // makes a writer, from just the filename and some other // options (and the input stage) - static Stage* makeWriter(const std::string& filename, Stage *stage); + static std::shared_ptr makeWriter(const std::string& filename, std::shared_ptr stage); static PipelineManager* makePipeline(const std::string& filename); private: diff --git a/include/pdal/PipelineManager.hpp b/include/pdal/PipelineManager.hpp index d2224c6f95..f456b02ff8 100644 --- a/include/pdal/PipelineManager.hpp +++ b/include/pdal/PipelineManager.hpp @@ -54,18 +54,18 @@ class PDAL_DLL PipelineManager ~PipelineManager(); // Use these to manually add stages into the pipeline manager. - Stage* addReader(const std::string& type); - Stage* addFilter(const std::string& type, Stage *prevStage); - Stage* addFilter(const std::string& type, - const std::vector& prevStages); - Stage* addWriter(const std::string& type, Stage *prevStage); + std::shared_ptr addReader(const std::string& type); + std::shared_ptr addFilter(const std::string& type, std::shared_ptr prevStage); + std::shared_ptr addFilter(const std::string& type, + const std::vector >& prevStages); + std::shared_ptr addWriter(const std::string& type, std::shared_ptr prevStage); // returns true if the pipeline endpoint is a writer bool isWriterPipeline() const { return (bool)getStage(); } // return the pipeline reader endpoint (or NULL, if not a reader pipeline) - Stage* getStage() const + std::shared_ptr getStage() const { return m_stages.empty() ? NULL : m_stages.back(); } void prepare() const; @@ -86,7 +86,7 @@ class PDAL_DLL PipelineManager PointContext m_context; PointBufferSet m_pbSet; - typedef std::vector StagePtrList; + typedef std::vector > StagePtrList; StagePtrList m_stages; PipelineManager& operator=(const PipelineManager&); // not implemented diff --git a/include/pdal/PipelineReader.hpp b/include/pdal/PipelineReader.hpp index f34bb581bf..660e792c2c 100644 --- a/include/pdal/PipelineReader.hpp +++ b/include/pdal/PipelineReader.hpp @@ -68,11 +68,11 @@ class PDAL_DLL PipelineReader typedef std::map map_t; bool parseElement_Pipeline(const boost::property_tree::ptree&); - Stage* parseElement_anystage(const std::string& name, + std::shared_ptr parseElement_anystage(const std::string& name, const boost::property_tree::ptree& subtree); - Stage* parseElement_Reader(const boost::property_tree::ptree& tree); - Stage* parseElement_Filter(const boost::property_tree::ptree& tree); - Stage* parseElement_Writer(const boost::property_tree::ptree& tree); + std::shared_ptr parseElement_Reader(const boost::property_tree::ptree& tree); + std::shared_ptr parseElement_Filter(const boost::property_tree::ptree& tree); + std::shared_ptr parseElement_Writer(const boost::property_tree::ptree& tree); Option parseElement_Option(const boost::property_tree::ptree& tree); void collect_attributes(map_t& attrs, const boost::property_tree::ptree& tree); diff --git a/include/pdal/Stage.hpp b/include/pdal/Stage.hpp index 1b45418d8c..e41ac2e7ed 100644 --- a/include/pdal/Stage.hpp +++ b/include/pdal/Stage.hpp @@ -57,7 +57,7 @@ class StageBlockIterator; class StageRunner; class StageTester; -class PDAL_DLL Stage +class PDAL_DLL Stage : public std::enable_shared_from_this { friend class StageTester; friend class StageRunner; @@ -66,9 +66,9 @@ class PDAL_DLL Stage virtual ~Stage() {} - void setInput(const std::vector& inputs) + void setInput(const std::vector >& inputs) { m_inputs = inputs; } - void setInput(Stage *input) + void setInput(std::shared_ptr input) { m_inputs.push_back(input); } QuickInfo preview() @@ -100,10 +100,9 @@ class PDAL_DLL Stage return m_options.getValueOrDefault("verbose", 0); } virtual std::string getName() const = 0; - //virtual std::string getDescription() const = 0; - const std::vector& getInputs() const + const std::vector >& getInputs() const { return m_inputs; } - std::vector findStage(std::string name); + std::vector > findStage(std::string name); virtual Options getDefaultOptions() { return Options(); } static Dimension::IdList getDefaultDimensions() @@ -134,7 +133,7 @@ class PDAL_DLL Stage private: bool m_debug; uint32_t m_verbose; - std::vector m_inputs; + std::vector > m_inputs; LogPtr m_log; SpatialReference m_spatialReference; diff --git a/include/pdal/StageRunner.hpp b/include/pdal/StageRunner.hpp index afd1be3ea7..e7c2958456 100644 --- a/include/pdal/StageRunner.hpp +++ b/include/pdal/StageRunner.hpp @@ -45,7 +45,7 @@ namespace pdal class StageRunner { public: - StageRunner(Stage *s, PointBufferPtr pointBuf) : + StageRunner(std::shared_ptr s, PointBufferPtr pointBuf) : m_stage(s), m_pointBuf(pointBuf) {} @@ -57,7 +57,7 @@ class StageRunner { return m_bufSet; } private: - Stage *m_stage; + std::shared_ptr m_stage; PointBufferPtr m_pointBuf; PointBufferSet m_bufSet; }; diff --git a/include/pdal/Writer.hpp b/include/pdal/Writer.hpp index 50ea61c789..c3c4facf2c 100644 --- a/include/pdal/Writer.hpp +++ b/include/pdal/Writer.hpp @@ -36,7 +36,6 @@ #include #include -//#include #include #include @@ -56,19 +55,14 @@ class PDAL_DLL Writer : public Stage public: /// Constructs an end-stage consumer of a pipeline of data -- a writer - Writer() //: m_callback(new UserCallback) + Writer() {} /// Serialize the pipeline to a boost::property_tree::ptree /// @return boost::property_tree::ptree with xml attributes virtual boost::property_tree::ptree serializePipeline() const; - /// Sets the UserCallback to manage progress/cancel operations -// void setUserCallback(UserCallback* userCallback) -// { m_callback.reset(userCallback); } - protected: -// std::unique_ptr m_callback; std::string m_filename; XForm m_xXform; XForm m_yXform; @@ -87,7 +81,7 @@ class PDAL_DLL Writer : public Stage } virtual void writerProcessOptions(const Options& options); virtual void write(const PointBuffer& /*buffer*/) - { /*std::cerr << "Can't write with stage = " << getName() << "!\n";*/ } + { std::cerr << "Can't write with stage = " << getName() << "!\n"; } Writer& operator=(const Writer&); // not implemented Writer(const Writer&); // not implemented diff --git a/kernels/delta/DeltaKernel.cpp b/kernels/delta/DeltaKernel.cpp index 2769e21918..6250a43965 100644 --- a/kernels/delta/DeltaKernel.cpp +++ b/kernels/delta/DeltaKernel.cpp @@ -284,7 +284,7 @@ int DeltaKernel::execute() sourceOptions.add("debug", isDebug()); sourceOptions.add("verbose", getVerboseLevel()); } - std::unique_ptr source(KernelSupport::makeReader(m_sourceFile)); + std::shared_ptr source(KernelSupport::makeReader(m_sourceFile)); source->setOptions(sourceOptions); source->prepare(sourceCtx); PointBufferSet pbSet = source->execute(sourceCtx); @@ -300,7 +300,7 @@ int DeltaKernel::execute() candidateOptions.add("verbose", getVerboseLevel()); } - std::unique_ptr candidate(KernelSupport::makeReader(m_candidateFile)); + std::shared_ptr candidate(KernelSupport::makeReader(m_candidateFile)); candidate->setOptions(candidateOptions); candidate->prepare(candidateCtx); pbSet = candidate->execute(candidateCtx); diff --git a/kernels/diff/DiffKernel.cpp b/kernels/diff/DiffKernel.cpp index c42776dc85..ca37535a31 100644 --- a/kernels/diff/DiffKernel.cpp +++ b/kernels/diff/DiffKernel.cpp @@ -156,7 +156,7 @@ int DiffKernel::execute() sourceOptions.add("debug", isDebug()); sourceOptions.add("verbose", getVerboseLevel()); } - std::unique_ptr source(KernelSupport::makeReader(m_sourceFile)); + std::shared_ptr source(KernelSupport::makeReader(m_sourceFile)); source->setOptions(sourceOptions); source->prepare(sourceCtx); PointBufferSet sourceSet = source->execute(sourceCtx); @@ -171,7 +171,7 @@ int DiffKernel::execute() candidateOptions.add("verbose", getVerboseLevel()); } - std::unique_ptr candidate(KernelSupport::makeReader(m_candidateFile)); + std::shared_ptr candidate(KernelSupport::makeReader(m_candidateFile)); candidate->setOptions(candidateOptions); candidate->prepare(candidateCtx); PointBufferSet candidateSet = candidate->execute(candidateCtx); diff --git a/kernels/info/InfoKernel.cpp b/kernels/info/InfoKernel.cpp index a26a2559bd..e0cd661f49 100644 --- a/kernels/info/InfoKernel.cpp +++ b/kernels/info/InfoKernel.cpp @@ -356,7 +356,7 @@ int InfoKernel::execute() m_manager = std::unique_ptr( KernelSupport::makePipeline(filename)); m_reader = m_manager->getStage(); - Stage *stage = m_reader; + std::shared_ptr stage = m_reader; if (m_Dimensions.size()) m_options.add("dimensions", m_Dimensions, "List of dimensions"); diff --git a/kernels/info/InfoKernel.hpp b/kernels/info/InfoKernel.hpp index 5d89bca93b..ad8272f4d6 100644 --- a/kernels/info/InfoKernel.hpp +++ b/kernels/info/InfoKernel.hpp @@ -91,9 +91,9 @@ class PDAL_DLL InfoKernel : public Kernel std::string m_pipelineFile; bool m_showSummary; - Stage *m_statsStage; - Stage *m_hexbinStage; - Stage *m_reader; + std::shared_ptr m_statsStage; + std::shared_ptr m_hexbinStage; + std::shared_ptr m_reader; MetadataNode m_tree; std::unique_ptr m_manager; diff --git a/kernels/pipeline/PipelineKernel.cpp b/kernels/pipeline/PipelineKernel.cpp index ee59fac6e4..02088701ed 100644 --- a/kernels/pipeline/PipelineKernel.cpp +++ b/kernels/pipeline/PipelineKernel.cpp @@ -97,7 +97,7 @@ int PipelineKernel::execute() { std::string name = pi.first; Options options = pi.second; - std::vector stages = manager.getStage()->findStage(name); + std::vector > stages = manager.getStage()->findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); diff --git a/kernels/random/RandomKernel.cpp b/kernels/random/RandomKernel.cpp index 8e078259c7..abb8d864bd 100644 --- a/kernels/random/RandomKernel.cpp +++ b/kernels/random/RandomKernel.cpp @@ -99,7 +99,7 @@ Stage* RandomKernel::makeReader(Options readerOptions) } StageFactory factory; - std::unique_ptr reader_stage(factory.createStage("readers.faux")); + std::shared_ptr reader_stage(factory.createStage("readers.faux")); reader_stage->setOptions(readerOptions); return reader_stage.get(); @@ -165,9 +165,9 @@ int RandomKernel::execute() } } - Stage* final_stage = makeReader(readerOptions); + std::shared_ptr final_stage(makeReader(readerOptions)); - Stage* writer = KernelSupport::makeWriter(m_outputFile, final_stage); + std::shared_ptr writer = KernelSupport::makeWriter(m_outputFile, final_stage); writer->setOptions(writerOptions); PointContext ctx; @@ -183,9 +183,6 @@ int RandomKernel::execute() if (isVisualize()) visualize(*pbSet.begin()); - delete writer; - delete final_stage; - return 0; } diff --git a/kernels/sort/SortKernel.cpp b/kernels/sort/SortKernel.cpp index c9a7326d9d..6abba091d7 100644 --- a/kernels/sort/SortKernel.cpp +++ b/kernels/sort/SortKernel.cpp @@ -87,7 +87,7 @@ void SortKernel::addSwitches() addPositionalSwitch("output", 1); } -std::unique_ptr SortKernel::makeReader(Options readerOptions) +std::shared_ptr SortKernel::makeReader(Options readerOptions) { if (isDebug()) { @@ -100,11 +100,10 @@ std::unique_ptr SortKernel::makeReader(Options readerOptions) readerOptions.add("log", "STDERR"); } - Stage* stage = KernelSupport::makeReader(m_inputFile); + std::shared_ptr stage(KernelSupport::makeReader(m_inputFile)); stage->setOptions(readerOptions); - std::unique_ptr reader_stage(stage); - return reader_stage; + return stage; } @@ -117,7 +116,7 @@ int SortKernel::execute() readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); - std::unique_ptr readerStage = makeReader(readerOptions); + std::shared_ptr readerStage(makeReader(readerOptions)); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the @@ -128,17 +127,17 @@ int SortKernel::execute() // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointBufferPtr input_buffer = *pbSetIn.begin(); - BufferReader bufferReader; - bufferReader.setOptions(readerOptions); - bufferReader.addBuffer(input_buffer); + std::shared_ptr bufferReader(new BufferReader); + bufferReader->setOptions(readerOptions); + bufferReader->addBuffer(input_buffer); Options sortOptions; sortOptions.add("debug", isDebug()); sortOptions.add("verbose", getVerboseLevel()); StageFactory f; - Stage* sortStage = f.createStage2("filters.mortonorder"); - sortStage->setInput(&bufferReader); + std::shared_ptr sortStage(f.createStage("filters.mortonorder")); + sortStage->setInput(bufferReader); sortStage->setOptions(sortOptions); Options writerOptions; @@ -155,7 +154,7 @@ int SortKernel::execute() cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); - std::unique_ptr writer(KernelSupport::makeWriter(m_outputFile, sortStage)); + std::shared_ptr writer(KernelSupport::makeWriter(m_outputFile, sortStage)); // Some options are inferred by makeWriter based on filename // (compression, driver type, etc). @@ -167,7 +166,7 @@ int SortKernel::execute() { std::string name = pi.first; Options options = pi.second; - std::vector stages = writer->findStage(name); + std::vector > stages = writer->findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); diff --git a/kernels/sort/SortKernel.hpp b/kernels/sort/SortKernel.hpp index b44c6beae6..c161b86b27 100644 --- a/kernels/sort/SortKernel.hpp +++ b/kernels/sort/SortKernel.hpp @@ -55,7 +55,7 @@ class PDAL_DLL SortKernel : public Kernel void addSwitches(); void validateSwitches(); - std::unique_ptr makeReader(Options readerOptions); + std::shared_ptr makeReader(Options readerOptions); std::string m_inputFile; std::string m_outputFile; diff --git a/kernels/translate/TranslateKernel.cpp b/kernels/translate/TranslateKernel.cpp index 6c6f903980..e80fae3d6c 100644 --- a/kernels/translate/TranslateKernel.cpp +++ b/kernels/translate/TranslateKernel.cpp @@ -177,7 +177,7 @@ void TranslateKernel::addSwitches() addPositionalSwitch("output", 1); } -std::unique_ptr TranslateKernel::makeReader(Options readerOptions) +std::shared_ptr TranslateKernel::makeReader(Options readerOptions) { if (isDebug()) { @@ -190,25 +190,24 @@ std::unique_ptr TranslateKernel::makeReader(Options readerOptions) readerOptions.add("log", "STDERR"); } - Stage* stage = KernelSupport::makeReader(m_inputFile); + std::shared_ptr stage(KernelSupport::makeReader(m_inputFile)); stage->setOptions(readerOptions); - std::unique_ptr reader_stage(stage); - return reader_stage; + return stage; } -Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_stage) +std::shared_ptr TranslateKernel::makeTranslate(Options translateOptions, std::shared_ptr reader_stage) { StageFactory f; - Stage* final_stage = reader_stage; + std::shared_ptr final_stage(reader_stage); Options readerOptions = reader_stage->getOptions(); std::map extra_opts = getExtraStageOptions(); if (!m_bounds.empty() || !m_wkt.empty() || !m_output_srs.empty() || extra_opts.size() > 0) { - Stage* next_stage = reader_stage; - Stage* crop_stage = f.createStage2("filters.crop"); - Stage* reprojection_stage = f.createStage2("filters.reprojection"); + std::shared_ptr next_stage(reader_stage); + std::shared_ptr crop_stage(f.createStage("filters.crop")); + std::shared_ptr reprojection_stage(f.createStage("filters.reprojection")); bool bHaveReprojection = extra_opts.find("filters.reprojection") != extra_opts.end(); @@ -217,15 +216,13 @@ Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_st if (!m_output_srs.empty()) { translateOptions.add("out_srs", m_output_srs.getWKT()); - reprojection_stage = - new ReprojectionFilter(); + std::shared_ptr reprojection_stage(f.createStage("filters.reprojection")); reprojection_stage->setInput(next_stage); reprojection_stage->setOptions(readerOptions); next_stage = reprojection_stage; } else if (bHaveReprojection) { - reprojection_stage = - new ReprojectionFilter(); + std::shared_ptr reprojection_stage(f.createStage("filters.reprojection")); reprojection_stage->setInput(next_stage); reprojection_stage->setOptions(extra_opts.find("filters.reprojection")->second); next_stage = reprojection_stage; @@ -271,7 +268,7 @@ Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_st if (boost::iequals(m_decimation_method, "VoxelGrid")) { - Stage* decimation_stage(f.createStage2("filters.pclblock")); + std::shared_ptr decimation_stage(f.createStage("filters.pclblock")); Options decimationOptions; std::ostringstream ss; @@ -303,7 +300,7 @@ Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_st decimationOptions.add("step", m_decimation_step); decimationOptions.add("offset", m_decimation_offset); decimationOptions.add("limit", m_decimation_limit); - Stage* decimation_stage(f.createStage2("filters.decimation")); + std::shared_ptr decimation_stage(f.createStage("filters.decimation")); decimation_stage->setInput(final_stage); decimation_stage->setOptions(decimationOptions); final_stage = decimation_stage; @@ -323,23 +320,23 @@ int TranslateKernel::execute() if (!m_input_srs.empty()) readerOptions.add("spatialreference", m_input_srs.getWKT()); - std::unique_ptr readerStage = makeReader(readerOptions); + std::shared_ptr readerStage(makeReader(readerOptions)); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the // processing pipeline and the visualizer - readerStage->prepare(ctx); - PointBufferSet pbSetIn = readerStage->execute(ctx); + //readerStage->prepare(ctx); + //PointBufferSet pbSetIn = readerStage->execute(ctx); // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline - PointBufferPtr input_buffer = *pbSetIn.begin(); - BufferReader bufferReader; - bufferReader.setOptions(readerOptions); - bufferReader.addBuffer(input_buffer); + //PointBufferPtr input_buffer = *pbSetIn.begin(); + //BufferReader bufferReader; + //bufferReader.setOptions(readerOptions); + //bufferReader.addBuffer(input_buffer); // the translation consumes the BufferReader rather than the readerStage - Stage* finalStage = makeTranslate(readerOptions, &bufferReader); + std::shared_ptr finalStage(makeTranslate(readerOptions, readerStage)); Options writerOptions; writerOptions.add("filename", m_outputFile); @@ -358,7 +355,7 @@ int TranslateKernel::execute() cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); - std::unique_ptr writer( KernelSupport::makeWriter(m_outputFile, finalStage)); + std::shared_ptr writer(KernelSupport::makeWriter(m_outputFile, finalStage)); if (!m_output_srs.empty()) writer->setSpatialReference(m_output_srs); @@ -372,7 +369,7 @@ int TranslateKernel::execute() { std::string name = pi.first; Options options = pi.second; - std::vector stages = writer->findStage(name); + std::vector > stages = writer->findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); diff --git a/kernels/translate/TranslateKernel.hpp b/kernels/translate/TranslateKernel.hpp index c006521adb..2cb8f48ae2 100644 --- a/kernels/translate/TranslateKernel.hpp +++ b/kernels/translate/TranslateKernel.hpp @@ -55,8 +55,8 @@ class PDAL_DLL TranslateKernel : public Kernel void addSwitches(); void validateSwitches(); - std::unique_ptr makeReader(Options readerOptions); - Stage* makeTranslate(Options translateOptions, Stage* reader); + std::shared_ptr makeReader(Options readerOptions); + std::shared_ptr makeTranslate(Options translateOptions, std::shared_ptr reader); void forwardMetadata(Options & options, Metadata metadata); std::string m_inputFile; diff --git a/plugins/cpd/kernel/Cpd.cpp b/plugins/cpd/kernel/Cpd.cpp index ada192a2ee..2736a1a3a6 100644 --- a/plugins/cpd/kernel/Cpd.cpp +++ b/plugins/cpd/kernel/Cpd.cpp @@ -134,7 +134,7 @@ PointBufferPtr CpdKernel::readFile(const std::string& filename, PointContext& ct boundsOptions.add("bounds", m_bounds); StageFactory f; std::shared_ptr crop(f.createStage("filters.crop")); - crop->setInput(source.get()); + crop->setInput(source); crop->setOptions(boundsOptions); source = crop; } @@ -238,8 +238,8 @@ int CpdKernel::execute() } } - BufferReader reader; - reader.addBuffer(bufout); + std::shared_ptr reader(new BufferReader); + reader->addBuffer(bufout); Options writerOpts; writerOpts.add("filename", m_output); @@ -247,7 +247,7 @@ int CpdKernel::execute() writerOpts.add("keep_unspecified", false); setCommonOptions(writerOpts); - std::unique_ptr writer(KernelSupport::makeWriter(m_output, &reader)); + std::shared_ptr writer(KernelSupport::makeWriter(m_output, reader)); writer->setOptions(writerOpts + writer->getOptions()); writer->prepare(ctxout); writer->execute(ctxout); @@ -277,11 +277,11 @@ cpd::Registration::ResultPtr CpdKernel::chipThenRegister(const cpd::NonrigidLowr const PointBufferPtr& bufX, const PointContext& ctx) { - BufferReader reader; - reader.addBuffer(bufX); + std::shared_ptr reader(new BufferReader); + reader->addBuffer(bufX); ChipperFilter chipper; - chipper.setInput(&reader); + chipper.setInput(reader); Options options; options.add("capacity", m_chip_capacity); chipper.setOptions(options); diff --git a/plugins/cpd/test/CpdKernelTest.cpp b/plugins/cpd/test/CpdKernelTest.cpp index 6039741bfe..0f738f31f0 100644 --- a/plugins/cpd/test/CpdKernelTest.cpp +++ b/plugins/cpd/test/CpdKernelTest.cpp @@ -65,17 +65,17 @@ class CpdKernelTest : public ::testing::Test Options readerOptions; readerOptions.add("filename", m_x); - Stage * reader = mrManager.addReader("readers.las"); + std::shared_ptr reader(mrManager.addReader("readers.las")); reader->setOptions(readerOptions); Options transformationOptions; transformationOptions.add("matrix", "0.36 0.48 -0.8 1\n-0.8 0.6 0.0 2\n0.48 0.64 0.60 3\n0 0 0 1"); - Stage* filter = mrManager.addFilter("filters.transformation", reader); + std::shared_ptr filter(mrManager.addFilter("filters.transformation", reader)); filter->setOptions(transformationOptions); Options writerOptions; writerOptions.add("filename", m_y); - Stage * writer = mrManager.addWriter("writers.las", reader); + std::shared_ptr writer(mrManager.addWriter("writers.las", filter)); writer->setOptions(writerOptions); point_count_t np = mrManager.execute(); diff --git a/plugins/hexbin/test/HexbinFilterTest.cpp b/plugins/hexbin/test/HexbinFilterTest.cpp index 0b6e099d66..22e718e219 100644 --- a/plugins/hexbin/test/HexbinFilterTest.cpp +++ b/plugins/hexbin/test/HexbinFilterTest.cpp @@ -71,14 +71,14 @@ TEST(HexbinFilterTest, HexbinFilterTest_test_1) "use in situations where you do not want to estimate based on " "a sample"); - std::unique_ptr reader(f.createStage("readers.las")); + std::shared_ptr reader(f.createStage("readers.las")); EXPECT_TRUE(reader.get()); reader->setOptions(options); - std::unique_ptr hexbin(f.createStage("filters.hexbin")); + std::shared_ptr hexbin(f.createStage("filters.hexbin")); EXPECT_TRUE(hexbin.get()); hexbin->setOptions(options); - hexbin->setInput(reader.get()); + hexbin->setInput(reader); PointContext ctx; diff --git a/plugins/nitf/test/NitfReaderTest.cpp b/plugins/nitf/test/NitfReaderTest.cpp index 87dfbae5e9..56ebe54ef4 100644 --- a/plugins/nitf/test/NitfReaderTest.cpp +++ b/plugins/nitf/test/NitfReaderTest.cpp @@ -63,7 +63,7 @@ TEST(NitfReaderTest, test_one) PointContext ctx; - std::unique_ptr nitf_reader(f.createStage("readers.nitf")); + std::shared_ptr nitf_reader(f.createStage("readers.nitf")); EXPECT_TRUE(nitf_reader.get()); nitf_reader->setOptions(nitf_opts); nitf_reader->prepare(ctx); @@ -91,7 +91,7 @@ TEST(NitfReaderTest, test_one) PointContext ctx2; - std::unique_ptr las_reader(f.createStage("readers.las")); + std::shared_ptr las_reader(f.createStage("readers.las")); EXPECT_TRUE(las_reader.get()); las_reader->setOptions(las_opts); las_reader->prepare(ctx2); @@ -156,16 +156,16 @@ TEST(NitfReaderTest, optionSrs) PointContext ctx; - std::unique_ptr nitfReader(f.createStage("readers.nitf")); + std::shared_ptr nitfReader(f.createStage("readers.nitf")); EXPECT_TRUE(nitfReader.get()); nitfReader->setOptions(nitfOpts); Options lasOpts; lasOpts.add("filename", "/dev/null"); - std::unique_ptr lasWriter(f.createStage("writers.las")); + std::shared_ptr lasWriter(f.createStage("writers.las")); EXPECT_TRUE(lasWriter.get()); - lasWriter->setInput(nitfReader.get()); + lasWriter->setInput(nitfReader); lasWriter->setOptions(lasOpts);; lasWriter->prepare(ctx); diff --git a/plugins/nitf/test/NitfWriterTest.cpp b/plugins/nitf/test/NitfWriterTest.cpp index 181871c38c..022707d82d 100644 --- a/plugins/nitf/test/NitfWriterTest.cpp +++ b/plugins/nitf/test/NitfWriterTest.cpp @@ -147,14 +147,14 @@ TEST(NitfWriterTest, test1) // writer_opts.add(verbose); writer_opts.add(writer_opt1); - std::unique_ptr reader(f.createStage("readers.las")); + std::shared_ptr reader(f.createStage("readers.las")); EXPECT_TRUE(reader.get()); reader->setOptions(reader_opts); - std::unique_ptr writer(f.createStage("writers.nitf")); + std::shared_ptr writer(f.createStage("writers.nitf")); EXPECT_TRUE(writer.get()); writer->setOptions(writer_opts); - writer->setInput(reader.get()); + writer->setInput(reader); { // writer.setCompressed(false); // // writer.setDate(0, 0); diff --git a/plugins/pcl/kernel/GroundKernel.cpp b/plugins/pcl/kernel/GroundKernel.cpp index 535d24c181..a2bcd54853 100644 --- a/plugins/pcl/kernel/GroundKernel.cpp +++ b/plugins/pcl/kernel/GroundKernel.cpp @@ -106,7 +106,7 @@ void GroundKernel::addSwitches() addPositionalSwitch("output", 1); } -std::unique_ptr GroundKernel::makeReader(Options readerOptions) +std::shared_ptr GroundKernel::makeReader(Options readerOptions) { if (isDebug()) { @@ -119,11 +119,10 @@ std::unique_ptr GroundKernel::makeReader(Options readerOptions) readerOptions.add("log", "STDERR"); } - Stage* stage = KernelSupport::makeReader(m_inputFile); + std::shared_ptr stage = KernelSupport::makeReader(m_inputFile); stage->setOptions(readerOptions); - std::unique_ptr reader_stage(stage); - return reader_stage; + return stage; } int GroundKernel::execute() @@ -135,7 +134,7 @@ int GroundKernel::execute() readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); - std::unique_ptr readerStage = makeReader(readerOptions); + std::shared_ptr readerStage = makeReader(readerOptions); Options groundOptions; groundOptions.add("maxWindowSize", m_maxWindowSize); @@ -147,16 +146,16 @@ int GroundKernel::execute() groundOptions.add("extract", m_extract); StageFactory f; - std::unique_ptr groundStage(f.createStage("filters.ground")); + std::shared_ptr groundStage(f.createStage("filters.ground")); groundStage->setOptions(groundOptions); - groundStage->setInput(readerStage.get()); + groundStage->setInput(readerStage); // setup the Writer and write the results Options writerOptions; writerOptions.add("filename", m_outputFile); setCommonOptions(writerOptions); - std::unique_ptr writer(KernelSupport::makeWriter(m_outputFile, groundStage.get())); + std::shared_ptr writer(KernelSupport::makeWriter(m_outputFile, groundStage)); writer->setOptions(writerOptions); std::vector cmd = getProgressShellCommand(); @@ -170,7 +169,7 @@ int GroundKernel::execute() { std::string name = pi.first; Options options = pi.second; - std::vector stages = writer->findStage(name); + std::vector > stages = writer->findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); diff --git a/plugins/pcl/kernel/GroundKernel.hpp b/plugins/pcl/kernel/GroundKernel.hpp index 0ddf30338e..31db430ddb 100644 --- a/plugins/pcl/kernel/GroundKernel.hpp +++ b/plugins/pcl/kernel/GroundKernel.hpp @@ -60,7 +60,7 @@ class PDAL_DLL GroundKernel : public Kernel void addSwitches(); void validateSwitches(); - std::unique_ptr makeReader(Options readerOptions); + std::shared_ptr makeReader(Options readerOptions); std::string m_inputFile; std::string m_outputFile; diff --git a/plugins/pcl/kernel/PCLKernel.cpp b/plugins/pcl/kernel/PCLKernel.cpp index 817c1d300f..09cdeea870 100644 --- a/plugins/pcl/kernel/PCLKernel.cpp +++ b/plugins/pcl/kernel/PCLKernel.cpp @@ -94,7 +94,7 @@ void PCLKernel::addSwitches() addPositionalSwitch("pcl", 1); } -std::unique_ptr PCLKernel::makeReader(Options readerOptions) +std::shared_ptr PCLKernel::makeReader(Options readerOptions) { if (isDebug()) { @@ -107,11 +107,10 @@ std::unique_ptr PCLKernel::makeReader(Options readerOptions) readerOptions.add("log", "STDERR"); } - Stage* stage = KernelSupport::makeReader(m_inputFile); + std::shared_ptr stage = KernelSupport::makeReader(m_inputFile); stage->setOptions(readerOptions); - std::unique_ptr reader_stage(stage); - return reader_stage; + return stage; } @@ -124,7 +123,7 @@ int PCLKernel::execute() readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); - std::unique_ptr readerStage = makeReader(readerOptions); + std::shared_ptr readerStage = makeReader(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the @@ -135,16 +134,16 @@ int PCLKernel::execute() // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointBufferPtr input_buffer = *pbSetIn.begin(); - BufferReader bufferReader; - bufferReader.addBuffer(input_buffer); + std::shared_ptr bufferReader(new BufferReader); + bufferReader->addBuffer(input_buffer); Options pclOptions; pclOptions.add("filename", m_pclFile); pclOptions.add("debug", isDebug()); pclOptions.add("verbose", getVerboseLevel()); - std::unique_ptr pclStage(new PCLBlock()); - pclStage->setInput(&bufferReader); + std::shared_ptr pclStage(new PCLBlock()); + pclStage->setInput(bufferReader); pclStage->setOptions(pclOptions); // the PCLBlock stage consumes the BufferReader rather than the @@ -164,8 +163,8 @@ int PCLKernel::execute() cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); - std::unique_ptr - writer(KernelSupport::makeWriter(m_outputFile, pclStage.get())); + std::shared_ptr + writer(KernelSupport::makeWriter(m_outputFile, pclStage)); // Some options are inferred by makeWriter based on filename // (compression, driver type, etc). @@ -177,7 +176,7 @@ int PCLKernel::execute() { std::string name = pi.first; Options options = pi.second; - std::vector stages = writer->findStage(name); + std::vector > stages = writer->findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); diff --git a/plugins/pcl/kernel/PCLKernel.hpp b/plugins/pcl/kernel/PCLKernel.hpp index 4b3d02223d..c51d4885c7 100644 --- a/plugins/pcl/kernel/PCLKernel.hpp +++ b/plugins/pcl/kernel/PCLKernel.hpp @@ -51,7 +51,7 @@ class PDAL_DLL PCLKernel : public Kernel void addSwitches(); void validateSwitches(); - std::unique_ptr makeReader(Options readerOptions); + std::shared_ptr makeReader(Options readerOptions); std::string m_inputFile; std::string m_outputFile; diff --git a/plugins/pcl/kernel/SmoothKernel.cpp b/plugins/pcl/kernel/SmoothKernel.cpp index 62d8a1d474..9e36f29b2c 100644 --- a/plugins/pcl/kernel/SmoothKernel.cpp +++ b/plugins/pcl/kernel/SmoothKernel.cpp @@ -82,7 +82,7 @@ void SmoothKernel::addSwitches() addPositionalSwitch("output", 1); } -std::unique_ptr SmoothKernel::makeReader(Options readerOptions) +std::shared_ptr SmoothKernel::makeReader(Options readerOptions) { if (isDebug()) { @@ -95,11 +95,10 @@ std::unique_ptr SmoothKernel::makeReader(Options readerOptions) readerOptions.add("log", "STDERR"); } - Stage* stage = KernelSupport::makeReader(m_inputFile); + std::shared_ptr stage = KernelSupport::makeReader(m_inputFile); stage->setOptions(readerOptions); - std::unique_ptr reader_stage(stage); - return reader_stage; + return stage; } @@ -112,7 +111,7 @@ int SmoothKernel::execute() readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); - std::unique_ptr readerStage = makeReader(readerOptions); + std::shared_ptr readerStage = makeReader(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the @@ -123,9 +122,9 @@ int SmoothKernel::execute() // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointBufferPtr input_buffer = *pbSetIn.begin(); - BufferReader bufferReader; - bufferReader.setOptions(readerOptions); - bufferReader.addBuffer(input_buffer); + std::shared_ptr bufferReader(new BufferReader); + bufferReader->setOptions(readerOptions); + bufferReader->addBuffer(input_buffer); Options smoothOptions; std::ostringstream ss; @@ -141,15 +140,15 @@ int SmoothKernel::execute() smoothOptions.add("debug", isDebug()); smoothOptions.add("verbose", getVerboseLevel()); - std::unique_ptr smoothStage(new PCLBlock()); + std::shared_ptr smoothStage(new PCLBlock()); smoothStage->setOptions(smoothOptions); - smoothStage->setInput(&bufferReader); + smoothStage->setInput(bufferReader); Options writerOptions; writerOptions.add("filename", m_outputFile); setCommonOptions(writerOptions); - std::unique_ptr writer(KernelSupport::makeWriter(m_outputFile, smoothStage.get())); + std::shared_ptr writer(KernelSupport::makeWriter(m_outputFile, smoothStage)); writer->setOptions(writerOptions); std::vector cmd = getProgressShellCommand(); @@ -165,8 +164,8 @@ int SmoothKernel::execute() { std::string name = pi->first; Options options = pi->second; - std::vector stages = writer->findStage(name); - std::vector::iterator s; + std::vector > stages = writer->findStage(name); + std::vector >::iterator s; for (s = stages.begin(); s != stages.end(); ++s) { Options opts = (*s)->getOptions(); diff --git a/plugins/pcl/kernel/SmoothKernel.hpp b/plugins/pcl/kernel/SmoothKernel.hpp index 7804b57661..45e6853aa5 100644 --- a/plugins/pcl/kernel/SmoothKernel.hpp +++ b/plugins/pcl/kernel/SmoothKernel.hpp @@ -54,7 +54,7 @@ class PDAL_DLL SmoothKernel : public Kernel void addSwitches(); void validateSwitches(); - std::unique_ptr makeReader(Options readerOptions); + std::shared_ptr makeReader(Options readerOptions); std::string m_inputFile; std::string m_outputFile; diff --git a/plugins/pcl/kernel/ViewKernel.cpp b/plugins/pcl/kernel/ViewKernel.cpp index 8fa25362e0..5b29163cc6 100644 --- a/plugins/pcl/kernel/ViewKernel.cpp +++ b/plugins/pcl/kernel/ViewKernel.cpp @@ -126,9 +126,7 @@ vector getListOfPoints(std::string p) ViewKernel::ViewKernel() : Kernel() , m_inputFile("") -{ - return; -} +{} void ViewKernel::validateSwitches() @@ -137,8 +135,6 @@ void ViewKernel::validateSwitches() { throw app_usage_error("--input/-i required"); } - - return; } @@ -156,7 +152,7 @@ void ViewKernel::addSwitches() addPositionalSwitch("input", 1); } -std::unique_ptr ViewKernel::makeReader(Options readerOptions) +std::shared_ptr ViewKernel::makeReader(Options readerOptions) { if (isDebug()) { @@ -169,11 +165,10 @@ std::unique_ptr ViewKernel::makeReader(Options readerOptions) readerOptions.add("log", "STDERR"); } - Stage* stage = KernelSupport::makeReader(m_inputFile); + std::shared_ptr stage(KernelSupport::makeReader(m_inputFile)); stage->setOptions(readerOptions); - std::unique_ptr reader_stage(stage); - return reader_stage; + return stage; } @@ -184,7 +179,7 @@ int ViewKernel::execute() readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); - std::unique_ptr readerStage = makeReader(readerOptions); + std::shared_ptr readerStage(makeReader(readerOptions)); PointContext ctx; readerStage->prepare(ctx); PointBufferSet pbSetIn = readerStage->execute(ctx); diff --git a/plugins/pcl/kernel/ViewKernel.hpp b/plugins/pcl/kernel/ViewKernel.hpp index 0bece45363..347d5e9ee4 100644 --- a/plugins/pcl/kernel/ViewKernel.hpp +++ b/plugins/pcl/kernel/ViewKernel.hpp @@ -54,7 +54,7 @@ class PDAL_DLL ViewKernel : public Kernel void addSwitches(); void validateSwitches(); - std::unique_ptr makeReader(Options readerOptions); + std::shared_ptr makeReader(Options readerOptions); std::string m_inputFile; std::string m_pointIndexes; diff --git a/plugins/pcl/test/PCLBlockFilterTest.cpp b/plugins/pcl/test/PCLBlockFilterTest.cpp index 8a29d0d9a2..2c02ed92d2 100644 --- a/plugins/pcl/test/PCLBlockFilterTest.cpp +++ b/plugins/pcl/test/PCLBlockFilterTest.cpp @@ -48,18 +48,7 @@ using namespace pdal; TEST(PCLBlockFilterTest, PCLBlockFilterTest_example_passthrough_xml) { StageFactory f; - //std::vector nv = f.getStageNames(); - //std::cerr << nv.size() << std::endl; - //for (auto name : nv) - // std::cout << name << std::endl; - std::unique_ptr filter(f.createStage("filters.pclblock")); - - //std::unique_ptr filter(f.createStage("filters.pclblock")); - //PluginManager & pm = PluginManager::getInstance(); - - //void * stage = pm.createObject("filters.pclblock"); - //EXPECT_TRUE(stage); - //Filter * filter = (Filter*)stage; + std::shared_ptr filter(f.createStage("filters.pclblock")); EXPECT_TRUE(filter.get()); PipelineManager pipeline; @@ -95,7 +84,7 @@ static void test_filter(const std::string& jsonFile, options.add(debug); options.add(verbose); - std::unique_ptr reader(f.createStage("readers.las")); + std::shared_ptr reader(f.createStage("readers.las")); EXPECT_TRUE(reader.get()); reader->setOptions(options); @@ -103,10 +92,10 @@ static void test_filter(const std::string& jsonFile, Options filter_options; filter_options.add(fname); - std::unique_ptr pcl_block(f.createStage("filters.pclblock")); + std::shared_ptr pcl_block(f.createStage("filters.pclblock")); EXPECT_TRUE(pcl_block.get()); pcl_block->setOptions(filter_options); - pcl_block->setInput(reader.get()); + pcl_block->setInput(reader); PointContext ctx; pcl_block->prepare(ctx); diff --git a/plugins/python/test/PredicateFilterTest.cpp b/plugins/python/test/PredicateFilterTest.cpp index b568365789..477a68ec1a 100644 --- a/plugins/python/test/PredicateFilterTest.cpp +++ b/plugins/python/test/PredicateFilterTest.cpp @@ -54,7 +54,7 @@ TEST(PredicateFilterTest, PredicateFilterTest_test1) readerOps.add("num_points", 1000); readerOps.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(readerOps); // keep all points where x less than 1.0 @@ -76,24 +76,24 @@ TEST(PredicateFilterTest, PredicateFilterTest_test1) opts.add(module); opts.add(function); - std::unique_ptr filter(f.createStage("filters.predicate")); + std::shared_ptr filter(f.createStage("filters.predicate")); filter->setOptions(opts); - filter->setInput(reader.get()); + filter->setInput(reader); Options statOpts; - StatsFilter stats; - stats.setOptions(statOpts); - stats.setInput(filter.get()); + std::shared_ptr stats(new StatsFilter); + stats->setOptions(statOpts); + stats->setInput(filter); PointContext ctx; - stats.prepare(ctx); - PointBufferSet pbSet = stats.execute(ctx); + stats->prepare(ctx); + PointBufferSet pbSet = stats->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); - const stats::Summary& statsX = stats.getStats(Dimension::Id::X); - const stats::Summary& statsY = stats.getStats(Dimension::Id::Y); - const stats::Summary& statsZ = stats.getStats(Dimension::Id::Z); + const stats::Summary& statsX = stats->getStats(Dimension::Id::X); + const stats::Summary& statsY = stats->getStats(Dimension::Id::Y); + const stats::Summary& statsZ = stats->getStats(Dimension::Id::Z); EXPECT_TRUE(Utils::compare_approx(statsX.minimum(), 0.0, 0.01)); EXPECT_TRUE(Utils::compare_approx(statsY.minimum(), 0.0, 0.01)); @@ -114,7 +114,7 @@ TEST(PredicateFilterTest, PredicateFilterTest_test2) readerOps.add("num_points", 1000); readerOps.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(readerOps); Option source("source", @@ -134,24 +134,24 @@ TEST(PredicateFilterTest, PredicateFilterTest_test2) opts.add(module); opts.add(function); - std::unique_ptr filter(f.createStage("filters.predicate")); + std::shared_ptr filter(f.createStage("filters.predicate")); filter->setOptions(opts); - filter->setInput(reader.get()); + filter->setInput(reader); Options statOpts; - StatsFilter stats; - stats.setOptions(statOpts); - stats.setInput(filter.get()); + std::shared_ptr stats(new StatsFilter); + stats->setOptions(statOpts); + stats->setInput(filter); PointContext ctx; - stats.prepare(ctx); - PointBufferSet pbSet = stats.execute(ctx); + stats->prepare(ctx); + PointBufferSet pbSet = stats->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); - const stats::Summary& statsX = stats.getStats(Dimension::Id::X); - const stats::Summary& statsY = stats.getStats(Dimension::Id::Y); - const stats::Summary& statsZ = stats.getStats(Dimension::Id::Z); + const stats::Summary& statsX = stats->getStats(Dimension::Id::X); + const stats::Summary& statsY = stats->getStats(Dimension::Id::Y); + const stats::Summary& statsZ = stats->getStats(Dimension::Id::Z); EXPECT_TRUE(Utils::compare_approx(statsX.minimum(), 1.0, 0.01)); EXPECT_TRUE(Utils::compare_approx(statsY.minimum(), 1.0, 0.01)); @@ -172,7 +172,7 @@ TEST(PredicateFilterTest, PredicateFilterTest_test3) readerOpts.add("num_points", 1000); readerOpts.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(readerOpts); // keep all points where x less than 1.0 @@ -194,9 +194,9 @@ TEST(PredicateFilterTest, PredicateFilterTest_test3) opts1.add(module1); opts1.add(function1); - std::unique_ptr filter1(f.createStage("filters.predicate")); + std::shared_ptr filter1(f.createStage("filters.predicate")); filter1->setOptions(opts1); - filter1->setInput(reader.get()); + filter1->setInput(reader); // keep all points where y greater than 0.5 const Option source2("source", @@ -217,22 +217,22 @@ TEST(PredicateFilterTest, PredicateFilterTest_test3) opts2.add(module2); opts2.add(function2); - std::unique_ptr filter2(f.createStage("filters.predicate")); + std::shared_ptr filter2(f.createStage("filters.predicate")); filter2->setOptions(opts2); - filter2->setInput(filter1.get()); + filter2->setInput(filter1); Options statOpts; - StatsFilter stats; - stats.setOptions(statOpts); - stats.setInput(filter2.get()); + std::shared_ptr stats(new StatsFilter); + stats->setOptions(statOpts); + stats->setInput(filter2); PointContext ctx; - stats.prepare(ctx); - stats.execute(ctx); + stats->prepare(ctx); + stats->execute(ctx); - const stats::Summary& statsX = stats.getStats(Dimension::Id::X); - const stats::Summary& statsY = stats.getStats(Dimension::Id::Y); - const stats::Summary& statsZ = stats.getStats(Dimension::Id::Z); + const stats::Summary& statsX = stats->getStats(Dimension::Id::X); + const stats::Summary& statsY = stats->getStats(Dimension::Id::Y); + const stats::Summary& statsZ = stats->getStats(Dimension::Id::Z); EXPECT_TRUE(Utils::compare_approx(statsX.minimum(), 0.5, 0.01)); EXPECT_TRUE(Utils::compare_approx(statsY.minimum(), 0.5, 0.01)); @@ -253,7 +253,7 @@ TEST(PredicateFilterTest, PredicateFilterTest_test4) readerOpts.add("num_points", 1000); readerOpts.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(readerOpts); const Option source("source", @@ -273,25 +273,25 @@ TEST(PredicateFilterTest, PredicateFilterTest_test4) opts.add(module); opts.add(function); - std::unique_ptr filter(f.createStage("filters.predicate")); + std::shared_ptr filter(f.createStage("filters.predicate")); filter->setOptions(opts); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; PointBufferPtr buf(new PointBuffer(ctx)); filter->prepare(ctx); - StageTester::ready(reader.get(), ctx); - PointBufferSet pbSet = StageTester::run(reader.get(), buf); - StageTester::done(reader.get(), ctx); + StageTester::ready(reader, ctx); + PointBufferSet pbSet = StageTester::run(reader, buf); + StageTester::done(reader, ctx); EXPECT_EQ(pbSet.size(), 1u); buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 1000u); - StageTester::ready(filter.get(), ctx); - pbSet = StageTester::run(filter.get(), buf); - StageTester::done(filter.get(), ctx); + StageTester::ready(filter, ctx); + pbSet = StageTester::run(filter, buf); + StageTester::done(filter, ctx); EXPECT_EQ(pbSet.size(), 1u); buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 750u); @@ -308,7 +308,7 @@ TEST(PredicateFilterTest, PredicateFilterTest_test5) readerOpts.add("num_points", 1000); readerOpts.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(readerOpts); const Option source("source", @@ -328,9 +328,9 @@ TEST(PredicateFilterTest, PredicateFilterTest_test5) opts.add(module); opts.add(function); - std::unique_ptr filter(f.createStage("filters.predicate")); + std::shared_ptr filter(f.createStage("filters.predicate")); filter->setOptions(opts); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); diff --git a/plugins/python/test/ProgrammableFilterTest.cpp b/plugins/python/test/ProgrammableFilterTest.cpp index 07f6985a7e..655aa91ca5 100644 --- a/plugins/python/test/ProgrammableFilterTest.cpp +++ b/plugins/python/test/ProgrammableFilterTest.cpp @@ -54,7 +54,7 @@ TEST(ProgrammableFilterTest, ProgrammableFilterTest_test1) ops.add("num_points", 10); ops.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Option source("source", "import numpy as np\n" @@ -79,23 +79,23 @@ TEST(ProgrammableFilterTest, ProgrammableFilterTest_test1) opts.add(module); opts.add(function); - std::unique_ptr filter(f.createStage("filters.programmable")); + std::shared_ptr filter(f.createStage("filters.programmable")); filter->setOptions(opts); - filter->setInput(reader.get()); + filter->setInput(reader); - StatsFilter stats; - stats.setInput(filter.get()); + std::shared_ptr stats(new StatsFilter); + stats->setInput(filter); PointContext ctx; - stats.prepare(ctx); - PointBufferSet pbSet = stats.execute(ctx); + stats->prepare(ctx); + PointBufferSet pbSet = stats->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); - const stats::Summary& statsX = stats.getStats(Dimension::Id::X); - const stats::Summary& statsY = stats.getStats(Dimension::Id::Y); - const stats::Summary& statsZ = stats.getStats(Dimension::Id::Z); + const stats::Summary& statsX = stats->getStats(Dimension::Id::X); + const stats::Summary& statsY = stats->getStats(Dimension::Id::Y); + const stats::Summary& statsZ = stats->getStats(Dimension::Id::Z); EXPECT_FLOAT_EQ(statsX.minimum(), 10.0); EXPECT_FLOAT_EQ(statsX.maximum(), 11.0); @@ -137,7 +137,7 @@ TEST(ProgrammableFilterTest, add_dimension) ops.add("num_points", 10); ops.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Option source("source", "import numpy\n" @@ -157,9 +157,9 @@ TEST(ProgrammableFilterTest, add_dimension) opts.add(intensity); opts.add(scanDirection); - std::unique_ptr filter(f.createStage("filters.programmable")); + std::shared_ptr filter(f.createStage("filters.programmable")); filter->setOptions(opts); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); diff --git a/src/Kernel.cpp b/src/Kernel.cpp index 83863790e0..d31e13e4a4 100644 --- a/src/Kernel.cpp +++ b/src/Kernel.cpp @@ -353,12 +353,12 @@ bool Kernel::isVisualize() const void Kernel::visualize(PointBufferPtr buffer) const { - BufferReader bufferReader; - bufferReader.addBuffer(buffer); + std::shared_ptr bufferReader(new BufferReader); + bufferReader->addBuffer(buffer); StageFactory f; - std::unique_ptr writer(f.createStage("writers.pclvisualizer")); - writer->setInput(&bufferReader); + std::shared_ptr writer(f.createStage("writers.pclvisualizer")); + writer->setInput(bufferReader); PointContext ctx; writer->prepare(ctx); diff --git a/src/KernelSupport.cpp b/src/KernelSupport.cpp index f4933824d8..0632211cf7 100644 --- a/src/KernelSupport.cpp +++ b/src/KernelSupport.cpp @@ -76,7 +76,7 @@ PipelineManager* KernelSupport::makePipeline(const std::string& inputFile) } -Stage *KernelSupport::makeReader(const std::string& inputFile) +std::shared_ptr KernelSupport::makeReader(const std::string& inputFile) { if (!FileUtils::fileExists(inputFile)) throw app_runtime_error("file not found: " + inputFile); @@ -87,14 +87,14 @@ Stage *KernelSupport::makeReader(const std::string& inputFile) throw app_runtime_error("Cannot determine input file type of " + inputFile); - Stage* stage = factory.createStage2(driver); + std::shared_ptr stage(factory.createStage(driver)); if (!stage) throw app_runtime_error("reader creation failed"); return stage; } -Stage* KernelSupport::makeWriter(const std::string& outputFile, Stage *stage) +std::shared_ptr KernelSupport::makeWriter(const std::string& outputFile, std::shared_ptr stage) { pdal::StageFactory factory; std::string driver = factory.inferWriterDriver(outputFile); @@ -103,7 +103,7 @@ Stage* KernelSupport::makeWriter(const std::string& outputFile, Stage *stage) outputFile); Options options = factory.inferWriterOptionsChanges(outputFile); - Stage* writer = factory.createStage2(driver); + std::shared_ptr writer(factory.createStage(driver)); if (!writer) throw app_runtime_error("writer creation failed"); writer->setInput(stage); diff --git a/src/PipelineManager.cpp b/src/PipelineManager.cpp index 0e6606fc0f..4aa8b12b0b 100644 --- a/src/PipelineManager.cpp +++ b/src/PipelineManager.cpp @@ -45,43 +45,42 @@ PipelineManager::~PipelineManager() { while (m_stages.size()) { - Stage* stage = m_stages.back(); + std::shared_ptr stage = m_stages.back(); m_stages.pop_back(); - delete stage; } } -Stage* PipelineManager::addReader(const std::string& type) +std::shared_ptr PipelineManager::addReader(const std::string& type) { - Stage *r = m_factory.createStage2(type); + std::shared_ptr r(m_factory.createStage(type)); m_stages.push_back(r); return r; } -Stage* PipelineManager::addFilter(const std::string& type, - const std::vector& prevStages) +std::shared_ptr PipelineManager::addFilter(const std::string& type, + const std::vector >& prevStages) { - Stage* stage = m_factory.createStage2(type); + std::shared_ptr stage(m_factory.createStage(type)); stage->setInput(prevStages); m_stages.push_back(stage); return stage; } -Stage* PipelineManager::addFilter(const std::string& type, Stage *prevStage) +std::shared_ptr PipelineManager::addFilter(const std::string& type, std::shared_ptr prevStage) { - Stage* stage = m_factory.createStage2(type); + std::shared_ptr stage(m_factory.createStage(type)); stage->setInput(prevStage); m_stages.push_back(stage); return stage; } -Stage* PipelineManager::addWriter(const std::string& type, Stage *prevStage) +std::shared_ptr PipelineManager::addWriter(const std::string& type, std::shared_ptr prevStage) { - Stage* writer = m_factory.createStage2(type); + std::shared_ptr writer(m_factory.createStage(type)); writer->setInput(prevStage); m_stages.push_back(writer); return writer; @@ -90,7 +89,7 @@ Stage* PipelineManager::addWriter(const std::string& type, Stage *prevStage) void PipelineManager::prepare() const { - Stage *s = getStage(); + std::shared_ptr s = getStage(); if (s) s->prepare(m_context); } @@ -100,7 +99,7 @@ point_count_t PipelineManager::execute() { prepare(); - Stage *s = getStage(); + std::shared_ptr s = getStage(); if (!s) return 0; m_pbSet = s->execute(m_context); diff --git a/src/PipelineReader.cpp b/src/PipelineReader.cpp index 60bf2207d1..7b7ce2e9d4 100644 --- a/src/PipelineReader.cpp +++ b/src/PipelineReader.cpp @@ -212,10 +212,10 @@ Option PipelineReader::parseElement_Option(const ptree& tree) } -Stage* PipelineReader::parseElement_anystage(const std::string& name, +std::shared_ptr PipelineReader::parseElement_anystage(const std::string& name, const ptree& subtree) { - Stage* stage = NULL; + std::shared_ptr stage = NULL; if (name == "Filter") { @@ -238,7 +238,7 @@ Stage* PipelineReader::parseElement_anystage(const std::string& name, } -Stage* PipelineReader::parseElement_Reader(const ptree& tree) +std::shared_ptr PipelineReader::parseElement_Reader(const ptree& tree) { Options options(m_baseOptions); @@ -300,13 +300,13 @@ Stage* PipelineReader::parseElement_Reader(const ptree& tree) context.validate(); - Stage* reader = m_manager.addReader(type); + std::shared_ptr reader(m_manager.addReader(type)); reader->setOptions(options); return reader; } -Stage* PipelineReader::parseElement_Filter(const ptree& tree) +std::shared_ptr PipelineReader::parseElement_Filter(const ptree& tree) { Options options(m_baseOptions); // Stage* prevStage = NULL; @@ -316,7 +316,7 @@ Stage* PipelineReader::parseElement_Filter(const ptree& tree) map_t attrs; collect_attributes(attrs, tree); - std::vector prevStages; + std::vector > prevStages; for (auto iter = tree.begin(); iter != tree.end(); ++iter) { const std::string& name = iter->first; @@ -353,9 +353,10 @@ Stage* PipelineReader::parseElement_Filter(const ptree& tree) context.addType(); } - Stage* ptr = m_manager.addFilter(type, prevStages); + std::shared_ptr ptr(m_manager.addFilter(type, prevStages)); ptr->setOptions(options); - if (dynamic_cast(ptr)) + //if (dynamic_cast >(ptr)) + if (ptr) context.setCardinality(StageParserContext::Many); context.validate(); return ptr; @@ -385,10 +386,10 @@ void PipelineReader::collect_attributes(map_t& attrs, const ptree& tree) } -Stage* PipelineReader::parseElement_Writer(const ptree& tree) +std::shared_ptr PipelineReader::parseElement_Writer(const ptree& tree) { Options options(m_baseOptions); - Stage* prevStage = NULL; + std::shared_ptr prevStage = NULL; StageParserContext context; map_t attrs; @@ -431,7 +432,7 @@ Stage* PipelineReader::parseElement_Writer(const ptree& tree) } context.validate(); - Stage* writer = m_manager.addWriter(type, prevStage); + std::shared_ptr writer(m_manager.addWriter(type, prevStage)); writer->setOptions(options); return writer; } @@ -439,8 +440,8 @@ Stage* PipelineReader::parseElement_Writer(const ptree& tree) bool PipelineReader::parseElement_Pipeline(const ptree& tree) { - Stage* stage = NULL; - Stage* writer = NULL; + std::shared_ptr stage = NULL; + std::shared_ptr writer = NULL; map_t attrs; collect_attributes(attrs, tree); diff --git a/src/PipelineWriter.cpp b/src/PipelineWriter.cpp index 1970a5d8c6..87599ede21 100644 --- a/src/PipelineWriter.cpp +++ b/src/PipelineWriter.cpp @@ -134,7 +134,7 @@ void PipelineWriter::writeMetadata(boost::property_tree::ptree& tree, void PipelineWriter::writePipeline(const std::string& filename) const { - const Stage* stage = m_manager.getStage(); + const std::shared_ptr stage = m_manager.getStage(); ptree tree = generateTreeFromStage(*stage); #if BOOST_VERSION >= 105600 diff --git a/src/Stage.cpp b/src/Stage.cpp index 94c2e80a4f..c34b55b994 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -62,7 +62,7 @@ void Stage::prepare(PointContextRef ctx) { for (size_t i = 0; i < m_inputs.size(); ++i) { - Stage *prev = m_inputs[i]; + std::shared_ptr prev(m_inputs[i]); prev->prepare(ctx); } l_processOptions(m_options); @@ -85,7 +85,7 @@ PointBufferSet Stage::execute(PointContextRef ctx) { for (size_t i = 0; i < m_inputs.size(); ++i) { - Stage *prev = m_inputs[i]; + std::shared_ptr prev(m_inputs[i]); PointBufferSet temp = prev->execute(ctx); buffers.insert(temp.begin(), temp.end()); } @@ -97,7 +97,7 @@ PointBufferSet Stage::execute(PointContextRef ctx) ready(ctx); for (auto const& it : buffers) { - StageRunnerPtr runner(new StageRunner(this, it)); + StageRunnerPtr runner(new StageRunner(shared_from_this(), it)); runners.push_back(runner); runner->run(); } @@ -205,11 +205,11 @@ void Stage::setSpatialReference(MetadataNode& m, } } -std::vector Stage::findStage(std::string name) +std::vector > Stage::findStage(std::string name) { - std::vector output; + std::vector > output; if (boost::iequals(getName(), name)) - output.push_back(this); + output.push_back(std::shared_ptr (this)); for (auto const& stage : m_inputs) { diff --git a/src/StageFactory.cpp b/src/StageFactory.cpp index c667f9f810..cd4dcb5720 100644 --- a/src/StageFactory.cpp +++ b/src/StageFactory.cpp @@ -82,7 +82,7 @@ std::string StageFactory::inferReaderDriver(const std::string& filename) // filename may actually be a greyhound uri + pipelineId std::string http = filename.substr(0, 4); - if (boost::iequals(http, "http") && pm.createObject("readers.greyhound")) + if (boost::iequals(http, "http")) return "readers.greyhound"; std::string ext = boost::filesystem::extension(filename); @@ -90,25 +90,17 @@ std::string StageFactory::inferReaderDriver(const std::string& filename) drivers["las"] = "readers.las"; drivers["laz"] = "readers.las"; drivers["bin"] = "readers.terrasolid"; - if (pm.createObject("readers.greyhound")) - drivers["greyhound"] = "readers.greyhound"; + drivers["greyhound"] = "readers.greyhound"; drivers["qi"] = "readers.qfit"; - if (pm.createObject("readers.nitf")) - { - drivers["nitf"] = "readers.nitf"; - drivers["ntf"] = "readers.nitf"; - drivers["nsf"] = "readers.nitf"; - } + drivers["nitf"] = "readers.nitf"; + drivers["ntf"] = "readers.nitf"; + drivers["nsf"] = "readers.nitf"; drivers["bpf"] = "readers.bpf"; drivers["sbet"] = "readers.sbet"; drivers["icebridge"] = "readers.icebridge"; drivers["sqlite"] = "readers.sqlite"; - - if (pm.createObject("readers.rxp")) - drivers["rxp"] = "readers.rxp"; - - if (pm.createObject("readers.pcd")) - drivers["pcd"] = "readers.pcd"; + drivers["rxp"] = "readers.rxp"; + drivers["pcd"] = "readers.pcd"; if (ext == "") return ""; ext = ext.substr(1, ext.length()-1); @@ -132,17 +124,14 @@ std::string StageFactory::inferWriterDriver(const std::string& filename) drivers["bpf"] = "writers.bpf"; drivers["las"] = "writers.las"; drivers["laz"] = "writers.las"; - if (pm.createObject("writers.pcd")) - drivers["pcd"] = "writers.pcd"; - if (pm.createObject("writers.pclvisualizer")) - drivers["pclviz"] = "writers.pclvisualizer"; + drivers["pcd"] = "writers.pcd"; + drivers["pclviz"] = "writers.pclvisualizer"; drivers["sbet"] = "writers.sbet"; drivers["csv"] = "writers.text"; drivers["json"] = "writers.text"; drivers["xyz"] = "writers.text"; drivers["txt"] = "writers.text"; - if (pm.createObject("writers.nitf")) - drivers["ntf"] = "writers.nitf"; + drivers["ntf"] = "writers.nitf"; drivers["sqlite"] = "writers.sqlite"; if (boost::algorithm::iequals(filename, "STDOUT")) diff --git a/test/unit/LogTest.cpp b/test/unit/LogTest.cpp index 25ce800f71..aee646278b 100644 --- a/test/unit/LogTest.cpp +++ b/test/unit/LogTest.cpp @@ -60,7 +60,7 @@ TEST(LogTest, test_one) { PointContext ctx; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(opts); reader->prepare(ctx); @@ -140,16 +140,16 @@ TEST(LogTest, test_two_a) } { - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(reader_opts); - std::unique_ptr xfilter(f.createStage("filters.programmable")); + std::shared_ptr xfilter(f.createStage("filters.programmable")); xfilter->setOptions(xfilter_opts); - xfilter->setInput(reader.get()); + xfilter->setInput(reader); - std::unique_ptr yfilter(f.createStage("filters.programmable")); + std::shared_ptr yfilter(f.createStage("filters.programmable")); yfilter->setOptions(yfilter_opts); - yfilter->setInput(xfilter.get()); + yfilter->setInput(xfilter); PointContext ctx; yfilter->prepare(ctx); @@ -239,16 +239,16 @@ TEST(LogTest, test_two_b) } { - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(reader_opts); - std::unique_ptr xfilter(f.createStage("filters.programmable")); + std::shared_ptr xfilter(f.createStage("filters.programmable")); xfilter->setOptions(xfilter_opts); - xfilter->setInput(reader.get()); + xfilter->setInput(reader); - std::unique_ptr yfilter(f.createStage("filters.programmable")); + std::shared_ptr yfilter(f.createStage("filters.programmable")); yfilter->setOptions(yfilter_opts); - yfilter->setInput(xfilter.get()); + yfilter->setInput(xfilter); PointContext ctx; yfilter->prepare(ctx); @@ -328,12 +328,12 @@ TEST(LogTest, test_three) } { - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(reader_opts); - std::unique_ptr xfilter(f.createStage("filters.programmable")); + std::shared_ptr xfilter(f.createStage("filters.programmable")); xfilter->setOptions(xfilter_opts); - xfilter->setInput(reader.get()); + xfilter->setInput(reader); PointContext ctx; xfilter->prepare(ctx); diff --git a/test/unit/OptionsTest.cpp b/test/unit/OptionsTest.cpp index a2f938541b..171dd923ef 100644 --- a/test/unit/OptionsTest.cpp +++ b/test/unit/OptionsTest.cpp @@ -51,13 +51,13 @@ TEST(OptionsTest, test_static_options) Options ops; StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); EXPECT_TRUE(reader.get()); reader->setOptions(ops); - std::unique_ptr crop(f.createStage("filters.crop")); + std::shared_ptr crop(f.createStage("filters.crop")); EXPECT_TRUE(crop.get()); crop->setOptions(ops); - crop->setInput(reader.get()); + crop->setInput(reader); auto opts = crop->getDefaultOptions(); EXPECT_EQ(opts.getOptions().size(), 3u); EXPECT_TRUE(opts.hasOption("bounds")); diff --git a/test/unit/PipelineManagerTest.cpp b/test/unit/PipelineManagerTest.cpp index 17940415f4..03799f426a 100644 --- a/test/unit/PipelineManagerTest.cpp +++ b/test/unit/PipelineManagerTest.cpp @@ -50,12 +50,12 @@ TEST(PipelineManagerTest, basic) Options optsR; optsR.add("filename", Support::datapath("las/1.2-with-color.las")); - Stage* reader = mgr.addReader("readers.las"); + std::shared_ptr reader(mgr.addReader("readers.las")); reader->setOptions(optsR); Options optsW; optsW.add("filename", outfile, "file to write to"); - Stage* writer = mgr.addWriter("writers.las", reader); + std::shared_ptr writer(mgr.addWriter("writers.las", reader)); writer->setOptions(optsW); point_count_t np = mgr.execute(); diff --git a/test/unit/SpatialReferenceTest.cpp b/test/unit/SpatialReferenceTest.cpp index 08463a829c..4c64d78702 100644 --- a/test/unit/SpatialReferenceTest.cpp +++ b/test/unit/SpatialReferenceTest.cpp @@ -147,12 +147,12 @@ TEST(SpatialReferenceTest, test_read_srs) Options ops; ops.add("filename", Support::datapath("las/utm17.las")); - LasReader reader; - reader.setOptions(ops); - reader.prepare(ctx); - reader.execute(ctx); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops); + reader->prepare(ctx); + reader->execute(ctx); - const SpatialReference& ref = reader.getSpatialReference(); + const SpatialReference& ref = reader->getSpatialReference(); const std::string ret_wkt = ref.getWKT(); const std::string ret_proj4 = ref.getProj4(); @@ -189,29 +189,29 @@ TEST(SpatialReferenceTest, test_vertical_datums) // Write a very simple file with our SRS and one point. Options ops1; ops1.add("filename", Support::datapath("las/1.2-with-color.las")); - LasReader reader; - reader.setOptions(ops1); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); // need to scope the writer, so that's it dtor can use the stream Options opts; opts.add("filename", tmpfile); - LasWriter writer; - writer.setOptions(opts); - writer.setInput(&reader); - writer.setSpatialReference(ref); - writer.prepare(ctx); - writer.execute(ctx); - SpatialReference sr = writer.getSpatialReference(); + std::shared_ptr writer(new LasWriter); + writer->setOptions(opts); + writer->setInput(reader); + writer->setSpatialReference(ref); + writer->prepare(ctx); + writer->execute(ctx); + SpatialReference sr = writer->getSpatialReference(); // Reopen and check contents. PointContext ctx2; - LasReader reader2; - reader2.setOptions(opts); - reader2.prepare(ctx2); - reader2.execute(ctx2); + std::shared_ptr reader2(new LasReader); + reader2->setOptions(opts); + reader2->prepare(ctx2); + reader2->execute(ctx2); - const SpatialReference ref2 = reader2.getSpatialReference(); + const SpatialReference ref2 = reader2->getSpatialReference(); const std::string wkt2 = ref2.getWKT(SpatialReference::eCompoundOK); EXPECT_TRUE(wkt == wkt2); @@ -241,22 +241,22 @@ TEST(SpatialReferenceTest, test_writing_vlr) FileUtils::deleteFile(tmpfile); PointContext ctx; - LasReader readerx; + std::shared_ptr readerx(new LasReader); Options readerOpts; readerOpts.add("filename", ::Support::datapath("las/1.2-with-color.las")); - readerx.setOptions(readerOpts); + readerx->setOptions(readerOpts); Options writerOpts; - LasWriter writer; + std::shared_ptr writer(new LasWriter); writerOpts.add("filename", tmpfile); - writer.setOptions(writerOpts); - writer.setInput(&readerx); - writer.prepare(ctx); - writer.setSpatialReference(ref); - writer.execute(ctx); + writer->setOptions(writerOpts); + writer->setInput(readerx); + writer->prepare(ctx); + writer->setSpatialReference(ref); + writer->execute(ctx); } // Reopen and check contents. @@ -264,14 +264,14 @@ TEST(SpatialReferenceTest, test_writing_vlr) PointContext ctx; Options ops; ops.add("filename", tmpfile); - LasReader reader; - reader.setOptions(ops); - reader.prepare(ctx); - reader.execute(ctx); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops); + reader->prepare(ctx); + reader->execute(ctx); - SpatialReference result_ref = reader.getSpatialReference(); + SpatialReference result_ref = reader->getSpatialReference(); - EXPECT_EQ(reader.header().vlrCount(), 4u); + EXPECT_EQ(reader->header().vlrCount(), 4u); std::string wkt = result_ref.getWKT(); EXPECT_EQ(wkt, reference_wkt); } diff --git a/test/unit/StageTester.hpp b/test/unit/StageTester.hpp index 44a352438b..c938c3bb54 100644 --- a/test/unit/StageTester.hpp +++ b/test/unit/StageTester.hpp @@ -11,23 +11,23 @@ namespace pdal class StageTester { public: - static void initialize(Stage *s, PointContext ctx) + static void initialize(std::shared_ptr s, PointContext ctx) { s->l_initialize(ctx); s->initialize(); } - static void processOptions(Stage *s, const Options& options) + static void processOptions(std::shared_ptr s, const Options& options) { s->processOptions(options); } - static void addDimensions(Stage *s, PointContext ctx) + static void addDimensions(std::shared_ptr s, PointContext ctx) { s->addDimensions(ctx); } - static void ready(Stage *s, PointContext ctx) + static void ready(std::shared_ptr s, PointContext ctx) { s->ready(ctx); } - static void done(Stage *s, PointContext ctx) + static void done(std::shared_ptr s, PointContext ctx) { s->l_done(ctx); s->done(ctx); } - static PointBufferSet run(Stage *s, PointBufferPtr buffer) + static PointBufferSet run(std::shared_ptr s, PointBufferPtr buffer) { return s->run(buffer); } }; @@ -35,7 +35,7 @@ class StageTester class FilterTester : public StageTester { public: - static void filter(Filter *f, PointBuffer& buffer) + static void filter(std::shared_ptr f, PointBuffer& buffer) { f->filter(buffer); } }; @@ -44,7 +44,7 @@ class FilterTester : public StageTester class WriterTester : public StageTester { public: - static void write(Writer *w, PointBuffer& buffer) + static void write(std::shared_ptr w, PointBuffer& buffer) { w->write(buffer); } }; diff --git a/test/unit/apps/pc2pcTest.cpp b/test/unit/apps/pc2pcTest.cpp index 4ed36dcb7c..17c35a0529 100644 --- a/test/unit/apps/pc2pcTest.cpp +++ b/test/unit/apps/pc2pcTest.cpp @@ -95,10 +95,10 @@ static bool fileIsCompressed(const std::string& name) Options ops; ops.add("filename", name); - LasReader reader; - reader.setOptions(ops); - reader.prepare(ctx); - return reader.header().compressed(); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops); + reader->prepare(ctx); + return reader->header().compressed(); } @@ -108,11 +108,11 @@ static bool fileHasSrs(const std::string& name) Options ops; ops.add("filename", name); - LasReader reader; - reader.setOptions(ops); - reader.prepare(ctx); - reader.execute(ctx); - return !reader.getSpatialReference().empty(); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops); + reader->prepare(ctx); + reader->execute(ctx); + return !reader->getSpatialReference().empty(); } diff --git a/test/unit/filters/ChipperTest.cpp b/test/unit/filters/ChipperTest.cpp index d45c87cda9..f0818a17cc 100644 --- a/test/unit/filters/ChipperTest.cpp +++ b/test/unit/filters/ChipperTest.cpp @@ -55,8 +55,8 @@ TEST(ChipperTest, test_construction) Options ops1; std::string filename(Support::datapath("las/1.2-with-color.las")); ops1.add("filename", filename); - LasReader reader; - reader.setOptions(ops1); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); { // need to scope the writer, so that's it dtor can use the stream @@ -65,11 +65,11 @@ TEST(ChipperTest, test_construction) Option capacity("capacity", 15, "capacity"); options.add(capacity); - ChipperFilter chipper; - chipper.setInput(&reader); - chipper.setOptions(options); - chipper.prepare(ctx); - PointBufferSet pbSet = chipper.execute(ctx); + std::shared_ptr chipper(new ChipperFilter); + chipper->setInput(reader); + chipper->setOptions(options); + chipper->prepare(ctx); + PointBufferSet pbSet = chipper->execute(ctx); EXPECT_EQ(pbSet.size(), 71u); std::vector buffers; @@ -111,11 +111,11 @@ TEST(ChipperTest, empty_buffer) Options ops; - ChipperFilter chipper; - chipper.prepare(ctx); - StageTester::ready(&chipper, ctx); - PointBufferSet pbSet = StageTester::run(&chipper, buf); - StageTester::done(&chipper, ctx); + std::shared_ptr chipper(new ChipperFilter); + chipper->prepare(ctx); + StageTester::ready(chipper, ctx); + PointBufferSet pbSet = StageTester::run(chipper, buf); + StageTester::done(chipper, ctx); EXPECT_EQ(pbSet.size(), 0u); } @@ -135,9 +135,9 @@ TEST(ChipperTest, test_ordering) options.add(capacity); LasReader candidate_reader(options); - ChipperFilter chipper(options); - chipper.setInput(&candidate_reader); - chipper.prepare(); + std::shared_ptr chipper(new ChipperFilter)(options); + chipper->setInput(&candidate_reader); + chipper->prepare(); Option& query = options.getOptionByRef("filename"); query.setValue(source_filename); @@ -145,12 +145,12 @@ TEST(ChipperTest, test_ordering) LasReader source_reader(options); source_reader.prepare(); - EXPECT_EQ(chipper.getNumPoints(), source_reader.getNumPoints()); + EXPECT_EQ(chipper->getNumPoints(), source_reader.getNumPoints()); - PointBuffer candidate(chipper.getSchema(), chipper.getNumPoints()); - PointBuffer patch(chipper.getSchema(), chipper.getNumPoints()); + PointBuffer candidate(chipper->getSchema(), chipper->getNumPoints()); + PointBuffer patch(chipper->getSchema(), chipper->getNumPoints()); - StageSequentialIterator* iter_c = chipper.createSequentialIterator(patch); + StageSequentialIterator* iter_c = chipper->createSequentialIterator(patch); uint64_t numRead(0); while (true) @@ -161,7 +161,7 @@ TEST(ChipperTest, test_ordering) candidate.copyPointsFast(candidate.getNumPoints(), 0, patch, patch.getNumPoints()); candidate.setNumPoints(candidate.getNumPoints() + patch.getNumPoints()); } - EXPECT_EQ(candidate.getNumPoints(), chipper.getNumPoints()); + EXPECT_EQ(candidate.getNumPoints(), chipper->getNumPoints()); PointBuffer source(source_reader.getSchema(), source_reader.getNumPoints()); diff --git a/test/unit/filters/ColorizationFilterTest.cpp b/test/unit/filters/ColorizationFilterTest.cpp index a08495e5b2..2ac81b8472 100644 --- a/test/unit/filters/ColorizationFilterTest.cpp +++ b/test/unit/filters/ColorizationFilterTest.cpp @@ -46,8 +46,8 @@ TEST(ColorizationFilterTest, ColorizationFilterTest_test_1) { Options ops1; ops1.add("filename", Support::datapath("autzen/autzen-point-format-3.las")); - LasReader reader; - reader.setOptions(ops1); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); Options options; @@ -84,14 +84,14 @@ TEST(ColorizationFilterTest, ColorizationFilterTest_test_1) reader_options.add(blue); reader_options.add(datasource); - ColorizationFilter filter; - filter.setOptions(reader_options); - filter.setInput(&reader); + std::shared_ptr filter(new ColorizationFilter); + filter->setOptions(reader_options); + filter->setInput(reader); PointContext ctx; - filter.prepare(ctx); - PointBufferSet pbSet = filter.execute(ctx); + filter->prepare(ctx); + PointBufferSet pbSet = filter->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); diff --git a/test/unit/filters/CropFilterTest.cpp b/test/unit/filters/CropFilterTest.cpp index 8d25a37685..e8bc62aac0 100644 --- a/test/unit/filters/CropFilterTest.cpp +++ b/test/unit/filters/CropFilterTest.cpp @@ -51,7 +51,7 @@ TEST(CropFilterTest, test_crop) opts.add("bounds", srcBounds); opts.add("num_points", 1000); opts.add("mode", "ramp"); - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); EXPECT_TRUE(reader.get()); reader->setOptions(opts); @@ -60,26 +60,26 @@ TEST(CropFilterTest, test_crop) Options cropOpts; cropOpts.add("bounds", dstBounds); - std::unique_ptr filter(f.createStage("filters.crop")); + std::shared_ptr filter(f.createStage("filters.crop")); EXPECT_TRUE(filter.get()); filter->setOptions(cropOpts); - filter->setInput(reader.get()); + filter->setInput(reader); Options statOpts; - StatsFilter stats; - stats.setOptions(statOpts); - stats.setInput(filter.get()); + std::shared_ptr stats(new StatsFilter); + stats->setOptions(statOpts); + stats->setInput(filter); PointContext ctx; - stats.prepare(ctx); - PointBufferSet pbSet = stats.execute(ctx); + stats->prepare(ctx); + PointBufferSet pbSet = stats->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); - const stats::Summary& statsX = stats.getStats(Dimension::Id::X); - const stats::Summary& statsY = stats.getStats(Dimension::Id::Y); - const stats::Summary& statsZ = stats.getStats(Dimension::Id::Z); + const stats::Summary& statsX = stats->getStats(Dimension::Id::X); + const stats::Summary& statsY = stats->getStats(Dimension::Id::Y); + const stats::Summary& statsZ = stats->getStats(Dimension::Id::Z); EXPECT_EQ(buf->size(), 333u); const double minX = statsX.minimum(); @@ -115,7 +115,7 @@ TEST(CropFilterTest, test_crop_polygon) Options ops1; ops1.add("filename", Support::datapath("las/1.2-with-color.las")); - std::unique_ptr reader(f.createStage("readers.las")); + std::shared_ptr reader(f.createStage("readers.las")); EXPECT_TRUE(reader.get()); reader->setOptions(ops1); @@ -136,9 +136,9 @@ TEST(CropFilterTest, test_crop_polygon) Option polygon("polygon", wkt, ""); options.add(polygon); - std::unique_ptr crop(f.createStage("filters.crop")); + std::shared_ptr crop(f.createStage("filters.crop")); EXPECT_TRUE(crop.get()); - crop->setInput(reader.get()); + crop->setInput(reader); crop->setOptions(options); PointContext ctx; @@ -196,19 +196,19 @@ TEST(CropFilterTest, test_crop_polygon_reprojection) Option polygon("polygon", wkt, ""); options.add(polygon); - std::unique_ptr reader(f.createStage("readers.las")); + std::shared_ptr reader(f.createStage("readers.las")); EXPECT_TRUE(reader.get()); reader->setOptions(options); - std::unique_ptr reprojection(f.createStage("filters.reprojection")); + std::shared_ptr reprojection(f.createStage("filters.reprojection")); EXPECT_TRUE(reprojection.get()); reprojection->setOptions(options); - reprojection->setInput(reader.get()); + reprojection->setInput(reader); - std::unique_ptr crop(f.createStage("filters.crop")); + std::shared_ptr crop(f.createStage("filters.crop")); EXPECT_TRUE(crop.get()); crop->setOptions(options); - crop->setInput(reprojection.get()); + crop->setInput(reprojection); PointContext ctx; PointBufferPtr buffer(new PointBuffer(ctx)); diff --git a/test/unit/filters/DecimationFilterTest.cpp b/test/unit/filters/DecimationFilterTest.cpp index 2bfc182684..f859d42f18 100644 --- a/test/unit/filters/DecimationFilterTest.cpp +++ b/test/unit/filters/DecimationFilterTest.cpp @@ -49,17 +49,17 @@ TEST(DecimationFilterTest, DecimationFilterTest_test1) ops.add("mode", "random"); ops.add("num_points", 30); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); EXPECT_TRUE(reader.get()); reader->setOptions(ops); Options decimationOps; decimationOps.add("step", 10); - std::unique_ptr filter(f.createStage("filters.decimation")); + std::shared_ptr filter(f.createStage("filters.decimation")); EXPECT_TRUE(filter.get()); filter->setOptions(decimationOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; diff --git a/test/unit/filters/FerryFilterTest.cpp b/test/unit/filters/FerryFilterTest.cpp index 6ed49eb3a7..620fbeb38e 100644 --- a/test/unit/filters/FerryFilterTest.cpp +++ b/test/unit/filters/FerryFilterTest.cpp @@ -48,7 +48,7 @@ TEST(FerryFilterTest, test_ferry_copy) PipelineReader specReader(mgr); specReader.readPipeline(Support::configuredpath("filters/ferry.xml")); - Stage *stage = mgr.getStage(); + std::shared_ptr stage(mgr.getStage()); mgr.execute(); PointContext ctx = mgr.context(); @@ -78,7 +78,7 @@ TEST(FerryFilterTest, test_ferry_invalid) Options ops1; ops1.add("filename", Support::datapath("las/1.2-with-color.las")); StageFactory f; - std::unique_ptr reader(f.createStage("readers.las")); + std::shared_ptr reader(f.createStage("readers.las")); EXPECT_TRUE(reader.get()); reader->setOptions(ops1); @@ -91,9 +91,9 @@ TEST(FerryFilterTest, test_ferry_invalid) x.setOptions(xO); options.add(x); - std::unique_ptr ferry(f.createStage("filters.ferry")); + std::shared_ptr ferry(f.createStage("filters.ferry")); EXPECT_TRUE(ferry.get()); - ferry->setInput(reader.get()); + ferry->setInput(reader); ferry->setOptions(options); PointContext ctx; diff --git a/test/unit/filters/RangeFilterTest.cpp b/test/unit/filters/RangeFilterTest.cpp index 2687167dbb..92d6bfca4d 100644 --- a/test/unit/filters/RangeFilterTest.cpp +++ b/test/unit/filters/RangeFilterTest.cpp @@ -43,14 +43,14 @@ using namespace pdal; TEST(RangeFilterTest, createStage) { StageFactory f; - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); EXPECT_TRUE(filter.get()); } TEST(RangeFilterTest, noDimension) { StageFactory f; - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); PointContext ctx; EXPECT_THROW(filter->prepare(ctx), pdal_error); @@ -62,7 +62,7 @@ TEST(RangeFilterTest, noRange) rangeOps.add("dimension", "Z"); StageFactory f; - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); PointContext ctx; @@ -79,7 +79,7 @@ TEST(RangeFilterTest, singleDimension) ops.add("num_points", 10); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Options range; @@ -92,9 +92,9 @@ TEST(RangeFilterTest, singleDimension) Options rangeOps; rangeOps.add(dim); - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); @@ -118,7 +118,7 @@ TEST(RangeFilterTest, multipleDimensions) ops.add("num_points", 10); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Options y_range; @@ -139,9 +139,9 @@ TEST(RangeFilterTest, multipleDimensions) rangeOps.add(y_dim); rangeOps.add(z_dim); - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); @@ -168,7 +168,7 @@ TEST(RangeFilterTest, onlyMin) ops.add("num_points", 10); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Options range; @@ -180,9 +180,9 @@ TEST(RangeFilterTest, onlyMin) Options rangeOps; rangeOps.add(dim); - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); @@ -208,7 +208,7 @@ TEST(RangeFilterTest, onlyMax) ops.add("num_points", 10); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Options range; @@ -220,9 +220,9 @@ TEST(RangeFilterTest, onlyMax) Options rangeOps; rangeOps.add(dim); - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); @@ -248,7 +248,7 @@ TEST(RangeFilterTest, equals) ops.add("num_points", 10); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Options range; @@ -260,9 +260,9 @@ TEST(RangeFilterTest, equals) Options rangeOps; rangeOps.add(dim); - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); @@ -284,7 +284,7 @@ TEST(RangeFilterTest, negativeValues) ops.add("num_points", 21); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); reader->setOptions(ops); Options range; @@ -297,9 +297,9 @@ TEST(RangeFilterTest, negativeValues) Options rangeOps; rangeOps.add(dim); - std::unique_ptr filter(f.createStage("filters.range")); + std::shared_ptr filter(f.createStage("filters.range")); filter->setOptions(rangeOps); - filter->setInput(reader.get()); + filter->setInput(reader); PointContext ctx; filter->prepare(ctx); diff --git a/test/unit/filters/SortFilterTest.cpp b/test/unit/filters/SortFilterTest.cpp index 13a3b63997..481fef8072 100644 --- a/test/unit/filters/SortFilterTest.cpp +++ b/test/unit/filters/SortFilterTest.cpp @@ -53,8 +53,8 @@ void doSort(point_count_t count) opts.add("dimension", "X"); - SortFilter filter; - filter.setOptions(opts); + std::shared_ptr filter(new SortFilter); + filter->setOptions(opts); PointContext ctx; PointBuffer buf(ctx); @@ -67,10 +67,10 @@ void doSort(point_count_t count) for (PointId i = 0; i < count; ++i) buf.setField(Dimension::Id::X, i, dist(generator)); - filter.prepare(ctx); - FilterTester::ready(&filter, ctx); - FilterTester::filter(&filter, buf); - FilterTester::done(&filter, ctx); + filter->prepare(ctx); + FilterTester::ready(filter, ctx); + FilterTester::filter(filter, buf); + FilterTester::done(filter, ctx); EXPECT_EQ(count, buf.size()); for (PointId i = 1; i < count; ++i) diff --git a/test/unit/filters/SplitterTest.cpp b/test/unit/filters/SplitterTest.cpp index f0c84bd647..5709aec26b 100644 --- a/test/unit/filters/SplitterTest.cpp +++ b/test/unit/filters/SplitterTest.cpp @@ -47,7 +47,7 @@ TEST(SplitterTest, test_tile_filter) // create the reader Options ops1; ops1.add("filename", Support::datapath("las/1.2-with-color.las")); - std::unique_ptr r(f.createStage("readers.las")); + std::shared_ptr r(f.createStage("readers.las")); EXPECT_TRUE(r.get()); r->setOptions(ops1); @@ -56,24 +56,24 @@ TEST(SplitterTest, test_tile_filter) o.add(length); // create the tile filter and prepare - std::unique_ptr s(f.createStage("filters.splitter")); + std::shared_ptr s(f.createStage("filters.splitter")); EXPECT_TRUE(s.get()); s->setOptions(o); - s->setInput(r.get()); + s->setInput(r); PointContext ctx; PointBufferPtr buf(new PointBuffer(ctx)); s->prepare(ctx); - StageTester::ready(r.get(), ctx); - PointBufferSet pbSet = StageTester::run(r.get(), buf); - StageTester::done(r.get(), ctx); + StageTester::ready(r, ctx); + PointBufferSet pbSet = StageTester::run(r, buf); + StageTester::done(r, ctx); EXPECT_EQ(pbSet.size(), 1u); buf = *pbSet.begin(); - StageTester::ready(s.get(), ctx); - pbSet = StageTester::run(s.get(), buf); - StageTester::done(s.get(), ctx); + StageTester::ready(s, ctx); + pbSet = StageTester::run(s, buf); + StageTester::done(s, ctx); std::vector buffers; for (auto it = pbSet.begin(); it != pbSet.end(); ++it) diff --git a/test/unit/filters/StatsFilterTest.cpp b/test/unit/filters/StatsFilterTest.cpp index 11f23c46b6..edc59ae9dc 100644 --- a/test/unit/filters/StatsFilterTest.cpp +++ b/test/unit/filters/StatsFilterTest.cpp @@ -50,21 +50,21 @@ TEST(StatsFilterTest, simple) ops.add("mode", "constant"); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); EXPECT_TRUE(reader.get()); reader->setOptions(ops); - StatsFilter filter; - filter.setInput(reader.get()); - EXPECT_EQ(filter.getName(), "filters.stats"); + std::shared_ptr filter(new StatsFilter); + filter->setInput(reader); + EXPECT_EQ(filter->getName(), "filters.stats"); PointContext ctx; - filter.prepare(ctx); - filter.execute(ctx); + filter->prepare(ctx); + filter->execute(ctx); - const stats::Summary& statsX = filter.getStats(Dimension::Id::X); - const stats::Summary& statsY = filter.getStats(Dimension::Id::Y); - const stats::Summary& statsZ = filter.getStats(Dimension::Id::Z); + const stats::Summary& statsX = filter->getStats(Dimension::Id::X); + const stats::Summary& statsY = filter->getStats(Dimension::Id::Y); + const stats::Summary& statsZ = filter->getStats(Dimension::Id::Z); EXPECT_EQ(statsX.count(), 1000u); EXPECT_EQ(statsY.count(), 1000u); @@ -92,24 +92,24 @@ TEST(StatsFilterTest, dimset) ops.add("mode", "constant"); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); EXPECT_TRUE(reader.get()); reader->setOptions(ops); Options filterOps; filterOps.add("dimensions", " , X, Z "); - StatsFilter filter; - filter.setInput(reader.get()); - filter.setOptions(filterOps); - EXPECT_EQ(filter.getName(), "filters.stats"); + std::shared_ptr filter(new StatsFilter); + filter->setInput(reader); + filter->setOptions(filterOps); + EXPECT_EQ(filter->getName(), "filters.stats"); PointContext ctx; - filter.prepare(ctx); - filter.execute(ctx); + filter->prepare(ctx); + filter->execute(ctx); - const stats::Summary& statsX = filter.getStats(Dimension::Id::X); - EXPECT_THROW(filter.getStats(Dimension::Id::Y), pdal_error); - const stats::Summary& statsZ = filter.getStats(Dimension::Id::Z); + const stats::Summary& statsX = filter->getStats(Dimension::Id::X); + EXPECT_THROW(filter->getStats(Dimension::Id::Y), pdal_error); + const stats::Summary& statsZ = filter->getStats(Dimension::Id::Z); EXPECT_EQ(statsX.count(), 1000u); EXPECT_EQ(statsZ.count(), 1000u); @@ -134,20 +134,20 @@ TEST(StatsFilterTest, metadata) ops.add("mode", "constant"); StageFactory f; - std::unique_ptr reader(f.createStage("readers.faux")); + std::shared_ptr reader(f.createStage("readers.faux")); EXPECT_TRUE(reader.get()); reader->setOptions(ops); Options filterOps; filterOps.add("dimensions", " , X, Z "); - StatsFilter filter; - filter.setInput(reader.get()); - filter.setOptions(filterOps); + std::shared_ptr filter(new StatsFilter); + filter->setInput(reader); + filter->setOptions(filterOps); PointContext ctx; - filter.prepare(ctx); - filter.execute(ctx); - MetadataNode m = filter.getMetadata(); + filter->prepare(ctx); + filter->execute(ctx); + MetadataNode m = filter->getMetadata(); std::vector children = m.children("statistic"); auto findNode = [](MetadataNode m, diff --git a/test/unit/filters/TransformationFilterTest.cpp b/test/unit/filters/TransformationFilterTest.cpp index 378785d691..0fd4f8e7b6 100644 --- a/test/unit/filters/TransformationFilterTest.cpp +++ b/test/unit/filters/TransformationFilterTest.cpp @@ -63,12 +63,12 @@ class TransformationFilterTest : public ::testing::Test readerOpts.add("bounds", bounds); reader->setOptions(readerOpts); - filter->setInput(reader.get()); + filter->setInput(reader); } StageFactory factory; - std::unique_ptr reader; - std::unique_ptr filter; + std::shared_ptr reader; + std::shared_ptr filter; }; diff --git a/test/unit/io/bpf/BPFTest.cpp b/test/unit/io/bpf/BPFTest.cpp index 22f6f9301c..a14efad181 100644 --- a/test/unit/io/bpf/BPFTest.cpp +++ b/test/unit/io/bpf/BPFTest.cpp @@ -76,11 +76,11 @@ void test_file_type(const std::string& filename) ops.add("filename", Support::datapath(filename)); ops.add("count", 506); - BpfReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new BpfReader); + reader->setOptions(ops); - reader.prepare(context); - PointBufferSet pbSet = reader.execute(context); + reader->prepare(context); + PointBufferSet pbSet = reader->execute(context); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); diff --git a/test/unit/io/buffer/BufferTest.cpp b/test/unit/io/buffer/BufferTest.cpp index 1c9c9813e3..4556363470 100644 --- a/test/unit/io/buffer/BufferTest.cpp +++ b/test/unit/io/buffer/BufferTest.cpp @@ -62,33 +62,34 @@ TEST(BufferTest, test_basic) } Options ops; - BufferReader r; - r.setOptions(ops); - r.addBuffer(buf); + std::shared_ptr r(new BufferReader); + EXPECT_TRUE(r.get()); + r->setOptions(ops); + r->addBuffer(buf); - StatsFilter s; - s.setOptions(ops); - s.setInput(&r); + std::shared_ptr s(new StatsFilter); + s->setOptions(ops); + s->setInput(r); - s.prepare(ctx); - PointBufferSet pbSet = s.execute(ctx); + s->prepare(ctx); + PointBufferSet pbSet = s->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 20u); - stats::Summary xSummary = s.getStats(Dimension::Id::X); + stats::Summary xSummary = s->getStats(Dimension::Id::X); EXPECT_FLOAT_EQ(xSummary.minimum(), 0); EXPECT_FLOAT_EQ(xSummary.maximum(), 19); EXPECT_EQ(xSummary.count(), 20u); EXPECT_FLOAT_EQ(xSummary.average(), 9.5); - stats::Summary ySummary = s.getStats(Dimension::Id::Y); + stats::Summary ySummary = s->getStats(Dimension::Id::Y); EXPECT_FLOAT_EQ(ySummary.minimum(), 0); EXPECT_FLOAT_EQ(ySummary.maximum(), 38); EXPECT_EQ(ySummary.count(), 20u); EXPECT_FLOAT_EQ(ySummary.average(), 19); - stats::Summary zSummary = s.getStats(Dimension::Id::Z); + stats::Summary zSummary = s->getStats(Dimension::Id::Z); EXPECT_FLOAT_EQ(zSummary.minimum(), -19); EXPECT_FLOAT_EQ(zSummary.maximum(), 0); EXPECT_EQ(zSummary.count(), 20u); diff --git a/test/unit/io/faux/FauxReaderTest.cpp b/test/unit/io/faux/FauxReaderTest.cpp index 7a37d46a49..d4c9d4a02b 100644 --- a/test/unit/io/faux/FauxReaderTest.cpp +++ b/test/unit/io/faux/FauxReaderTest.cpp @@ -46,13 +46,12 @@ TEST(FauxReaderTest, test_constant_mode_sequential_iter) ops.add("bounds", bounds); ops.add("count", 750); ops.add("mode", "constant"); - FauxReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new FauxReader); + reader->setOptions(ops); PointContext ctx; - reader.prepare(ctx); - //EXPECT_EQ(reader.getDescription(), "Faux Reader"); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 750u); @@ -78,12 +77,12 @@ TEST(FauxReaderTest, test_random_mode) ops.add("bounds", bounds); ops.add("count", 750); ops.add("mode", "constant"); - FauxReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new FauxReader); + reader->setOptions(ops); PointContext ctx; - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 750u); @@ -117,12 +116,12 @@ TEST(FauxReaderTest, test_ramp_mode_1) ops.add("count", 2); ops.add("mode", "ramp"); - FauxReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new FauxReader); + reader->setOptions(ops); PointContext ctx; - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 2u); @@ -156,12 +155,12 @@ TEST(FauxReaderTest, test_ramp_mode_2) ops.add("bounds", bounds); ops.add("count", 750); ops.add("mode", "ramp"); - FauxReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new FauxReader); + reader->setOptions(ops); PointContext ctx; - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 750u); @@ -194,12 +193,12 @@ TEST(FauxReaderTest, test_return_number) ops.add("count", 100); ops.add("mode", "constant"); ops.add("number_of_returns", 9); - FauxReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new FauxReader); + reader->setOptions(ops); PointContext ctx; - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 100u); diff --git a/test/unit/io/las/LasReaderTest.cpp b/test/unit/io/las/LasReaderTest.cpp index 40b547e0c0..aee13c9b1a 100644 --- a/test/unit/io/las/LasReaderTest.cpp +++ b/test/unit/io/las/LasReaderTest.cpp @@ -80,10 +80,10 @@ TEST(LasReaderTest, test_base_options) Options opts; opts.add(opt_filename); - LasReader reader; - reader.setOptions(opts); - EXPECT_TRUE(reader.getVerboseLevel() == 0); - EXPECT_TRUE(reader.isDebug() == false); + std::shared_ptr reader(new LasReader); + reader->setOptions(opts); + EXPECT_TRUE(reader->getVerboseLevel() == 0); + EXPECT_TRUE(reader->isDebug() == false); } { @@ -91,10 +91,10 @@ TEST(LasReaderTest, test_base_options) opts.add(opt_filename); opts.add(opt_verbose_string); opts.add(opt_debug_string); - LasReader reader; - reader.setOptions(opts); - EXPECT_TRUE(reader.getVerboseLevel() == 99); - EXPECT_TRUE(reader.isDebug() == true); + std::shared_ptr reader(new LasReader); + reader->setOptions(opts); + EXPECT_TRUE(reader->getVerboseLevel() == 99); + EXPECT_TRUE(reader->isDebug() == true); } { @@ -102,10 +102,10 @@ TEST(LasReaderTest, test_base_options) opts.add(opt_filename); opts.add(opt_verbose_uint8); opts.add(opt_debug_bool); - LasReader reader; - reader.setOptions(opts); - EXPECT_TRUE(reader.getVerboseLevel() == 99); - EXPECT_TRUE(reader.isDebug() == true); + std::shared_ptr reader(new LasReader); + reader->setOptions(opts); + EXPECT_TRUE(reader->getVerboseLevel() == 99); + EXPECT_TRUE(reader->isDebug() == true); } } @@ -115,12 +115,12 @@ TEST(LasReaderTest, header) PointContext ctx; Options ops; ops.add("filename", Support::datapath("las/simple.las")); - LasReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops); - reader.prepare(ctx); + reader->prepare(ctx); // This tests the copy ctor, too. - LasHeader h = reader.header(); + LasHeader h = reader->header(); EXPECT_EQ(h.fileSignature(), "LASF"); EXPECT_EQ(h.fileSourceId(), 0); @@ -161,11 +161,11 @@ TEST(LasReaderTest, test_sequential) Options ops1; ops1.add("filename", Support::datapath("las/1.2-with-color.las")); ops1.add("count", 103); - LasReader reader; - reader.setOptions(ops1); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); Support::check_p0_p1_p2(*buf); @@ -185,15 +185,15 @@ static void test_a_format(const std::string& file, uint8_t majorVersion, uint8_t Options ops1; ops1.add("filename", Support::datapath(file)); ops1.add("count", 1); - LasReader reader; - reader.setOptions(ops1); - reader.prepare(ctx); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); + reader->prepare(ctx); - EXPECT_EQ(reader.header().pointFormat(), pointFormat); - EXPECT_EQ(reader.header().versionMajor(), majorVersion); - EXPECT_EQ(reader.header().versionMinor(), minorVersion); + EXPECT_EQ(reader->header().pointFormat(), pointFormat); + EXPECT_EQ(reader->header().versionMajor(), majorVersion); + EXPECT_EQ(reader->header().versionMinor(), minorVersion); - PointBufferSet pbSet = reader.execute(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 1u); @@ -221,10 +221,10 @@ TEST(LasReaderTest, inspect) Options ops; ops.add("filename", Support::datapath("las/epsg_4326.las")); - LasReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops); - QuickInfo qi = reader.preview(); + QuickInfo qi = reader->preview(); std::string testWkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"unretrievable - using WGS84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],AUTHORITY[\"EPSG\",\"4326\"]]"; #ifdef PDAL_HAVE_LIBGEOTIFF @@ -266,12 +266,12 @@ TEST(LasReaderTest, test_vlr) Options ops1; ops1.add("filename", Support::datapath("las/lots_of_vlr.las")); - LasReader reader; - reader.setOptions(ops1); - reader.prepare(ctx); - reader.execute(ctx); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); + reader->prepare(ctx); + reader->execute(ctx); - EXPECT_EQ(reader.header().getVLRs().getAll().size(), 390); + EXPECT_EQ(reader->header().getVLRs().getAll().size(), 390); } **/ @@ -282,10 +282,10 @@ TEST(LasReaderTest, testInvalidFileSignature) Options ops1; ops1.add("filename", Support::datapath("las/1.2-with-color.las.wkt")); - LasReader reader; - reader.setOptions(ops1); + std::shared_ptr reader(new LasReader); + reader->setOptions(ops1); - EXPECT_TRUE(reader.header().valid()); + EXPECT_TRUE(reader->header().valid()); } TEST(LasReaderTest, extraBytes) @@ -294,10 +294,10 @@ TEST(LasReaderTest, extraBytes) Options readOps; readOps.add("filename", Support::datapath("las/extrabytes.las")); - LasReader reader; - reader.setOptions(readOps); + std::shared_ptr reader(new LasReader); + reader->setOptions(readOps); - reader.prepare(ctx); + reader->prepare(ctx); DimTypeList dimTypes = ctx.dimTypes(); EXPECT_EQ(dimTypes.size(), (size_t)24); @@ -320,7 +320,7 @@ TEST(LasReaderTest, extraBytes) Dimension::Id::Enum time2 = ctx.findProprietaryDim("Time"); EXPECT_EQ(ctx.dimType(time2), Dimension::Type::Unsigned64); - PointBufferSet pbSet = reader.execute(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), (size_t)1); PointBufferPtr pb = *pbSet.begin(); diff --git a/test/unit/io/las/LasWriterTest.cpp b/test/unit/io/las/LasWriterTest.cpp index d444efe1e1..4118fd9ef0 100644 --- a/test/unit/io/las/LasWriterTest.cpp +++ b/test/unit/io/las/LasWriterTest.cpp @@ -54,10 +54,10 @@ class LasTester { public: template - static T headerVal(LasWriter& w, const std::string& s) - { return w.headerVal(s); } - LasHeader *header(LasWriter& w) - { return &w.m_lasHeader; } + static T headerVal(std::shared_ptr w, const std::string& s) + { return w->headerVal(s); } + LasHeader *header(std::shared_ptr w) + { return &w->m_lasHeader; } }; } // namespace pdal @@ -82,26 +82,26 @@ TEST(LasWriterTest, auto_offset) writerOps.add("filename", FILENAME); writerOps.add("offset_x", "auto"); - LasWriter writer; - writer.setOptions(writerOps); + std::shared_ptr writer(new LasWriter); + writer->setOptions(writerOps); - writer.prepare(ctx); + writer->prepare(ctx); - WriterTester::ready(&writer, ctx); - WriterTester::write(&writer, *buf); - WriterTester::done(&writer, ctx); + WriterTester::ready(writer, ctx); + WriterTester::write(writer, *buf); + WriterTester::done(writer, ctx); Options readerOps; readerOps.add("filename", FILENAME); PointContext readCtx; - LasReader reader; - reader.setOptions(readerOps); + std::shared_ptr reader(new LasReader); + reader->setOptions(readerOps); - reader.prepare(readCtx); - EXPECT_FLOAT_EQ(reader.header().offsetX(), 74529.00); - PointBufferSet pbSet = reader.execute(readCtx); + reader->prepare(readCtx); + EXPECT_FLOAT_EQ(reader->header().offsetX(), 74529.00); + PointBufferSet pbSet = reader->execute(readCtx); EXPECT_EQ(pbSet.size(), 1u); buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 3u); @@ -116,19 +116,19 @@ TEST(LasWriterTest, extra_dims) Options readerOps; readerOps.add("filename", Support::datapath("las/1.2-with-color.las")); - LasReader reader; - reader.setOptions(readerOps); + std::shared_ptr reader(new LasReader); + reader->setOptions(readerOps); Options writerOps; writerOps.add("extra_dims", "Red=int32, Blue = int16, Green = int32_t"); writerOps.add("filename", Support::temppath("simple.las")); - LasWriter writer; - writer.setInput(&reader); - writer.setOptions(writerOps); + std::shared_ptr writer(new LasWriter); + writer->setInput(reader); + writer->setOptions(writerOps); PointContext ctx; - writer.prepare(ctx); - PointBufferSet pbSet = writer.execute(ctx); + writer->prepare(ctx); + PointBufferSet pbSet = writer->execute(ctx); LasTester tester; LasHeader *header = tester.header(writer); @@ -152,12 +152,12 @@ TEST(LasWriterTest, extra_dims) Options reader2Ops; reader2Ops.add("filename", Support::temppath("simple.las")); reader2Ops.add("extra_dims", "R1 =int32, B1= int16 ,G1=int32_t"); - LasReader reader2; - reader2.setOptions(reader2Ops); + std::shared_ptr reader2(new LasReader); + reader2->setOptions(reader2Ops); PointContext ctx2; - reader2.prepare(ctx2); - pbSet = reader2.execute(ctx2); + reader2->prepare(ctx2); + pbSet = reader2->execute(ctx2); pb = *pbSet.begin(); Dimension::Id::Enum r1 = ctx2.findDim("R1"); EXPECT_TRUE(r1 != Dimension::Id::Unknown); @@ -190,13 +190,13 @@ TEST(LasWriterTest, metadata_options) metadataOp.setOptions(metadataOps); ops.add(metadataOp); - LasWriter writer; - writer.setOptions(ops); + std::shared_ptr writer(new LasWriter); + writer->setOptions(ops); PointContext ctx; - writer.prepare(ctx); + writer->prepare(ctx); - MetadataNode m = writer.getMetadata(); + MetadataNode m = writer->getMetadata(); m.add("minor_version", 56); uint8_t format = @@ -265,14 +265,14 @@ TEST(LasWriterTest, simple) writerOpts.add("creation_year", 2014); writerOpts.add("filename", outfile); - LasReader reader; - reader.setOptions(readerOpts); + std::shared_ptr reader(new LasReader); + reader->setOptions(readerOpts); - LasWriter writer; - writer.setOptions(writerOpts); - writer.setInput(&reader); - writer.prepare(ctx); - writer.execute(ctx); + std::shared_ptr writer(new LasWriter); + writer->setOptions(writerOpts); + writer->setInput(&reader); + writer->prepare(ctx); + writer->execute(ctx); diffdump(infile, outfile); } @@ -301,12 +301,12 @@ TEST(LasWriterTest, LasWriterTest_test_simple_laz) Support::temppath("LasWriterTest_test_simple_laz.laz")); // need to scope the writer, so that's it dtor can use the stream - LasWriter writer(ofs); - writer.setOptions(writer); - writer.setInput(&reader); + std::shared_ptr writer(new LasWriter)(ofs); + writer->setOptions(writer); + writer->setInput(&reader); - writer.prepare(ctx); - writer.execute(ctx); + writer->prepare(ctx); + writer->execute(ctx); FileUtils::closeFile(ofs); @@ -343,8 +343,8 @@ static void test_a_format(const std::string& refFile, uint8_t majorVersion, Options readerOpts; readerOpts.add("filename", Support::datapath(directory + "1.2_3.las")); - LasReader reader; - reader.setOptions(readerOpts); + std::shared_ptr reader(new LasReader); + reader->setOptions(readerOpts); Options writerOpts; writerOpts.add("compression", false); @@ -362,13 +362,13 @@ static void test_a_format(const std::string& refFile, uint8_t majorVersion, std::ostream* ofs = FileUtils::createFile(Support::temppath("temp.las")); // need to scope the writer, so that's it dtor can use the stream - LasWriter writer(ofs); - writer.setOptions(writerOpts); - writer.setInput(&reader); - EXPECT_EQ(writer.getDescription(), "Las Writer"); + std::shared_ptr writer(new LasWriter)(ofs); + writer->setOptions(writerOpts); + writer->setInput(&reader); + EXPECT_EQ(writer->getDescription(), "Las Writer"); - writer.prepare(ctx); - writer.execute(ctx); + writer->prepare(ctx); + writer->execute(ctx); bool filesSame = Support::compare_files("temp.las", Support::datapath(directory + refFile)); @@ -441,8 +441,8 @@ TEST(LasWriterTest, LasWriterTest_test_drop_extra_returns) ops.add("num_points", 100); ops.add("mode", "constant"); ops.add("number_of_returns", 10); - FauxReader reader; - reader.setOptions(ops); + std::shared_ptr reader(new FauxReader); + reader->setOptions(ops); std::ostream* ofs = FileUtils::createFile(Support::temppath(temp_filename)); @@ -454,23 +454,23 @@ TEST(LasWriterTest, LasWriterTest_test_drop_extra_returns) writerOptions.add("system_id", ""); writerOptions.add("software_id", "TerraScan"); - LasWriter writer(ofs); - writer.setOptions(writerOptions); - writer.setInput(&reader); - writer.prepare(ctx); - writer.execute(ctx); + std::shared_ptr writer(new LasWriter)(ofs); + writer->setOptions(writerOptions); + writer->setInput(&reader); + writer->prepare(ctx); + writer->execute(ctx); Options readerOptions; readerOptions.add("filename", Support::temppath(temp_filename)); readerOptions.add("count", 6); - LasReader reader2; - reader2.setOptions(readerOptions); + std::shared_ptr reader2(new LasReader); + reader2->setOptions(readerOptions); PointContext ctx2; - reader2.prepare(ctx2); - PointBufferSet pbSet = reader2.execute(ctx2); + reader2->prepare(ctx2); + PointBufferSet pbSet = reader2->execute(ctx2); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); diff --git a/test/unit/io/qfit/QFITReaderTest.cpp b/test/unit/io/qfit/QFITReaderTest.cpp index 27c6d78958..734962cba9 100644 --- a/test/unit/io/qfit/QFITReaderTest.cpp +++ b/test/unit/io/qfit/QFITReaderTest.cpp @@ -74,14 +74,13 @@ TEST(QFITReaderTest, test_10_word) options.add("scale_z", 0.001f, "Z scale from mm to m"); options.add("count", 3); - QfitReader reader; - reader.setOptions(options); - //EXPECT_TRUE(reader.getDescription() == "QFIT Reader"); - EXPECT_EQ(reader.getName(), "readers.qfit"); + std::shared_ptr reader(new QfitReader); + reader->setOptions(options); + EXPECT_EQ(reader->getName(), "readers.qfit"); PointContext ctx; - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 3u); @@ -103,10 +102,10 @@ TEST(QFITReaderTest, test_14_word) options.add("count", 3); PointContext ctx; - QfitReader reader; - reader.setOptions(options); - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + std::shared_ptr reader(new QfitReader); + reader->setOptions(options); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); EXPECT_EQ(buf->size(), 3u); diff --git a/test/unit/io/sbet/SbetReaderTest.cpp b/test/unit/io/sbet/SbetReaderTest.cpp index 3c332c7357..8fc6875cbd 100644 --- a/test/unit/io/sbet/SbetReaderTest.cpp +++ b/test/unit/io/sbet/SbetReaderTest.cpp @@ -83,13 +83,13 @@ TEST(SbetReaderTest, testRead) { Option filename("filename", Support::datapath("sbet/2-points.sbet"), ""); Options options(filename); - SbetReader reader; - reader.setOptions(options); + std::shared_ptr reader(new SbetReader); + reader->setOptions(options); PointContext ctx; - reader.prepare(ctx); - PointBufferSet pbSet = reader.execute(ctx); + reader->prepare(ctx); + PointBufferSet pbSet = reader->execute(ctx); EXPECT_EQ(pbSet.size(), 1u); PointBufferPtr buf = *pbSet.begin(); @@ -119,11 +119,11 @@ TEST(SbetReaderTest, testBadFile) { Option filename("filename", Support::datapath("sbet/badfile.sbet"), ""); Options options(filename); - SbetReader reader; - reader.setOptions(options); + std::shared_ptr reader(new SbetReader); + reader->setOptions(options); PointContext ctx; - reader.prepare(ctx); - EXPECT_THROW(reader.execute(ctx), pdal_error); + reader->prepare(ctx); + EXPECT_THROW(reader->execute(ctx), pdal_error); } TEST(SbetReaderTest, testPipeline) diff --git a/test/unit/io/sbet/SbetWriterTest.cpp b/test/unit/io/sbet/SbetWriterTest.cpp index 4ce426d555..1f10c6128c 100644 --- a/test/unit/io/sbet/SbetWriterTest.cpp +++ b/test/unit/io/sbet/SbetWriterTest.cpp @@ -60,14 +60,13 @@ Options makeWriterOptions() TEST(SbetWriterTest, testConstructor) { - SbetReader reader; - reader.setOptions(makeReaderOptions()); - SbetWriter writer; - writer.setOptions(makeWriterOptions()); - writer.setInput(&reader); + std::shared_ptr reader(new SbetReader); + reader->setOptions(makeReaderOptions()); + std::shared_ptr writer(new SbetWriter); + writer->setOptions(makeWriterOptions()); + writer->setInput(reader); - //EXPECT_TRUE(writer.getDescription() == "SBET Writer"); - EXPECT_EQ(writer.getName(), "writers.sbet"); + EXPECT_EQ(writer->getName(), "writers.sbet"); } TEST(SbetWriterTest, testWrite) @@ -77,15 +76,15 @@ TEST(SbetWriterTest, testWrite) // Scope forces the writer's buffer to get written to the file. Otherwise // the output file will show a file size of zero and no contents. { - SbetReader reader; - reader.setOptions(makeReaderOptions()); - SbetWriter writer; - writer.setOptions(makeWriterOptions()); - writer.setInput(&reader); + std::shared_ptr reader(new SbetReader); + reader->setOptions(makeReaderOptions()); + std::shared_ptr writer(new SbetWriter); + writer->setOptions(makeWriterOptions()); + writer->setInput(reader); PointContext ctx; - writer.prepare(ctx); - writer.execute(ctx); + writer->prepare(ctx); + writer->execute(ctx); } //ABELL - Write of a read file is no longer identical.