Important: The information in this document is obsolete and should not be used for new development.
Lists and Iteration
A list is a data structure that stores a variable number of items of similar types. MacApp provides classes for creating and manipulating lists, making it possible for your application to use lists without having to implement the low-level details.MacApp's list classes are implemented on top of a dynamic array model. Each item in a list has a unique index--you can access items in a list by index or by standard list-traversal methods.
The following list describes some of MacApp's list classes:
Iteration is a general-purpose mechanism for traversing the items in a list. MacApp provides the
- TDynamicArray. The
TDynamicArray
class descends fromTObject
and is the base class for all MacApp list classes. Objects of this class manage a dynamically allocated array of elements.- TSortedDynamicArray. The
TSortedDynamicArray
class adds ordering to the array with the addition of methods for comparing array elements and for adding elements in order.- TSortedList. The
TSortedList
class adds methods and fields for an ordered list in which each element is a reference to an object.TSortedList
and its descendant classes work only with objects that descend from theTObject
class.- TList. The
TList
class is a special case ofTSortedList
that doesn't sort the objects. This class is used widely by MacApp and can be a valuable tool in your application as well.- TAssociation. The
TAssociation
class manages a sorted list of entries, in which each entry associates aCString
key with aCString
value.TAssociation
is useful for storing a list of strings that can be accessed by their associated keys.- THandleList. The
THandleList
class stores references to handles. It can be useful for dealing with a variety of developer-defined data types.
CIterator
class and a large number of specialized subclasses that operate on lists containing items of various types. Iteration classes can traverse the items in a list without knowing the exact details of the data structures involved.The use of iteration classes with MacApp's failure-handling mechanism can require extra caution. See "Failure Handling Embedded in Objects" on page 59 for more information. For additional information on using lists and iterators in your application, see Chapter 25, "Working With Lists and Iteration."