InspIRCd  4.0
Public Types | Public Member Functions | Public Attributes | List of all members
ConfigTag Class Reference

#include <configreader.h>

Public Types

typedef insp::flat_map< std::string, std::string, irc::insensitive_swoItems
 

Public Member Functions

 ConfigTag (const std::string &Name, const FilePosition &Source)
 
std::string getString (const std::string &key, const std::string &def, const std::function< bool(const std::string &)> &validator) const
 
std::string getString (const std::string &key, const std::string &def="", size_t minlen=0, size_t maxlen=UINT32_MAX) const
 
long getInt (const std::string &key, long def, long min=LONG_MIN, long max=LONG_MAX) const
 
unsigned long getUInt (const std::string &key, unsigned long def, unsigned long min=0, unsigned long max=ULONG_MAX) const
 
double getFloat (const std::string &key, double def, double min=DBL_MIN, double max=DBL_MAX) const
 
bool getBool (const std::string &key, bool def=false) const
 
unsigned long getDuration (const std::string &key, unsigned long def, unsigned long min=0, unsigned long max=ULONG_MAX) const
 
template<typename TReturn >
TReturn getEnum (const std::string &key, TReturn def, std::initializer_list< std::pair< const char *, TReturn >> enumvals)
 
bool readString (const std::string &key, std::string &value, bool allow_newline=false) const
 
const ItemsGetItems () const
 
ItemsGetItems ()
 

Public Attributes

const std::string name
 
const FilePosition source
 

Detailed Description

Structure representing a single <tag> in config

Member Typedef Documentation

◆ Items

typedef insp::flat_map<std::string, std::string, irc::insensitive_swo> ConfigTag::Items

A mapping of configuration keys to their assigned values.

Constructor & Destructor Documentation

◆ ConfigTag()

ConfigTag::ConfigTag ( const std::string &  Name,
const FilePosition Source 
)

Creates a new ConfigTag instance with the specified tag name, file, and line.

Parameters
NameThe name of this config tag (e.g. "foo" for <foo bar="baz">).
SourceThe source of this config tag.

Member Function Documentation

◆ getBool()

bool ConfigTag::getBool ( const std::string &  key,
bool  def = false 
) const

Get the value of an option, using def if it does not exist

◆ getDuration()

unsigned long ConfigTag::getDuration ( const std::string &  key,
unsigned long  def,
unsigned long  min = 0,
unsigned long  max = ULONG_MAX 
) const

Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format, using a default value if it does not exist or is out of bounds.

Parameters
keyThe config key name
defDefault value (optional)
minMinimum acceptable value (optional)
maxMaximum acceptable value (optional)
Returns
The duration in seconds

◆ getFloat()

double ConfigTag::getFloat ( const std::string &  key,
double  def,
double  min = DBL_MIN,
double  max = DBL_MAX 
) const

Get the value of an option, using def if it does not exist

◆ getInt()

long ConfigTag::getInt ( const std::string &  key,
long  def,
long  min = LONG_MIN,
long  max = LONG_MAX 
) const

Get the value of an option, using def if it does not exist

◆ GetItems()

const Items& ConfigTag::GetItems ( ) const
inline

Retrieves the underlying map of config entries.

◆ getString() [1/2]

std::string ConfigTag::getString ( const std::string &  key,
const std::string &  def,
const std::function< bool(const std::string &)> &  validator 
) const

Get the value of an option, using def if it does not exist

◆ getString() [2/2]

std::string ConfigTag::getString ( const std::string &  key,
const std::string &  def = "",
size_t  minlen = 0,
size_t  maxlen = UINT32_MAX 
) const

Get the value of an option, using def if it does not exist

◆ getUInt()

unsigned long ConfigTag::getUInt ( const std::string &  key,
unsigned long  def,
unsigned long  min = 0,
unsigned long  max = ULONG_MAX 
) const

Get the value of an option, using def if it does not exist

◆ readString()

bool ConfigTag::readString ( const std::string &  key,
std::string &  value,
bool  allow_newline = false 
) const

Get the value of an option

Parameters
keyThe option to get
valueThe location to store the value (unmodified if does not exist)
allow_newlineAllow newlines in the option (normally replaced with spaces)
Returns
true if the option exists

Member Data Documentation

◆ name

const std::string ConfigTag::name

The name of the configuration tag (e.g. "foo" for <foo bar="baz">).

◆ source

const FilePosition ConfigTag::source

The position within the source file that this tag was read from.


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