Skip to content
/ config Public
forked from taocpp/config

C++ header-only config reader library based on JSON

License

Notifications You must be signed in to change notification settings

Bjoe/config

 
 

Repository files navigation

The Art of C++ / Config

Windows CI macOS CI Linux CI Android CI
clang-analyze clang-tidy Sanitizer CodeQL Code Coverage

The Art of C++ / Config is a C++ header-only library that reads config files based on JSON and JAXN and produces a single JSON Value as result.

Documentation

Features

  • JAXN syntax with extensions (backward compatible with JSON).
  • JAXN data model (JSON extended with binary data and non-finites).
  • Meta data, all sub-values are annotated with filename and position.
  • Copy, reference, replace and delete anything in the JSON structure.
  • Multiple ways to read and include other config and data files, and
  • use environment variables and the output of arbitrary shell commands.
  • The function tao::config::parse_file() is all you need to get going.

Status

This library is still under heavy development and not very well documented...

...however it generally works, and test coverage and error messages are not too bad.

To compile the tests and examples it requires taocpp/json checked out next to it.

Introduction

The config parser is backward compatible with JSON; every JSON file with a top-level object can be used as config file.

{
   "ip": "127.0.0.2",
   "port": 27960,
   "maps": [ "ztn", "dm13", "t9" ]
}

This small example can be rendered differently using some of the additional syntactic possibilities of the config file format.

#!/usr/local/bin/q3s

ip = "127.0.0.2"
port = 27960
maps = [ "ztn" "dm13" "t9" ]  // Add dm6 or t4?

Semantic features like deleting and referencing values, or including files and reading environment variables, usually only make sense with larger, non-trivial real-world examples.

Parsing a config file generally entails nothing more than calling the appropriate parse_file() function with the filename.

#include <tao/config.hpp>

const tao::config::value config = tao::config::parse_file( "foo.cfg" );

The resulting value is nothing other but a JSON Value from The Art of C++ / JSON with a custom traits class. It can be inspected using all the facilities of that JSON library.

Contact

Join us on Discord

For questions and suggestions regarding The Art of C++ / Config, success or failure stories, and any other kind of feedback, please feel free to join our Discord server, open a discussion, an issue or a pull request on GitHub or contact the authors at taocpp(at)icemx.net.

License

The Art of C++ / Config is certified Open Source software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the MIT license reproduced here.

Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

C++ header-only config reader library based on JSON

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.0%
  • CMake 2.4%
  • Other 0.6%