Interfacing with the Model
When interfacing with the model, the code can be separated in two parts :
- the part that control the model
- the part that reacts to model changes
Controlling the Model
Controlling the model is done by directly changing the model as you would think with regular classes.
If a class Element has two members _position and _length , changing the position and the length of the element is as simple as :
element._position = position; |
element._length = length; |
The members used in classes, are actually Flip classes object. They are proxies that will handle the change to the model.
For example if you would write a class with a member :
int _position; |
You would transform it to :
flip::Int64 _position; |
And if you would write a class with a member :
std::list <Element> _element_arr; |
You would transform it to :
flip::Array <Element> _element_arr; |
Manipulating the Flip containers is close to the standard library naming. Adding an element is done through insert and erasing an element is done through erase . Others functions are provided in a quite monolithic way like in the original standard to ensure that client using already the standard library will feel like just at home.
Observing the Model
When a client modify its own model or receive a modification (transaction) of the model from another client through the server, the model is directly modified.
The client of the model will have registered one or multiple observers to observer how the model is modified.
The client observer is then called with the model root object as a parameter.
When the client observer is called, Flip maintains the previous version of the model as well as the current one as applied by the transaction. This allows to know :
- exactly which objects where modified
- the value of an object before of a modification
- what was inserted/erased from a container
- was was moved from a container to another

The client is then responsible to parse the model tree to ensure that its local representation of the model match the one from Flip.
Furthermore, Flip was designed to make this task as simple as possible :
- the model tree can be parsed in any direction, parsed multiple times, etc.
- one or multiple represented objects can be attached to Flip objects
- we made up a few pattern of code to simplify your work
As long as the model client does not exit from the observer call, Flip still maintains the old and current version of the model. Each flip object as well as your custom classes have an is_invalid () member to know if an object or its compound contains a modification, and this recursively.
Whenether your local model uses object pointers, references or ids, you can attach it to any flip object. This also itself a best case interoperability with your external libraries or your GUI in a very simple way.