https://github.com/pfnet/jsonconfig
https://github.com/pfnet/jsonconfig
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/pfnet/jsonconfig
- Owner: pfnet
- License: mit
- Created: 2012-12-18T03:58:29.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T05:39:19.000Z (over 8 years ago)
- Last Synced: 2025-03-02T16:37:17.847Z (over 1 year ago)
- Language: C++
- Size: 585 KB
- Stars: 0
- Watchers: 105
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
jsonconfig
==========
.. image:: https://travis-ci.org/unnonouno/jsonconfig.png?branch=master
:target: https://travis-ci.org/unnonouno/jsonconfig
.. image:: https://coveralls.io/repos/unnonouno/jsonconfig/badge.png
:target: https://coveralls.io/r/unnonouno/jsonconfig
jsonconfig is a simple helper class with json object for application configuration.
- simply wrap pficommon json object
- readable error messages with jsonpath which indicates invalid configuration
Build
-----
::
$ ./waf configure & ./waf & ./waf install
Supported Types
---------------
pficommon json compatible.
- bool
- int
- long
- float
- double
- std::string
- std::vector
- std::map
- pfi::data::unordered_map
- pfi::data::optional
Example
-------
Assume you have a configuration file like this::
{ "web_server": {
"host": "http://hoge.com",
"port": 8080 },
"users": ["saitama", "gumma", "ibaraki"]
}
You can access it with `as` method::
jsonconfig::config_root config = jsonconfig::load("path/to/json/file");
// print "http://hoge.com"
std::cout << config["web_server"]["host"].as() << std::endl;
// print 8080
std::cout << config["web_server"]["port"].as() << std::endl;
You can use struct to define schema of configuration explicitly::
struct server_conf {
struct web_conf {
std::string host;
int port;
templpate
void serialize(Ar& ar) {
ar & MEMBER(host) & MEMBER(port);
}
} web_server;
std::vector users;
template
void serialize(Ar& ar) {
ar & MEMBER(web_server) & MEMBER(users);
}
};
server_conf server = jsonconfig::config_cast(conf);
License
-------
MIT