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

Factory builder for creating EngineInstance objects. More...

#include <EngineConnection.h>

Public Member Functions

 EngineInstanceBuilder (std::shared_ptr< PatternMatcher > validator, std::shared_ptr< Marschaler< Move > > marschaler)
 Constructor for the builder.
 
EngineInstance< Move > * build (ProcessWrapper *engineProcess)
 Build an EngineInstance with default logging (no-op logger).
 
EngineInstance< Move > * build (ProcessWrapper *engineProcess, LoggerBuilder logger)
 Build an EngineInstance with custom logging configuration.
 

Detailed Description

template<class Move>
class UCILoader::EngineInstanceBuilder< Move >

Factory builder for creating EngineInstance objects.

Template Parameters
MoveThe move type to use (standard chess, variant, etc.)

EngineInstanceBuilder is a factory class that creates and configures EngineInstance objects. It encapsulates move validation and parsing logic, allowing different chess variants to be supported.

Standard Chess Usage: If developing for standard chess, use the preconfigured StandardChess::ChessEngineInstanceBuilder:

auto process = openProcess({"stockfish.exe"}, "/");
auto engine = StandardChess::ChessEngineInstanceBuilder->build(
process,
);
engine->sync();
const LoggerTrait & Pretty
Trait that formats log messages for human readability.
Definition: Logger.cpp:165
LoggerBuilder toFile(const std::string &filename)
Create a logger that outputs to a file.
Definition: Logger.cpp:185

Custom Variant Usage: For custom chess variants, provide your own PatternMatcher and Marschaler:

class CustomMove { ... };
auto validator = std::make_shared<MyMoveValidator>();
auto marshaler = std::make_shared<MyMoveMarshaler>();
EngineInstanceBuilder<CustomMove> builder(validator, marshaler);
auto engine = builder.build(process, logger);
Factory builder for creating EngineInstance objects.
Definition: EngineConnection.h:1211
See also
EngineInstance for the created object interface
Logger for logging configuration
ProcessWrapper for engine process management

Constructor & Destructor Documentation

◆ EngineInstanceBuilder()

template<class Move >
UCILoader::EngineInstanceBuilder< Move >::EngineInstanceBuilder ( std::shared_ptr< PatternMatcher validator,
std::shared_ptr< Marschaler< Move > >  marschaler 
)
inline

Constructor for the builder.

Parameters
validatorShared pointer to PatternMatcher for move validation
marschalerShared pointer to Marschaler for move parsing

Member Function Documentation

◆ build() [1/2]

template<class Move >
EngineInstance< Move > * UCILoader::EngineInstanceBuilder< Move >::build ( ProcessWrapper engineProcess)
inline

Build an EngineInstance with default logging (no-op logger).

Parameters
engineProcessRaw pointer to a ProcessWrapper for the engine executable
Returns
Raw pointer to the newly created EngineInstance

The EngineInstance takes ownership of the engine process, so the caller does NOT need to manage its lifetime. However, the caller IS responsible for deleting the returned EngineInstance pointer when no longer needed.

For obtaining a ProcessWrapper, see the documentation of openEngineProcessFunction.

See also
build(ProcessWrapper*, LoggerBuilder) for building with custom logging

◆ build() [2/2]

template<class Move >
EngineInstance< Move > * UCILoader::EngineInstanceBuilder< Move >::build ( ProcessWrapper engineProcess,
LoggerBuilder  logger 
)
inline

Build an EngineInstance with custom logging configuration.

Parameters
engineProcessRaw pointer to a ProcessWrapper for the engine executable
loggerConfigured LoggerBuilder for logging UCI messages
Returns
Raw pointer to the newly created EngineInstance

The EngineInstance takes ownership of both the engine process and the logger instance, so the caller does NOT need to manage their lifetimes. However, the caller IS responsible for deleting the returned EngineInstance pointer when no longer needed.

Example:

auto logger = Loggers::toFile("engine.log")
auto engine = builder.build(process, logger);
const LoggerTrait & Timestamp
Trait that prepends timestamps to all logged messages.
Definition: Logger.cpp:169

For obtaining a ProcessWrapper, see the documentation of openEngineProcessFunction. For logger configuration options, see the Logger and Loggers documentation.

See also
Logger for logging configuration options
Loggers namespace for factory functions
LoggerTraits namespace for customization traits

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