All Projects → netcan → config-loader

netcan / config-loader

Licence: MIT License
Simple C++ Config Loader Framework(Serialization & Reflection)

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to config-loader

Metayaml
A powerful schema validator!
Stars: ✭ 92 (+5.75%)
Mutual labels:  yaml, xml
Configurate
A simple configuration library for Java applications providing a node structure, a variety of formats, and tools for transformation
Stars: ✭ 148 (+70.11%)
Mutual labels:  yaml, xml
Yq
Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
Stars: ✭ 1,688 (+1840.23%)
Mutual labels:  yaml, xml
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (+1198.85%)
Mutual labels:  yaml, xml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+158.62%)
Mutual labels:  yaml, xml
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-18.39%)
Mutual labels:  yaml, xml
Cfgdiff
diff(1) all your configs
Stars: ✭ 138 (+58.62%)
Mutual labels:  yaml, xml
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+7003.45%)
Mutual labels:  yaml, xml
Renderer
Simple, lightweight and faster response (JSON, JSONP, XML, YAML, HTML, File) rendering package for Go
Stars: ✭ 220 (+152.87%)
Mutual labels:  yaml, xml
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (+134.48%)
Mutual labels:  yaml, xml
Feedr
Use feedr to fetch the data from a remote url, respect its caching, and parse its data. Despite its name, it's not just for feed data but also for all data that you can feed into it (including binary data).
Stars: ✭ 56 (-35.63%)
Mutual labels:  yaml, xml
odin
Data-structure definition/validation/traversal, mapping and serialisation toolkit for Python
Stars: ✭ 24 (-72.41%)
Mutual labels:  yaml, xml
Ansible Config encoder filters
Ansible role used to deliver the Config Encoder Filters.
Stars: ✭ 48 (-44.83%)
Mutual labels:  yaml, xml
Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (-9.2%)
Mutual labels:  yaml, serializer
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+772.41%)
Mutual labels:  yaml, xml
Oq
A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
Stars: ✭ 132 (+51.72%)
Mutual labels:  yaml, xml
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (+327.59%)
Mutual labels:  yaml, xml
Countries
World countries in JSON, CSV, XML and Yaml. Any help is welcome!
Stars: ✭ 5,379 (+6082.76%)
Mutual labels:  yaml, xml
Gelatin
Transform text files to XML, JSON, or YAML
Stars: ✭ 150 (+72.41%)
Mutual labels:  yaml, xml
jzon
A correct and safe JSON parser.
Stars: ✭ 78 (-10.34%)
Mutual labels:  serializer, deserializer

config-loader 中文版

config-loader is a static reflection framework written in C++17 from parse configuration file to native data structure. It has the following characteristics:

  • Simple interface, users need to define data structure and provide corresponding configuration file, the framework uses meta-programming technology to generate load interface
  • The design conforms to the opening and closing principle, extends the data structure without modifying the framework
  • Currently supports XML, JSON and YAML format configuration files, a variety of methods can be flexibly composed
  • Lightweight, easy to integrate, less than ~1000 lines of code
  • Support nested data structure, STL container
  • Complete test cases
  • Support from native data structure to config file, stringify data structure

Future plans:

  • Provide additional C++20 version

Build & Run

Build

$ git clone --recursive https://github.com/netcan/config-loader.git
$ cd config-loader
$ mkdir build
$ cd build
$ cmake ..
$ make -j

Run

$ cd bin/
$ ./config_loader_test

Quickly start

Firstly use DEFINE_SCHEMA macro to define the data structure:

// define and reflect a struct
DEFINE_SCHEMA(Point,                          // struct Point {
              (double) x,                     //     double x;
              (double) y);                    //     double y;
                                              // };

// vector and string
DEFINE_SCHEMA(SomeOfPoints,                   // struct SomeOfPoints {
              (std::string) name,             //     std::string name;
              (std::vector<Point>) points);   //     std::vector<Point> points;
                                              // };

Provide configuration files, using loadXML2Obj/loadJSON2Obj/loadYAML2Obj interfaces:

SomeOfPoints someOfPoints;
auto res = loadJSON2Obj(someOfPoints, [] {
    return R"(
        {
            "name": "Some of points",
            "points":[
                { "x": 1.2, "y": 3.4 },
                { "x": 5.6, "y": 7.8 },
                { "x": 2.2, "y": 3.3 }
            ]
        }
    )";
});
REQUIRE(res == Result::SUCCESS);
REQUIRE_THAT(someOfPoints.name, Equals("Some of points"));
REQUIRE(someOfPoints.points.size() == 3);

Or, through an XML configuration file.

SomeOfPoints someOfPoints;
auto res = loadXML2Obj(someOfPoints, "configs/xml/SomeOfPoints.xml");
REQUIRE(res == Result::SUCCESS);
REQUIRE_THAT(someOfPoints.name, Equals("Some of points"));
REQUIRE(someOfPoints.points.size() == 3);

Through a YAML configuration file.

SomeOfPoints someOfPoints;
auto res = loadYAML2Obj(someOfPoints, [] {
return R"(
        name: Some of points
        points:
          - x: 1.2
            y: 3.4
          - x: 5.6
            y: 7.8
          - x: 2.2
            y: 3.3
    )";
});
REQUIRE(res == Result::SUCCESS);
REQUIRE_THAT(someOfPoints.name, Equals("Some of points"));
REQUIRE(someOfPoints.points.size() == 3);

Notice

The current framework depends on the following libraries:

  • tinyxml2, used for parsing xml configuration files
  • jsoncpp, used for parsing json configuration files
  • yamlcpp, used for parsing yaml configuration files

In the future, these libraries may be enabled through CMake options to avoid unnecessary dependencies in actual use: only using xml will only rely on the xml parsing library.

This framework requires configuration files to be provided in a standardized format. Taking XML as an example, the field name is required to correspond to the XML tag name, and the value corresponds to the text content of the XML; for the map data structure, the tag uses the attribute name as the key name.

The semantics of the current error code.

enum class Result {
    SUCCESS,              // parse successfully
    ERR_EMPTY_CONTENT,    // The parsing file is empty
    ERR_ILL_FORMED,       // Illegal parsing file
    ERR_MISSING_FIELD,    // Missing field
    ERR_EXTRACTING_FIELD, // Failed to parse the value
    ERR_TYPE,             // Type error
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].