Code Monkey home page Code Monkey logo

iod

Inline object definitions and declarations for C++11. This library embeds in C++11 a fast type-safe json-like domain specific language. It allows, in one C++ statement, to define, declare and instantiate a C++ object, without any overhead execution time.

While keeping the performance and type-checking of C++, it adds to C++11 the flexibility of dynamic languages like javascript where declaring an object or extending it can be done on the fly.

Overview of the library

// Headers
#include "iod.hh"
#include "iod_json.hh"

// Declaration of the attributes used by the inline object definitions.
iod_define_attribute(name);
iod_define_attribute(age);
iod_define_attribute(cars);
iod_define_attribute(model);
iod_define_attribute(cities);
iod_define_attribute(lastname);

int main()
{
  // Inline object definition.
  auto person = iod(
    name_ = "Philippe",
    age_ = 42,
    cities_ = {"Paris", "Toronto", "New York City"},
    cars_ = {
        iod(name_ = "Renault", model_ = "Clio"),
        iod(name_ = "Mercedes", model_ = "Class A")
      }
    );

  // Access to the content of the object.
  std::cout << person.name << std::endl;
  std::cout << person.cars[1].model << std::endl;

  // Serialize an object to json.
  std::string json = iod_to_json(person);
  std::cout << json << std::endl;

  // Load an object from a json string.
  std::string json_string = R"json({"name":"John", "age": 12})json";
  auto test = iod(name_ = "", age_ = int());
  iod_from_json(test, json_string);

  // Extend and object. (todo)
  auto extended_person = iod_extend(person, iod(lastname_ = "Doe"));
}

Contributing

Contributions or suggestions are welcome. Do not hesitate to fill issues, send pull requests, or discuss by email at [email protected].

iod's Projects

framingham icon framingham

Ruby gem to implement Framingham Heart Study calculators

iod icon iod

Inline object definitions and declarations for C++11. Json-like C++11 embedded domain specific language

traffairious icon traffairious

Traffic v.s. Air Quality data visualization experiments for http://HackUpstate.com

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.