A model is a data structure defined in the Xc++ language which is directly mapped to a corresponding C/C++ struct. For example
$model+ Point
{
float32 x,y;
};
$model+ Circle
{
Point centre;
float32 radius;
};
$model+ Triangle
{
Point vertices[3];
};
$model+ Rectangle
{
float32 x1,y1,x2,y2;
};
When a $model is reflected an instance of a ReflectedClass is registered in the ReflectedClass registry.
There is support for schema evolution of a model by allowing for attributes to be added or dropped over time. This information is related back to release numbers of the library in which the model definition appears.
Remarkably schema evolution can be deployed on sites incrementally – i.e. without needing to upgrade all sites at the same time (which may not be practical in large complex systems).
Here is a rather contrived example where a z coordinate was added, then dropped again and then the representation changed from Cartesian to polar coordinates:
$model+ Point
{
float64 r;
float64 theta;
$dropped
{
float64 x;
float64 y;
float64 z;
}
$schema
{
1: +x +y // Release #1 : (x,y)
2: +z // Release #2,3 : (x,y,z)
4: -z // Release #4 : (x,y)
5: -x -y +r +theta // Release #5- : (r,theta)
}
$evolve
{
r(x,y) { r = sqrt(x*x + y*y); }
theta(x,y) { theta = atan2(y,x); }
}
};
A model may contain a constructor allowing for initialisation of the members. For example
$model+ Point
{
float64 x;
float64 y;
// constructor, has C++ syntax except $$ is used for
// the class name
$$() :
x(0.0),
y(0.0)
{
}
};