UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
Loading...
Searching...
No Matches
UCILoader::PipeScanner Class Reference

Blocking line-oriented reader built on top of AbstractPipeReader. More...

#include <AbstractPipe.h>

Public Member Functions

 PipeScanner (std::shared_ptr< AbstractPipeReader > source)
 Construct a PipeScanner from a source reader.
 
std::string getLine ()
 Read the next complete line from the pipe.
 

Detailed Description

Blocking line-oriented reader built on top of AbstractPipeReader.

PipeScanner provides a convenient way to read complete lines from a pipe. It wraps AbstractPipeReader and handles:

  • Buffering data as it arrives from the pipe
  • Detecting line boundaries (newline character)
  • Returning complete lines without the trailing newline

Design Notes:

  • Uses an internal 256-byte buffer for efficiency
  • Polls the pipe every 2ms when waiting for more data
  • Blocks until a complete line is received or pipe closes
  • Throws PipeClosedException if pipe closes before a newline is received

Thread Safety: Not thread-safe. The source pipe must not be accessed from other threads while getLine() is being called.

Usage Example:

auto reader = process->getReader();
PipeScanner scanner(reader);
try {
while (true) {
std::string line = scanner.getLine();
std::cout << "Received: " << line << std::endl;
}
} catch (const PipeClosedException&) {
std::cout << "Process terminated" << std::endl;
}
Blocking line-oriented reader built on top of AbstractPipeReader.
Definition: AbstractPipe.h:202
See also
AbstractPipeReader for the underlying pipe interface
ProcessWrapper::listen() for how this is used internally

Constructor & Destructor Documentation

◆ PipeScanner()

UCILoader::PipeScanner::PipeScanner ( std::shared_ptr< AbstractPipeReader source)
inline

Construct a PipeScanner from a source reader.

Parameters
sourceShared pointer to AbstractPipeReader to read from
Warning
The caller is responsible for ensuring the source pipe is not accessed from other threads or other getLine() calls, as this will cause data corruption.

Member Function Documentation

◆ getLine()

std::string PipeScanner::getLine ( )

Read the next complete line from the pipe.

Returns
A complete line without the trailing newline character
Exceptions
PipeClosedExceptionif the pipe is closed before a complete line is received

This method blocks until a complete line (ending with '\n') is received from the pipe. The returned string does not include the newline character.

Blocking Behavior:

  • Polls the pipe every 2ms if partial data is available
  • Blocks indefinitely waiting for the newline character
  • Returns as soon as a complete line is available

Exception Safety: If PipeClosedException is thrown, the pipe is broken and no further getLine() calls should be made.


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