DynO++ Logo DynO++
Dynamic Objects Framework in C++

Written by Andrea Ferrero

SourceForge.net Logo

Introduction

DynO++ is a C++ framework for dynamic programming. The main idea is to allow the compilation of each C++ object as a separate module. Thanks to that each object, instead of being statically linked to the application at compile time, is dynamically loaded into the application at runtime.
Each object interacts with the rest of the application through a signal/callback mechanism with strong run-time type checking of the transmitted data.The framework introduces some features that increase the robustness of the application:
  1. no internal reference to other objects is stored in the object iself; all dependencies are managed internally by the library.
  2. an object can be destroyed only when it is not used anymore
  3. the use of already destroyed objects is by definition impossible
The framework is based on three main elements:
The code is already in a stable stage and provides all the functionalities described above. In particular, the script language is provided with most of the standard conditional instructions, like if statements or for and while loops.


Compiling DynO++

DynO++ should compile on most Linux distributions using gcc, flex an yacc. I have specifically tested it under SuSE 9.0 and gcc 3.2, more tests will probably come in the near future. In order to compile the GUI modules (window, buttons, text labels, etc.etc.) the Imlib library must be installed in the system.
In order to compile DynO++ just unpack the archive, change into the dyno directory and type make.
If you also want to compile the GUI modules then run make gui after make.


The "Hello World!" example with DynO++

In this small tutorial we will create a simple application that prints "Hello World!" and then a wellcome message that we will pass from the command line.
The example will introduce the basic aspects of programming with DynO++, such as creating dynamic objects, connecting them together and building a complete application using the built-in script language.

For this small example we need two elements:

  1. a source file, called wellcome.cpp and containing the code of the Wellcome object;
  2. the helloworld.s script in which we load create a new instance of the Wellcome object and we print the wellcome message.

Creating the main object

To begin with, we need to create a Wellcome object that prints the wellcome message to the standard output. The object interface comprises a data member (or property in the DynO++ language) in which to store the wellcome message we wish to print, a "wellcome()" function (or callback in the DynO++ language) to print everything to the terminal, and a "bye()" signal that will be rised when the print is finished. The complete source file for the Wellcome object can be found here.

In general, a module called module.m must contain a function with a prototype like id new_module(signal_0*), that should create and initialize a new instance of the object provided by the module.
In our case, we have introduced the function id new_wellcome(signal_0*).

The next step is to properly implement the Wellcome object. Here is the complete listing of the object code:

class Wellcome
{
  string message;

public:
  signal_1<string> bye;

  Wellcome() {}
  ~Wellcome() {}

  void set_message(string msg) { message = msg; }
  string get_message() { return message; }

  void wellcome() {
    cout<<"Hello World!"<<endl;
    cout<<message<<endl;
    bye(message);
  }
};
The Wellcome object has a private data member, called message, which will store the message passed from the command line. Two accessor functions, set_message and get_message are introduced to set and get the value of the data member.
The object provides also a so-called signal, called bye and accepting one argument of type string. A signal is a C++ object that overrides the () operator, thus providing an interface similar to standard member functions. The call to a signal (like bye(mesage) in out example) does not directly produce any result: if the signal is not connected to any callback the call of the signal produces nothing.

DynO++ provides a wrapper object, called interface, which allows to define properties, signals and callbacks and to access them in a standardized way.
Pointers to interface objects are commonly used in DynO++, therefore they have been assigned a special type, called id. Therefore id is equivalent to interface*.

Let's have a closer look to the id new_wellcome(signal_0*) function. Althought the function is used to create a new instance of the Wellcome object, what is actually returned is the pointer to the Wellcome object interface, instead of the object itself.

In DynO++ the properties are created by means of two member functions, one for setting and one for getting the property value.
string message;
void set_message(string msg) { message = msg; }
string get_message() { return message; }

Compiling a dynamic module

Writing the hello_world.s script

Executing the script




Future developments

Here is a list of features that I'm planning to introduce in the next releases of DynO++:


Download

The current version of DynO++ is 0.1.0. It can be downloaded from here.