DynaMix  1.3.7
A new take on polymorphism in C++
Using the library

Platforms

The library has been (and continues to be) developed and tested with and 32 and 64 bit builds with the compilers:

  • On Windows: Visual C++ 14 (2015) and newer, mingw-gcc 5.1.0 and newer
  • On Linux: gcc 4.9 amd newer, clang 3.0 and newer
  • On OSX and iOS: clang 3.0 and newer
  • On Android: arm-gcc 4.9 and newer

Other C++11 compliant compilers (like icc) will most likely also work.

Dependencies

The library has no external dependencies other than the standard C++ libraries.

Getting the library

You can get DynaMix from its official repository at GitHub.

Building the library

A CMakeLists.txt file for CMake is provided for the library.

If you want something else, all you need to do is compile and link all the .cpp files from the src directory.

For most cases a dynamic (shared) library is the preferred way to use DynaMix, but a static library build is also possible.

Note that if you're not using CMake and you want DynaMix as a dynamic library, you will have to make sure that DYNAMIX_DYNLIB is defined when building the library and the projects which use it (say by adding -DDYNAMIX_DYNLIB to the compiler's command line). If you're building it as a static libray (or embedded in your own project) no additional steps are necessary.

Configuration

Here is a list of the configuration options from config.hpp. You need to rebiuld the library if you change any of those.

  • DYNAMIX_USE_TYPEID – determines the way by which the mixin class names are obtained by the library. The default value is nonzero which makes use of C++'s Runtime type information (RTTI): typeid and type_info. If you set it to zero, then, in order for your code to compile, every mixin type will need to have the mixin_name feature with which the users set mixin names manually.
  • DYNAMIX_USE_MIXIN_NAME_FROM_MACRO – obtains mixin names automatically from the DYNAMIX_DEFINE_MIXIN macro. It can be used instead of RTTI but does not support mixins in namespaces.
  • DYNAMIX_MAX_MIXINS – determines the maximum number of mixins that can be registered in an application.
  • DYNAMIX_MAX_MESSAGES – determines the maximum number of messages that can be registered in an application.
  • DYNAMIX_USE_EXCEPTIONS – shows whether the library throws exceptions. You can disable this for a small performance gain.
  • DYNAMIX_OBJECT_IMPLICIT_COPY – enables and disables the copy-constructros and assignment operators for dynamix::object. The default is off to prevent unwanted copies.
  • DYNAMIX_THREAD_SAFE_MUTATIONS – allows the mutation of objects in different threads. You can disable this for a small performance gain on mutation. HOWEVER:
    • Mutating the same object in multiple threads is never safe.
    • Mutating an object in one thread and calling messages for this object in another is never safe.
  • DYNAMIX_ADDITIONAL_METRICS – allows the access to some useful metrics about the library's usage such as number of mixins of a given type.
  • DYNAMIX_OBJECT_REPLACE_MIXIN – enables object::move_mixin, object::hard_replace_mixin and object::reallocate_mixins, which allow users to replace mixins within an object. These functions can be dangerous as pointers to mixins within an object will become invalid if the mixin is replaced, so users which never use them, may decide to disable them.

If you don't want to edit config.hpp in the library source (or you're using it as a submodule and can't edit it), you can add a custom configuration file by defining DYNAMIX_CUSTOM_CONFIG_FILE when building and using the library. Define it to a string containing you own configuration, which can define any (or all) of the above options. If you're using CMake to build the library you can add -DDYNAMIX_CUSTOM_CONFIG_FILE="path/to/your/file.hpp" to your command line to set the custom configuration header.

Using the library

To use the library in your programs, you only need to include its main header: dynamix/dynamix.hpp.

No special initialization or deinitialization code is needed.

Before including the header you can optionally this configuration option. No need to rebuild the library if you change it. Only projects which use it:

  • DYNAMIX_NO_MSG_THROW - defining this will disable exceptions which can be thrown by messages and replace them with assert-s. This will message calls slightly faster but if a situation which leadst to dynamix::bad_message_call arises and assert-s are disabled (ie Release mode), it will lead to undefined behvaior and most likely crashes

Contacts

For questions and comments you're welcome to use the GitHub issue tracker of the library.