14 #ifndef HTGS_IRULE_HPP 15 #define HTGS_IRULE_HPP 99 template<
class T,
class U>
101 static_assert(std::is_base_of<IData, T>::value,
"T must derive from IData");
102 static_assert(std::is_base_of<IData, U>::value,
"U must derive from IData");
109 output =
new std::list<std::shared_ptr<U>>();
119 output =
new std::list<std::shared_ptr<U>>();
152 return "Unnamed IRule";
163 virtual void applyRule(std::shared_ptr<T> data,
size_t pipelineId) = 0;
189 this->
output->push_back(result);
198 this->
output->push_back(std::shared_ptr<U>(result));
246 std::list<std::shared_ptr<U>>
283 this->height = height;
284 this->emptyData = emptyData;
285 data =
new T[width * height];
287 for (
size_t i = 0; i < width * height; i++) {
288 data[i] = this->emptyData;
305 void set(
size_t row,
size_t col, T &value)
const {
306 data[computeIndex(row, col)] = value;
315 void assign(
size_t row,
size_t col, T value)
const {
316 data[computeIndex(row, col)] = value;
324 void set(
size_t index, T &value)
const {
333 void assign(
size_t index, T value)
const {
343 T &
get(
size_t row,
size_t col)
const {
344 return data[computeIndex(row, col)];
352 T &
get(
size_t index)
const {
361 void remove(
size_t row,
size_t col) {
362 set(row, col, emptyData);
369 void remove(
size_t index) {
370 set(index, emptyData);
382 bool has(
size_t row,
size_t col)
const {
383 return data[computeIndex(row, col)] != emptyData;
394 bool has(
size_t index)
const {
395 return data[index] != emptyData;
404 for (
size_t r = 0; r < height; r++) {
405 for (
size_t c = 0; c < width; c++) {
411 std::cout << std::endl;
420 for (
size_t r = 0; r < height; r++) {
421 for (
size_t c = 0; c < width; c++) {
422 std::cout << this->
get(r, c) <<
" ";
424 std::cout << std::endl;
436 return row * width + col;
447 #endif //HTGS_IRULE_HPP bool has(size_t row, size_t col) const
Checks whether the specified row column has data.
Definition: IRule.hpp:382
virtual std::string getName() override
Virtual function to get the name of the IRule.
Definition: IRule.hpp:151
Class to hold one/two dimensional state information.
Definition: IRule.hpp:28
void printContents()
Prints the contents of the state container.
Definition: IRule.hpp:419
virtual bool canTerminateRule(size_t pipelineId) override
Virtual function to determine if a rule is ready to be terminated.
Definition: IRule.hpp:141
size_t width
The width of the StateContainer.
Definition: IRule.hpp:440
virtual void applyRule(std::shared_ptr< T > data, size_t pipelineId)=0
Pure virtual function to process input data.
StateContainer< V > * allocStateContainer(size_t height, size_t width, V defaultValue)
Allocates a two dimensional state container using the template argument.
Definition: IRule.hpp:220
bool has(size_t index) const
Checks whether the specified index has data.
Definition: IRule.hpp:394
void addResult(U *result)
Adds a result value to the output.
Definition: IRule.hpp:197
bool useLocks
Will enable using the mutex to lock the rule to ensure this rule is only accessed by a thread at a ti...
Definition: AnyIRule.hpp:94
IRule()
Creates an IRule.
Definition: IRule.hpp:108
size_t computeIndex(size_t row, size_t col) const
Computes the one dimensional index from two dimension.
Definition: IRule.hpp:435
Provides an interface to send data along RuleManager edges for processing state and dependencies...
Definition: ExecutionPipeline.hpp:34
Base class for an htgs::IRule to hide the template arguments.
StateContainer< std::shared_ptr< T > > * allocStateContainer(size_t size)
Allocates a one dimensional state container using the input type of the IRule.
Definition: IRule.hpp:229
Base class for an htgs::IRule.
Definition: AnyIRule.hpp:25
StateContainer(size_t height, size_t width, T emptyData)
Constructs a state container with a width and height, and what it considers to be empty data...
Definition: IRule.hpp:281
void addResult(std::shared_ptr< U > result)
Adds a result value to the output.
Definition: IRule.hpp:188
Implements the IData class, which is used for all data types entering/leaving a task graph...
~StateContainer()
Destructor.
Definition: IRule.hpp:295
size_t height
The height of the StateContainer.
Definition: IRule.hpp:441
void assign(size_t row, size_t col, T value) const
Sets a value at a row column (uses assignment operator)
Definition: IRule.hpp:315
std::list< std::shared_ptr< U > > * output
The output data that is sent as soon as the applyRule has finished processing.
Definition: IRule.hpp:247
void assign(size_t index, T value) const
Sets a value at an index (uses assignment operator)
Definition: IRule.hpp:333
T emptyData
The data value that represents no data.
Definition: IRule.hpp:442
T * data
The pointer to data for the StateContainer.
Definition: IRule.hpp:439
IRule(bool useLocks)
Creates an IRule with locks specified.
Definition: IRule.hpp:118
void printState()
Prints the state of the state container.
Definition: IRule.hpp:403
virtual void shutdownRule(size_t pipelineId) override
Virtual function that handles when a rule is being shutdown for a particular pipelineId.
Definition: IRule.hpp:146
std::list< std::shared_ptr< U > > * applyRuleFunction(std::shared_ptr< T > data, size_t pipelineId)
Applies the virtual rule function and processes output.
Definition: IRule.hpp:178
StateContainer< V > * allocStateContainer(size_t size, V defaultValue)
Allocates a one dimensional state container using the input type of the IRule.
Definition: IRule.hpp:241
Definition: Bookkeeper.hpp:23
StateContainer< std::shared_ptr< T > > * allocStateContainer(size_t height, size_t width)
Allocates a two dimensional state container using the input type of the IRule.
Definition: IRule.hpp:207
virtual ~IRule() override
Destructor.
Definition: IRule.hpp:129