NDEVR
API Documentation
INIFactory

Contains methods for easily reading and writing to an INI file including efficient casting, callback, and variable storage methods. More...

Public Member Functions

 INIFactory ()
 Constructs a default INIFactory with default delimiter and comment settings.
 INIFactory (const INIFactory &reader)=delete
 Deleted copy constructor to prevent unintended duplication of option ownership.
 INIFactory (INIFactory &&reader) noexcept
 Move constructor that transfers ownership of all options and state.
virtual ~INIFactory ()
 Virtual destructor that cleans up all owned INIOption instances.
void addINIOption (const StringView &label, INIOption *option)
 Registers an INIOption under the given label.
bool addManagedOption (const StringView &option_label, const StringView &option, bool replace=true)
 Adds or updates a managed string option that is stored internally by the factory.
template<class t_type, uint01 t_row_dims, uint01 t_col_dims>
void addOption (const String &label, Resource< Matrix< t_type, t_row_dims, t_col_dims > > &mem_loc)
 Registers a Matrix Resource option that will be read/written by the factory.
template<class t_type>
void addOption (const StringView &label, const Resource< t_type > &mem_loc)=delete
 Deleted overload to prevent binding to const Resource references.
template<class t_type>
void addOption (const StringView &label, const t_type &mem_loc)=delete
 Deleted overload to prevent binding to const references.
template<class t_type>
void addOption (const StringView &label, Resource< t_type > &mem_loc)
 Registers a Resource option that will be read/written by the factory.
template<uint01 t_dims, class t_type>
void addOption (const StringView &label, Resource< Vector< t_dims, t_type > > &mem_loc)
 Registers a Vector Resource option that will be read/written by the factory.
template<class t_type>
void addOption (const StringView &label, t_type &mem_loc)
 Registers a raw typed option that will be read/written by the factory.
template<uint01 t_dims, class t_type>
void addOption (const StringView &label, Vector< t_dims, t_type > &mem_loc)
 Registers a raw Vector option that will be read/written by the factory.
void clear ()
 Removes all registered options and frees their memory.
Dictionary< String, StringextraOptions () const
 Returns a copy of all extra (unregistered) options as key-value pairs.
Dictionary< String, String * > & extraOptionsRef ()
 Returns a mutable reference to the extra options dictionary.
String getOption (const StringView &option, const StringView &default_value=StringView()) const
 Retrieves the string value of a registered or extra option by label.
bool hasOption (const StringView &option) const
 Checks whether an option with the given label has been registered.
bool hasOption (uint08 hash_option) const
 Checks whether an option with the given hash exists.
bool preserveOrder () const
 Returns whether the factory preserves option ordering.
void read (Scanner &file)
 Reads option values from a Scanner stream, applying them to registered options.
void readAsciiFile (File &file)
 Reads all options from an ASCII-formatted INI file.
void readBinaryFile (File &file)
 Reads all options from a binary-formatted INI file.
void setComment (char comment)
 Sets the comment character used to identify comment lines in the INI file.
void setDelimiter (char delimiter)
 Sets the delimiter character used to separate keys from values.
void setPreserveOrder (bool preserve_order)
 Sets whether to preserve the order in which options appear in the file.
void setUseHashLabels (bool use_hash_labels)
 Enables or disables using hashed labels for option lookup.
void writeToAsciiFile (File &file, bool include_end_comment=false)
 Writes all registered options to an ASCII-formatted INI file.
void writeToBinaryFile (File &file)
 Writes all registered options to a binary-formatted INI file.
void writeToLog (const StringView &title, LogPtr &log, uint01 log_level=2)
 Writes all registered options to a log with the given title and level.

Static Public Member Functions

static void ConvertFromINIString (String &s)
 Converts INI escape sequences in a string back to their original characters.
static void ConvertToINIString (String &s)
 Converts special characters in a string to INI-safe escape sequences.
template<class t_type>
static INIOptionToOption (Resource< t_type > &value)
 Creates an INIOption wrapper for a Resource variable.
template<class t_type>
static INIOptionToOption (t_type &mem_loc)
 Creates an INIOption wrapper for a raw typed variable.

Detailed Description

Contains methods for easily reading and writing to an INI file including efficient casting, callback, and variable storage methods.


addOption functions take a REFERENCE to an object and will modify that reference when option is read in.

See also
INIInterface, JSONNode, ApplicationOptions

Definition at line 106 of file INIReader.h.

Constructor & Destructor Documentation

◆ INIFactory()

INIFactory::INIFactory ( INIFactory && reader)
noexcept

Move constructor that transfers ownership of all options and state.

Parameters
[in]readerThe INIFactory to move from.

References INIFactory().

Member Function Documentation

◆ addINIOption()

void INIFactory::addINIOption ( const StringView & label,
INIOption * option )

Registers an INIOption under the given label.

Takes ownership of the option pointer.

Parameters
[in]labelThe key name for this option in the INI file.
[in]optionThe INIOption to register. Ownership is transferred to the factory.

Referenced by addOption(), addOption(), addOption(), addOption(), and addOption().

◆ addManagedOption()

bool INIFactory::addManagedOption ( const StringView & option_label,
const StringView & option,
bool replace = true )

Adds or updates a managed string option that is stored internally by the factory.

Parameters
[in]option_labelThe key name for this option.
[in]optionThe string value to store.
[in]replaceWhether to replace the value if the label already exists.
Returns
True if the option was successfully added or replaced.

Referenced by TranslationTools::addOption().

◆ addOption() [1/5]

template<class t_type, uint01 t_row_dims, uint01 t_col_dims>
void INIFactory::addOption ( const String & label,
Resource< Matrix< t_type, t_row_dims, t_col_dims > > & mem_loc )
inline

Registers a Matrix Resource option that will be read/written by the factory.

Parameters
[in]labelThe key name for this option in the INI file.
[in]mem_locReference to the Resource<Matrix> that will be updated when the option is read.

Definition at line 193 of file INIReader.h.

References addINIOption().

◆ addOption() [2/5]

template<class t_type>
void INIFactory::addOption ( const StringView & label,
Resource< t_type > & mem_loc )
inline

Registers a Resource option that will be read/written by the factory.

Parameters
[in]labelThe key name for this option in the INI file.
[in]mem_locReference to the Resource that will be updated when the option is read.

Definition at line 167 of file INIReader.h.

References addINIOption().

◆ addOption() [3/5]

template<uint01 t_dims, class t_type>
void INIFactory::addOption ( const StringView & label,
Resource< Vector< t_dims, t_type > > & mem_loc )
inline

Registers a Vector Resource option that will be read/written by the factory.

Parameters
[in]labelThe key name for this option in the INI file.
[in]mem_locReference to the Resource<Vector> that will be updated when the option is read.

Definition at line 141 of file INIReader.h.

References addINIOption().

Referenced by RasterInfo::getINI().

◆ addOption() [4/5]

template<class t_type>
void INIFactory::addOption ( const StringView & label,
t_type & mem_loc )
inline

Registers a raw typed option that will be read/written by the factory.

Parameters
[in]labelThe key name for this option in the INI file.
[in]mem_locReference to the variable that will be updated when the option is read.

Definition at line 182 of file INIReader.h.

References addINIOption().

◆ addOption() [5/5]

template<uint01 t_dims, class t_type>
void INIFactory::addOption ( const StringView & label,
Vector< t_dims, t_type > & mem_loc )
inline

Registers a raw Vector option that will be read/written by the factory.

Parameters
[in]labelThe key name for this option in the INI file.
[in]mem_locReference to the Vector that will be updated when the option is read.

Definition at line 152 of file INIReader.h.

References addINIOption().

◆ ConvertFromINIString()

void INIFactory::ConvertFromINIString ( String & s)
static

Converts INI escape sequences in a string back to their original characters.

Parameters
[in]sThe string to convert in-place.

◆ ConvertToINIString()

void INIFactory::ConvertToINIString ( String & s)
static

Converts special characters in a string to INI-safe escape sequences.

Parameters
[in]sThe string to convert in-place.

◆ extraOptions()

Dictionary< String, String > INIFactory::extraOptions ( ) const

Returns a copy of all extra (unregistered) options as key-value pairs.

Returns
A Dictionary of extra option labels to their string values.

Referenced by TranslationTools::convertFromBrackets().

◆ extraOptionsRef()

Dictionary< String, String * > & INIFactory::extraOptionsRef ( )
inline

Returns a mutable reference to the extra options dictionary.

Returns
A reference to the internal Dictionary of extra option label-to-value pointers.

Definition at line 305 of file INIReader.h.

Referenced by TranslationTools::convertBrackets(), and TranslationTools::convertFromBrackets().

◆ getOption()

String INIFactory::getOption ( const StringView & option,
const StringView & default_value = StringView() ) const

Retrieves the string value of a registered or extra option by label.

Parameters
[in]optionThe label of the option to retrieve.
[in]default_valueThe value to return if the option is not found.
Returns
The option value string, or the default value if not found.

Referenced by TranslationTools::addOption().

◆ hasOption() [1/2]

bool INIFactory::hasOption ( const StringView & option) const

Checks whether an option with the given label has been registered.

Parameters
[in]optionThe label to search for.
Returns
True if the option exists.

Referenced by TranslationTools::addOption().

◆ hasOption() [2/2]

bool INIFactory::hasOption ( uint08 hash_option) const

Checks whether an option with the given hash exists.

Parameters
[in]hash_optionThe hash of the label to search for.
Returns
True if the option exists.

◆ preserveOrder()

bool INIFactory::preserveOrder ( ) const
inline

Returns whether the factory preserves option ordering.

Returns
True if insertion order is preserved.

Definition at line 266 of file INIReader.h.

◆ read()

void INIFactory::read ( Scanner & file)

Reads option values from a Scanner stream, applying them to registered options.

Parameters
[in]fileThe scanner to read from.

◆ readAsciiFile()

void INIFactory::readAsciiFile ( File & file)

Reads all options from an ASCII-formatted INI file.

Parameters
[in]fileThe file to read from.

Referenced by IMUNoiseSimulator::loadAccelerometerSettings(), IMUNoiseSimulator::loadGyroSettings(), and TranslationTools::makeTranslation().

◆ readBinaryFile()

void INIFactory::readBinaryFile ( File & file)

Reads all options from a binary-formatted INI file.

Parameters
[in]fileThe file to read from.

◆ setComment()

void INIFactory::setComment ( char comment)
inline

Sets the comment character used to identify comment lines in the INI file.

Parameters
[in]commentThe comment character (e.g., '#' or ';').

Definition at line 236 of file INIReader.h.

◆ setDelimiter()

void INIFactory::setDelimiter ( char delimiter)

Sets the delimiter character used to separate keys from values.

Parameters
[in]delimiterThe delimiter character (e.g., '=' or ':').

◆ setPreserveOrder()

void INIFactory::setPreserveOrder ( bool preserve_order)
inline

Sets whether to preserve the order in which options appear in the file.

Parameters
[in]preserve_orderTrue to maintain insertion order during writes.

Definition at line 260 of file INIReader.h.

Referenced by IMUNoiseSimulator::loadAccelerometerSettings(), IMUNoiseSimulator::loadGyroSettings(), TranslationTools::makeTranslation(), IMUNoiseSimulator::saveAccelerometerSettings(), and IMUNoiseSimulator::saveGyroSettings().

◆ setUseHashLabels()

void INIFactory::setUseHashLabels ( bool use_hash_labels)

Enables or disables using hashed labels for option lookup.

Parameters
[in]use_hash_labelsTrue to use hash-based label lookup.

Referenced by TranslationTools::makeTranslation().

◆ ToOption() [1/2]

template<class t_type>
INIOption * INIFactory::ToOption ( Resource< t_type > & value)
inlinestatic

Creates an INIOption wrapper for a Resource variable.

Parameters
[in]valueReference to the Resource to wrap.
Returns
A newly allocated INIOption that reads/writes the Resource.

Definition at line 344 of file INIReader.h.

◆ ToOption() [2/2]

template<class t_type>
INIOption * INIFactory::ToOption ( t_type & mem_loc)
inlinestatic

Creates an INIOption wrapper for a raw typed variable.

Parameters
[in]mem_locReference to the variable to wrap.
Returns
A newly allocated INIOption that reads/writes the variable.

Definition at line 333 of file INIReader.h.

Referenced by ApplicationOption< t_type >::iniOption().

◆ writeToAsciiFile()

void INIFactory::writeToAsciiFile ( File & file,
bool include_end_comment = false )

Writes all registered options to an ASCII-formatted INI file.

Parameters
[in]fileThe file to write to.
[in]include_end_commentWhether to append a trailing comment marker.

Referenced by TranslationTools::makeTranslation(), IMUNoiseSimulator::saveAccelerometerSettings(), and IMUNoiseSimulator::saveGyroSettings().

◆ writeToBinaryFile()

void INIFactory::writeToBinaryFile ( File & file)

Writes all registered options to a binary-formatted INI file.

Parameters
[in]fileThe file to write to.

◆ writeToLog()

void INIFactory::writeToLog ( const StringView & title,
LogPtr & log,
uint01 log_level = 2 )

Writes all registered options to a log with the given title and level.

Parameters
[in]titleThe title to display in the log entry.
[in]logThe log to write to.
[in]log_levelThe verbosity level for the log entry.

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