next up previous contents index
Next: SortedPointerTable Class Up: SortedTable Classes Previous: SortedTable Classes

SortableObject Interface

  


  
Figure 3.3: SortableObject Interface
\begin{figure}
\begin{center}

\includegraphics [scale=1]{SortableObject.ps}
\end{center}\end{figure}

The SortableObject interface (See Figure 3.3) shows the requirements for the elements of SortedTable. Unfortunately, the class derivation and template mechanism are not flexible enough to use the SortableObject class as the base class for the element objects without tricky and awkward coding. Thus, there is no real C++ class named SortableObject.

The required operations for a SortableObject is fairly simple. It must provide the accessor for getting the key of the object and for its nullity. Based on such key mechanisms, it must provide the operations for comparison with a key or another instance of the object. The return values of comparisons conform to the conventions in strcmp() and qsort(). For example, when the instance A is compared with the instance B via A.compare(B), the operation returns 0 if A and B are equal, a positive value if A is greater than B, a negative value if A is smaller than B.

Similarly, when the instance A is compared with the key key via A.compare(key), the operation returns an integer value with the same meaning as in A.compare(B).

The key may not be explicitly declared in the object. Instead, it can be generated each time it is requested. Of course, the key of any object must be constant throughout operations.

The static instance named nullObject is declared to return a null value by the operations of SortedTable. All the keys except for the nullObject must be non-null.


next up previous contents index
Next: SortedPointerTable Class Up: SortedTable Classes Previous: SortedTable Classes
Mori Tetsuya / t2y3141592@gmail.com