aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
gum::Configuration Class Reference

Sectioned key/value configuration with typed and documented keys. More...

#include <agrum/base/core/configuration/configuration.h>

Classes

struct  Meta
 metadata attached to a key by a ### line More...
struct  SchemaEntry
 one line of the schema (see schema()) More...
struct  Notice
 a message that cannot be an exception (the operation went on), see takeNotices() More...
struct  DefaultsSource
 a text of defaults, with the name designating it in error messages More...
struct  Item

Public Types

enum class  Kind : unsigned char {
  INT , FLOAT , BOOL , STR ,
  ENUM , DEPRECATED
}
 the declared type of a key More...
using Value = std::variant< bool, std::int64_t, double, std::string >
 a value converted according to the declared type of its key (see getValue())
using Hook = std::function< void(const Configuration&) >

Public Member Functions

Accessors
std::string get (std::string_view section, std::string_view key) const
 Value of section.key, as a string.
template<typename T>
T typed (std::string_view section, std::string_view key) const
 Value of section.key converted according to its declared type.
Value getValue (std::string_view section, std::string_view key) const
 Value of section.key converted according to its declared type (following a deprecation).
bool has (std::string_view section, std::string_view key) const
Meta meta (std::string_view section, std::string_view key) const
std::string doc (std::string_view section, std::string_view key) const
std::vector< SchemaEntry > schema () const
std::vector< std::string > sections () const
Modifiers
void set (std::string_view section, std::string_view key, std::string_view value, bool noHook=false)
 Sets section.key.
void reset ()
 Back to the defaults. Runs the hooks.
void push ()
 Pushes the current values on a stack.
void pop ()
 Restores the values on top of the stack.
Files and display
void load (const std::string &filename)
 Loads a user file and changes the values it contains.
void save (const std::string &filename) const
 Writes the difference with the defaults (see diff()) in a file.
std::string grep (std::string_view search) const
std::string diff () const
std::string toString () const
std::string describe () const
Numerical tolerances
double epsilonCoarse () const noexcept
 The coarse tolerance (key core.epsilonCoarse, 1e-2 by default).
double epsilonStandard () const noexcept
double epsilonFine () const noexcept
Hooks and notices
void addHook (Hook hook)
 Adds a function called after each change (see set(), reset(), pop(), load()).
void runHooks () const
 Runs the hooks (outside of any lock).
std::vector< Notice > takeNotices ()

Static Public Member Functions

static std::string kindName (Kind kind)

Private Types

using Snapshot = std::vector< std::string >

Private Member Functions

void _parse_ (std::string_view text, std::string_view origin)
void _groupBySection_ ()
void _checkSchema_ ()
std::size_t _tryFind_ (std::string_view section, std::string_view key) const
std::size_t _find_ (std::string_view section, std::string_view key) const
bool _hasSection_ (std::string_view section) const
std::size_t _resolve_ (std::size_t pos, std::vector< Notice > *sink=nullptr) const
std::pair< std::string, Kind > _typedRaw_ (std::string_view section, std::string_view key) const
void _setAt_ (std::size_t pos, std::string_view value)
void _loadUserFile_ ()
std::string _render_ (const std::function< bool(const Item &) > &keep) const
Snapshot _snapshot_ () const
void _restore_ (const Snapshot &snapshot)
void _refreshEpsilons_ ()
void _queue_ (Notice::Kind kind, std::string message) const

Static Private Member Functions

static std::string _indexKey_ (std::string_view section, std::string_view key)
static bool _validate_ (const Item &item, std::string_view value, std::string &canonical, std::string &error)

Private Attributes

std::shared_mutex _mutex_
std::vector< Item > _items_
std::vector< std::string > _sections_
std::unordered_map< std::string, std::size_t > _index_
std::vector< Snapshot > _stack_
std::vector< Hook > _hooks_
std::array< std::atomic< double >, _nbEpsilons_ > _epsilons_ {{1e-2, 1e-6, 1e-10}}
std::array< std::size_t, _nbEpsilons_ > _epsilonPos_ {}
std::mutex _noticeMutex_
std::vector< Notice > _notices_

Static Private Attributes

static constexpr std::size_t _nbEpsilons_ = 3
static constexpr std::size_t _npos_ = static_cast< std::size_t >(-1)

Constructors, destructor and singleton

static Configuration & instance ()
 The global configuration.
static std::string userFileName ()
 Configuration (std::string_view defaultsText, std::string_view origin="defaults.ini")
 Builds a configuration from a defaults text.
 Configuration (std::initializer_list< DefaultsSource > sources)
 Builds a configuration from several defaults texts (e.g.
 Configuration (const Configuration &)=delete
 The global configuration.
Configuration & operator= (const Configuration &)=delete
 The global configuration.
 ~Configuration ()=default
 The global configuration.

Detailed Description

Sectioned key/value configuration with typed and documented keys.

Values are stored as strings and canonicalized according to the declared type of their key: booleans are stored as True or False (accepted spellings, whatever the case: TRUE, 1, ON, YES / FALSE, 0, OFF, NO), enumerated values with the casing declared in the defaults.

Section names are case-sensitive, key names are not (they are stored in lowercase).

Thread-safety: every public method is thread-safe (readers run concurrently, writers are exclusive). Values are returned by copy. Hooks are run outside of any lock, so a hook may freely read the configuration.

See also the howto How to use the configuration singleton (gum::Configuration) (syntax of the defaults, hooks, notices, examples).

Errors:

Definition at line 105 of file configuration.h.

Member Typedef Documentation

◆ Hook

using gum::Configuration::Hook = std::function< void(const Configuration&) >

Definition at line 161 of file configuration.h.

◆ Snapshot

using gum::Configuration::Snapshot = std::vector< std::string >
private

Definition at line 378 of file configuration.h.

◆ Value

using gum::Configuration::Value = std::variant< bool, std::int64_t, double, std::string >

a value converted according to the declared type of its key (see getValue())

Definition at line 141 of file configuration.h.

Member Enumeration Documentation

◆ Kind

enum class gum::Configuration::Kind : unsigned char
strong

the declared type of a key

Enumerator
INT 
FLOAT 
BOOL 
STR 
ENUM 
DEPRECATED 

Definition at line 108 of file configuration.h.

108: unsigned char { INT, FLOAT, BOOL, STR, ENUM, DEPRECATED };

Constructor & Destructor Documentation

◆ Configuration() [1/3]

gum::Configuration::Configuration ( std::string_view defaultsText,
std::string_view origin = "defaults.ini" )
explicit

Builds a configuration from a defaults text.

Parameters
defaultsTextthe content of a defaults ini.
originthe name used in error messages to designate the defaults text.
Exceptions
SyntaxErrorif the text or its metadata are malformed, or if a deprecated key points to an unknown (or itself deprecated) key.
InvalidArgumentif a default value does not respect its own declared type.

Definition at line 319 of file configuration.cpp.

319 :
320 Configuration(std::initializer_list< DefaultsSource >{DefaultsSource{defaultsText, origin}}) {
321 }
Configuration(std::string_view defaultsText, std::string_view origin="defaults.ini")
Builds a configuration from a defaults text.
a text of defaults, with the name designating it in error messages

References Configuration().

Referenced by Configuration(), Configuration(), ~Configuration(), instance(), and operator=().

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

◆ Configuration() [2/3]

gum::Configuration::Configuration ( std::initializer_list< DefaultsSource > sources)
explicit

Builds a configuration from several defaults texts (e.g.

those of aGrUM and of pyAgrum).

The sources are read in order. A section may be opened by several sources (the keys of the later ones are added to the section), but only once inside a source. A key can be defined only once, whatever the sources. In the resulting configuration, the keys of a section are grouped: those of the first source defining the section come first. A source whose text is empty is ignored. A deprecated key may point to a key defined by another source.

Parameters
sourcesthe defaults texts, in reading order.
Exceptions
SyntaxErrorif a text or its metadata are malformed, if a section is opened twice in a source, if a key is defined twice, or if a deprecated key points to an unknown (or itself deprecated) key.
InvalidArgumentif a default value does not respect its own declared type.

Definition at line 323 of file configuration.cpp.

323 {
324 for (const auto& source: sources) {
325 if (!source.text.empty()) _parse_(source.text, source.origin);
326 }
329 for (std::size_t i = 0; i < _nbEpsilons_; ++i)
330 _epsilonPos_[i] = _tryFind_("core", _epsilonKeys_[i]);
332 }
std::array< std::size_t, _nbEpsilons_ > _epsilonPos_
void _parse_(std::string_view text, std::string_view origin)
std::size_t _tryFind_(std::string_view section, std::string_view key) const
static constexpr std::size_t _nbEpsilons_

References _checkSchema_(), _epsilonPos_, _groupBySection_(), _nbEpsilons_, _parse_(), _refreshEpsilons_(), and _tryFind_().

Here is the call graph for this function:

◆ Configuration() [3/3]

gum::Configuration::Configuration ( const Configuration & )
delete

The global configuration.

Built at first call from the defaults embedded in the library (those of aGrUM and, for a pyAgrum build, those of pyAgrum). If the user file (see userFileName()) exists in the current directory, it is loaded: it can change the value of a key but never creates one (problems are queued in the notices, see takeNotices()).

References Configuration().

Here is the call graph for this function:

◆ ~Configuration()

gum::Configuration::~Configuration ( )
default

The global configuration.

Built at first call from the defaults embedded in the library (those of aGrUM and, for a pyAgrum build, those of pyAgrum). If the user file (see userFileName()) exists in the current directory, it is loaded: it can change the value of a key but never creates one (problems are queued in the notices, see takeNotices()).

References Configuration(), addHook(), describe(), diff(), doc(), epsilonCoarse(), epsilonFine(), epsilonStandard(), get(), getValue(), grep(), has(), instance(), load(), meta(), pop(), push(), reset(), runHooks(), save(), schema(), sections(), set(), takeNotices(), toString(), typed(), and userFileName().

Here is the call graph for this function:

Member Function Documentation

◆ _checkSchema_()

void gum::Configuration::_checkSchema_ ( )
private

Definition at line 432 of file configuration.cpp.

432 {
433 for (auto& item: _items_) {
434 if (item.meta.kind == Kind::DEPRECATED) {
435 const auto pos = _tryFind_(item.meta.targetSection, item.meta.targetKey);
436 if (pos == _npos_) {
437 GUM_SYNTAX_ERROR("deprecated key '"
438 << item.section << "." << item.key << "' redirects to unknown key '"
439 << item.meta.targetSection << "." << item.meta.targetKey << "'",
440 item.origin,
441 0,
442 0)
443 }
444 if (_items_[pos].meta.kind == Kind::DEPRECATED) {
445 GUM_SYNTAX_ERROR("deprecated key '" << item.section << "." << item.key
446 << "' redirects to deprecated key '"
447 << item.meta.targetSection << "."
448 << item.meta.targetKey << "'",
449 item.origin,
450 0,
451 0)
452 }
453 } else {
454 std::string canonical, error;
455 if (!_validate_(item, item.value, canonical, error)) {
456 GUM_ERROR(InvalidArgument, "[" << item.origin << "] " << error)
457 }
458 item.value = canonical;
459 item.defaultValue = canonical;
460 }
461 }
462 }
static constexpr std::size_t _npos_
static bool _validate_(const Item &item, std::string_view value, std::string &canonical, std::string &error)
std::vector< Item > _items_
Meta meta(std::string_view section, std::string_view key) const
#define GUM_SYNTAX_ERROR(msg, filename, line, column)
Definition exceptions.h:121
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References _items_, _npos_, _tryFind_(), _validate_(), DEPRECATED, GUM_ERROR, GUM_SYNTAX_ERROR, and meta().

Referenced by Configuration().

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

◆ _find_()

std::size_t gum::Configuration::_find_ ( std::string_view section,
std::string_view key ) const
private

Definition at line 484 of file configuration.cpp.

484 {
485 const auto pos = _tryFind_(section, key);
486 if (pos != _npos_) return pos;
487 if (!_hasSection_(section)) {
488 GUM_SYNTAX_ERROR("Section '" << section << "' unknown in configuration.", "", 0, 0)
489 }
490 GUM_SYNTAX_ERROR("Key '" << section << "." << key << "' unknown in configuration.", "", 0, 0)
491 }
bool _hasSection_(std::string_view section) const

References _hasSection_(), _npos_, _tryFind_(), and GUM_SYNTAX_ERROR.

Referenced by _typedRaw_(), doc(), get(), meta(), and set().

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

◆ _groupBySection_()

void gum::Configuration::_groupBySection_ ( )
private

Definition at line 415 of file configuration.cpp.

415 {
416 // a section opened by several sources has its items spread in _items_: gather them, keeping
417 // the order of the sections and, inside a section, the order of reading
418 std::vector< Item > grouped;
419 grouped.reserve(_items_.size());
420 for (const auto& section: _sections_) {
421 for (auto& item: _items_) {
422 if (item.section == section) grouped.push_back(std::move(item));
423 }
424 }
425 _items_ = std::move(grouped);
426 _index_.clear();
427 for (std::size_t pos = 0; pos < _items_.size(); ++pos) {
428 _index_[_indexKey_(_items_[pos].section, _items_[pos].key)] = pos;
429 }
430 }
std::unordered_map< std::string, std::size_t > _index_
static std::string _indexKey_(std::string_view section, std::string_view key)
std::vector< std::string > _sections_

References _index_, _indexKey_(), _items_, and _sections_.

Referenced by Configuration().

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

◆ _hasSection_()

bool gum::Configuration::_hasSection_ ( std::string_view section) const
private

Definition at line 480 of file configuration.cpp.

480 {
481 return std::find(_sections_.begin(), _sections_.end(), section) != _sections_.end();
482 }

References _sections_.

Referenced by _find_(), _parse_(), and load().

Here is the caller graph for this function:

◆ _indexKey_()

std::string gum::Configuration::_indexKey_ ( std::string_view section,
std::string_view key )
staticprivate

Definition at line 468 of file configuration.cpp.

468 {
469 std::string res(section);
470 res += '\0';
471 res += toLower(key);
472 return res;
473 }
GUM_SHARED_PUBLIC std::string toLower(std::string_view str)
Returns the lowercase version of str.

References gum::toLower().

Referenced by _groupBySection_(), _parse_(), and _tryFind_().

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

◆ _loadUserFile_()

void gum::Configuration::_loadUserFile_ ( )
private

Definition at line 879 of file configuration.cpp.

879 {
880 try {
881 const auto filename = userFileName();
882 if (std::filesystem::is_regular_file(filename)) load(filename);
883 } catch (const std::exception& e) {
884 _queue_(Notice::Kind::FILE, std::string("[") + userFileName() + "] " + e.what());
885 }
886 }
void _queue_(Notice::Kind kind, std::string message) const
static std::string userFileName()
void load(const std::string &filename)
Loads a user file and changes the values it contains.

References _queue_(), gum::Configuration::Notice::FILE, load(), and userFileName().

Referenced by instance().

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

◆ _parse_()

void gum::Configuration::_parse_ ( std::string_view text,
std::string_view origin )
private

Definition at line 334 of file configuration.cpp.

334 {
335 const auto lines = _lines_(text);
336
337 // a section can be reopened by another source but not inside the same one
338 std::vector< std::string > openedHere;
339
340 bool inSection = false;
341 std::string section;
342 bool pending = false;
343 Meta pendingMeta;
344 std::size_t numline = 0;
345
346 auto err = [&](const std::string& msg) { _syntaxError_(msg, origin, numline); };
347
348 for (const auto& rawLine: lines) {
349 ++numline;
350 const auto trimmed = trim_copy(rawLine);
351 std::string key, value, name;
352
353 const bool hasKeyValue = !_isCommentOrBlank_(trimmed) && _splitKeyValue_(trimmed, key, value);
354 const bool isKeyLine = hasKeyValue && _isIdentifier_(key);
355
356 if (pending && !isKeyLine) {
357 err("metadata line must be immediately followed by a 'key = value' line");
358 }
359
360 if (_isMetaLine_(trimmed)) {
361 const auto payload = trim_copy(std::string_view(trimmed).substr(3));
362 const auto sep = payload.find("::");
363 if (sep == std::string::npos) {
364 err("metadata line must follow the syntax '### type :: documentation'");
365 }
366 const auto spec = trim_copy(std::string_view(payload).substr(0, sep));
367 const auto doc = trim_copy(std::string_view(payload).substr(sep + 2));
368 if (doc.empty()) err("missing documentation in metadata line");
369 std::string error;
370 if (!_parseMetaSpec_(spec, doc, pendingMeta, error)) err(error);
371 pending = true;
372 continue;
373 }
374
375 if (_isCommentOrBlank_(trimmed)) continue;
376
377 if (_isSectionLine_(trimmed, name)) {
378 if (std::find(openedHere.begin(), openedHere.end(), name) != openedHere.end()) {
379 err("duplicate section '" + name + "'");
380 }
381 openedHere.push_back(name);
382 if (!_hasSection_(name)) _sections_.push_back(name);
383 section = name;
384 inSection = true;
385 continue;
386 }
387
388 if (!inSection) err("key outside of any section");
389 if (!hasKeyValue) err("malformed line '" + trimmed + "'");
390
391 key = toLower(key);
392 if (const auto first = _tryFind_(section, key); first != _npos_) {
393 err("duplicate key '" + section + "." + key + "' (already defined in "
394 + _items_[first].origin + ")");
395 }
396
397 Item item;
398 item.section = section;
399 item.key = key;
400 item.value = value;
401 item.origin = std::string(origin);
402 if (pending) {
403 item.meta = pendingMeta;
404 pending = false;
405 } else {
406 item.meta.doc = std::string(_undocumented_);
407 }
408 _index_[_indexKey_(section, key)] = _items_.size();
409 _items_.push_back(std::move(item));
410 }
411
412 if (pending) err("metadata line at end of file");
413 }
std::string doc(std::string_view section, std::string_view key) const
GUM_SHARED_PUBLIC std::string trim_copy(std::string_view s)
trim from both ends (copying)
metadata attached to a key by a ### line

References _hasSection_(), _index_, _indexKey_(), _items_, _npos_, _sections_, _tryFind_(), doc(), gum::Configuration::Meta::doc, gum::Configuration::Item::key, gum::Configuration::Item::meta, gum::Configuration::Item::origin, gum::Configuration::Item::section, gum::toLower(), gum::trim_copy(), and gum::Configuration::Item::value.

Referenced by Configuration().

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

◆ _queue_()

void gum::Configuration::_queue_ ( Notice::Kind kind,
std::string message ) const
private

Definition at line 493 of file configuration.cpp.

493 {
494 std::lock_guard< std::mutex > lock(_noticeMutex_);
495 // a notice already waiting is not queued twice (e.g. a deprecated key read in a loop)
496 const auto same = [&](const Notice& n) { return n.kind == kind && n.message == message; };
497 if (std::none_of(_notices_.begin(), _notices_.end(), same)) {
498 _notices_.push_back(Notice{kind, std::move(message)});
499 }
500 }
std::mutex _noticeMutex_
std::vector< Notice > _notices_
a message that cannot be an exception (the operation went on), see takeNotices()

References _noticeMutex_, and _notices_.

Referenced by _loadUserFile_(), _resolve_(), instance(), and load().

Here is the caller graph for this function:

◆ _refreshEpsilons_()

void gum::Configuration::_refreshEpsilons_ ( )
private

Definition at line 661 of file configuration.cpp.

661 {
662 for (std::size_t i = 0; i < _nbEpsilons_; ++i) {
663 double value = 0;
664 if (_epsilonPos_[i] != _npos_ && parseDecimal(_items_[_epsilonPos_[i]].value, value)) {
665 _epsilons_[i].store(value, std::memory_order_relaxed);
666 }
667 }
668 }
std::array< std::atomic< double >, _nbEpsilons_ > _epsilons_
bool parseDecimal(std::string_view val, double &res)
parse a decimal number, whatever the locale of the program

References _epsilonPos_, _epsilons_, _items_, _nbEpsilons_, _npos_, and gum::parseDecimal().

Referenced by Configuration(), _restore_(), _setAt_(), load(), reset(), and set().

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

◆ _render_()

std::string gum::Configuration::_render_ ( const std::function< bool(const Item &) > & keep) const
private

Definition at line 812 of file configuration.cpp.

812 {
813 std::shared_lock lock(_mutex_);
814 std::string res;
815 // the keys of a section are contiguous in _items_ (a duplicate section is refused by _parse_)
816 const std::string* current = nullptr; // section of the last rendered key
817 for (const auto& item: _items_) {
818 if (item.meta.kind == Kind::DEPRECATED || !keep(item)) continue;
819 if (current == nullptr || *current != item.section) {
820 if (current != nullptr) res += '\n';
821 res += "[" + item.section + "]";
822 current = &item.section;
823 }
824 res += "\n " + item.key + " = " + item.value;
825 }
826 return res;
827 }
std::shared_mutex _mutex_

References _items_, _mutex_, and DEPRECATED.

Referenced by diff(), grep(), and toString().

Here is the caller graph for this function:

◆ _resolve_()

std::size_t gum::Configuration::_resolve_ ( std::size_t pos,
std::vector< Notice > * sink = nullptr ) const
private

Definition at line 502 of file configuration.cpp.

502 {
503 const auto& item = _items_[pos];
504 if (item.meta.kind != Kind::DEPRECATED) return pos;
506 "'" + item.section + "." + item.key + "' is deprecated (" + item.meta.doc
507 + "), use '" + item.meta.targetSection + "." + item.meta.targetKey
508 + "' instead."};
509 if (sink != nullptr) sink->push_back(std::move(notice));
510 else _queue_(notice.kind, std::move(notice.message));
511 return _tryFind_(item.meta.targetSection, item.meta.targetKey); // checked by _checkSchema_
512 }

References _items_, _queue_(), _tryFind_(), DEPRECATED, gum::Configuration::Notice::DEPRECATION, gum::Configuration::Notice::kind, and gum::Configuration::Notice::message.

Referenced by _typedRaw_(), get(), load(), and set().

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

◆ _restore_()

void gum::Configuration::_restore_ ( const Snapshot & snapshot)
private

Definition at line 708 of file configuration.cpp.

708 {
709 for (std::size_t i = 0; i < _items_.size(); ++i)
710 _items_[i].value = snapshot[i];
712 }

References _items_, and _refreshEpsilons_().

Referenced by pop().

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

◆ _setAt_()

void gum::Configuration::_setAt_ ( std::size_t pos,
std::string_view value )
private

Definition at line 651 of file configuration.cpp.

651 {
652 std::string canonical, error;
653 if (!_validate_(_items_[pos], value, canonical, error)) { GUM_ERROR(InvalidArgument, error) }
654 _items_[pos].value = std::move(canonical);
655 // the atomics only depend on the three tolerances
656 if (std::find(_epsilonPos_.begin(), _epsilonPos_.end(), pos) != _epsilonPos_.end()) {
658 }
659 }

References _epsilonPos_, _items_, _refreshEpsilons_(), _validate_(), and GUM_ERROR.

Referenced by set().

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

◆ _snapshot_()

Configuration::Snapshot gum::Configuration::_snapshot_ ( ) const
private

Definition at line 700 of file configuration.cpp.

700 {
701 Snapshot res;
702 res.reserve(_items_.size());
703 for (const auto& item: _items_)
704 res.push_back(item.value);
705 return res;
706 }
std::vector< std::string > Snapshot

References _items_.

Referenced by push().

Here is the caller graph for this function:

◆ _tryFind_()

std::size_t gum::Configuration::_tryFind_ ( std::string_view section,
std::string_view key ) const
private

Definition at line 475 of file configuration.cpp.

475 {
476 const auto it = _index_.find(_indexKey_(section, key));
477 return it == _index_.end() ? _npos_ : it->second;
478 }

References _index_, _indexKey_(), and _npos_.

Referenced by Configuration(), _checkSchema_(), _find_(), _parse_(), _resolve_(), has(), and load().

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

◆ _typedRaw_()

std::pair< std::string, Configuration::Kind > gum::Configuration::_typedRaw_ ( std::string_view section,
std::string_view key ) const
private

Definition at line 515 of file configuration.cpp.

515 {
516 std::shared_lock lock(_mutex_);
517 const auto& item = _items_[_resolve_(_find_(section, key))];
518 return {item.value, item.meta.kind};
519 }
std::size_t _find_(std::string_view section, std::string_view key) const
std::size_t _resolve_(std::size_t pos, std::vector< Notice > *sink=nullptr) const

References _find_(), _items_, _mutex_, and _resolve_().

Referenced by getValue(), and typed().

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

◆ _validate_()

bool gum::Configuration::_validate_ ( const Item & item,
std::string_view value,
std::string & canonical,
std::string & error )
staticprivate

Definition at line 525 of file configuration.cpp.

528 {
529 const auto name = item.section + "." + item.key;
530 const auto s = trim_copy(value);
531 canonical = s;
532
533 switch (item.meta.kind) {
534 case Kind::INT : {
535 std::int64_t res = 0;
536 if (!_toInt_(s, res)) {
537 error = "'" + s + "' must be an int for '" + name + "'.";
538 return false;
539 }
540 if (!item.meta.domain.contains(static_cast< double >(res))) {
541 error = "'" + s + "' must be in " + item.meta.domain.text + " for '" + name + "'.";
542 return false;
543 }
544 return true;
545 }
546 case Kind::FLOAT : {
547 double res = 0;
548 if (!parseDecimal(s, res)) {
549 error = "'" + s + "' must be a float for '" + name + "'.";
550 return false;
551 }
552 if (!item.meta.domain.contains(res)) {
553 error = "'" + s + "' must be in " + item.meta.domain.text + " for '" + name + "'.";
554 return false;
555 }
556 return true;
557 }
558 case Kind::BOOL : {
559 const auto low = toLower(s);
560 if (low == "true" || low == "1" || low == "on" || low == "yes") {
561 canonical = "True";
562 return true;
563 }
564 if (low == "false" || low == "0" || low == "off" || low == "no") {
565 canonical = "False";
566 return true;
567 }
568 error
569 = "'" + s + "' must be a boolean (False/True, 0/1, Off/On, No/Yes) for '" + name + "'.";
570 return false;
571 }
572 case Kind::ENUM : {
573 const auto low = toLower(s);
574 for (const auto& v: item.meta.values) {
575 if (toLower(v) == low) {
576 canonical = v;
577 return true;
578 }
579 }
580 error = "'" + s + "' must be one of " + item.meta.joinedValues() + " for '" + name + "'.";
581 return false;
582 }
583 default : canonical = std::string(value); return true;
584 }
585 }

References BOOL, gum::Configuration::Meta::Domain::contains(), gum::Configuration::Meta::domain, ENUM, FLOAT, INT, gum::Configuration::Meta::joinedValues(), gum::Configuration::Item::key, gum::Configuration::Meta::kind, gum::Configuration::Item::meta, gum::parseDecimal(), gum::Configuration::Item::section, gum::Configuration::Meta::Domain::text, gum::toLower(), gum::trim_copy(), and gum::Configuration::Meta::values.

Referenced by _checkSchema_(), _setAt_(), and load().

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

◆ addHook()

void gum::Configuration::addHook ( Hook hook)

Adds a function called after each change (see set(), reset(), pop(), load()).

Definition at line 853 of file configuration.cpp.

853 {
854 std::unique_lock lock(_mutex_);
855 _hooks_.push_back(std::move(hook));
856 }
std::vector< Hook > _hooks_

References _hooks_, and _mutex_.

Referenced by ~Configuration(), and instance().

Here is the caller graph for this function:

◆ describe()

std::string gum::Configuration::describe ( ) const
Returns
diff() if the configuration differs from the defaults, otherwise a comment saying so followed by toString().

Definition at line 844 of file configuration.cpp.

844 {
845 const auto changes = diff();
846 return changes.empty() ? "# no customized property\n" + toString() : changes;
847 }
std::string diff() const
std::string toString() const

References diff(), and toString().

Referenced by ~Configuration().

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

◆ diff()

std::string gum::Configuration::diff ( ) const
Returns
the visible keys whose value differs from the default.

Definition at line 836 of file configuration.cpp.

836 {
837 return _render_([](const Item& item) { return item.value != item.defaultValue; });
838 }
std::string _render_(const std::function< bool(const Item &) > &keep) const

References _render_(), gum::Configuration::Item::defaultValue, and gum::Configuration::Item::value.

Referenced by ~Configuration(), describe(), and save().

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

◆ doc()

std::string gum::Configuration::doc ( std::string_view section,
std::string_view key ) const
Returns
type :: documentation for section.key (str :: (undocumented) if none).

Definition at line 621 of file configuration.cpp.

621 {
622 std::shared_lock lock(_mutex_);
623 const auto& m = _items_[_find_(section, key)].meta;
624 switch (m.kind) {
625 case Kind::DEPRECATED :
626 return "deprecated -> " + m.targetSection + "." + m.targetKey + " :: " + m.doc;
627 case Kind::ENUM : return m.joinedValues() + " :: " + m.doc;
628 default : return kindName(m.kind) + m.domain.text + " :: " + m.doc;
629 }
630 }
static std::string kindName(Kind kind)

References _find_(), _items_, _mutex_, DEPRECATED, ENUM, and kindName().

Referenced by ~Configuration(), and _parse_().

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

◆ epsilonCoarse()

INLINE double gum::Configuration::epsilonCoarse ( ) const
noexcept

The coarse tolerance (key core.epsilonCoarse, 1e-2 by default).

The three tolerances of aGrUM are read without any lock nor allocation (an atomic load), so that they can be used in loops. Their domains do not overlap (coarse in [1e-3,1e-1], standard in [1e-8,1e-5], fine in [1e-11,1e-9]), so that fine < standard < coarse always holds : a value out of the domain is refused as any invalid value (see set() and load()).

Definition at line 56 of file configuration_inl.h.

56 {
57 return _epsilons_[0].load(std::memory_order_relaxed);
58 }

References _epsilons_.

Referenced by ~Configuration(), and gum::IBayesNet< GUM_SCALAR >::check().

Here is the caller graph for this function:

◆ epsilonFine()

INLINE double gum::Configuration::epsilonFine ( ) const
noexcept
Returns
the fine tolerance (key core.epsilonFine, 1e-10 by default).

Definition at line 66 of file configuration_inl.h.

66 {
67 return _epsilons_[2].load(std::memory_order_relaxed);
68 }

References _epsilons_.

Referenced by ~Configuration().

Here is the caller graph for this function:

◆ epsilonStandard()

INLINE double gum::Configuration::epsilonStandard ( ) const
noexcept

◆ get()

std::string gum::Configuration::get ( std::string_view section,
std::string_view key ) const

Value of section.key, as a string.

Exceptions
SyntaxErrorif the section or the key does not exist.

Definition at line 591 of file configuration.cpp.

591 {
592 std::shared_lock lock(_mutex_);
593 return _items_[_resolve_(_find_(section, key))].value;
594 }

References _find_(), _items_, _mutex_, and _resolve_().

Referenced by ~Configuration().

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

◆ getValue()

Configuration::Value gum::Configuration::getValue ( std::string_view section,
std::string_view key ) const

Value of section.key converted according to its declared type (following a deprecation).

Returns
a bool (bool key), an int64_t (int key), a double (float key) or a std::string (str and enum keys).
Exceptions
SyntaxErrorif the section or the key does not exist.

Definition at line 596 of file configuration.cpp.

597 {
598 const auto [value, kind] = _typedRaw_(section, key);
599 switch (kind) {
600 case Kind::BOOL : return value == "True";
601 case Kind::INT : return static_cast< std::int64_t >(std::strtoll(value.c_str(), nullptr, 10));
602 case Kind::FLOAT : {
603 double res = 0;
604 parseDecimal(value, res);
605 return res;
606 }
607 default : return value;
608 }
609 }
std::pair< std::string, Kind > _typedRaw_(std::string_view section, std::string_view key) const

References _typedRaw_(), BOOL, FLOAT, INT, and gum::parseDecimal().

Referenced by ~Configuration().

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

◆ grep()

std::string gum::Configuration::grep ( std::string_view search) const
Returns
the visible keys (all but the deprecated ones) containing search, with their section; a matching section name selects the whole section.

Definition at line 829 of file configuration.cpp.

829 {
830 const auto low = toLower(search);
831 return _render_([&](const Item& item) {
832 return contains(toLower(item.section), low) || contains(item.key, low);
833 });
834 }
GUM_SHARED_PUBLIC bool contains(std::string_view s, std::string_view needle)
true if needle in s

References _render_(), gum::contains(), gum::Configuration::Item::key, gum::Configuration::Item::section, and gum::toLower().

Referenced by ~Configuration().

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

◆ has()

bool gum::Configuration::has ( std::string_view section,
std::string_view key ) const
Returns
true if section.key exists.

Definition at line 611 of file configuration.cpp.

611 {
612 std::shared_lock lock(_mutex_);
613 return _tryFind_(section, key) != _npos_;
614 }

References _mutex_, _npos_, and _tryFind_().

Referenced by ~Configuration().

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

◆ instance()

Configuration & gum::Configuration::instance ( )
static

The global configuration.

Built at first call from the defaults embedded in the library (those of aGrUM and, for a pyAgrum build, those of pyAgrum). If the user file (see userFileName()) exists in the current directory, it is loaded: it can change the value of a key but never creates one (problems are queued in the notices, see takeNotices()).

Definition at line 890 of file configuration.cpp.

890 {
891 // built, completed by the user file and applied once (thread-safe), the first time it is needed
892 static Configuration& instanceRef = []() -> Configuration& {
893 static Configuration global{
894 {configurationEmbeddedDefaults(), "defaults.ini (aGrUM)"},
895 {configurationEmbeddedPyAgrumDefaults(), "defaults.ini (pyAgrum)"}};
896 // the number of threads is the only [core] key acting directly on the library; a negative
897 // value gives back what the machine (or OMP_NUM_THREADS) provides, read before any change
898 global.addHook([machine = gum::getMaxNumberOfThreads()](const Configuration& c) {
899 const auto n = c.typed< std::int64_t >("core", "maxNumberOfThreads");
900 gum::setNumberOfThreads(n < 0 ? machine : static_cast< unsigned int >(n));
901 });
902 global._loadUserFile_();
903 try {
904 global.runHooks();
905 } catch (const std::exception& e) {
906 // e.g. a number of threads that cannot be honoured: the library must stay usable
907 global._queue_(Notice::Kind::FILE, std::string("hook failed: ") + e.what());
908 }
909 return global;
910 }();
911 return instanceRef;
912 }
void setNumberOfThreads(unsigned int number)
Set the max number of threads to be used when entering the next parallel region.
Definition threads.cpp:55
std::string_view configurationEmbeddedPyAgrumDefaults()
GUM_SHARED_PUBLIC unsigned int getMaxNumberOfThreads()
Returns the maximum number of threads you should use at any time.
std::string_view configurationEmbeddedDefaults()

References Configuration(), _loadUserFile_(), _queue_(), addHook(), gum::configurationEmbeddedDefaults(), gum::configurationEmbeddedPyAgrumDefaults(), gum::Configuration::Notice::FILE, gum::getMaxNumberOfThreads(), runHooks(), gum::setNumberOfThreads(), and typed().

Referenced by gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), ~Configuration(), gum::config(), gum::defaultJgumIndent(), gum::ApproximationScheme::setFromConfiguration_(), gum::ApproximationScheme::sizeFromConfiguration_(), and gum::Tensor< GUM_SCALAR >::toString().

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

◆ kindName()

std::string gum::Configuration::kindName ( Kind kind)
static
Returns
the name of a kind: int, float, bool, str, enum or deprecated.

Definition at line 304 of file configuration.cpp.

304 {
305 switch (kind) {
306 case Kind::INT : return "int";
307 case Kind::FLOAT : return "float";
308 case Kind::BOOL : return "bool";
309 case Kind::ENUM : return "enum";
310 case Kind::DEPRECATED : return "deprecated";
311 default : return "str";
312 }
313 }

References BOOL, DEPRECATED, ENUM, FLOAT, and INT.

Referenced by doc().

Here is the caller graph for this function:

◆ load()

void gum::Configuration::load ( const std::string & filename)

Loads a user file and changes the values it contains.

Runs the hooks.

Unknown sections, unknown keys, invalid values and deprecated keys do not stop the loading: they are queued as notices and the file is never modified (a deprecated key is applied to its replacement; save() writes the replacement, not the deprecated key). Only a malformed line stops the loading, and nothing is changed in this case.

Exceptions
IOErrorif the file cannot be read.
SyntaxErrorif the file contains a malformed line.

Definition at line 743 of file configuration.cpp.

743 {
744 const auto lines = _lines_(_readFile_(filename));
745
746 // The whole file is read before anything is changed: a malformed line leaves the values (and
747 // thus the state driven by the hooks) untouched.
748 std::vector< std::pair< std::size_t, std::string > > changes; // (position, canonical value)
749 std::vector< Notice > notices;
750 auto note = [&](std::string message) {
751 notices.push_back(Notice{Notice::Kind::FILE, "[" + filename + "] " + std::move(message)});
752 };
753 {
754 std::shared_lock lock(_mutex_);
755 std::string section;
756 bool knownSection = false;
757 std::size_t numline = 0;
758
759 for (const auto& rawLine: lines) {
760 ++numline;
761 const auto trimmed = trim_copy(rawLine);
762 std::string name, key, value;
763 if (_isCommentOrBlank_(trimmed)) continue;
764
765 if (_isSectionLine_(trimmed, name)) {
766 section = name;
767 knownSection = _hasSection_(section);
768 if (!knownSection) { note("Section '" + section + "' does not exist."); }
769 continue;
770 }
771
772 if (section.empty() || !_splitKeyValue_(trimmed, key, value)) {
773 _syntaxError_("malformed line '" + trimmed + "'", filename, numline);
774 }
775 if (!knownSection) continue;
776
777 const auto pos = _tryFind_(section, key);
778 if (pos == _npos_) {
779 note("Option '" + section + "." + toLower(key) + "' does not exist.");
780 continue;
781 }
782 const auto target = _resolve_(pos, &notices);
783
784 std::string canonical, error;
785 if (_validate_(_items_[target], value, canonical, error)) {
786 changes.emplace_back(target, std::move(canonical));
787 } else {
788 note("Invalid value for '" + section + "." + toLower(key) + "': " + error);
789 }
790 }
791 }
792
793 {
794 std::unique_lock lock(_mutex_);
795 for (auto& [pos, value]: changes)
796 _items_[pos].value = std::move(value);
798 }
799 for (auto& notice: notices)
800 _queue_(notice.kind, std::move(notice.message));
801 runHooks();
802 }
void runHooks() const
Runs the hooks (outside of any lock).

References _hasSection_(), _items_, _mutex_, _npos_, _queue_(), _refreshEpsilons_(), _resolve_(), _tryFind_(), _validate_(), gum::Configuration::Notice::FILE, runHooks(), gum::toLower(), and gum::trim_copy().

Referenced by ~Configuration(), and _loadUserFile_().

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

◆ meta()

Configuration::Meta gum::Configuration::meta ( std::string_view section,
std::string_view key ) const
Returns
the metadata of section.key.

Definition at line 616 of file configuration.cpp.

616 {
617 std::shared_lock lock(_mutex_);
618 return _items_[_find_(section, key)].meta;
619 }

References _find_(), _items_, and _mutex_.

Referenced by ~Configuration(), and _checkSchema_().

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

◆ operator=()

Configuration & gum::Configuration::operator= ( const Configuration & )
delete

The global configuration.

Built at first call from the defaults embedded in the library (those of aGrUM and, for a pyAgrum build, those of pyAgrum). If the user file (see userFileName()) exists in the current directory, it is loaded: it can change the value of a key but never creates one (problems are queued in the notices, see takeNotices()).

References Configuration().

Here is the call graph for this function:

◆ pop()

void gum::Configuration::pop ( )

Restores the values on top of the stack.

Runs the hooks.

Exceptions
OperationNotAllowedif the stack is empty.

Definition at line 729 of file configuration.cpp.

729 {
730 {
731 std::unique_lock lock(_mutex_);
732 if (_stack_.empty()) { GUM_ERROR(OperationNotAllowed, "No configuration to pop.") }
733 _restore_(_stack_.back());
734 _stack_.pop_back();
735 }
736 runHooks();
737 }
std::vector< Snapshot > _stack_
void _restore_(const Snapshot &snapshot)

References _mutex_, _restore_(), _stack_, GUM_ERROR, and runHooks().

Referenced by ~Configuration().

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

◆ push()

void gum::Configuration::push ( )

Pushes the current values on a stack.

Definition at line 724 of file configuration.cpp.

724 {
725 std::unique_lock lock(_mutex_);
726 _stack_.push_back(_snapshot_());
727 }
Snapshot _snapshot_() const

References _mutex_, _snapshot_(), and _stack_.

Referenced by ~Configuration().

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

◆ reset()

void gum::Configuration::reset ( )

Back to the defaults. Runs the hooks.

Definition at line 714 of file configuration.cpp.

714 {
715 {
716 std::unique_lock lock(_mutex_);
717 for (auto& item: _items_)
718 if (item.meta.kind != Kind::DEPRECATED) item.value = item.defaultValue;
720 }
721 runHooks();
722 }

References _items_, _mutex_, _refreshEpsilons_(), DEPRECATED, and runHooks().

Referenced by ~Configuration().

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

◆ runHooks()

void gum::Configuration::runHooks ( ) const

Runs the hooks (outside of any lock).

Definition at line 858 of file configuration.cpp.

858 {
859 std::vector< Hook > hooks;
860 {
861 std::shared_lock lock(_mutex_);
862 hooks = _hooks_;
863 }
864 for (const auto& hook: hooks)
865 hook(*this);
866 }

References _hooks_, and _mutex_.

Referenced by ~Configuration(), instance(), load(), pop(), reset(), and set().

Here is the caller graph for this function:

◆ save()

void gum::Configuration::save ( const std::string & filename) const

Writes the difference with the defaults (see diff()) in a file.

Exceptions
IOErrorif the file cannot be written.

Definition at line 804 of file configuration.cpp.

804 {
805 const auto content = diff();
806 std::ofstream f(filename, std::ios::binary | std::ios::trunc);
807 if (!f) { GUM_ERROR(IOError, "Cannot write file '" << filename << "'.") }
808 f << content << '\n';
809 if (!f) { GUM_ERROR(IOError, "Cannot write file '" << filename << "'.") }
810 }

References diff(), and GUM_ERROR.

Referenced by ~Configuration().

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

◆ schema()

std::vector< Configuration::SchemaEntry > gum::Configuration::schema ( ) const
Returns
the whole schema (in the order of the defaults).

Definition at line 632 of file configuration.cpp.

632 {
633 std::shared_lock lock(_mutex_);
634 std::vector< SchemaEntry > res;
635 res.reserve(_items_.size());
636 for (const auto& item: _items_) {
637 res.push_back(SchemaEntry{item.section, item.key, item.meta, item.defaultValue});
638 }
639 return res;
640 }
one line of the schema (see schema())

References _items_, and _mutex_.

Referenced by ~Configuration().

Here is the caller graph for this function:

◆ sections()

std::vector< std::string > gum::Configuration::sections ( ) const
Returns
the names of the sections, in the order of the defaults.

Definition at line 642 of file configuration.cpp.

642 {
643 std::shared_lock lock(_mutex_);
644 return _sections_;
645 }

References _mutex_, and _sections_.

Referenced by ~Configuration().

Here is the caller graph for this function:

◆ set()

void gum::Configuration::set ( std::string_view section,
std::string_view key,
std::string_view value,
bool noHook = false )

Sets section.key.

Setting a deprecated key sets its replacement and queues a deprecation notice. If a hook throws, the previous value is restored (the hooks are run again, their exceptions being ignored) and the exception is propagated.

Parameters
noHookif true, the hooks are not run.
Exceptions
SyntaxErrorif the section or the key does not exist.
InvalidArgumentif the value does not respect the declared type of the key.

Definition at line 670 of file configuration.cpp.

673 {
674 std::size_t pos = 0;
675 std::string previous;
676 {
677 std::unique_lock lock(_mutex_);
678 pos = _resolve_(_find_(section, key));
679 previous = _items_[pos].value;
680 _setAt_(pos, value);
681 }
682 if (noHook) return;
683
684 try {
685 runHooks();
686 } catch (...) {
687 {
688 std::unique_lock lock(_mutex_);
689 _items_[pos].value = std::move(previous);
691 }
692 // bring back the state driven by the hooks; the original exception is the one to report
693 try {
694 runHooks();
695 } catch (...) {}
696 throw;
697 }
698 }
void _setAt_(std::size_t pos, std::string_view value)

References _find_(), _items_, _mutex_, _refreshEpsilons_(), _resolve_(), _setAt_(), and runHooks().

Referenced by ~Configuration().

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

◆ takeNotices()

std::vector< Configuration::Notice > gum::Configuration::takeNotices ( )
Returns
the queued notices (deprecations, problems found when loading a file) and empties the queue.

Definition at line 868 of file configuration.cpp.

868 {
869 std::lock_guard< std::mutex > lock(_noticeMutex_);
870 return std::exchange(_notices_, {});
871 }

References _noticeMutex_, and _notices_.

Referenced by ~Configuration().

Here is the caller graph for this function:

◆ toString()

std::string gum::Configuration::toString ( ) const
Returns
all the visible keys.

Definition at line 840 of file configuration.cpp.

840 {
841 return _render_([](const Item&) { return true; });
842 }

References _render_().

Referenced by ~Configuration(), and describe().

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

◆ typed()

template<typename T>
T gum::Configuration::typed ( std::string_view section,
std::string_view key ) const

Value of section.key converted according to its declared type.

Template Parameters
Tbool (for a bool key), int64_t (int key), double (float or int key) or std::string (any key).
Exceptions
SyntaxErrorif the section or the key does not exist.
InvalidArgumentif T is not compatible with the declared type of the key.

Definition at line 62 of file configuration_tpl.h.

62 {
63 static_assert(std::is_same_v< T, bool > || std::is_same_v< T, int64_t >
64 || std::is_same_v< T, double > || std::is_same_v< T, std::string >,
65 "Configuration::typed<T>: T must be bool, int64_t, double or std::string");
66
67 const auto [value, kind] = _typedRaw_(section, key);
68
69 if constexpr (std::is_same_v< T, std::string >) {
70 return value;
71 } else if constexpr (std::is_same_v< T, bool >) {
72 if (kind != Kind::BOOL) {
73 GUM_ERROR(InvalidArgument, "'" << section << "." << key << "' is not a bool")
74 }
75 return value == "True";
76 } else if constexpr (std::is_same_v< T, int64_t >) {
77 if (kind != Kind::INT) {
78 GUM_ERROR(InvalidArgument, "'" << section << "." << key << "' is not an int")
79 }
80 return static_cast< int64_t >(std::strtoll(value.c_str(), nullptr, 10));
81 } else {
82 if (kind != Kind::FLOAT && kind != Kind::INT) {
83 GUM_ERROR(InvalidArgument, "'" << section << "." << key << "' is not a float")
84 }
85 double res = 0;
86 parseDecimal(value, res);
87 return res;
88 }
89 }

References _typedRaw_(), BOOL, FLOAT, GUM_ERROR, INT, and gum::parseDecimal().

Referenced by ~Configuration(), gum::defaultJgumIndent(), gum::learning::IKTBNLearner< GUM_SCALAR >::defaultPriorWeight_(), gum::learning::IKTBNLearner< GUM_SCALAR >::defaultTabuListSize_(), gum::learning::IKTBNLearner< GUM_SCALAR >::defaultTabuNbDecrease_(), instance(), gum::learning::IBNLearner::preferredAlgo(), gum::ApproximationScheme::sizeFromConfiguration_(), and gum::Tensor< GUM_SCALAR >::toString().

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

◆ userFileName()

std::string gum::Configuration::userFileName ( )
static
Returns
the name of the user file loaded from the current directory by instance().

Definition at line 877 of file configuration.cpp.

#define GUM_CONFIGURATION_USER_FILE

References GUM_CONFIGURATION_USER_FILE.

Referenced by ~Configuration(), and _loadUserFile_().

Here is the caller graph for this function:

Member Data Documentation

◆ _epsilonPos_

std::array< std::size_t, _nbEpsilons_ > gum::Configuration::_epsilonPos_ {}
private

Definition at line 393 of file configuration.h.

Referenced by Configuration(), _refreshEpsilons_(), and _setAt_().

◆ _epsilons_

std::array< std::atomic< double >, _nbEpsilons_ > gum::Configuration::_epsilons_ {{1e-2, 1e-6, 1e-10}}
private

Definition at line 392 of file configuration.h.

Referenced by _refreshEpsilons_(), epsilonCoarse(), epsilonFine(), and epsilonStandard().

◆ _hooks_

std::vector< Hook > gum::Configuration::_hooks_
private

Definition at line 386 of file configuration.h.

Referenced by addHook(), and runHooks().

◆ _index_

std::unordered_map< std::string, std::size_t > gum::Configuration::_index_
private

Definition at line 384 of file configuration.h.

Referenced by _groupBySection_(), _parse_(), and _tryFind_().

◆ _items_

std::vector< Item > gum::Configuration::_items_
private

◆ _mutex_

std::shared_mutex gum::Configuration::_mutex_
mutableprivate

◆ _nbEpsilons_

std::size_t gum::Configuration::_nbEpsilons_ = 3
staticconstexprprivate

Definition at line 391 of file configuration.h.

Referenced by Configuration(), and _refreshEpsilons_().

◆ _noticeMutex_

std::mutex gum::Configuration::_noticeMutex_
mutableprivate

Definition at line 395 of file configuration.h.

Referenced by _queue_(), and takeNotices().

◆ _notices_

std::vector< Notice > gum::Configuration::_notices_
mutableprivate

Definition at line 396 of file configuration.h.

Referenced by _queue_(), and takeNotices().

◆ _npos_

std::size_t gum::Configuration::_npos_ = static_cast< std::size_t >(-1)
staticconstexprprivate

Definition at line 405 of file configuration.h.

Referenced by _checkSchema_(), _find_(), _parse_(), _refreshEpsilons_(), _tryFind_(), has(), and load().

◆ _sections_

std::vector< std::string > gum::Configuration::_sections_
private

Definition at line 382 of file configuration.h.

Referenced by _groupBySection_(), _hasSection_(), _parse_(), and sections().

◆ _stack_

std::vector< Snapshot > gum::Configuration::_stack_
private

Definition at line 385 of file configuration.h.

Referenced by pop(), and push().


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