Public Member Functions | Static Public Member Functions | List of all members
rapidsmpf::config::Options Class Reference

Manages configuration options for RapidsMPF operations. More...

#include <config.hpp>

Public Member Functions

 Options (std::unordered_map< std::string, OptionValue > options={})
 Constructs an Options instance from option values. More...
 
 Options (std::unordered_map< std::string, std::string > options_as_strings)
 Constructs an Options instance from option values as strings. More...
 
bool insert_if_absent (std::string const &key, std::string option_as_string)
 Inserts an option only if it is not already present. More...
 
std::size_t insert_if_absent (std::unordered_map< std::string, std::string > options_as_strings)
 Inserts multiple options if they are not already present. More...
 
template<typename T >
T const & get (const std::string &key, OptionFactory< T > factory)
 Retrieves a configuration option by key. More...
 
std::unordered_map< std::string, std::string > get_strings () const
 Retrieves all option values as strings. More...
 
std::vector< std::uint8_t > serialize () const
 Serializes the options into a binary buffer. More...
 

Static Public Member Functions

static Options deserialize (std::vector< std::uint8_t > const &buffer)
 Deserializes a binary buffer into an Options object. More...
 

Detailed Description

Manages configuration options for RapidsMPF operations.

The Options class provides a high-level interface for storing and retrieving configuration options.

All keys are trimmed and converted to lower case using rapidsmpf::trim() and rapidsmpf::to_lower().

Note
Copying rapidsmpf::config::Options is efficient as it uses a shared pointer to the shared options (OptionsShared).

Definition at line 124 of file config.hpp.

Constructor & Destructor Documentation

◆ Options() [1/2]

rapidsmpf::config::Options::Options ( std::unordered_map< std::string, OptionValue options = {})

Constructs an Options instance from option values.

Parameters
optionsA map of option keys to their corresponding option value.
Exceptions
std::invalid_argumentIf keys are not case-insensitive.

◆ Options() [2/2]

rapidsmpf::config::Options::Options ( std::unordered_map< std::string, std::string >  options_as_strings)

Constructs an Options instance from option values as strings.

Parameters
options_as_stringsA map of option keys to their string representations.
Exceptions
std::invalid_argumentIf keys are not case-insensitive.

Member Function Documentation

◆ deserialize()

static Options rapidsmpf::config::Options::deserialize ( std::vector< std::uint8_t > const &  buffer)
static

Deserializes a binary buffer into an Options object.

See Options::serialize() for the binary format.

Parameters
bufferThe binary buffer produced by Options::serialize().
Returns
An Options object reconstructed from the buffer.
Exceptions
std::invalid_argumentIf the buffer is malformed or incomplete.
std::out_of_rangeIf offsets exceed buffer boundaries.

◆ get()

template<typename T >
T const& rapidsmpf::config::Options::get ( const std::string &  key,
OptionFactory< T >  factory 
)
inline

Retrieves a configuration option by key.

If the option is not present, it will be constructed using the provided factory, which receives the string representation of the option (or an empty string if unset).

Template Parameters
TThe type of the option to retrieve.
Parameters
keyThe option key (should be lower case).
factoryFunction to construct the option from a string.
Returns
Reference to the option value.
Exceptions
std::invalid_argumentIf the stored option type does not match T.
std::bad_any_castIf T doesn't match the type of the option.
Note
Once a key has been accessed with a particular T, subsequent calls to get on the same key must use the same T. Using a different T for the same key will result in a std::bad_any_cast.

Definition at line 194 of file config.hpp.

◆ get_strings()

std::unordered_map<std::string, std::string> rapidsmpf::config::Options::get_strings ( ) const

Retrieves all option values as strings.

This method returns a map of all currently stored options where both the keys and values are represented as strings.

Returns
A map where each key is the option name and each value is the string representation of the corresponding option's value.

◆ insert_if_absent() [1/2]

bool rapidsmpf::config::Options::insert_if_absent ( std::string const &  key,
std::string  option_as_string 
)

Inserts an option only if it is not already present.

This method checks whether the given option key exists in the current set of options. If it does not, the option is inserted in its string representation.

Parameters
keyThe option key to insert. The key is trimmed and converted to lower case before insertion.
option_as_stringThe string representation of the option value.
Returns
true if the option was inserted; false if it was already present.

◆ insert_if_absent() [2/2]

std::size_t rapidsmpf::config::Options::insert_if_absent ( std::unordered_map< std::string, std::string >  options_as_strings)

Inserts multiple options if they are not already present.

This method attempts to insert each option key-value pair from the provided map into the current set of options. Each insertion is performed only if the key does not already exist in the options.

Parameters
options_as_stringsA map of option keys to their string representations.
Returns
Number of newly inserted options (0 if none were added).

◆ serialize()

std::vector<std::uint8_t> rapidsmpf::config::Options::serialize ( ) const

Serializes the options into a binary buffer.

An Options instance can only be serialized if no options have been accessed. This is because serialization is based on the original string representations of the options. Once an option has been accessed and parsed, its string value may no longer accurately reflect its state, making serialization potentially inconsistent.

The format (v1) is:

  • [4 bytes MAGIC "RMPF"][1 byte version][1 byte flags][2 bytes reserved]
  • [uint64_t count] — number of key-value pairs.
  • [count * 2 * uint64_t] — offset pairs (key_offset, value_offset) for each entry.
  • [raw bytes] — all key and value strings, contiguous and null-free.

Offsets are absolute byte positions into the buffer.

Serialization limits:

  • Maximum options: 65,536 entries
  • Maximum key size: 4 KiB
  • Maximum value size: 1 MiB
  • Maximum total buffer size: 64 MiB
Returns
A byte vector representing the serialized options.
Exceptions
std::invalid_argumentIf any option has already been accessed.
Note
To ease Python/Cython compatibility, a std::vector<std::uint8_t> is returned instead of std::vector<std::byte>.

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