enum
, EType, containing the values kRock, kPaper, and kScissors.
NOTE The notation used in the CommonPoint documentation is described in "Reading notation diagrams" on page x of the Preface.
Classes that use RTTI require a set of utility functions. You can provide these supporting functions easily by calling the macro
Classes that require RTTI must also define the following functions:
In addition to a default and copy constructor, TTile defines a constructor that lets you create a tile of a specific kind, color, size and position. This diagram shows the complete interface for the class TTile:
The TArrayOf<TTile> used by TTilesModel is constructed with a Nil comparator and a TMonomorphicStreamer<TTile>. It requires a streamer because the contents of the array are streamed when the model is streamed. See Chapter 1, "Collections," in Foundation Services for more information on these classes and on using collections.
To provide flexibility, it makes sense to allow the array to contain an arbitrary number of TTile instances. TTilesModel has two functions, AdoptTile and OrphanTile, that add a tile to or remove a tile from the model's array. In the first stage of developing this model, however, the number of tiles in the array is defined in the default constructor and is fixed at three. In a later step you'll see how to add the ability for the user to control the number of tiles in the array. (See "Ownership semantics TaligentTypeExtension
The model for this program, TTilesModel, stores TTile instances in a collection and streams them in and out as part of the model. Because instances of the TTile class are saved as a persistent part of a Tiles document component, the TTile class needs to use TaligentTypeExtension, a facility that supports RTTI (Run Time Type Identification).TaligentTypeExtensionDeclarationsMacro
in your class header file, and the macro TaligentTypeExtensionMacro
in the source file. These macros define functions that support versioning and that allow objects to be streamed in and out of persistent storage.
NOTE
Often you can declare the assignment operator as a private function because it will never be used.
Storing the TTile objects
TTilesModel stores the collection of TTile instances in a TArrayOf<TTile>. TArrayOf<AType> is a collection class that encapsulates an indexed sequence of objects of the type specified when the TArrayOf<AType> class template is instantiated. You'll see in the TTilesModel code that TArrayOf requires two parameters when it is constructed--a comparator, used to compare any two elements in the array, and a streamer, used by the collection to save itself as a persistent object. The TArrayOf<AType> constructor requires values for these two parameters, even if both values are Nil.