StormByte C++ Library 0.0.9999
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
|
A class designed to execute a sequence of functions asynchronously in a pipeline. More...
#include <pipeline.hxx>
Public Member Functions | |
Pipeline () noexcept=default | |
Default constructor Initializes an empty pipeline buffer. | |
Pipeline (const Pipeline &other)=default | |
Copy constructor Creates a new Pipeline that shares the same underlying buffer as the original. | |
Pipeline (Pipeline &&other) noexcept=default | |
Move constructor Moves the contents of another Pipeline into this instance. | |
~Pipeline () noexcept=default | |
Destructor. | |
Pipeline & | operator= (const Pipeline &other)=default |
Copy assignment operator. | |
Pipeline & | operator= (Pipeline &&other) noexcept=default |
Move assignment operator. | |
void | AddPipe (const PipeFunction &pipe) |
Adds a new pipe function to the pipeline. | |
void | AddPipe (PipeFunction &&pipe) |
Moves a new pipe function to the pipeline. | |
Consumer | Process (Consumer buffer) const noexcept |
Processes the pipeline buffer. | |
A class designed to execute a sequence of functions asynchronously in a pipeline.
The Pipeline
class allows users to define a chain of processing functions, where each function:
bool
indicating the success or failure of the operation.Functions are executed in the order they are added to the pipeline. Each function runs asynchronously in a detached thread, allowing all functions in the chain to execute concurrently. The output of one function is fed as the input to the next function in the chain. If any function in the chain returns false
, the output buffer is marked with a status of Status::Error
. It is the responsibility of each subsequent function in the chain to check the input buffer's status and return false
if the status is Status::Error
. This ensures that the error condition is propagated consistently until the end of the pipeline.
Buffer Status Handling:
true
will set the output buffer's status to Status::EoF
, signaling to the next function that the input has finished.false
will set the output buffer's status to Status::Error
, ensuring that subsequent functions return false
accordingly.Thread Synchronization:
Async
buffer's shared ownership model to manage thread synchronization and lifetime.Process
function represents the final output of the pipeline. Its status indicates the state of the processing:Status::Ready
: Data is still being processed in at least one thread.Status::EoF
: All threads have completed successfully.Status::Error
: An error occurred in one of the threads, and processing was terminated.Important Notes:
bool
or does not finish execution, the behavior of the pipeline is undefined.std::shared_ptr
. Buffer are destroyed when no longer needed.
|
defaultnoexcept |
Adds a new pipe function to the pipeline.
pipe | Pipe function to add |
void StormByte::Buffer::Pipeline::AddPipe | ( | PipeFunction && | pipe | ) |
Moves a new pipe function to the pipeline.
pipe | Pipe function to move |
Processes the pipeline buffer.
The provided buffer is passed through the chain of functions in the pipeline. Each function processes the buffer and passes its output to the next function in the chain. All functions are executed asynchronously in detached threads, allowing concurrent processing of the pipeline stages.
The returned buffer represents the final output of the pipeline. Its status indicates the state of the processing:
Status::Ready
: Data is still being processed in at least one thread.Status::EoF
: All threads have completed successfully.Status::Error
: An error occurred in one of the threads, and processing was terminated.Execution Details:
Async
buffer ensures proper synchronization and lifetime management.Status::Error
if a function fails.buffer | Buffer to process |