Scarab  v3.4.4
Project 8 C++ Utility Library
Classes | Public Member Functions | Protected Types | Protected Attributes | List of all members
config_decorator Class Reference

Adds the ability to create options and subcommands that are tied to a main_app's primary config. More...

#include <application.hh>

Inheritance diagram for config_decorator:
Inheritance graph

Classes

struct  app_option_holder
 
struct  app_option_holder_bool_flag
 
struct  app_option_holder_typed
 
struct  app_option_holder_vector_typed
 

Public Member Functions

 config_decorator (main_app *a_main, app *a_this_app)
 
 config_decorator (const config_decorator &)=delete
 
 config_decorator (config_decorator &&)=delete
 
virtual ~config_decorator ()
 
config_decoratoroperator= (const config_decorator &)=delete
 
config_decoratoroperator= (config_decorator &&)=delete
 
main_appmain () const
 
appthis_app () const
 
config_decoratoradd_config_subcommand (std::string a_subcommand_name, std::string a_description="")
 Add a subcommand that is linked to a particular main_app and can create options that modify that main_app's primary config. More...
 
template<typename T , CLI::enable_if_t< ! CLI::is_vector< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_option (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 Add an option that gets automatically added to the primary config of a main_app. More...
 
template<typename T , CLI::enable_if_t< ! CLI::is_vector< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_multi_option (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 Add an option that gets automatically added to the primary config of a main_app. More...
 
template<typename T , CLI::enable_if_t< std::is_integral< T >::value &&! CLI::is_bool< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_flag (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 
template<typename T , CLI::enable_if_t< CLI::is_bool< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_flag (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 

Protected Types

using conf_dec_ptr_t = std::unique_ptr< config_decorator >
 

Protected Attributes

main_appf_main
 
appf_this
 
std::vector< conf_dec_ptr_tf_subcommand_decorators
 

Detailed Description

Adds the ability to create options and subcommands that are tied to a main_app's primary config.

Author
N. S. Oblath

Note that while this class is called a decorator, it does not follow the actual decorator pattern. It does, however, follow the spirit of that pattern in that it adds a capability to the CLI::App class.

Subcommands and options are tied to the main_app in slightly different ways because of the different ways in which those two CLI11 classes are used.

Subcommands are CLI::App objects, and any App can have subcommands. Therefore the collection of Apps in use in a given application can form a multi-level parent-child structure. Each parent App can have multiple children, and owns those child App objects. The children can also be parents, of course. The scarab::config_decorator for each subcommand App object is created by the parent config_decorator's add_config_subcommand() function. That decorator has a link to its App and is owned by its parent decorator.

At the top of the App hierarchy is the primary App. In Scarab, that's the main_app, which also inherits from config_decorator. So main_app is also the top of the config_decorator hierarchy.

Options, on the other hand, do not form their own hierarchy. Each App owns its options. On the Scarab side, though, even options that belong to subcommands contribute to the main_app's primary config. Therefore when config_decorator::add_config_option() is used, the app_option_holder that corresponds to the new option is given directly to the main_app.

Definition at line 55 of file application.hh.

Member Typedef Documentation

◆ conf_dec_ptr_t

using conf_dec_ptr_t = std::unique_ptr< config_decorator >
protected

Definition at line 163 of file application.hh.

Constructor & Destructor Documentation

◆ config_decorator() [1/3]

config_decorator ( main_app a_main,
app a_this_app 
)

Definition at line 23 of file application.cc.

◆ config_decorator() [2/3]

config_decorator ( const config_decorator )
delete

◆ config_decorator() [3/3]

◆ ~config_decorator()

~config_decorator ( )
virtual

Definition at line 30 of file application.cc.

Member Function Documentation

◆ add_config_flag() [1/2]

CLI::Option * add_config_flag ( std::string  a_name,
std::string  a_primary_config_addr,
std::string  a_description = "" 
)

Add a flag that gets automatically added to the primary config of a main_app The flag can be passed multiple times, and the number of instances will be recorded in the config

Definition at line 361 of file application.hh.

◆ add_config_flag() [2/2]

CLI::Option* add_config_flag ( std::string  a_name,
std::string  a_primary_config_addr,
std::string  a_description = "" 
)

Add a flag that gets automatically added to the primary config of a main_app This flag is recorded in the config as a boolean: false if it doesn't appear in the command line, and true if it does

◆ add_config_multi_option()

CLI::Option * add_config_multi_option ( std::string  a_name,
std::string  a_primary_config_addr,
std::string  a_description = "" 
)

Add an option that gets automatically added to the primary config of a main_app.

Definition at line 349 of file application.hh.

◆ add_config_option()

CLI::Option * add_config_option ( std::string  a_name,
std::string  a_primary_config_addr,
std::string  a_description = "" 
)

Add an option that gets automatically added to the primary config of a main_app.

Definition at line 337 of file application.hh.

◆ add_config_subcommand()

config_decorator * add_config_subcommand ( std::string  a_subcommand_name,
std::string  a_description = "" 
)

Add a subcommand that is linked to a particular main_app and can create options that modify that main_app's primary config.

Definition at line 34 of file application.cc.

◆ main()

main_app * main ( ) const
inline

Definition at line 389 of file application.hh.

◆ operator=() [1/2]

config_decorator& operator= ( const config_decorator )
delete

◆ operator=() [2/2]

config_decorator& operator= ( config_decorator &&  )
delete

◆ this_app()

app * this_app ( ) const
inline

Definition at line 384 of file application.hh.

Member Data Documentation

◆ f_main

main_app* f_main
protected

Definition at line 159 of file application.hh.

◆ f_subcommand_decorators

std::vector< conf_dec_ptr_t > f_subcommand_decorators
protected

Definition at line 164 of file application.hh.

◆ f_this

app* f_this
protected

Definition at line 160 of file application.hh.


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