Code Monkey home page Code Monkey logo

cpp-configurable-class's Introduction

cpp-configurable-class

Experimenting with configurable classes in C++. The goal was to allow self-registration of classes and their parameters, and to allow the user to configure the classes from a configuration file or from the command line.

This kinda works but is far from being as flexible as I would like it to be. Just leaving it here for posterity.

Maybe I'll come back to it one day, but I think it need to be rethought from the ground up.

I wish there was a more standard way to do this in C++. Boost has some stuff but it's not really well documented and I don't think it's actively maintained.

Basic principles

The idea is to provide an interface for classes to give a comprehensive description of their parameters, and to provide a way to configure them from a configuration file or from the command line, all from the class itself. This way, classes can be added easily to the system without having to modify the configuration system itself.

A basic test is included. It declares a simple "Printer" class with configurable text and padding. The registry is now populated with the Printer class, and the configuration system can be used to configure it, along with providing a "usage" message.

Example with the following configuration file:

[printer]
text = hello world
padding = 10
$ ./configurable-test
Registered options:
Printer options:
  --printer.text arg (=UNINITIALIZED) text to print
  --printer.padding arg (=0)          padding to add before printing


Loading config file "../test.cfg"...
PRINTER:           hello world

Parameters can be overridden from the command line:

$ ./configurable_test --printer.text="yeahhhhhh uhhhhh can i get uhhhhhhh     mcburger" --printer.padding=0
Registered options:
Printer options:
  --printer.text arg (=UNINITIALIZED) text to print
  --printer.padding arg (=0)          padding to add before printing


Loading config file "../test.cfg"...
PRINTER: yeahhhhhh uhhhhh can i get uhhhhhhh     mcburger

Anyways, not in a usable state, but it's a start.

cpp-configurable-class's People

Contributors

nicolasiragne avatar

Watchers

James Cloos avatar  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.