Permalink
Browse files

[cpp][core] Transformed Pipeline into a component based object instea…

…d of a base class.
  • Loading branch information...
1 parent 266fca0 commit b543e582e004c04085c4b0a11c5474c0ab6efcfc @nical committed Oct 19, 2011
@@ -25,7 +25,6 @@ SET(KIWI_SRC ${KIWI_SRC}
core/Connect.cpp
core/Pipeline.cpp
core/DataTypeManager.cpp
- processing/ProcessingPipeline.cpp
# kiwi::core source files
)
@@ -12,9 +12,41 @@ void Pipeline::setNodePipeline(Node* n, Pipeline* p)
Pipeline::~Pipeline()
{
+ removeAllNodes();
+ if ( _updater ) delete _updater;
+ if ( _optimizer ) delete _optimizer;
}
+bool Pipeline::setInput(uint32 index, Data* inputData)
+{
+ return false;
+}
+
+bool Pipeline::setOutput(uint32 index, Data* inputData)
+{
+ return false;
+}
+
+bool Pipeline::addNode( Node* n )
+{
+ return false;
+}
+
+bool Pipeline::removeNode( Node* n )
+{
+ return false;
+}
+bool Pipeline::removeAllNodes()
+{
+ return false;
+}
+
+bool Pipeline::contains(const Node* n)
+{
+ return false;
+}
+
}//namespace
}//namespace
@@ -1,27 +1,164 @@
#ifndef KIWI_CORE_PIPELINE_HPP
#define KIWI_CORE_PIPELINE_HPP
+#include "kiwi/core/Commons.hpp"
+#include <vector>
+
namespace kiwi{
namespace core{
+class Data;
class Node;
+class Pipeline;
+
+/**
+ * Interface for immutable logic bloc.
+ *
+ * This is the class to inherit from in order to create "compiled" pipelines.
+ * Custom pipelines should inherit from Pipeline instead.
+ */
+class Procedure
+{
+public:
+ virtual bool update() = 0;
+ virtual bool setInput(uint32 index, Data* inputData) = 0;
+ virtual bool setOutput(uint32 index, Data* inputData) = 0;
+ virtual ~Procedure(){};
+};
+
+
+
+// --------------------------------------------------------- Pipeline components
+
+class PipelineComponent
+{
+ virtual string name() = 0;
+};
+
+class PipelineUpdater : public PipelineComponent
+{
+public:
+ virtual bool update( Pipeline* p, uint32 flags ) = 0;
+ virtual ~PipelineUpdater() {}
+};
+class PipelineRuleSet : PipelineComponent
+{
+public:
+ virtual bool check( Pipeline* p );
+ virtual ~PipelineRuleSet() {}
+};
-class Pipeline
+class PipelineOptimizer : PipelineComponent
{
public:
+ /**
+ * Optimizes the pipeline.
+ */
+ virtual Procedure* optimize( Pipeline* p, uint32 flags ) = 0;
+ /**
+ * returns all the supported optimize flags
+ */
+ virtual uint32 modes() = 0;
+
+ virtual ~PipelineOptimizer() {}
+};
+
+
+
+
+
+/**
+ * Node based pipeline. Groups nodes and takes care of ordering
+ *
+ */
+class Pipeline : public Procedure
+{
+public:
+ typedef std::vector<Node*> NodeArray;
+
+ // update flags
+ enum{ LAZY = 1, STEPBYSTEP = 2 };
+ // optimize flags
+ enum{ SPEED = 1, MEMORY = 2 };
+
+ /**
+ * Constructor.
+ */
+ Pipeline( PipelineUpdater* p_updater
+ , PipelineOptimizer* p_optimizer
+ , PipelineRuleSet* p_rules )
+ : _updater(p_updater), _optimizer( p_optimizer ), _rules( p_rules )
+ {
+ }
+
+ /**
+ * Updates the nodes in a correct order (eventually in parallel) using a
+ * PipelineUpdater.
+ *
+ * Returns false in case of error.
+ */
+ bool update(uint32 flags)
+ {
+ if(_updater)
+ return _updater->update(this, flags);
+ return false;
+ }
+
+ /**
+ * Updates without flags (inherited from Procedure).
+ */
+ bool update() // override
+ {
+ return update(0);
+ }
+
+ /**
+ * Creates a Procedure object that can execute the same actions that this
+ * pipeline in a more optimized way.
+ *
+ * The optimization is performed by a PipelineOptimizer object and the nature
+ * of the optimization is up to the PipelineOptimizer (though it can use hints
+ * provided by the flags parameter).
+ */
+ Procedure* optimize(uint32 flags)
+ {
+ if(_optimizer)
+ return _optimizer->optimize(this, flags);
+
+ return 0;
+ }
+
+ /**
+ * Returns this pipeline's nodes in a vector.
+ */
+ const NodeArray& nodes()
+ {
+ return _nodes;
+ }
+
+ bool setInput(uint32 index, Data* inputData); // override
+ bool setOutput(uint32 index, Data* inputData); // override
- virtual bool addNode(Node* n) = 0;
- virtual bool update() = 0;
- virtual ~Pipeline();
+ bool addNode( Node* n );
+ bool removeNode( Node* n );
+ bool removeAllNodes();
+ bool contains(const Node* n);
+
+ ~Pipeline();
protected:
void setNodePipeline(Node* n, Pipeline* p);
+private:
+ NodeArray _nodes;
+ // components
+ PipelineUpdater* _updater;
+ PipelineOptimizer* _optimizer;
+ PipelineRuleSet* _rules;
};
-
}//namespace
}//namespace
@@ -1,22 +0,0 @@
-
-#include "kiwi/core/Node.hpp"
-#include "kiwi/processing/ProcessingPipeline.hpp"
-
-namespace kiwi{
-namespace processing{
-
-
-bool ProcessingPipeline::addNode(core::Node* n)
-{
- _nodes.push_back(n);
- setNodePipeline(n,this);
- return true;
-}
-
-bool ProcessingPipeline::update()
-{
- return false;
-}
-
-}//namespace
-}//namespace
@@ -1,31 +0,0 @@
-
-#pragma once
-#ifndef KIWI_PROCESSING_PROCESSINGPIPELINE_HPP
-#define KIWI_PROCESSING_PROCESSINGPIPELINE_HPP
-
-namespace kiwi{
-namespace core{
-class Node;
-}//namespace
-}//namespace
-
-
-namespace kiwi{
-namespace processing{
-
-class ProcessingPipeline : public core::Pipeline
-{
-public:
- typedef std::vector<core::Node*> NodeVector;
-
- bool addNode(core::Node* n);
- bool update();
-
-private:
- NodeVector _nodes;
-};
-
-}//namespace
-}//namespace
-
-#endif
@@ -7,12 +7,10 @@
#include "kiwi/core/OpConnect.hpp"
#include "kiwi/core/Container.hpp"
#include "kiwi/extern/log/DebugStream.hpp"
-#include "kiwi/processing/ProcessingPipeline.hpp"
#include "kiwi/mock/MockNodeUpdater.hpp"
using namespace kiwi;
using namespace kiwi::core;
-using namespace kiwi::processing;
struct Dummy{};
KIWI_DECLARE_CONTAINER(int,"Int");
@@ -95,7 +93,7 @@ int main()
, info1->name() == "NodeTest1" );
}
- ProcessingPipeline p;
+ Pipeline p(0,0,0);
auto n1 = new Node(&p, NodeTypeManager::TypeOf("NodeTest1") );
auto n2 = new Node(&p, NodeTypeManager::TypeOf("NodeTest2") );
@@ -7,12 +7,10 @@
#include "kiwi/core/OpConnect.hpp"
#include "kiwi/core/Container.hpp"
#include "kiwi/extern/log/DebugStream.hpp"
-#include "kiwi/processing/ProcessingPipeline.hpp"
#include "kiwi/mock/MockNodeUpdater.hpp"
using namespace kiwi;
using namespace kiwi::core;
-using namespace kiwi::processing;
struct Dummy{};
KIWI_DECLARE_CONTAINER(int,"Int");
@@ -58,7 +56,7 @@ int main()
NodeTypeManager::RegisterNode("NodeTest1", layout1, new mock::MockNodeUpdater);
NodeTypeManager::RegisterNode("NodeTest2", layout2, new mock::MockNodeUpdater);
- ProcessingPipeline p;
+ Pipeline p(0,0,0);
auto n1 = new Node(&p, NodeTypeManager::TypeOf("NodeTest1") );
auto n2 = new Node(&p, NodeTypeManager::TypeOf("NodeTest2") );
View
@@ -1,3 +1,3 @@
echo "--kiwi build"
-dmd -I/usr/include/d/dmd/phobos/ -I/usr/include/d/dmd/druntime/import -Iinclude/extern -debug -unittest -g -odbin/ -ofbin/core_test src/kiwi/core/*.d src/kiwi/processing/*.d src/kiwi/text/*.d src/extern/*/*.d test/core.d && echo "--done" && ./bin/core_test || echo "\033[1;31m\n--error\033[0m\n"
+dmd -L-lrt -I/usr/include/d/dmd/phobos/ -I/usr/include/d/dmd/druntime/import -Iinclude/extern -debug -unittest -g -odbin/ -ofbin/core_test src/kiwi/core/*.d src/kiwi/processing/*.d src/kiwi/text/*.d src/extern/*/*.d test/core.d && echo "--done" && ./bin/core_test || echo "\033[1;31m\n--error\033[0m\n"

0 comments on commit b543e58

Please sign in to comment.