Flip Programming Guide

 

Writing a DocumentTweaker

This chapter will describe the use of flip::DocumentTweaker with the Flip framework.

Overview

The Flip framework offers a flip::DocumentTweaker template class which is the basis to write a document tweaker. A document tweaker is loaded upon load of the Flip document by the server, but before any clients receive the document.

This allows to make change to the document that couldn’t be done when the document is live.

A typical example is to simplify the model with classes which objects can only be added but never removed. As those objects would keep polluting the model when they may not be all necessary, the tweaker is a way to clean the document before it is read by the clients.

Setting Up

To set up the tweaker, we have to make a DocumentTweaker for the Root class. For that we make a class that inherits from ohm::flip::DocumentTweaker which template parameter is Root .

ListingDocumentTweaker declaration

class DocumentTweaker
:  public ohm::flip::DocumentTweaker <Root>
{
public:
                  DocumentTweaker ();
   virtual        DocumentTweaker () {}
   // inherited from ohm::flip::DocumentTweaker <model::Root>
   virtual void   process (Root & root);
};

Then the client will bind the tweaker to the Flip ohm::flip::DocumentServer . At this point the server will notify the tweaker each time a document is loaded to allow it to make changes to the model before the clients are reading the document.