Menu Content/Inhalt
Start arrow HS Object Kernel arrow HS OK - Articles arrow Basics of the construction and functionality of HSOK
Basics of the construction and functionality of HSOK: THSBaseList and descendants Print
20 June 2007
Article Index
THSField class
THSBaseObject class
THSObject class
THSBaseList and descendants
"Weak" and "strong" references
Unicode support
XML support
The kernel object

THSBaseList and descendants

Object lists (THSObjectList), reference lists (THSObjectRefList), strong reference lists (THSStrongRefList) and collections (THSObjectCollection) inherit from the THSBaseList class. This class defines properties and methods common to all lists and optimizes memory management. Each list is implemented as an array of pointers to the elements of the list. The memory for that list is allocated and released in portions of size depending on actual list size. In this way we avoid frequent calls to the memory manager. Besides an obvious property ListCapacity and methods GetObjectCount, GetObjects, AddObject, DeleteObject, DeleteThisObject, MoveObject, ObjectIndex THSBaseList class provides several very useful methods :

  1. ObjectIndexByFieldValues – finds the last element on the list with given features (list of fields and their values)
  2. FindObject – like above, but using binary search with the assumption, that the list is ordered by given fields (you may specify whether the order is descending or ascending and whether it is case sensitive)  
  3. FindObjectByFun – finds an object using binary search with given comparing function
  4. DeleteObjects – deletes object with given features (list of fields and their alues)
  5. SortByFields – sorts the list by given fields (you may specify which fields should be ascending and which descending)
  6. SortObjects – sorts the list using QuickSort algoithm with given comparing function
  7. MergeList – appends objects from another list (you may specify whether duplicates are allowed and whether objects should be copied or moved)
  8. MergeListByFields – appends objects with given features from another list (list of fields and their values)

THSObjectList class represents a list of objects. It's ObjectClass method must be overridden in descendant classes to specify type of the elements of the list (look at the factory method pattern). THSObjectRefList allows creating lists of "weak" references to other objects and corresponds to a list of standard pointers. THSStrongRefList allows creating lists of "strong" references, described later. Released objects are automatically removed from such lists by HSOK. It simplifies implementation of "indices" to lists of objects (e.g. different kinds of sorting), which automatically correct their content when indexed objects are released.

List of "weak" and "strong" references provide two useful methods : FindThisObject and AppendObjectIfNotFound. They use binary search by reference value. These methods may be used to create lists of references that allow quick check whether an object belongs to the list (e.g. list of selected rows in a table view, used to choose the color of the grid cell while drawing it).

Collections (THSObjectCollection) allow storing in one list objects of different classes. All classes used to build a collection must be registered in the HSOK kernel object by RegisterClass method in order to be properly read from text files. You don't have to register classes which have edit functions already registered with RegisterEditFunction method.