Giter Site home page Giter Site logo

cpp-hocon's Introduction

C++ HOCON Parser

Travis CI Appveyor

This is a port of the TypesafeConfig library to C++.

The library provides C++ support for the HOCON configuration file format.

          MMMMMMMMMMMMMMMMMMMM
         .====================.
         MMMMMMMMMMMMMMMMMMMMMM
        .MMMMMMMMMMMMMMMMMMMMMM.
    ===.7MMMIN7NMMMMMMMMM7M=MMMM,===
    MMM.7MM:     DMMMMM7    :MMM=MMM
    MMM.7MM,     DMMMMM?    ~MMM=MMM
    MMM.7MMM~++~?MMMMMMM~++~MMMM=MMM
        .MMMMMMMMMMMMMMMMMMMMMM.
         MMMMMMMMMMMMMMMMMMMMMM
         MMMMMMMMMMMMMMMMMMMMMM
         MMM      HOCON     MMM
         MMMMMMMMMMMMMMMMMMMMMM
          .MMMMMMMMMMMMMMMMMM.
          .MMMMMMMMMMMMMMMMMM.
       .MMMMMMMMMMMMMMMMMMMMMMMM
 .    MMMMMMMMMMMMM88MMMMMMMMMM8MM    .
7=MMMMMMMM++ A CONFIG FILE  ++M8MMMMMM7=
M=MMMMMMMM+ FORMAT DESIGNED  +M8MMMMMM7M
M=MMMMMMMM++  FOR HUMANS   ++M8MMMMMM7M
 =MMMMMMMMMMMMMMMMM88MMMMMMMMMM8MMMMMM7
  7MM.88MMMMMMMMMMM88MMMMMMMMMMO88 MM8
  7MM   MMMMMMMMMMM88MMMMMMMMMM8   MM8
  7MM   MMMMMMMMMMM88MMMMMMMMMM8   MM8
  7MM   MMMDMMMM?MM88MM?MMMMOMM8   MM8

To get started, install it, then to parse a file:

#include <hocon/parser/config_document_factory.hpp>
#include <fstream>

using hocon::config_document_factory::parse_file;

int main(int argc, char** argv) {
    auto doc = parse_file("file.conf");
    doc = doc->with_value_text("a", "42");

    std::ofstream out("file.conf");
    out << doc->render();
    return 0;
}

If you build cpp-hocon with -DBUILD_SHARED_LIBS=ON, then the example can be built with

c++ example.cc -o example -std=c++11 -lcpp-hocon

You can use hocon::config_document_factory::parse_string to parse a string. config_document is used to modify a file while preserving all formatting. Use config to read from the config or if you don't care about preserving formatting.

Note that file extensions matter. A .conf file will be parsed as HOCON, a .json file will be parsed as JSON, and other extensions will be ignored.

See the docs for more.

Caveats

This is a mostly complete implementation of the HOCON format. It currently has some known limitations

  • Include requires the location specifier, i.e. include "foo" won't work but include file("foo") will. URL is not yet implemented, and classpath won't be supported as it makes less sense outside of the JVM.
  • Unicode testing is absent so support is unknown. There are likely things that won't work.

Install

Build Requirements

  • OSX or Linux
  • GCC >= 4.8 or Clang >= 3.4 (with libc++)
  • CMake >= 3.2.2
  • Boost Libraries >= 1.54
  • Leatherman

Pre-Build

Prepare the cmake release environment:

$ mkdir release
$ cd release
$ cmake ..

Optionally, also prepare the debug environment:

$ mkdir debug
$ cd debug
$ cmake -DCMAKE_BUILD_TYPE=Debug ..

Building

  1. Enter your build environment of choice, i.e. cd release or cd debug
  2. make
  3. (optional) install with make install

Testing

Run tests with make test.

cpp-hocon's People

Contributors

magisus avatar mikaelsmith avatar whopper avatar hail9000 avatar branan avatar caseywilliams avatar joshcooper avatar rick avatar mihaibuzgau avatar mhashizume avatar luben avatar tvpartytonight avatar seatalk avatar theshanx avatar gimmyxd avatar ekinanp avatar mcdonaldseanp avatar peterhuene avatar mwaggett avatar jwakely avatar jmslagle avatar jbeich avatar iankronquist avatar greno4ka avatar gabrielnagy avatar dorin-pleava avatar donoghuc avatar briancain avatar troizky avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.