• Stars
    star
    103
  • Rank 322,527 (Top 7 %)
  • Language
    C++
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

The Art of C++ / Config

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

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

Documentation

Contact

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

Introduction

  • 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::from_file() is all you need to get going.

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.

These features can be used to manage situations that go beyond single deployments with a single config, for example providing the tools to manage configuration templates that are adapted to different environments.

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

#include <tao/config.hpp>

const tao::config::value config = tao::config::from_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.

License

Open Source Initiative

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-2023 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.