Nix  2.93.0-dev
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Config Class Reference

#include <config.hh>

Inheritance diagram for nix::Config:
[legend]
Collaboration diagram for nix::Config:
[legend]

Classes

struct  SettingData
 

Public Types

using Settings = std::map<std::string, SettingData>
 

Public Member Functions

 Config (StringMap initials={})
 
bool set (const std::string &name, const std::string &value, const ApplyConfigOptions &options={}) override
 
void addSetting (AbstractSetting *setting)
 
void getSettings (std::map< std::string, SettingInfo > &res, bool overriddenOnly=false) override
 
void resetOverridden () override
 
JSON toJSON () override
 
void convertToArgs (Args &args, const std::string &category) override
 
- Public Member Functions inherited from nix::AbstractConfig
void applyConfig (const std::string &contents, const ApplyConfigOptions &options={})
 
void warnUnknownSettings ()
 
void reapplyUnknownSettings ()
 

Friends

class AbstractSetting
 

Additional Inherited Members

- Protected Member Functions inherited from nix::AbstractConfig
 AbstractConfig (StringMap initials={})
 
- Protected Attributes inherited from nix::AbstractConfig
StringMap unknownSettings
 

Detailed Description

A class to simplify providing configuration settings. The typical use is to inherit Config and add Setting<T> members:

class MyClass : private Config { Setting<int> foo{this, 123, "foo", "the number of foos to use"}; Setting<std::string> bar{this, "blabla", "bar", "the name of the bar"};

MyClass() : Config(readConfigFile("/etc/my-app.conf")) { std::cout << foo << "\n"; // will print 123 unless overridden } };

Member Function Documentation

◆ convertToArgs()

void nix::Config::convertToArgs ( Args & args,
const std::string & category )
overridevirtual

Converts settings to Args to be used on the command line interface

  • args: args to write to
  • category: category of the settings

Implements nix::AbstractConfig.

◆ getSettings()

void nix::Config::getSettings ( std::map< std::string, SettingInfo > & res,
bool overriddenOnly = false )
overridevirtual

Adds the currently known settings to the given result map res.

  • res: map to store settings in
  • overriddenOnly: when set to true only overridden settings will be added to res

Implements nix::AbstractConfig.

◆ resetOverridden()

void nix::Config::resetOverridden ( )
overridevirtual

Resets the overridden flag of all Settings

Implements nix::AbstractConfig.

◆ set()

bool nix::Config::set ( const std::string & name,
const std::string & value,
const ApplyConfigOptions & options = {} )
overridevirtual

Sets the value referenced by name to value. Returns true if the setting is known, false otherwise.

Implements nix::AbstractConfig.

◆ toJSON()

JSON nix::Config::toJSON ( )
overridevirtual

Outputs all settings to JSON

  • out: JSONObject to write the configuration to

Implements nix::AbstractConfig.


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