Coder Social home page Coder Social logo

ezhangle / dynamix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibob/dynamix

0.0 2.0 0.0 672 KB

:fish_cake: A new take on polymorphism in C++

Home Page: https://ibob.github.io/dynamix/

License: Other

CMake 3.56% Batchfile 0.07% C++ 95.50% Ruby 0.87% HTML 0.01%

dynamix's Introduction

DynaMix

Language Standard License

Travis CI AppVeyor

DynaMix (Dynamic Mixins) is a new take on polymorphism. It lets the user compose and modify types at run time in C++.

The library is a means to create a project's architecture rather than achieve its purpose. It focuses on maximal performance and minimal memory overhead.

DynaMix is great for the software architecture of systems with very complex objects including, but not limited to:

  • Games (especially role-playing ones or strategies)
  • CAD systems
  • Enterprise systems
  • UI libraries

The library uses the type dynamix::object as a placeholder, whose instances can be extended with existing classes (mixins), thus providing a particular instance with the functionality of all those types. Accessing the newly formed type's interface is made through messages – stand-alone functions generated by the library, which can be thought of as methods.

Here is a small example of what your code may look like if you use the library:

    // assuming my_objects.get_ally(0); is a way to get an ally to the
    // main character in a game
    dynamix::object& obj = my_objects.get_ally(0);

    // now let's make the object think some positive thoughts about the
    // main character

    think(obj); // C++ doesn't allow us to have obj.think().
                // DynaMix's messages are standalone functions

    // type composition
    dynamix::mutate(obj)
        .add<flying_creature>();

    // object can now respond to fly()

    fly(obj); // ...instead of obj.fly()

    // type mutation
    dynamix::mutate(obj)
        .remove<ally>()
        .add<enemy>();

    think(obj); // the same object now thinks negative thoughts about the main
                // character, since it's no longer an ally, but an enemy

Here are some of the key features of the library:

  • Compose types from mixins at run time
  • Physically separate interface and implementation
  • Fast polymorphic calls – comparable to std::function
  • No external dependencies other than the standard library
  • Non-intrusive – mixins don't need to have a common parent or any special code inside
  • Mutate "live" objects by changing their composition at run time
  • Have multicast messages, which are handled by many mixins within an object
  • Possibility to have custom allocators to finely tune the memory and aim for cache-locality for critical parts of the code
  • Ability to have dynamic libraries that can enrich or modify objects, without modifying, or even rebuilding, the executable.
  • Thread safe message calls – as thread safe as the underlying methods.

Documentation

The full documentation is available at the GitHub page of the library

Tutorials

Several small fully working annotated tutorial programs are provided with the library:

  • Basic – a program which illustrates the basic usage of DynaMix. It's a tutorial on creating mixins and messages, and creating and modifying (or mutating) objects.
  • Messages – a tutorial which takes a deeper look at creating and calling the various types of messages.
  • Mutation – a tutorial about the various ways by which objects can be created and mutated.
    • Mutation rules – a deeper look at the library's capabilities for automatic object mutation.
  • Combinators a tutorial about handling the return type of multicast messages.
  • Allocators a tutorial about using the library's mixin allocators.
  • Serialization a tutorial which looks at the possibilities available for serializing objects.

Building

There is an accompanying CMakeLists.txt file in the repo. Use CMake to generate project or make files for your desired platform and compiler.

Contributing

Contributions in the form of issues and pull requests are welcome.

You can also help by donating money with Pledgie:

Donate to support

License

This software is distributed under the MIT Software License.

See accompanying file LICENSE.txt or copy here.

Copyright © 2013-2016 Borislav Stanimirov, Zahary Karadjov

Boost.Mixin

DynaMix was initially developed as Boost.Mixin but is now a separate library, that doesn't depend on the Boost libraries Collection.

DynaMix, unlike Boost.Mixin, has no C++98 support. It's C++11 only.

DynaMix is distributed under the MIT license, whereas Boost.Mixin is distributed under the Boost Software License.

dynamix's People

Contributors

ibob avatar

Watchers

 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.