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
CLI::App * get () 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.

67{ SERVER, CLIENT };

Constructor & Destructor Documentation

◆ ConfigInstance() [1/3]

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

Definition at line 81 of file ConfigInstance.cpp.

83 , role(role) {
85 std::string("Configuration for ")
86 .append(role == Role::SERVER ? "server" : "client")
87 .append(" instance '")
88 .append(instanceName)
89 .append("'"),
90 "Instances");
91
93 ->add_flag_function(
94 "--disabled{true}",
95 [this](std::size_t) {
97 },
98 "Disable this instance")
99 ->multi_option_policy(CLI::MultiOptionPolicy::TakeLast)
100 ->trigger_on_parse()
101 ->default_str("false")
102 ->type_name("bool")
103 ->check(CLI::IsMember({"true", "false"}))
104 ->group(instanceSc->get_formatter()->get_label("Persistent Options"));
105 }
static void disabled(CLI::App *instance, bool disabled=true)
Definition Config.cpp:889
static CLI::App * addInstance(const std::string &name, const std::string &description, const std::string &group, bool final=false)
Definition Config.cpp:736

References utils::Config::addInstance(), utils::Config::disabled(), disableOpt, instanceName, instanceSc, role, and SERVER.

Here is the call graph for this function:

◆ ~ConfigInstance()

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

Definition at line 107 of file ConfigInstance.cpp.

107 {
109 }
static bool removeInstance(CLI::App *instance)
Definition Config.cpp:917

References instanceSc, and utils::Config::removeInstance().

Here is the call graph for this function:

◆ 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 123 of file ConfigInstance.cpp.

123 {
124 CLI::App* sectionSc = instanceSc //
125 ->add_subcommand(name, description)
126 ->fallthrough()
127 ->configurable(false)
128 ->allow_extras(false)
129 ->group(group)
130 ->ignore_case(false)
131 ->disabled(this->instanceName.empty() || name.empty());
132
133 sectionSc //
134 ->option_defaults()
135 ->configurable(!sectionSc->get_disabled());
136
137 if (!sectionSc->get_disabled()) {
140 }
141
142 return sectionSc;
143 }
static CLI::App * addSimpleHelp(CLI::App *app)
Definition Config.cpp:851
static CLI::App * addStandardFlags(CLI::App *app)
Definition Config.cpp:771

References utils::Config::addSimpleHelp(), utils::Config::addStandardFlags(), instanceName, and instanceSc.

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

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

◆ get()

CLI::App * net::config::ConfigInstance::get ( ) const

Definition at line 172 of file ConfigInstance.cpp.

172 {
173 return instanceSc;
174 }

References instanceSc.

◆ getDisabled()

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

Definition at line 197 of file ConfigInstance.cpp.

197 {
198 return disableOpt //
199 ->as<bool>();
200 }

References disableOpt.

Referenced by required().

Here is the caller graph for this function:

◆ getInstanceName()

◆ getRequired()

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

Definition at line 168 of file ConfigInstance.cpp.

168 {
169 return requiredCount > 0;
170 }

References requiredCount.

◆ getRole()

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

Definition at line 111 of file ConfigInstance.cpp.

111 {
112 return role;
113 }

References role.

◆ getSection()

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

Definition at line 176 of file ConfigInstance.cpp.

176 {
177 CLI::App* resultSc = nullptr;
178
179 CLI::App* sectionSc = instanceSc->get_subcommand_no_throw(name);
180 CLI::App* parentSectionSc = instanceSc->get_parent()->get_subcommand_no_throw(name);
181
182 if (sectionSc != nullptr && (sectionSc->count_all() > 0 || !onlyGot)) {
183 resultSc = sectionSc;
184 } else if (recursive && parentSectionSc != nullptr && (parentSectionSc->count_all() > 0 || !onlyGot)) {
185 resultSc = parentSectionSc;
186 }
187
188 return resultSc;
189 }

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 191 of file ConfigInstance.cpp.

191 {
192 return instanceSc //
193 ->got_subcommand(name) ||
194 (recursive && instanceSc->get_parent()->got_subcommand(name));
195 }

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 145 of file ConfigInstance.cpp.

145 {
146 if (req != section->get_required()) {
147 if (req) {
149 instanceSc //
150 ->needs(section);
151 } else {
153 instanceSc //
154 ->remove_needs(section);
155 }
156
157 section //
158 ->required(req);
159 section //
160 ->ignore_case(req);
161
162 if (!getDisabled()) {
164 }
165 }
166 }
static void required(CLI::App *instance, bool required=true)
Definition Config.cpp:866

References getDisabled(), instanceSc, utils::Config::required(), 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 202 of file ConfigInstance.cpp.

202 {
203 disableOpt //
204 ->default_str(disabled ? "true" : "false")
205 ->clear();
206
208 }

References utils::Config::disabled(), disableOpt, and instanceSc.

Here is the call graph for this function:

◆ setInstanceName()

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

Definition at line 119 of file ConfigInstance.cpp.

119 {
121 }

References instanceName.

◆ net::config::ConfigSection

friend class net::config::ConfigSection
friend

Definition at line 109 of file ConfigInstance.h.

Member Data Documentation

◆ disableOpt

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

Definition at line 107 of file ConfigInstance.h.

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

◆ instanceName

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

Definition at line 101 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 102 of file ConfigInstance.h.

Referenced by getInstanceName().

◆ requiredCount

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

Definition at line 99 of file ConfigInstance.h.

Referenced by getRequired(), and required().

◆ role

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

Definition at line 104 of file ConfigInstance.h.

Referenced by ConfigInstance(), and getRole().


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