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_view 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 >
bool insert_if_absent (std::string const &key, T value) requires(!std
 Inserts an option only if it is not already present. More...
 
template<typename T >
T const & get (std::string const &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 140 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 ( std::string const &  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 245 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.

Options that do not have a string representation, such as those inserted using insert_if_absent<T>(), are included with an empty string value.

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/3]

bool rapidsmpf::config::Options::insert_if_absent ( std::string const &  key,
std::string_view  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/3]

template<typename T >
bool rapidsmpf::config::Options::insert_if_absent ( std::string const &  key,
value 
)
inline

Inserts an option only if it is not already present.

This method stores a typed value directly, bypassing the string-based representation used for lazy parsing. Once inserted, the option is initialized, and subsequent calls to get<T>() for the same key must use the same T.

This method is only enabled for non string-like types. Values convertible to std::string_view (for example std::string, std::string_view, or string literals) are handled by the string-based overloads instead.

Because no string representation is stored, inserting an option using this method makes the Options instance unserializable. This is consistent with the behavior of get(), as serialization relies exclusively on the original string representations of options.

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

Definition at line 215 of file config.hpp.

◆ insert_if_absent() [3/3]

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 all options are still represented exclusively by their original string values. Serialization is based on these string representations and cannot reflect options that have been accessed, parsed, or initialized with typed values.

As a result, serialization is disallowed if any option has been accessed via get() or inserted using the typed insert_if_absent<T>() method, since their string values may no longer accurately reflect their state.

The format (v1) is:

  • [4 bytes MAGIC "RMPF"][1 byte version][1 byte flags][2 bytes reserved]
  • [std::uint64_t count] — number of key-value pairs.
  • [count * 2 * std::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 or inserted as a typed value.
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: