StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ suite.
Loading...
Searching...
No Matches
Public Types | List of all members
StormByte::Buffer::Pipeline Class Referencefinal

High-performance multi-stage data-processing pipeline. More...

#include <StormByte/buffer/pipeline.hxx>

Public Types

using PipeFunction = std::function< void(ExternalReader &, ExternalWriter &, std::shared_ptr< Logger::Log >)>
 Signature of a pipeline stage.
 

Public Member Functions

Constructors / destructor / assignment
 Pipeline () noexcept
 Default construct an empty pipeline (no stages).
 
 Pipeline (const Pipeline &other)
 Copy construct.
 
 Pipeline (Pipeline &&other) noexcept
 Move construct.
 
 ~Pipeline () noexcept
 Destructor.
 
Pipelineoperator= (const Pipeline &other)
 Copy assignment.
 
Pipelineoperator= (Pipeline &&other) noexcept
 Move assignment.
 
Stage registration
void AddPipe (const PipeFunction &pipe)
 Append a processing stage (copy).
 
void AddPipe (PipeFunction &&pipe)
 Append a processing stage (move).
 
Execution / error
void SetError () const noexcept
 Propagate error state to all internal buffers.
 
Consumer Process (Consumer buffer, const ExecutionMode &mode, std::shared_ptr< Logger::Log > log) const noexcept
 Execute the pipeline.
 

Detailed Description

High-performance multi-stage data-processing pipeline.

Overview
Pipeline manages a sequence of transformation functions (stages). Each stage receives abstract ExternalReader / ExternalWriter interfaces, allowing the Pipeline to choose the concrete buffer implementation for every intermediate step without changing stage code.
Buffer strategy
  • Intermediate stages use the private high-performance LockFreeRing (SPSC lock-free circular buffer).
  • Final stage writes into a public Producer (backed by Ring), so the Consumer returned to the caller keeps the full public API and can be shared safely.
Execution modes (@ref ExecutionMode bitmask)
Flags are orthogonal and combinable with operator|:
  • Sync (0): stages sequential on the caller’s thread; Process blocks.
  • Async: work runs in background; Process returns immediately.
  • Parallel: one thread per stage (SPSC intermediates); without Async, Process still joins workers before returning.
  • Async | Parallel: concurrent stages and non-blocking Process.
Stage signature
void stage(ExternalReader& in, ExternalWriter& out,
std::shared_ptr<Logger::Log> log);
Abstract interface for reading data from an external or internal source.
Definition external.hxx:55
Abstract interface for writing data to an external or internal sink.
Definition external.hxx:284

When log is not null, Process passes log->Scope("Buffer/Pipeline") so c identifies this module without touching the thread-local component stack. Nested log->Scope("Decode") inside a stage becomes Buffer/Pipeline/Decode (or Multimedia/Buffer/Pipeline/Decode if the caller already scoped the parent module).

Best practices
  • Always call out.Close() (or out.SetError()) at the end of every stage.
  • Prefer Async | Parallel for multi-stage streaming production workloads.
  • Use Sync for deterministic debugging.
  • The returned Consumer is the only synchronization point the caller needs (wait on Consumer::EoF() / Consumer::IsWritable() as appropriate).
  • Pass the application or parent-module logger to Process; do not pre-scope Buffer/Pipeline or the path will be duplicated.
See also
ExternalReader, ExternalWriter, Producer, Consumer, LockFreeRing, ExecutionMode

Member Typedef Documentation

◆ PipeFunction

using StormByte::Buffer::Pipeline::PipeFunction = std::function<void( ExternalReader&, ExternalWriter&, std::shared_ptr<Logger::Log> )>

Signature of a pipeline stage.

Stages receive abstract reader/writer interfaces so the Pipeline can inject LockFreeRing for intermediates and Ring for the final output without changing stage code.

Parameters
inAbstract reader for the stage input.
outAbstract writer for the stage output.
logOptional logger (may be null). When set, this is already Scope("Buffer/Pipeline") relative to the logger passed to Process.

Constructor & Destructor Documentation

◆ Pipeline() [1/3]

StormByte::Buffer::Pipeline::Pipeline ( )
noexcept

Default construct an empty pipeline (no stages).

◆ Pipeline() [2/3]

StormByte::Buffer::Pipeline::Pipeline ( const Pipeline other)

Copy construct.

Parameters
otherSource pipeline (only the list of stages is copied; no running background work is shared).

◆ Pipeline() [3/3]

StormByte::Buffer::Pipeline::Pipeline ( Pipeline &&  other)
noexcept

Move construct.

Parameters
otherSource pipeline (left in a valid but unspecified state).

◆ ~Pipeline()

StormByte::Buffer::Pipeline::~Pipeline ( )
noexcept

Destructor.

Joins any running background execution before destroying state.

Member Function Documentation

◆ AddPipe() [1/2]

void StormByte::Buffer::Pipeline::AddPipe ( const PipeFunction pipe)

Append a processing stage (copy).

Parameters
pipeStage function matching PipeFunction.

◆ AddPipe() [2/2]

void StormByte::Buffer::Pipeline::AddPipe ( PipeFunction &&  pipe)

Append a processing stage (move).

Parameters
pipeStage function matching PipeFunction.

◆ operator=() [1/2]

Pipeline & StormByte::Buffer::Pipeline::operator= ( const Pipeline other)

Copy assignment.

Parameters
otherSource pipeline (stages only).
Returns
Reference to this pipeline.

◆ operator=() [2/2]

Pipeline & StormByte::Buffer::Pipeline::operator= ( Pipeline &&  other)
noexcept

Move assignment.

Parameters
otherSource pipeline.
Returns
Reference to this pipeline.

◆ Process()

Consumer StormByte::Buffer::Pipeline::Process ( Consumer  buffer,
const ExecutionMode mode,
std::shared_ptr< Logger::Log >  log 
) const
noexcept

Execute the pipeline.

Parameters
bufferInput Consumer for the first stage.
modeBitmask of ExecutionMode flags (Sync, Async, Parallel, or combinations).
logOptional logger (may be null). When set, every stage receives log->Scope("Buffer/Pipeline").
Returns
Consumer of the final stage. When Async is set, the Consumer is available immediately while background work continues; otherwise Process returns only after all stages have finished.
Note
Any previous background run is joined before starting a new one.
See also
ExecutionMode, HasExecutionFlag(), Consumer, Producer

◆ SetError()

void StormByte::Buffer::Pipeline::SetError ( ) const
noexcept

Propagate error state to all internal buffers.

Calls SetError() on every intermediate LockFreeRing and on the final Producer. Waiting stages wake and observe the error condition.


The documentation for this class was generated from the following file: