Extension: Json and NetCDF utilities
#include "dg/file/file.h" (includes both Json and NetCDF utilities)
JsonCPP utilities

Classes

struct  dg::file::WrappedJsonValue
 Wrapped Access to Json values with error handling. More...
 

Enumerations

enum class  dg::file::error { dg::file::error::is_throw , dg::file::error::is_warning , dg::file::error::is_silent }
 Switch between how to handle errors in a Json utitlity functions. More...
 
enum class  dg::file::comments { dg::file::comments::are_kept , dg::file::comments::are_discarded , dg::file::comments::are_forbidden }
 Switch how comments are treated in a json string or file. More...
 

Functions

static void dg::file::file2Json (std::string filename, Json::Value &js, enum comments comm=file::comments::are_discarded, enum error err=file::error::is_throw)
 Convenience wrapper to open a file and parse it into a Json::Value. More...
 
static void dg::file::string2Json (std::string input, Json::Value &js, enum comments comm=file::comments::are_discarded, enum error err=file::error::is_throw)
 Convenience wrapper to parse a string into a Json::Value. More...
 

Detailed Description

#include "dg/file/json_utilities.h" (link -ljsoncpp)

Enumeration Type Documentation

◆ comments

enum class dg::file::comments
strong

Switch how comments are treated in a json string or file.

Enumerator
are_kept 

Keep comments in the Json value.

are_discarded 

Allow comments but discard them in the Json value.

are_forbidden 

Treat comments as invalid Json.

◆ error

enum class dg::file::error
strong

Switch between how to handle errors in a Json utitlity functions.

Enumerator
is_throw 

throw an error

is_warning 

Handle the error by writing a warning to std::cerr.

is_silent 

Ignore the error and silently continue execution.

Function Documentation

◆ file2Json()

static void dg::file::file2Json ( std::string  filename,
Json::Value &  js,
enum comments  comm = file::comments::are_discarded,
enum error  err = file::error::is_throw 
)
inlinestatic

Convenience wrapper to open a file and parse it into a Json::Value.

Note
included in json_utilities.h
Parameters
filenameName of the JSON file to parse
jsContains all the found Json variables on output
commdetermines the handling of comments in the Json file
errdetermines how parser errors are handled by the function error::is_throw: throw a std::runtime_error containing an error message on any error that occurs on parsing; error::is_warning: write the error message to std::cerr and return; error::is_silent: silently return

◆ string2Json()

static void dg::file::string2Json ( std::string  input,
Json::Value &  js,
enum comments  comm = file::comments::are_discarded,
enum error  err = file::error::is_throw 
)
inlinestatic

Convenience wrapper to parse a string into a Json::Value.

Parse a string into a Json Value

Attention
This function will throw a std::runtime_error with the Json error string on any error that occurs on parsing.
Note
included in json_utilities.h
Parameters
inputThe string to interpret as a Json string
jsContains all the found Json variables on output
commdetermines the handling of comments in the Json string
errdetermines how parser errors are handled by the function error::is_throw: throw a std::runtime_error containing an error message on any error that occurs on parsing; error::is_warning: write the error message to std::cerr and return; error::is_silent: silently return