Flip Programming Guide

 

Using ObjectRefs

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

In the following, we will show the step by step construction of an hypothetic MyClass class.

This chapter will assume that your company is called ACME making the application “Product”.

Overview

The Flip framework offers a flip::ObjectRef template class that holds a reference to another Flip object of type T .

The flip::ObjectRef does not own the referenced object. In particular, if the flip::ObjectRef is destroyed, the referenced object will not be automatically destroyed.

A typical example of flip::ObjectRef use is an object selection container as available in most GUI applications. When the user click on an object, the selection is replaced by the object. Internally the selection object will only reference the object.

flip::ObjectRef template parameter can be any Flip classes, and will support polymorphism in the same way as with an object pointer in C++. If the template parameter is flip::Object itself, the flip::ObjectRef will be able to hold any Flip object. However it is interesting to set the type of the template parameter to a more concrete type, as the class handles dynamic casting automatically.

The use of flip::ObjectRef is straightforward and is exposed in details in the Flip Reference: ObjectRef Template Class Reference chapter.

Precautions

Some special precautions shall be made when using flip::ObjectRef .

Dandling references are a common scenario and is perfectly legal in the Flip framework and is therefore not validated in the Flip internal structural validation.

Fortunately, casting an flip::ObjectRef will return the null pointer if the object does not exist anymore or exist but is of the wrong type.

In particular, when using flip::Object as the template parameter of the flip::ObjectRef , implicit type should not assumed. It happens that a dandling reference in a document becomes non-dandling after a conversion, probably pointing to an object or even an object member arbitraly.