2019-08-03 15:01:15 +02:00
|
|
|
/* This file is part of xdgcfg. */
|
|
|
|
|
2018-08-10 02:22:06 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <libconfig.h++>
|
|
|
|
#include "xdgcfg.hpp"
|
|
|
|
|
2018-12-29 04:10:17 +01:00
|
|
|
int main()
|
2018-08-10 02:22:06 +02:00
|
|
|
{
|
2019-08-02 08:40:04 +02:00
|
|
|
xdgcfg config("test.cfg", // File name.
|
|
|
|
"xdgcfg"); // Sub directory (optional).
|
|
|
|
config.set_verbose(true); // Print error messages.
|
|
|
|
|
2018-08-10 02:22:06 +02:00
|
|
|
if (config.read() != 0)
|
|
|
|
{
|
2019-08-02 08:40:04 +02:00
|
|
|
std::cout << "File not found.\n";
|
2018-08-10 02:22:06 +02:00
|
|
|
}
|
2019-08-02 08:40:04 +02:00
|
|
|
|
|
|
|
// Get a reference to the libconfig::Config object and use it as you would
|
|
|
|
// normally do.
|
2018-08-10 02:22:06 +02:00
|
|
|
libconfig::Config &cfg = config.get_cfg();
|
|
|
|
libconfig::Setting &root = cfg.getRoot();
|
2019-08-02 08:40:04 +02:00
|
|
|
|
2018-08-10 02:22:06 +02:00
|
|
|
if (!root.exists("Hello"))
|
|
|
|
{
|
|
|
|
root.add("Hello", libconfig::Setting::TypeString) = "World";
|
|
|
|
}
|
2019-08-02 08:40:04 +02:00
|
|
|
|
|
|
|
if (!config.write())
|
|
|
|
{
|
|
|
|
std::cerr << "Writing failed.\n";
|
|
|
|
}
|
2018-08-10 02:22:06 +02:00
|
|
|
|
|
|
|
std::cout << "Hello: " << root["Hello"].c_str() << std::endl;
|
|
|
|
}
|