Configuru
Classes | Typedefs | Functions | Variables
configuru Namespace Reference

The Configuru namespace. More...

Classes

class  Config
 
struct  Config_Entry
 Helper: value in an object. More...
 
struct  ConfigComments
 Captures the comments related to a Config value. More...
 
struct  DocInfo
 Helper for describing a document. More...
 
struct  FormatOptions
 This struct basically contain all the way we can tweak the file format. More...
 
struct  Include
 
class  ParseError
 Thrown on a syntax error. More...
 
struct  ParseInfo
 

Typedefs

using DocInfo_SP = std::shared_ptr< DocInfo >
 
using Index = unsigned
 
using Comment = std::string
 
using Comments = std::vector< Comment >
 

Functions

template<typename T >
as (const configuru::Config &config)
 
bool operator== (const Config &a, const Config &b)
 
bool operator!= (const Config &a, const Config &b)
 
std::ostream & operator<< (std::ostream &os, const Config &cfg)
 Prints in JSON but in a fail-safe mannor, allowing uninitalized keys and inf/nan.
 
template<class Config , class Visitor >
void visit_configs (Config &&config, Visitor &&visitor)
 Recursively visit all values in a config.
 
void clear_doc (Config &root)
 
FormatOptions make_json_options ()
 Returns FormatOptions that are describe a JSON file format.
 
FormatOptions make_forgiving_options ()
 Returns format options that allow us parsing most files.
 
Config parse_string (const char *str, const FormatOptions &options, const char *name)
 
Config parse_file (const std::string &path, const FormatOptions &options)
 
Config parse_string (const char *str, const FormatOptions &options, DocInfo _doc, ParseInfo &info)
 Advanced usage:
 
Config parse_file (const std::string &path, const FormatOptions &options, DocInfo_SP doc, ParseInfo &info)
 
std::string dump_string (const Config &config, const FormatOptions &options)
 
void dump_file (const std::string &path, const Config &config, const FormatOptions &options)
 

Variables

const Index BAD_INDEX = static_cast<Index>(-1)
 

Detailed Description

The Configuru namespace.

Function Documentation

template<typename T >
T configuru::as ( const configuru::Config config)
inline

Overload this (in cofiguru namespace) for you own types, e.g:

namespace configuru {
template<>
inline Vector2f as(const Config& config)
{
auto&& array = config.as_array();
config.check(array.size() == 2, "Expected Vector2f");
return {(float)array[0], (float)array[1]};
}
}
void configuru::dump_file ( const std::string &  path,
const Config config,
const FormatOptions options 
)

Writes the config to a file. Like dump_string, but can may also call CONFIGURU_ONERROR if it fails to write to the given path.

std::string configuru::dump_string ( const Config config,
const FormatOptions options 
)

Writes the config as a string in the given format. May call CONFIGURU_ONERROR if the given config is invalid. This can happen if a Config is unitialized (and options write_uninitialized is not set) or a Config contains inf/nan (and options.inf/options.nan aren't set).

Config configuru::parse_string ( const char *  str,
const FormatOptions options,
const char *  name 
)

The parser may throw ParseError. str should be a zero-ended Utf-8 encoded string of characters. The name should be something akin to a filename. It is only for error reporting.