Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Static Private Member Functions | Private Attributes | List of all members
Config Class Reference

Contains configurable elements as attributes, populated from the command line, a configuration file or default values. More...

#include <Config.hpp>

Classes

struct  ArgumentInfo
 Informations about an argument. More...
 

Public Member Functions

 Config (const std::vector< std::string > &argv)
 
bool showHelp ()
 

Protected Member Functions

const std::vector< KeyValues > & arguments () const
 
void registerSection (const std::string &name)
 
void registerArgument (const std::string &longName, const std::string &shortName, const std::string &details, const std::vector< std::string > &params={})
 
void registerArgument (const std::string &longName, const std::string &shortName, const std::string &details, const std::string &param)
 

Static Private Member Functions

static void parseFromFile (const std::string &filePath, std::vector< KeyValues > &arguments)
 
static void parseFromArgs (const std::vector< std::string > &argv, std::vector< KeyValues > &arguments)
 

Private Attributes

std::vector< KeyValues_rawArguments
 Store the internal parsed (keys, [values]) extracted from a file or the command-line.
 
std::vector< ArgumentInfo_infos
 Store informations about each argument, for displaying the help message.
 
bool _showHelp = false
 Should the help be displayed.
 

Detailed Description

Contains configurable elements as attributes, populated from the command line, a configuration file or default values.

Inherited by ObjToSceneConfig, and RenderingConfig.

Constructor & Destructor Documentation

◆ Config()

Config::Config ( const std::vector< std::string > &  argv)
explicit

Initialize a new config object, parsing the input arguments and filling the attributes with their values.

Parameters
argvthe raw input arguments

Member Function Documentation

◆ arguments()

const std::vector< KeyValues > & Config::arguments ( ) const
protected

List of raw arguments.

Returns
the arguments list

◆ parseFromArgs()

void Config::parseFromArgs ( const std::vector< std::string > &  argv,
std::vector< KeyValues > &  arguments 
)
staticprivate

Helper to extract (key, [values]) from the given command-line arguments.

Parameters
argvthe raw input arguments
argumentsa vector will be populated with (key, [values]) tuples.

◆ parseFromFile()

void Config::parseFromFile ( const std::string &  filePath,
std::vector< KeyValues > &  arguments 
)
staticprivate

Helper to extract (key, [values]) from a configuration file on disk.

Parameters
filePaththe path to the configuration file.
argumentsa vector will be populated with (key, [values]) tuples.

◆ registerArgument() [1/2]

void Config::registerArgument ( const std::string &  longName,
const std::string &  shortName,
const std::string &  details,
const std::string &  param 
)
protected

Register help infos for an argument. The command will be listed as follow in the help message: "--shortName,--longName <param> Details."

Parameters
longNamethe command full name
shortNamethe command abbreviated name
detailsthe command description
paramname or type of the expected parameter

◆ registerArgument() [2/2]

void Config::registerArgument ( const std::string &  longName,
const std::string &  shortName,
const std::string &  details,
const std::vector< std::string > &  params = {} 
)
protected

Register help infos for an argument. The command will be listed as follow in the help message: "--shortName,--longName <param0> <param1> Details."

Parameters
longNamethe command full name
shortNamethe command abbreviated name
detailsthe command description
paramsname or type of each expected parameter

◆ registerSection()

void Config::registerSection ( const std::string &  name)
protected

Create a section in the help messages, to group arguments.

Parameters
namethe section name

◆ showHelp()

bool Config::showHelp ( )

Display help using the logger if the '–help' argument has been passed.

Returns
true if the help is shown, can be used for early exit
Note
Arguments with no name but a description will be used as headers.

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