SNode.C
Loading...
Searching...
No Matches
net::config::ConfigInstance Class Reference

#include <ConfigInstance.h>

Inheritance diagram for net::config::ConfigInstance:
Collaboration diagram for net::config::ConfigInstance:

Public Types

enum class  Role { SERVER , CLIENT }
 
using Instance = ConfigInstance
 

Public Member Functions

 ConfigInstance (ConfigInstance &)=delete
 
 ConfigInstance (ConfigInstance &&)=delete
 
ConfigInstanceoperator= (ConfigInstance &)=delete
 
ConfigInstanceoperator= (ConfigInstance &&)=delete
 
Role getRole ()
 
const std::string & getInstanceName () const
 
void setInstanceName (const std::string &instanceName)
 
bool getDisabled () const
 
void setDisabled (bool disabled=true)
 
CLI::App * addSection (const std::string &name, const std::string &description, const std::string &group="Sections")
 
CLI::App * getSection (const std::string &name, bool onlyGot=false, bool recursive=false) const
 
bool gotSection (const std::string &name, bool recursive=false) const
 
void required (CLI::App *section, bool req=true)
 
bool getRequired () const
 

Protected Member Functions

 ConfigInstance (const std::string &instanceName, Role role)
 
virtual ~ConfigInstance ()
 

Private Attributes

uint8_t requiredCount = 0
 
std::string instanceName
 
Role role
 
CLI::App * instanceSc = nullptr
 
CLI::Option * disableOpt = nullptr
 

Static Private Attributes

static const std::string nameAnonymous = "<anonymous>"
 

Friends

class net::config::ConfigSection
 

Detailed Description

Definition at line 63 of file ConfigInstance.h.

Member Typedef Documentation

◆ Instance

Member Enumeration Documentation

◆ Role

Enumerator
SERVER 
CLIENT 

Definition at line 67 of file ConfigInstance.h.

Constructor & Destructor Documentation

◆ ConfigInstance() [1/3]

net::config::ConfigInstance::ConfigInstance ( const std::string &  instanceName,
Role  role 
)
explicitprotected

Definition at line 75 of file ConfigInstance.cpp.

77 , role(role) {
79 std::string("Configuration for ")
80 .append(role == Role::SERVER ? "server" : "client")
81 .append(" instance '")
82 .append(instanceName)
83 .append("'"),
84 "Instances");
85
87 ->add_flag_function(
88 "--disabled{true}",
89 [this](std::size_t) {
91 },
92 "Disable this instance")
93 ->multi_option_policy(CLI::MultiOptionPolicy::TakeLast)
94 ->trigger_on_parse()
95 ->default_str("false")
96 ->type_name("bool")
97 ->check(CLI::IsMember({"true", "false"}))
98 ->group(instanceSc->get_formatter()->get_label("Persistent Options"));
99 }
static void disabled(CLI::App *instance, bool disabled=true)
Definition Config.cpp:850
static CLI::App * addInstance(const std::string &name, const std::string &description, const std::string &group)
Definition Config.cpp:707

References disableOpt, instanceName, instanceSc, role, and SERVER.

◆ ~ConfigInstance()

net::config::ConfigInstance::~ConfigInstance ( )
protectedvirtual

Definition at line 101 of file ConfigInstance.cpp.

101 {
103 }
static bool removeInstance(CLI::App *instance)
Definition Config.cpp:878

References instanceSc.

◆ ConfigInstance() [2/3]

net::config::ConfigInstance::ConfigInstance ( ConfigInstance )
delete

◆ ConfigInstance() [3/3]

net::config::ConfigInstance::ConfigInstance ( ConfigInstance &&  )
delete

Member Function Documentation

◆ addSection()

CLI::App * net::config::ConfigInstance::addSection ( const std::string &  name,
const std::string &  description,
const std::string &  group = "Sections" 
)

Definition at line 117 of file ConfigInstance.cpp.

117 {
118 CLI::App* sectionSc = instanceSc //
119 ->add_subcommand(name, description)
120 ->fallthrough()
121 ->configurable(false)
122 ->allow_extras(false)
123 ->group(group)
124 ->ignore_case(false)
125 ->disabled(this->instanceName.empty() || name.empty());
126
127 sectionSc //
128 ->option_defaults()
129 ->configurable(!sectionSc->get_disabled());
130
131 if (!sectionSc->get_disabled()) {
134 }
135
136 return sectionSc;
137 }
static CLI::App * addStandardFlags(CLI::App *app)
Definition Config.cpp:737
static CLI::App * addSimpleHelp(CLI::App *app)
Definition Config.cpp:814

References instanceName, and instanceSc.

Referenced by net::config::ConfigSection::ConfigSection().

Here is the caller graph for this function:

◆ getDisabled()

bool net::config::ConfigInstance::getDisabled ( ) const

Definition at line 184 of file ConfigInstance.cpp.

184 {
185 return disableOpt //
186 ->as<bool>();
187 }

References disableOpt.

Referenced by required().

Here is the caller graph for this function:

◆ getInstanceName()

◆ getRequired()

bool net::config::ConfigInstance::getRequired ( ) const

Definition at line 162 of file ConfigInstance.cpp.

162 {
163 return requiredCount > 0;
164 }

References requiredCount.

◆ getRole()

ConfigInstance::Role net::config::ConfigInstance::getRole ( )

Definition at line 105 of file ConfigInstance.cpp.

105 {
106 return role;
107 }

References role.

◆ getSection()

CLI::App * net::config::ConfigInstance::getSection ( const std::string &  name,
bool  onlyGot = false,
bool  recursive = false 
) const

Definition at line 166 of file ConfigInstance.cpp.

166 {
167 CLI::App* resultSc = (instanceSc->got_subcommand(name) || !onlyGot) ? instanceSc->get_subcommand_no_throw(name) : nullptr;
168
169 if (resultSc == nullptr && recursive) {
170 CLI::App* parentSc = instanceSc->get_parent();
171 resultSc =
172 (parentSc != nullptr && (parentSc->got_subcommand(name) || !onlyGot)) ? parentSc->get_subcommand_no_throw(name) : nullptr;
173 }
174
175 return resultSc;
176 }

References instanceSc.

Referenced by net::config::ConfigSection::ConfigSection().

Here is the caller graph for this function:

◆ gotSection()

bool net::config::ConfigInstance::gotSection ( const std::string &  name,
bool  recursive = false 
) const

Definition at line 178 of file ConfigInstance.cpp.

178 {
179 return instanceSc //
180 ->got_subcommand(name) ||
181 (recursive && instanceSc->get_parent()->got_subcommand(name));
182 }

References instanceSc.

◆ operator=() [1/2]

ConfigInstance & net::config::ConfigInstance::operator= ( ConfigInstance &&  )
delete

◆ operator=() [2/2]

ConfigInstance & net::config::ConfigInstance::operator= ( ConfigInstance )
delete

◆ required()

void net::config::ConfigInstance::required ( CLI::App *  section,
bool  req = true 
)

Definition at line 139 of file ConfigInstance.cpp.

139 {
140 if (req != section->get_required()) {
141 if (req) {
143 instanceSc //
144 ->needs(section);
145 } else {
147 instanceSc //
148 ->remove_needs(section);
149 }
150
151 section //
152 ->required(req);
153 section //
154 ->ignore_case(req);
155
156 if (!getDisabled()) {
158 }
159 }
160 }
static void required(CLI::App *instance, bool required=true)
Definition Config.cpp:827

References getDisabled(), instanceSc, and requiredCount.

Referenced by net::config::ConfigSection::required().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDisabled()

void net::config::ConfigInstance::setDisabled ( bool  disabled = true)

Definition at line 189 of file ConfigInstance.cpp.

189 {
190 disableOpt //
191 ->default_str(disabled ? "true" : "false")
192 ->clear();
193
195 }

References disableOpt, and instanceSc.

◆ setInstanceName()

void net::config::ConfigInstance::setInstanceName ( const std::string &  instanceName)

Definition at line 113 of file ConfigInstance.cpp.

113 {
115 }

References instanceName.

Friends And Related Symbol Documentation

◆ net::config::ConfigSection

friend class net::config::ConfigSection
friend

Definition at line 107 of file ConfigInstance.h.

Member Data Documentation

◆ disableOpt

CLI::Option* net::config::ConfigInstance::disableOpt = nullptr
private

Definition at line 105 of file ConfigInstance.h.

Referenced by ConfigInstance(), getDisabled(), and setDisabled().

◆ instanceName

std::string net::config::ConfigInstance::instanceName
private

Definition at line 99 of file ConfigInstance.h.

Referenced by addSection(), ConfigInstance(), getInstanceName(), and setInstanceName().

◆ instanceSc

CLI::App* net::config::ConfigInstance::instanceSc = nullptr
private

◆ nameAnonymous

const std::string net::config::ConfigInstance::nameAnonymous = "<anonymous>"
staticprivate

Definition at line 100 of file ConfigInstance.h.

Referenced by getInstanceName().

◆ requiredCount

uint8_t net::config::ConfigInstance::requiredCount = 0
private

Definition at line 97 of file ConfigInstance.h.

Referenced by getRequired(), and required().

◆ role

Role net::config::ConfigInstance::role
private

Definition at line 102 of file ConfigInstance.h.

Referenced by ConfigInstance(), and getRole().


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