ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
CLIArgs Class Reference

Description:


Specialization of abstract interface class ConfigurationPlugin, which takes all command line parameters in the constructor and reads variable values from those parameters on request. Its priority value usually is Priorities::CLI , which is higher than all other default plug-ins provided.

Variable categories are used as a prefix together with an underscore '_'. This means, if variable LOCALE in category ALIB is accessed, the command line parameter –ALIB_LOCALE=xyz is read.

Category and Variable names are insensitive in respect to character case.

Command line variables may be passed with either one hyphen ('-') or two ('–'). Both are accepted.

An application can specify one or more "default categories" by adding their string names to public field DefaultCategories. Variables of these categories are recognized by the plug-in also when given without the prefix of category name and underscore '_'.

Furthermore, an application may set public field AllowedMinimumShortCut to a value greater than 0. In this case, the plug-in recognizes variables in CLI arguments already when at least this amount of characters is provided. In other words, when reading an argument as many characters of the variable name as possible are 'consumed' and if a minimum number is given with AllowedMinimumShortCut, such minimum is sufficient. If the remaining part of the argument string is either empty or continues with an equal sign '=', then the variable is recognized (with an empty value or the value after the equal sign).
Fields AllowedMinimumShortCut and DefaultCategories may also be used in combination.

Friends

class detail::nextCLIArg (Used for implementation of iterator.)

Definition at line 320 of file config/plugins.hpp.

#include <plugins.hpp>

Inheritance diagram for CLIArgs:
[legend]
Collaboration diagram for CLIArgs:
[legend]

Public Field Index:

int AllowedMinimumShortCut = 0
 
std::vector< AStringAlternativeArgs
 
std::vector< AStringDefaultCategories
 
- Public Field Index: inherited from ConfigurationPlugin
XTernalizerStringConverter
 

Public Method Index:

 CLIArgs ()
 
virtual ~CLIArgs () override
 
virtual ALIB_API IteratorGetIterator (const String &sectionName) override
 
virtual ALIB_API bool Load (Variable &variable, bool searchOnly=false) override
 
virtual ALIB_API String Name () const override
 
void SetArgs (int argc, const void **argv=nullptr, bool areWideChar=false)
 
- Public Method Index: inherited from ConfigurationPlugin
virtual ~ConfigurationPlugin ()
 
virtual bool Store (Variable &variable)
 
virtual bool Store (Variable &variable, const String &externalizedValue)
 

Field Details:

◆ AllowedMinimumShortCut

int AllowedMinimumShortCut = 0

If this field is set to a value greater than 0, this plug-in recognizes variables in CLI arguments already when at least this amount of characters is provided. If the remaining part of the argument string is either empty or continues with an equal sign '=', then the variable is recognized.

Definition at line 363 of file config/plugins.hpp.

◆ AlternativeArgs

std::vector<AString> AlternativeArgs

If any value is added to this vector, its values are used as the source of command line arguments instead of using fields argCount and argVector.
This mechanic provides an alternative method to set the command line argument list.

Applications that have a dedicated (more sophisticated) CLI interface which performs more complex processing of CLI arguments, may collect any unrecognized CLI argument here to be duly recognized as a configuration variable instead

Definition at line 345 of file config/plugins.hpp.

◆ argCount

size_t argCount = 0
protected

The number of command line arguments.

Definition at line 328 of file config/plugins.hpp.

◆ argVector

const void** argVector = nullptr
protected

The list of command line arguments.

Definition at line 329 of file config/plugins.hpp.

◆ DefaultCategories

std::vector<AString> DefaultCategories

An application can specify one or more "default categories" by adding the category names here. Variables of these categories are recognized by the plug-in also when given without the prefix of category_.

Note
This list uses the global allocator. Additions may only be made during bootstrap.

Definition at line 355 of file config/plugins.hpp.

◆ wArgs

bool wArgs = false
protected

Determines if argv is of type 'wchar **' or 'nchar **'

Definition at line 330 of file config/plugins.hpp.

Constructor(s) / Destructor Details::

◆ CLIArgs()

CLIArgs ( )
inline

Constructor. After creation, method SetArgs should be called to equip this instance with the command line arguments.

Definition at line 369 of file config/plugins.hpp.

◆ ~CLIArgs()

virtual ~CLIArgs ( )
inlineoverridevirtual

Virtual Destructor.

Definition at line 376 of file config/plugins.hpp.

Method Details:

◆ GetIterator()

virtual ALIB_API Iterator * GetIterator ( const String & sectionName)
overridevirtual

Creates an iterator object to return all variables within a section.

The iterator object returned, needs to be deleted by the caller.

Note
Method Configuration::GetIterator returns an iterator that allows to iterate across all variables of a section found in all plug-ins
Parameters
sectionNameThe name of the section to iterate.
Returns
The iterator requested.

Reimplemented from ConfigurationPlugin.

◆ Load()

bool Load ( Variable & variable,
bool searchOnly = false )
overridevirtual

Searches the variable in the command line parameters.

Parameters
variableThe variable to retrieve.
searchOnlyIf true, the variable is not set. Defaults to false.
Returns
true if variable was found, false if not.

Implements ConfigurationPlugin.

Definition at line 178 of file plugins.cpp.

Here is the call graph for this function:

◆ Name()

String Name ( ) const
overridevirtual

Return the plug-in name, in this case, we read resource variable "CfgPlgCLI".

Returns
The name of the plug-in.

Implements ConfigurationPlugin.

Definition at line 173 of file plugins.cpp.

Here is the call graph for this function:

◆ SetArgs()

void SetArgs ( int argc,
const void ** argv = nullptr,
bool areWideChar = false )
inline

Sets the command line argument list. Needs to be called once after construction. Should not be invoked directly. Rather use method Configuration::SetCommandLineArgs .

Note
In standard application scenarios, this method is invoked with corresponding module initialization during library bootstrap.
Note
On the Windows platform, the Microsoft compiler provides the global variables __argc and __argv (respectively __wargv for wide character binaries. These variables a can be used if this method is invoked outside of the main() method.
Parameters
argcThe number of arguments in argv
argvThe list of command line arguments.
areWideCharIf true, parameter argv is of type wchar_t **', otherwise of type char **. Defaults to false.

Definition at line 399 of file config/plugins.hpp.


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