Bites
A small library of miscellaneous C++ codes.
 All Classes Namespaces Functions Friends Pages
Public Member Functions | Friends | List of all members
bites::Config Class Reference

#include <Config.hpp>

Public Member Functions

 Config (const std::string &fname="")
 
bool load (const std::string &fname)
 
void save (const std::string &fname) const
 
std::string & operator[] (const std::string &key)
 
std::vector< std::string > keys ()
 

Friends

std::ostream & operator<< (std::ostream &out, const Config &config)
 

Detailed Description

The Config class implements a micro config settings utility, a loadable, saveable, one-line-per-entry config class. It just wraps a lookup table with a configuration file input/output, and a stream output.

Config config("myapp.conf");
// All configured values are strings.
std::string name = config["nickname"];
std::cout << "The name is " << name << "." << std::endl;
int width( config["WIDTH"] );
// Dump the whole configuration to standard out.
std::cout << config << std::endl;

A configuration file myapp.conf may look like:

# Set the window dimensions.
WIDTH 1920
HEIGHT 1080
# Set user and group.
user admin
nickname The Big Cheese

Constructor & Destructor Documentation

bites::Config::Config ( const std::string &  fname = "")

Create config object, optionally load from file.

Parameters
fnamename of existing file.

Member Function Documentation

bool bites::Config::load ( const std::string &  fname)

Load config contents from file.

Parameters
fnamename of input file.
Returns
true if success, otherwise false.
void bites::Config::save ( const std::string &  fname) const

Save config contents to file.

Parameters
fnamename of output file.
std::string & bites::Config::operator[] ( const std::string &  key)

Access configuration setting.

Parameters
keyconfiguration setting to access for read/write.
std::vector< std::string > bites::Config::keys ( )

Return all keys (names of settings) present in the configuration.

Returns
a vector of strings.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Config config 
)
friend

Dump configuration to stream.

Parameters
outoutput destination stream.
configthe configuration whose contents are dumped.

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