I develop a software for urban planing oriented ecology. Initially Polaris is a CAD software (similar to AutoCAD or MicroStation) with tools about geomatics engineering and earthwork engineering. So this software may be also used to compute the thermal performance of the building. My work concerns especially generic programming to improve software and a project of rainwater sanitation simulation with pollution aspect. In a word, Polaris use C# code, even through I consider myself as a C++ developer.
I think C# language proposes an interesting syntactic sugar around the code with Attributes. So, what is an attribute and how create this with C++.
An attribute adds information to properties, methods or classes. These information can be used by the reflexion mechanism. The following example concerns an object with tree accessible properties and the aim is just to display the values with associated text.
The code which displays the three values is:
An the output of the method (with a MyCounter) may be:
The advantage of this code is to use the same method to display information of many different type. The description of the class is sufficient and the developer doesn't need to develop specific method for each object. An use of the reflexion mechanism may be to create graphical user interface: personally, I think forms design is a waste of time and I prefer work on computational mechanisms.
When I have begun my project Imbricable, I have considered this way and I have copied an idea which I have found during my thesis in the Sofa-Framework. So, I have created tree classes which correspond to accessors, attribute and a container of accessors. The equivalent of the MyCounter class using a mechanism as the one developed in my project may be:
Metadata (attribute) are defined as static because this is the behavior of C# attributes and the attributes are not runtime modifiable. A no-static object should cause an avoidable memory consumption due to duplication of the text.
Data is a template/generic class which inherit from a undefined accessors class (BaseData).
And the equivalent of the display method:
So the mechanism requires the next classes to work:
Note: The method toString() should be override depending the used template (here Data<int>::toString() must describe the int/string conversion).
The C# syntactic sugar which concerns attribute is not difficult to recreate. Nevertheless, it is dependent of the reflexion and each properties may be registered to the object. In my project, I have added smart pointer (and the fact to share value), link to other object and attribute for methods. The main use of this mechanism concerns the user interface creation and the XML serialization.