Code Monkey home page Code Monkey logo

ponder's Introduction

Ponder

Build Status

About

Ponder is a C++ multi-purpose reflection library. It provides an abstraction for most of the high-level concepts of C++:

  • Classes
  • Enumerations
  • Functions
  • Objects
  • Properties
  • Variables

By wrapping all these concepts into abstract structures, Ponder provides an extra layer of flexibility to programs, and allow them to fully expose their data structures at runtime.

Many applications can take advantage of Ponder, in order to automate tasks which would otherwise require a huge amount of work. For example, Ponder can be used to expose and edit objects' attributes into a graphical user interface. It can also be used to do automatic binding of C++ classes to script languages such as Python or Lua. Another possible application would be the serialization of objects to XML, text or binary formats. Or you can even combine all these examples to provide a powerful and consistent interface for manipulating your objects outside C++ code.

Example

The following example exposes our chosen view of a C++ class:

class Person  // A C++ class
{
public:
    Person(const std::string& name) : m_name(name), m_age(0) {}

    std::string name() const {return m_name;}

    unsigned int age() const {return m_age;}
    void setAge(unsigned int age) {m_age = age;}

    void speak() {
        std::cout << "Hi! My name is " << m_name << " and I'm " << m_age << " years old." << std::endl;
    }
    
private:
    std::string m_name;
    unsigned int m_age;
};

PONDER_TYPE(Person) // declare type

void declare() // register details (once)
{
    ponder::Class::declare<Person>("Person")
        .constructor<std::string>()
        .property("name", &Person::name)
        .property("age", &Person::age, &Person::setAge)
        .function("speak", &Person::speak)
        ;
}

void use()
{
    // Retrieve the metaclass by its name
    const ponder::Class& metaclass = ponder::classByName("Person");
    
    // Use the metaclass to construct a new person named John
    ponder::UserObject john = metaclass.construct(ponder::Args("John"));
    
    // Print its name
    std::cout << "John's name is: " << john.get("name") << std::endl;
    
    // Set its age to 24
    john.set("age", 24);
    
    // Make John say something
    john.call("speak");
    
    // Kill John
    metaclass.destroy(john);
}

History

Ponder is a fork of CAMP, which has been retired by the original authors. CAMP relies on Boost, and is pre-C++11. In Ponder, the Boost dependency has been removed (apart from testing) and, instead, C++11 features are used. CAMP was developed by Technogerma Systems France and then by Tegesoft (where the dev team has moved).

ponder's People

Contributors

billyquith avatar delaitre avatar laurentgomila avatar cofenberg avatar drbenmorgan avatar fredericleuba avatar

Watchers

John D. Pope 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.