Providing access to the model's data

To provide access to the TTile instances, TTilesModel needs to have accessor functions:

The difference between GetTileForReading and GetTileForWriting is important. GetTileForReading is a const member function, so it can be called on a const TTilesModel pointer or reference. Call this function when the data in the model needs to be accessed but not modified, for example, when rendering the data. Call GetTileForWriting when the data needs to be modified, for example, in selection functions for modifying selected data.

These two functions (GetTileForReading and GetTileForWriting) are required to support concurrent access to the model. Whenever a model is accessed it must be locked for either reading or writing. If it is locked for reading, only the const member function can be called. Therefore, careful use of const is necessary to support read-only locking of models. If the model is locked for writing, both const and non-const member functions can be invoked. See "Accessing the model" on page 17 for more information on locking a model for access.

Note that TTilesModel doesn't provide access to information about its tiles by duplicating the TTile interface. Instead, GetTileForReading and GetTileForWriting provide access to the TTile instances contained by the model--once you get a pointer to a TTile through these interfaces, you can access the data in the TTile instance itself using the TTile accessor functions.



[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker