Skip to content

Commit

Permalink
move from naked Stage pointers to shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
chambbj committed Feb 26, 2015
1 parent fefe6b8 commit cb4ea8c
Show file tree
Hide file tree
Showing 64 changed files with 604 additions and 650 deletions.
2 changes: 1 addition & 1 deletion apps/pdal.cpp
Expand Up @@ -142,7 +142,7 @@ void outputDrivers()
void outputOptions(std::string const& n)
{
StageFactory f(false);
std::unique_ptr<Stage> s = f.createStage(n);
std::shared_ptr<Stage> s(f.createStage(n));

if (!s)
{
Expand Down
4 changes: 2 additions & 2 deletions include/pdal/KernelSupport.hpp
Expand Up @@ -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<Stage> 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<Stage> makeWriter(const std::string& filename, std::shared_ptr<Stage> stage);
static PipelineManager* makePipeline(const std::string& filename);

private:
Expand Down
14 changes: 7 additions & 7 deletions include/pdal/PipelineManager.hpp
Expand Up @@ -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<Stage *>& prevStages);
Stage* addWriter(const std::string& type, Stage *prevStage);
std::shared_ptr<Stage> addReader(const std::string& type);
std::shared_ptr<Stage> addFilter(const std::string& type, std::shared_ptr<Stage> prevStage);
std::shared_ptr<Stage> addFilter(const std::string& type,
const std::vector<std::shared_ptr<Stage> >& prevStages);
std::shared_ptr<Stage> addWriter(const std::string& type, std::shared_ptr<Stage> 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<Stage> getStage() const
{ return m_stages.empty() ? NULL : m_stages.back(); }

void prepare() const;
Expand All @@ -86,7 +86,7 @@ class PDAL_DLL PipelineManager
PointContext m_context;
PointBufferSet m_pbSet;

typedef std::vector<Stage *> StagePtrList;
typedef std::vector<std::shared_ptr<Stage> > StagePtrList;
StagePtrList m_stages;

PipelineManager& operator=(const PipelineManager&); // not implemented
Expand Down
8 changes: 4 additions & 4 deletions include/pdal/PipelineReader.hpp
Expand Up @@ -68,11 +68,11 @@ class PDAL_DLL PipelineReader
typedef std::map<std::string, std::string> map_t;

bool parseElement_Pipeline(const boost::property_tree::ptree&);
Stage* parseElement_anystage(const std::string& name,
std::shared_ptr<Stage> 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<Stage> parseElement_Reader(const boost::property_tree::ptree& tree);
std::shared_ptr<Stage> parseElement_Filter(const boost::property_tree::ptree& tree);
std::shared_ptr<Stage> 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);
Expand Down
13 changes: 6 additions & 7 deletions include/pdal/Stage.hpp
Expand Up @@ -57,7 +57,7 @@ class StageBlockIterator;
class StageRunner;
class StageTester;

class PDAL_DLL Stage
class PDAL_DLL Stage : public std::enable_shared_from_this<Stage>
{
friend class StageTester;
friend class StageRunner;
Expand All @@ -66,9 +66,9 @@ class PDAL_DLL Stage
virtual ~Stage()
{}

void setInput(const std::vector<Stage *>& inputs)
void setInput(const std::vector<std::shared_ptr<Stage> >& inputs)
{ m_inputs = inputs; }
void setInput(Stage *input)
void setInput(std::shared_ptr<Stage> input)
{ m_inputs.push_back(input); }

QuickInfo preview()
Expand Down Expand Up @@ -100,10 +100,9 @@ class PDAL_DLL Stage
return m_options.getValueOrDefault<uint32_t>("verbose", 0);
}
virtual std::string getName() const = 0;
//virtual std::string getDescription() const = 0;
const std::vector<Stage *>& getInputs() const
const std::vector<std::shared_ptr<Stage> >& getInputs() const
{ return m_inputs; }
std::vector<Stage*> findStage(std::string name);
std::vector<std::shared_ptr<Stage> > findStage(std::string name);
virtual Options getDefaultOptions()
{ return Options(); }
static Dimension::IdList getDefaultDimensions()
Expand Down Expand Up @@ -134,7 +133,7 @@ class PDAL_DLL Stage
private:
bool m_debug;
uint32_t m_verbose;
std::vector<Stage *> m_inputs;
std::vector<std::shared_ptr<Stage> > m_inputs;
LogPtr m_log;
SpatialReference m_spatialReference;

Expand Down
4 changes: 2 additions & 2 deletions include/pdal/StageRunner.hpp
Expand Up @@ -45,7 +45,7 @@ namespace pdal
class StageRunner
{
public:
StageRunner(Stage *s, PointBufferPtr pointBuf) :
StageRunner(std::shared_ptr<Stage> s, PointBufferPtr pointBuf) :
m_stage(s), m_pointBuf(pointBuf)
{}

Expand All @@ -57,7 +57,7 @@ class StageRunner
{ return m_bufSet; }

private:
Stage *m_stage;
std::shared_ptr<Stage> m_stage;
PointBufferPtr m_pointBuf;
PointBufferSet m_bufSet;
};
Expand Down
10 changes: 2 additions & 8 deletions include/pdal/Writer.hpp
Expand Up @@ -36,7 +36,6 @@

#include <pdal/pdal_internal.hpp>
#include <pdal/Options.hpp>
//#include <pdal/UserCallback.hpp>
#include <pdal/Stage.hpp>

#include <string>
Expand All @@ -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<UserCallback> m_callback;
std::string m_filename;
XForm m_xXform;
XForm m_yXform;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kernels/delta/DeltaKernel.cpp
Expand Up @@ -284,7 +284,7 @@ int DeltaKernel::execute()
sourceOptions.add<bool>("debug", isDebug());
sourceOptions.add<uint32_t>("verbose", getVerboseLevel());
}
std::unique_ptr<Stage> source(KernelSupport::makeReader(m_sourceFile));
std::shared_ptr<Stage> source(KernelSupport::makeReader(m_sourceFile));
source->setOptions(sourceOptions);
source->prepare(sourceCtx);
PointBufferSet pbSet = source->execute(sourceCtx);
Expand All @@ -300,7 +300,7 @@ int DeltaKernel::execute()
candidateOptions.add<uint32_t>("verbose", getVerboseLevel());
}

std::unique_ptr<Stage> candidate(KernelSupport::makeReader(m_candidateFile));
std::shared_ptr<Stage> candidate(KernelSupport::makeReader(m_candidateFile));
candidate->setOptions(candidateOptions);
candidate->prepare(candidateCtx);
pbSet = candidate->execute(candidateCtx);
Expand Down
4 changes: 2 additions & 2 deletions kernels/diff/DiffKernel.cpp
Expand Up @@ -156,7 +156,7 @@ int DiffKernel::execute()
sourceOptions.add<bool>("debug", isDebug());
sourceOptions.add<uint32_t>("verbose", getVerboseLevel());
}
std::unique_ptr<Stage> source(KernelSupport::makeReader(m_sourceFile));
std::shared_ptr<Stage> source(KernelSupport::makeReader(m_sourceFile));
source->setOptions(sourceOptions);
source->prepare(sourceCtx);
PointBufferSet sourceSet = source->execute(sourceCtx);
Expand All @@ -171,7 +171,7 @@ int DiffKernel::execute()
candidateOptions.add<uint32_t>("verbose", getVerboseLevel());
}

std::unique_ptr<Stage> candidate(KernelSupport::makeReader(m_candidateFile));
std::shared_ptr<Stage> candidate(KernelSupport::makeReader(m_candidateFile));
candidate->setOptions(candidateOptions);
candidate->prepare(candidateCtx);
PointBufferSet candidateSet = candidate->execute(candidateCtx);
Expand Down
2 changes: 1 addition & 1 deletion kernels/info/InfoKernel.cpp
Expand Up @@ -356,7 +356,7 @@ int InfoKernel::execute()
m_manager = std::unique_ptr<PipelineManager>(
KernelSupport::makePipeline(filename));
m_reader = m_manager->getStage();
Stage *stage = m_reader;
std::shared_ptr<Stage> stage = m_reader;

if (m_Dimensions.size())
m_options.add("dimensions", m_Dimensions, "List of dimensions");
Expand Down
6 changes: 3 additions & 3 deletions kernels/info/InfoKernel.hpp
Expand Up @@ -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<Stage> m_statsStage;
std::shared_ptr<Stage> m_hexbinStage;
std::shared_ptr<Stage> m_reader;

MetadataNode m_tree;
std::unique_ptr<PipelineManager> m_manager;
Expand Down
2 changes: 1 addition & 1 deletion kernels/pipeline/PipelineKernel.cpp
Expand Up @@ -97,7 +97,7 @@ int PipelineKernel::execute()
{
std::string name = pi.first;
Options options = pi.second;
std::vector<Stage*> stages = manager.getStage()->findStage(name);
std::vector<std::shared_ptr<Stage> > stages = manager.getStage()->findStage(name);
for (const auto& s : stages)
{
Options opts = s->getOptions();
Expand Down
9 changes: 3 additions & 6 deletions kernels/random/RandomKernel.cpp
Expand Up @@ -99,7 +99,7 @@ Stage* RandomKernel::makeReader(Options readerOptions)
}

StageFactory factory;
std::unique_ptr<Stage> reader_stage(factory.createStage("readers.faux"));
std::shared_ptr<Stage> reader_stage(factory.createStage("readers.faux"));
reader_stage->setOptions(readerOptions);

return reader_stage.get();
Expand Down Expand Up @@ -165,9 +165,9 @@ int RandomKernel::execute()
}
}

Stage* final_stage = makeReader(readerOptions);
std::shared_ptr<Stage> final_stage(makeReader(readerOptions));

Stage* writer = KernelSupport::makeWriter(m_outputFile, final_stage);
std::shared_ptr<Stage> writer = KernelSupport::makeWriter(m_outputFile, final_stage);
writer->setOptions(writerOptions);
PointContext ctx;

Expand All @@ -183,9 +183,6 @@ int RandomKernel::execute()
if (isVisualize())
visualize(*pbSet.begin());

delete writer;
delete final_stage;

return 0;
}

Expand Down
23 changes: 11 additions & 12 deletions kernels/sort/SortKernel.cpp
Expand Up @@ -87,7 +87,7 @@ void SortKernel::addSwitches()
addPositionalSwitch("output", 1);
}

std::unique_ptr<Stage> SortKernel::makeReader(Options readerOptions)
std::shared_ptr<Stage> SortKernel::makeReader(Options readerOptions)
{
if (isDebug())
{
Expand All @@ -100,11 +100,10 @@ std::unique_ptr<Stage> SortKernel::makeReader(Options readerOptions)
readerOptions.add<std::string>("log", "STDERR");
}

Stage* stage = KernelSupport::makeReader(m_inputFile);
std::shared_ptr<Stage> stage(KernelSupport::makeReader(m_inputFile));
stage->setOptions(readerOptions);
std::unique_ptr<Stage> reader_stage(stage);

return reader_stage;
return stage;
}


Expand All @@ -117,7 +116,7 @@ int SortKernel::execute()
readerOptions.add("debug", isDebug());
readerOptions.add("verbose", getVerboseLevel());

std::unique_ptr<Stage> readerStage = makeReader(readerOptions);
std::shared_ptr<Stage> 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
Expand All @@ -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> bufferReader(new BufferReader);
bufferReader->setOptions(readerOptions);
bufferReader->addBuffer(input_buffer);

Options sortOptions;
sortOptions.add<bool>("debug", isDebug());
sortOptions.add<uint32_t>("verbose", getVerboseLevel());

StageFactory f;
Stage* sortStage = f.createStage2("filters.mortonorder");
sortStage->setInput(&bufferReader);
std::shared_ptr<Stage> sortStage(f.createStage("filters.mortonorder"));
sortStage->setInput(bufferReader);
sortStage->setOptions(sortOptions);

Options writerOptions;
Expand All @@ -155,7 +154,7 @@ int SortKernel::execute()
cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) :
(UserCallback *)new HeartbeatCallback();

std::unique_ptr<Stage> writer(KernelSupport::makeWriter(m_outputFile, sortStage));
std::shared_ptr<Stage> writer(KernelSupport::makeWriter(m_outputFile, sortStage));

// Some options are inferred by makeWriter based on filename
// (compression, driver type, etc).
Expand All @@ -167,7 +166,7 @@ int SortKernel::execute()
{
std::string name = pi.first;
Options options = pi.second;
std::vector<Stage*> stages = writer->findStage(name);
std::vector<std::shared_ptr<Stage> > stages = writer->findStage(name);
for (const auto& s : stages)
{
Options opts = s->getOptions();
Expand Down
2 changes: 1 addition & 1 deletion kernels/sort/SortKernel.hpp
Expand Up @@ -55,7 +55,7 @@ class PDAL_DLL SortKernel : public Kernel
void addSwitches();
void validateSwitches();

std::unique_ptr<Stage> makeReader(Options readerOptions);
std::shared_ptr<Stage> makeReader(Options readerOptions);

std::string m_inputFile;
std::string m_outputFile;
Expand Down

0 comments on commit cb4ea8c

Please sign in to comment.