Professional Documents
Culture Documents
CLASSLIB
CLASSLIB
___________________________________________________________________________
CONTENTS
i
Member functions . . . . . . . 75 Member functions . . . . . . . 92
HashTable . . . . . . . . . . . 75 Set . . . . . . . . . . . . . . . 92
Member functions . . . . . . . 76 Member functions . . . . . . . 92
Friends . . . . . . . . . . . 78 Sortable . . . . . . . . . . . . 93
HashTableIterator . . . . . . . 78 Member functions . . . . . . . 95
Member functions . . . . . . . 78 Related functions . . . . . . . 96
List . . . . . . . . . . . . . . 79 SortedArray . . . . . . . . . . . 97
Member functions . . . . . . . 79 Stack . . . . . . . . . . . . . . 97
Friends . . . . . . . . . . . 80 Example . . . . . . . . . . . . 98
ListIterator . . . . . . . . . . 81 Member functions . . . . . . . 99
Member functions . . . . . . . 81 String . . . . . . . . . . . . 100
MemBlocks . . . . . . . . . . . 82 Member functions . . . . . . 100
MemStack . . . . . . . . . . . . 83 Example . . . . . . . . . . . 101
Object . . . . . . . . . . . . . 84 Time . . . . . . . . . . . . . 102
Data member . . . . . . . . . 84 Member functions . . . . . . 103
Member functions . . . . . . . 84 Timer . . . . . . . . . . . . . 104
Friends . . . . . . . . . . . 87 Member functions . . . . . . 104
Related functions . . . . . . 87 TShouldDelete . . . . . . . . . 105
PriorityQueue . . . . . . . . . 88 Member functions . . . . . . 105
Member functions . . . . . . . 89
Queue . . . . . . . . . . . . . 90 Index 107
Example . . . . . . . . . . . 91
ii
Online document
___________________________________________________________________________
For more Turbo C++ version 3.0 includes two complete container
information about class libraries: an enhanced version of the Object-
templates, see based library supplied with version 1.0, plus a brand-
Chapter 13, "C++ new implementation based on templates. This chapter
specifics." describes both libraries. We assume that you are
familiar with the syntax and semantics of C++ and with
the basic concepts of object-oriented programming
(OOP). To understand the template-based version (called
BIDS, for Borland International Data Structures), you
should be acquainted with C++'s new template mechanism.
===========================================================================
What's new since version 1.0?
===========================================================================
- 1 -
class Object. Further, the data structures used to
implement each container class were fixed and (usually)
hidden from the programmer. This provides a simple,
effective model for most container applications.
Version 3.0 therefore offers an enhanced, code-
compatible version of the previous Object-based
container library. We call this the Object container
class library. In addition, a more flexible (but more
complex), template-based container library, called BIDS
(Borland International Data Structures), is supplied
with version 3.0. Through the power of templates, BIDS
lets you vary the underpinning data structure for a
container and lets you store arbitrary objects in a
container. With the appropriate template parameters,
BIDS can actually emulate the Object container library.
When you choose Existing Turbo C++ version 1.01 container class code
Container Class will still run with the version 3.0 libraries. The new
Library in the Object container class libraries, in directory
IDE's Options| \CLASSLIB, are distinguished by the prefix TC:
Linker|Libraries TCLASSx.LIB and TCLASDBx.LIB where x specifies the
dialog box, the memory model, and DB indicates the special debug
Object-based version. To reduce verbiage, we will often refer to
libraries will be this container implementation as the Object or TC
automatically version.
linked in.
- 2 -
To use the The corresponding libraries for the new template-based
template-based container classes are distinguished by the prefix BIDS:
libraries, you BIDSx.LIB and BIDSDBx.LIB. Let's review the reasons for
must explicitly having two sets of container libraries. The use of all
add the these libraries is covered on page 31.
appropriate
BIDS[DB]x.LIB
library to your
project or
makefile.
===========================================================================
Why two sets of libraries?
===========================================================================
- 3 -
Existing code Both the Object and BIDS versions provide the same
based on the functional interface. For example, the push and pop
Object container member functions work the same for all Stack objects.
classes will This makes the new template-based libraries highly
compile and run compatible with existing code written for the Object
perfectly using library.
the new BIDS
classes, just by The objects stored in Object library containers must be
linking in the derived from the class Object. To store ints, say, you
appropriate would have to derive an Integer class from Object
library. (you'll see how later). With BIDS you have complete
freedom and direct control over the types of objects
stored in a container. The stored data type is simply a
value passed as a template parameter. For instance,
BI_ListImp<int> gives you a list of ints.
===========================================================================
Container basics
===========================================================================
- 4 -
to be defined eventually in derived classes. In fact,
any class with at least one pure virtual function is,
by definition, an abstract class.
Object � � � E rror
� � S ortable � � � � � � S t r ing
� � � B aseDate � � � � � D a te
� � � B aseTime � � � � � T i me
� � A ssociation
� � C ontainer � � � � � C o llection � � � A bstractArray � � � A r ray
� � � � S ortedArray
� � � H ashTable
� � � B ag � � S et � � D ictionary
� � � L ist
� � � B tree
� � � D oubleList
� � S tack
� � D eque � � Q ueue
� � P riorityQueue
ContainerIterator � � � � � � H a s hTableIterator
� � L istIterator
� � D oubleListIterator
� � B treeIterator
� � A rrayIterator
Memblocks
MemStack
Note that TShouldDelete provides a second base
(multiple inheritance) for both Container and
Association.
- 5 -
To enhance your As you read this chapter, bear in mind that a derived
understanding of class inherits and can access all non-private data
the classes, you members and member functions from all its ancestral
can review their base classes. For example, the Array class does not
declarations in need to explicitly define a function to print an array,
the source code because its immediate parent class AbstractArray does
files in the so. The Container class, an ancestor further up the
CLASSLIB class tree, defines a different print function that can
directory. also be used with an array, because an array is a
container. To determine all the member functions
available to an object, you will have to ascend the
class hierarchy tree. Because the public interface is
intended to be sufficient for applications, object-
oriented programming makes a knowledge of private data
members unnecessary; therefore, private members (with a
few exceptions) are not documented in this chapter.
- 6 -
Non-container =======================================================
classes
The basic non-container classes provided are Object and
its three children: Error (instance), Sortable
(abstract), and Association (instance). Recall that the
main purpose of these classes is to provide objects
that can be stored as data elements in containers. To
this end, all Object-derived classes provide a hashing
function allowing any of their objects to be stored in
a hash table.
For more details Distinguish between the container object and the
on Sortable see objects it contains: Sortable is the base for non-
page 93 in the container objects; it is not a base for ordered
reference section. collections. Every class derived from Object inherits
the isSortable member function so that objects can be
queried as to their "sortability."
- 7 -
------------------ Association is a non-container, instance class
Association class providing special objects to be stored (typically) in
------------------ Dictionary collections. An Association object, known as
Association see an association, is a pair of objects known as the key
page 44 in the and the value. The key (which is unique in the
reference section. dictionary) can be used to retrieve the value. Every
class derived from Object inherits the isAssociation
member function so that objects can report whether they
are associations or not.
- 8 -
member function, that is, a general way of determining
whether a given object is an element of the container.
This is a deliberate design decision. As we move up the
hierarchy, you'll see that what distinguishes the
various derived container classes are the storage and
access rules that actually define each container's
underlying data structure. Thus push and pop member
functions are added for Stack, indexing operators are
added for Array, and so on. There is not enough in
common to warrant having generic add and retrieve
methods at the Container level. There is no one perfect
way of extracting common properties from groups of
containers, and therefore no perfect container class
hierarchy. The Object-based container hierarchy is just
one possible design based on reasonable compromises.
The BIDS version, as you'll see, offers a different
perspective.
- 9 -
void test()
{
Array a1( 10 ); // construct an array
Array a2( 10 ); // and another
- 10 -
container. The safest approach is to use the
container's methods to detach and destroy its contents.
Container =======================================================
iterators
You saw earlier that Container, the base for all
containers in the Object-based library, supports
iteration. Iteration means traversing or scanning a
container, accessing each stored object in turn to
perform some test or action. The separate
ContainerIterator-based hierarchy provides this
functionality. Iterator classes are derived from this
base to provide iterators for particular groups of
containers, so you'll find HashTableIterator,
ListIterator, BtreeIterator, and so on.
- 11 -
Returning to the container class hierarchy, we look at
three classes derived directly from Container: Stack,
Deque, and PriorityQueue.
Collections =======================================================
- 12 -
and the ordered collection Btree. In turn,
AbstractArray spawns the unordered Array and the
ordered SortedArray. Bag serves as the base for Set
which in turn is the base for Dictionary. These
collections all refine the storage and retrieval
methods in their own fashions.
o HashTable
o Bag, Set, and Dictionary
o List and DoubleList
o Array
o Btree
o SortedArray
===========================================================================
The BIDS template library
===========================================================================
- 13 -
For a basic With BIDS, the container is considered as an ADT
description of C++ (abstract data type), and its underlying data structure
templates see is independently treated as an FDS (fundamental data
Chapter 13. structure). BIDS also allows separate selections of the
type of objects to be stored, and whether to store the
objects themselves or pointers to objects.
Templates, =======================================================
classes, and
containers Computer science has devoted much attention to devising
suitable data structures for different applications.
Recall Wirth's equation, Programs = Algorithms + Data
Structures, which stresses the equal importance of data
structures and their access methods.
Container =======================================================
implementation
Often, you can implement the desired container
properties in many ways using different underlying data
structures. For example, a stack, characterized by its
Last-In-First-Out (LIFO) access, can be implemented as
a vector, a linked list, or perhaps some other
structure. The vector-based stack is appropriate when
the maximum number of elements to be stored on the
stack is known in advance. A vector allocates space for
all its elements when it is created. The stack as a
list is needed when there is no reasonable upper bound
to the size of the stack. The list is a slower imple-
mentation than the vector, but it doesn't use any more
memory than it needs for the current state of the
stack.
- 14 -
The way objects are stored in the container also
affects size and performance: they can be stored
directly by copying the object into the data structure,
or stored indirectly via pointers. The type of data to
be stored is a key factor. A stack of ints, for
example, would probably be stored directly, where large
structs would call for indirect storage to reduce
copying time. For "in-between" cases, however, choosing
strategies is not always so easy. Performance tuning
requires the comparison of different container
implementations, yet traditionally this entails drastic
recoding.
- 15 -
------------------ We discussed earlier the stack and its possible
ADTs and FDSs implementations as a linked list or as a vector. The
------------------ potential for confusion is that stacks, lists, and
vectors are all commonly referred to as data
structures. However, there is a difference. We can
define a stack abstractly in terms of its LIFO
accessibility, but it's difficult to envision a list
without thinking of specifics such as nodes and
pointers. Likewise, we picture a vector as a concrete
sequence of adjacent memory locations. So we call the
stack an ADT (abstract data type) and we call the list
and vector FDSs (fundamental data structures). The BIDS
container library offers each of the standard ADTs
implemented with a choice of appropriate FDSs. Table 1
indicates the combinations provided:
ADTs as
fundamental data -------------------------------------------------------
structures ADT Sorted
FDS Stack Queue Deque Bag Set Array Array
-------------------------------------------------------
Vector x x x x x x x
List x
DoubleList x x
-------------------------------------------------------
- 16 -
------------------ ADTs are implemented in both direct and indirect
Class templates versions. The direct versions store the objects
------------------ themselves, while the indirect versions store pointers
to objects. You can store whatever objects you want as
elements in these FDSs using the power of templates.
Here are the ADT and FDS templates we provide:
---------------------------------------------------------------------------
Table 2: FDS class templates
BI_VectorImp<T> vector of Ts
BI_VectorIteratorImp<T> iterator for a vector of Ts
BI_CVectorImp<T> counted vector of Ts
BI_SVectorImp<T> sorted vector of Ts
BI_IVectorImp<T> vector of pointers to T
BI_IVectorIteratorImp<T> iterator for a vector of pointers to T
BI_ICVectorImp<T> counted vector of pointers to T
BI_ISVectorImp<T> sorted vector of pointers to T
BI_ListImp<T> list of Ts
BI_SListImp<T> sorted list of Ts
BI_IListImp<T> list of pointers to T
BI_ISListImp<T> sorted list of pointers to T
BI_DoubleListImp<T> double-linked list of Ts
BI_SDoubleListImp<T> sorted double-linked list of Ts
BI_IDoubleListImp<T> double-linked list of pointers to T
BI_ISDoubleListImp<T> sorted double-linked list of pointers to T
---------------------------------------------------------------------------
- 17 -
type T must have meaningful copy semantics and a
default constructor. Indirect containers, however, hold
pointers to T, and pointers always have
- 18 -
good copy semantics. This means that indirect
containers can contain objects of any type.
Abbreviations in
CLASSLIB names
-----------------------------------------------------------------
Abbreviation Description
-----------------------------------------------------------------
I Indirect
C Counted
S Sorted
O Object-based, non-polymorphic
TC Object-based, polymorphic (compatible with
original Turbo C++ library)
-----------------------------------------------------------------
For details see For the sorted FDSs (BI_SVectorImp, BI_ISVectorImp, and
the discussion so on), T must have valid == and < operators to define
under Sortable on the ordering of the elements. It should be clear that
page 94. the IS variants refer to the objects being sorted, not
that the pointers to the objects are sorted.
----------------------------------------------------------------------------
Table 4: ADT class templates
... and so on
----------------------------------------------------------------------------
There are also Again, the <T> argument, either a class or predefined
BI_Oxxx and data type, provides the data type for the contained
BI_TCxxx variants elements. Each of the bulleted items ( x ) in Table 1
discussed soon. can be mapped to two templates (direct and indirect
versions) with names following this convention.
--------------------------------------------------------
Object-based FDS Class name Description
classes --------------------------------------------------------
- 20 -
Table 5: Object-based FDS classes (continued)__________
--------------------------------------------------------
- 21 -
In the Object container library, Stack implements a
stack as a polymorphic list of pointers to Object. The
BIDS class BI_TCStackAsList therefore mirrors the
Object-based class Stack. Even with BI_TCStackAsVector,
the public interface and semantics are the same as for
the Object-based Stack. The user "sees" the ADT while
the FDS is "hidden." For these reasons, we will not
repeat the alphabetic list of Object-based classes and
member functions for the BIDS library.
vectimp.h
listimp.h
dlistimp.h
stacks.h
queues.h
deques.h
bags.h
sets.h
arrays.h
- 22 -
Note the plural The file stacks.h, for example, defines the following
form that templates:
distinguishes the
BIDS include files BI_StackAsVector<T>
from the Object- BI_IStackAsVector<T>
based include file BI_OStackAsVector
BI_TCStackAsVector
BI_StackAsList<T>
BI_IStackAsList<T>
BI_OStackAsList
BI_TCStackAsList
Tuning an ========================================================
application
Consider the following example:
int main()
{
intStack is;
for( int i = 0; i < 10; i++ )
is.push( i );
for( i = 0; i < 10; i++ )
cout << is.pop() << endl;
return(0);
}
- 23 -
FDS implementation ========================================================
- 24 -
// semantics and a default constructor
{
public:
...
void add( T t ) { new BI_ListElement<T>( t,
findPred(t) ); }
// adds object in sorted position
...
};
- 25 -
The double list templates, in dlistimp.h, follows the
same pattern. The sorted versions of list and double
list provide exactly the same interface as the non-
sorted ones, except that the add member function adds
new elements in sorted order. This speeds up subsequent
access and also makes it easier to implement priority
queues.
- 26 -
{
public:
void add( T t );
// add at position that maintains sort
};
- 27 -
template <class Vect, class T> class
BI_StackAsVectorImp
{
public:
...
void push( T t ) { data[current++] = t; }
...
protected:
Vect data;
unsigned current;
};
- 28 -
That is, an BI_IStackAsVector is implemented by using a
BI_StackAsVectorImp, whose "implementation" is of type
BI_IVectorImp<T>, and whose elements are of type pointer
to T. The TShouldDelete base provides the ownership
control discussed in the Object-based class reference
section. TShouldDelete also serves as a second base for
the following classes.
TShouldDelete* � � � � � � � � � A s s ociation*
� � � C o ntainer
� � � B I _IArrayAsVector+
� � � B I _IBagAsVector+
� � � B I _IDequeAsDoubleList+
� � � B I _IDequeAsVector+ *Instance classes
� � � B I _ISArrayAsVector+
� � � B I _ISObjectArray+
� � � B I _IStackAsList+ +Template classes
� � � B I _IStackAsVector+
class BI_OStackAsVector
// non-polymorphic stack with vector of pointers to
Objects
{
public:
...
void push( Object *t ) { ostack.push(t); }
// ostack is type BI_IStackAsVector<Object>
// so we are pushing pointers to Object
...
private:
BI_IStackAsVector<Object> ostack;
};
- 29 -
{
public:
...
void push( Object& o ) { stk.push( &o ); }
// stk is type BI_OStackAsVector
// so we are pushing Objects
...
private:
BI_OStackAsVector stk;
};
Output string 1
string 2
string 3
Source
- 30 -
Doubly-linked list #include <iostream.h>
with indirect #include <strstream.h>
storage as FDS. #include <deques.h>
#include <strng.h>
===========================================================================
The class library directory
===========================================================================
- 31 -
�����������ͻ
� CLASSLIB\ �
�����������ͼ
������������������������������������������������
������Ŀ
����������ͻ ���������ͻ ����������Ŀ ������ͻ
�����������ͻ
� INCLUDE\ � � SOURCE\ � � OBJS � � LIB\ � � EXAMPLES\ �
����������ͼ ���������ͼ ������������ ������ͼ
�����������ͼ
Important! When you take a library that you have built and use it
in one of the sample projects, you must update the
project. See Chapter 7, "Managing multi-file projects"
for more information. You must also be sure to compile
your project with precisely the same switches and op-
tions you used to build the library. If you don't have
the same options, you will get warnings from the linker
when the executable file is built.
- 33 -
The LIB directory =======================================================
- 34 -
===========================================================================
Preconditions and checks
===========================================================================
-----------------------------------------------------------------
Class debugging __DEBUG PRECONDITION CHECK
modes
-----------------------------------------------------------------
0 Off Off
1 On Off
>1 On On
undefined On On
- 35 -
-----------------------------------------------------------------
===========================================================================
Container class reference
===========================================================================
- 36 -
AbstractArray
===========================================================================
AbstractArray abstarry.h
===========================================================================
������������Ŀ �������������ͻ
������������Ŀ
� Collection ��ĶAbstractArray���Ĵ Array �
�������������� �������������ͼ �
��������������
� ������������Ŀ
�ĴSortedArray �
��������������
The abstract class AbstractArray offers random access
to the elements of the collection via an indexing
mechanism that maps a range of integers to the array
elements. Indexes can be positive or negative integers
with arbitrary lower and upper bounds (within the range
of int). Arrays derived from AbstractArray can be
dynamically resized as elements are added to them. The
data member delta determines how many additional
elements are assigned to the array when overflow
occurs. AbstractArray exists because the derived
classes SortedArray and Array have enough in common to
warrant combining the common properties into an
abstract base class. Since the derived classes differ
only in the implementation of the member functions
detach and the subscript operator, the remaining
functions can be encapsulated in AbstractArray.
- 38 -
AbstractArray
- 39 -
AbstractArray
Friends =======================================================
- 40 -
Array
===========================================================================
Array array.h
===========================================================================
�������������Ŀ ������������ͻ
�AbstractArray��Ķ Array �
��������������� ������������ͼ
Example =======================================================
int main()
{
Array a(2);
// Print as a Container
cout << "As a container:\n" << a << endl << endl;
// Print as an Array
cout << "As an array:\n";
a.printContentsOn(cout);
// Print as elements
- 41 -
Array
Output As a container:
Array { a string,
another atring,
Association { a string, another string }
}
As an array:
Array { a string,
another atring,
Association { a string, another string }
}
As elements:
a string
another string
Association { a string, another string}
- 42 -
Array
===========================================================================
ArrayIterator abstarry.h
===========================================================================
�����������������Ŀ
������������������ͻ
�ContainerIterator��Ķ ArrayIterator �
�������������������
������������������ͼ
Provides iterator functions to traverse objects of the
class AbstractArray and its derived classes.
ArrayIterator is a friend class of AbstractArray
===========================================================================
Association assoc.h
===========================================================================
������������Ŀ ������������ͻ
� Object ��ĶAssociation �
�������������� ������������ͼ
Copy constructor.
- 44 -
Association
Example =======================================================
void identify(Object&);
main()
{
char s1[21], s2[81];
// Read a key
cout << "Enter a key: ";
cin >> s1;
cin.get(); // Eat newline
- 45 -
Association
String str1(s1);
identify(str1);
// Read a value
cout << "Enter a value: ";
cin.getline(s2,81);
s2[strlen(s2) - 1] = '\0';
String str2(s2);
identify(str2);
Association a1(str1,str2);
identify(a1);
Association a2 = a1;
identify(a2);
void identify(Object& o)
{
// Echo an object and its type
cout << "Value: " << o
<< ", Object type: " << o.nameOf()
<< endl << endl;
}
Equal: 1
- 46 -
Bag
===========================================================================
Bag bag.h
===========================================================================
������������Ŀ ������������ͻ
������������Ŀ
� Collection ��Ķ Bag ��Ĵ Set �
�������������� ������������ͼ
��������������
A Bag is an unordered collection that may contain more
than one of the same object. Bag also provides the base
class for Set. Unlike Bags, Sets can contain only one
copy of a any given object.
See Array::detach.
- 48 -
Bag
See TShouldDelete::ownsElements
===========================================================================
BaseDate ldate.h
===========================================================================
������������Ŀ ������������ͻ
������������Ŀ
� Sortable ��Ķ BaseDate ��Ĵ Date �
�������������� ������������ͼ
��������������
BaseDate is an abstract class derived from Sortable
that provides basic date manipulation functions.
Copy constructor.
- 50 -
BaseDate
===========================================================================
BaseTime ltime.h
===========================================================================
������������Ŀ ������������ͻ
������������Ŀ
� Sortable ��Ķ BaseTime ��Ĵ Time �
�������������� ������������ͼ
��������������
Copy constructor.
- 52 -
BaseTime
===========================================================================
Btree btree.h
===========================================================================
������������Ŀ ������������ͻ
� Collection ��Ķ Btree �
�������������� ������������ͼ
- 53 -
Btree
Adds the given object to the tree and returns the index
in the tree at which the object was inserted.
- 54 -
Btree
operator << is a Sends the formatted B-tree data to the given output
friend of Object. stream. printOn is for internal use by the overloaded
See page 87. operator <<.
Friends =======================================================
===========================================================================
BtreeIterator btree.h
===========================================================================
�����������������Ŀ
������������������ͻ
�ContainerIterator��Ķ BtreeIterator �
�������������������
������������������ͼ
See ContainerIterator::current
See ContainerIterator::operator ++
See ContainerIterator::restart
- 56 -
Collection
===========================================================================
Collection collect.h
===========================================================================
�������������Ŀ
�ĴAbstractArray�
� ���������������
� �������������Ŀ
�Ĵ HashTable �
� ���������������
������������Ŀ ������������ͻ �
�������������Ŀ
� Container ��Ķ Collection ���Ĵ List �
�������������� ������������ͼ �
���������������
� �������������Ŀ
�Ĵ DoubleList �
� ���������������
� �������������Ŀ
�Ĵ Bag �
� ���������������
� �������������Ŀ
�Ĵ Btree �
���������������
- 58 -
Collection
===========================================================================
Container contain.h
===========================================================================
������������Ŀ
�Ĵ Collection �
� ��������������
������������Ŀ ������������ͻ � ������������Ŀ
� Object ��Ķ Container ���Ĵ Stack �
�������������� ������������ͼ � ��������������
� ��������������������Ŀ
�Ĵ PriorityQueue �
� ����������������������
�
� ������������Ŀ ������������Ŀ
�Ĵ Deque �Ĵ Queue �
�������������� ��������������
- 59 -
Container
constructor Container();
- 60 -
Container
- 61 -
Container
- 62 -
Container
Friends =======================================================
- 63 -
ContainerIterator
===========================================================================
ContainerIterator contain.h
===========================================================================
������������������Ŀ
�ĴHashTableIterator �
� ��������������������
�����������������ͻ �
������������������Ŀ
�ContainerIterator���Ĵ ListIterator �
�����������������ͼ �
��������������������
� ������������������Ŀ
�ĴDoubleListIterator�
� ��������������������
� ������������������Ŀ
�Ĵ BtreeIterator �
� ��������������������
� ������������������Ŀ
�Ĵ ArrayIterator �
��������������������
===========================================================================
Date ldate.h
===========================================================================
������������Ŀ ������������ͻ
� BaseDate ��Ķ Date �
�������������� ������������ͼ
The Date instance class is a direct descendant of the
abstract class BaseDate, defining a printOn function.
You can vary Date for different national conventions
without disturbing BaseDate.
constructor Date();
- 65 -
Date
Copy constructor.
operator << is a Sends a formatted date to the given output stream. The
friend of Object. format is full month name, day, year, for example
See page 87. January 1, 1990. printOn is really for internal use by
the overloaded operator <<.
===========================================================================
Deque deque.h
===========================================================================
������������Ŀ ������������ͻ
������������Ŀ
� Container ��Ķ Deque �Ĵ Queue �
�������������� ������������ͼ
��������������
Example =======================================================
main()
{
Deque d;
String *s1 = new String("one");
String *s2 = new String("two");
String *s3 = new String("three");
String *s4 = new String("four");
// Print to cout
cout << "As a container:\n" << d << endl;
// Empty to cout
cout << "As a Deque:\n";
while (!d.isEmpty())
{
cout << d.getLeft() << endl;
}
// Should be empty
cout << "\nShould be empty:\n" << d;
}
Output As a container:
Deque { three,
one,
two,
four }
As a Deque:
three
one
two
four
Should be empty:
- 67 -
Deque
Deque { }
- 68 -
Deque
===========================================================================
Dictionary dict.h
===========================================================================
������������Ŀ ������������ͻ
� Set ��Ķ Dictionary �
�������������� ������������ͼ
A dictionary is a special collection of Association
type objects. The instance class Dictionary is derived
from Collection via Bag and Set, implying that no
duplicate association objects are allowed in a
dictionary. Dictionary overrides the add function and
adds a lookup function to the members inherited from
Set. lookup allows you to retrieve the value object of
an association stored in the dictionary if you supply
the key.
- 69 -
Dictionary
===========================================================================
DoubleList dbllist.h
===========================================================================
������������Ŀ ������������ͻ
� Collection ��Ķ DoubleList �
�������������� ������������ͼ
- 70 -
DoubleList
constructor DoubleList();
- 71 -
DoubleList
- 72 -
DoubleList
Friends =======================================================
===========================================================================
DoubleListIterator dbllist.h
===========================================================================
�����������������Ŀ
������������������ͻ
�ContainerIterator��ĶDoubleListIterator�
�������������������
������������������ͼ
DoubleListIterator, derived from ContainerIterator,
implements the special iterators for traversing
doubly-linked lists in either direction. This class
adds overloading of the pre- and postdecrement operator
- - to allow reverse iteration. For more details on
iterators, see ContainerIterator, and
DoubleList::initIterator.
===========================================================================
Error object.h
===========================================================================
������������Ŀ ������������ͻ
� Object ��Ķ Error �
�������������� ������������ͼ
- 74 -
Error
===========================================================================
HashTable hashtbl.h
===========================================================================
������������Ŀ ������������ͻ
� Collection ��Ķ HashTable �
�������������� ������������ͼ
- 75 -
HashTable
detach
- 76 -
HashTable
Returns the raw hash value of this table. This must not
be confused with the hash values calculated by the hash
table for each of the objects it stores. When an object
x of class X is added or retrieved from a hash table h,
the raw hash value used is x.hashValue(). The true hash
value (usually modulo size) is obtained from the hash
table object via h.getHashValue( x ). Only classes with
a proper hashValue member function can provide objects
for storage in a hash table. All standard Object-
derived classes in the library have meaningful hashing
functions provided. For example, BaseDate::hashValue
(unless overridden) returns the value YY + MM + DD from
which the (private) member function
HashTable::getHashValue computes a hash value (using
mod size). It is this value that governs the hash
table's add, findMember, and detach operations.
- 77 -
HashTable
Friends =======================================================
===========================================================================
HashTableIterator hashtbl.h
===========================================================================
�����������������Ŀ
������������������ͻ
�ContainerIterator��ĶHashTableIterator �
�������������������
������������������ͼ
See ContainerIterator::current
See ContainerIterator::operator ++
See ContainerIterator::restart
===========================================================================
List list.h
===========================================================================
������������Ŀ ������������ͻ
� Collection ��Ķ List �
�������������� ������������ͼ
constructor List();
detach
- 79 -
List
See Container::initIterator
Friends =======================================================
- 80 -
ListIterator
===========================================================================
ListIterator list.h
===========================================================================
�����������������Ŀ
������������������ͻ
�ContainerIterator��Ķ ListIterator �
�������������������
������������������ͼ
See ContainerIterator::current
See ContainerIterator::operator ++
See ContainerIterator::restart
- 81 -
MemBlocks
===========================================================================
MemBlocks memmgr.h
===========================================================================
������������ͻ
� MemBlocks �
������������ͼ
class Node
{
Node *next;
Object *obj;
static MemBlocks memBlocks;
void *operator new( size_t sz ) { return
memBlocks.allocate ( sz); }
void operator delete( void * blk ) { memBlocks.free
( blk ); }
...
};
- 82 -
MemBlocks
===========================================================================
MemStack memmgr.h
===========================================================================
������������ͻ
� MemStack �
������������ͼ
MemStack symbols;
void handleLocals()
{
Marker locals( symbols ); // marks current
state of symbols
Sym *symbol1 = new(symbols)Sym; // add a Sym to the
table
Sym *symbol2 = new(symbols)Sym; // and another
}
- 83 -
Object
===========================================================================
Object object.h
===========================================================================
������������Ŀ
�Ĵ Error �
� ��������������
������������ͻ � ������������Ŀ
� Object ���Ĵ Sortable �
������������ͼ � ��������������
� ������������Ŀ
�ĴAssociation �
� ��������������
� ������������Ŀ
�Ĵ Container �
��������������
constructors Object();
Object( Object& obj );
- 84 -
Object
- 85 -
Object
- 86 -
Object
Friends =======================================================
- 87 -
Object
===========================================================================
PriorityQueue priortyq.h
===========================================================================
������������Ŀ ��������������������ͻ
� Container ��Ķ PriorityQueue �
�������������� ��������������������ͼ
- 88 -
PriorityQueue
- 89 -
PriorityQueue
===========================================================================
Queue queue.h
===========================================================================
��������Ŀ ������������ͻ
� Deque ��Ķ Queue �
���������� ������������ͼ
- 90 -
Queue
Example =======================================================
main()
{
Queue q;
String *s1 = new String("a string");
String *s2 = new String("another string");
Association *a1 = new Association(*s1,*s2);
Output As a container:
Queue { Association { a string, another a string }
,
another string,
a string }
As a queue:
a string
another string
Association { a string, another string }
Should be empty:
Queue { }
- 91 -
Queue
===========================================================================
Set set.h
===========================================================================
������������Ŀ ������������ͻ
������������Ŀ
� Bag ��Ķ Set ��Ĵ Dictionary �
�������������� ������������ͼ
��������������
===========================================================================
Sortable sortable.h
===========================================================================
������������Ŀ
�Ĵ String �
� ��������������
������������Ŀ ������������ͻ �
������������Ŀ
� Object ��Ķ Sortable ���Ĵ BaseDate �
�������������� ������������ͼ �
��������������
� ������������Ŀ
�Ĵ BaseTime �
��������������
- 94 -
Sortable
- 95 -
Sortable
operator < int operator <( const Sortable& test1, const Sortable&
test2 );
operator <= int operator <=( const Sortable& test1, const Sortable&
test2 );
operator > int operator >( const Sortable& test1, const Sortable&
test2 );
operator >= int operator >=( const Sortable& test1, const Sortable&
test2 );
- 96 -
SortedArray
===========================================================================
SortedArray sortarry.h
===========================================================================
�������������Ŀ ������������ͻ
�AbstractArray��ĶSortedArray �
��������������� ������������ͼ
===========================================================================
Stack stack.h
===========================================================================
������������Ŀ ������������ͻ
� Container ��Ķ Stack �
�������������� ������������ͼ
- 97 -
Stack
Example =======================================================
main()
{
Stack s;
String *s1 = new String("a string");
String *s2 = new String("another string");
Association *a1 = new Association(*s1,*s2);
s.push(*s1);
s.push(*s2);
s.push(*a1);
Output As a Container:
Stack { Association { a string, another string }
,
another string,
a string }
As a Stack:
- 98 -
Stack
another string
a string
- 99 -
Stack
===========================================================================
String strng.h
===========================================================================
������������Ŀ ������������ͻ
� Sortable ��Ķ String �
�������������� ������������ͼ
Copy constructor.
- 100 -
String
Example =======================================================
#include <strng.h>
void identify(String&);
main()
{
char s1[21], s2[21];
- 101 -
String
// String assignment:
str2 = str1;
cout << "After assignment:\n" << "Equal: "
<< str1.isEqual(str2);
}
Equal: 0
Less than: 0
After assignment:
Equal: 1
===========================================================================
Time ltime.h
===========================================================================
������������Ŀ ������������ͻ
� BaseTime ��Ķ Time �
�������������� ������������ͼ
- 102 -
Time
constructor Time();
Copy constructor.
- 103 -
Timer
===========================================================================
Timer timer.h
===========================================================================
������������ͻ
� Timer �
������������ͼ
constructor Timer();
- 104 -
Timer
===========================================================================
TShouldDelete shddel.h
===========================================================================
TShouldDelete����������Association
���Container
- 105 -
TShouldDelete
-------------------------------------------------------
delObj
ownsElements no yes
-------------------------------------------------------
NoDelete no no
DefDelete no yes
Delete yes yes
-------------------------------------------------------
- 106 -
INDEX
___________________________________________________________________________
A B
abbreviations Bag class 47
CLASSLIB names and 19 BaseDate class 49
abstract classes 4 BaseTime class 51
abstract data types BI_ prefix
BIDS class names 19 class names 19
class library and 13 BIDS template library 13
AbstractArray class 37 Borland International Data
add Structures (BIDS) 13
Array member function 42 Btree class 53
Bag member function 47 BtreeIterator class 55
Btree member function 53
Collection member function 58
Dictionary member function 69 C
DoubleList member function 71 C prefix
HashTable member function 76 class names 19
List member function 79 CHECK macro 35
Sets member function 92 class templates 17
addAt classes
Array member function 42 abstract vs instance 4
addAtHead arrays
DoubleList member function 71 sorted 97
addAtTail collections 12
DoubleList member function 71 date and time 65, 102
ADT debugging modes 35
header files 22 hierarchies 4
ADT (abstract data types) 13 object-based 6
Array class 41 traversing 43
ArrayInterator lists 70
AbstractArray friend 40 priority queues 88
ArrayIterator class 43 queue 90
arrays queues
classes for 37, 41 double-ended 66
classes for sorted 97 sequence 12, 66, 90, 97
arraySize rules for 12
AbstractArray member function 38 sortable objects 93
ascending sort 97 stack 97
assertion macros 35 string 100
Association class 7, 44 CLASSLIB naming conventions 19
example program 34 Collection class 12, 57
Index 107
collections reference section 36
ordered 13 container classes 6, 8, 59
random access to 37 functions of 59
unordered 13 container hierarchy
Bag class 47 object-based 4
Dictionary class 69 ContainerIterator class 64
DoubleList class 70 containers and 64
HashTable class 75 hierarchy 11
List class 79 containers
Set class 92 basics 4
condFuncType definition 84 ContainerIterator class and 64
constructors direct 19
AbstractArray member function 38 elements of 59
Array member function 42 equality testing 60
ArrayIterator member function 43 flushing 10, 59
Association member function 44 implementation 14
Bag member function 47 indirect 19
Basedate member function 49 current
Basetime member function 51 ArrayIterator member function 43
Btree member function 53 BtreeIterator member function 56
BtreeIterator member function 56 ContainerIterator member function
Collection member function 58 64
Container member function 60 DoubleListIterator member
Date member function 65 function 73
Dictionary member function 70 HashTableIterator member function
DoubleList member function 71 78
DoubleListIterator member ListIterator member function 81
function 73
HashTable member function 76
HashTableIterator member function D
78 Date class 65
List member function 79 dates
ListIterator member function 81 class 65
Object member function 84 Day
Sets member function 93 Basedate member function 49
String member function 100 __DEBUG macro 35
Time member function 103 decrNofKeys
Timer member function 104 Btree member function 53
TShouldDelete member function 105 delete
container class library Error member function 75
directories 31 delObj
examples 34 TShouldDelete member function 106
INCLUDE 32 delta
lib 34 AbstractArray data member 37
source 32 Deque class 66
example programs 34 destroy
memory models and 32 AbstractArray member function 38
project files and 32 Collection member function 58
- 108 -
destroyFromHead HashTable member function 77
DoubleList member function 71 firstThat
destroyFromTail Bag member function 47
DoubleList member function 71 Container member function 60
detach Object member function 84
AbstractArray member function 38 flush
Bag member function 47 Bag member function 47
Btree member function 53 Btree member function 54
Collection member function 58 Container member function 61
DoubleList member function 71 Deque member function 68
HashTable member function 76 DoubleList member function 72
List member function 79 HashTable member function 77
SortedArray member function 97 List member function 80
detachFromHead PriorityQueue member function 89
DoubleList member function 71 Stacks member function 99
detachFromTail forEach
DoubleList member function 71 Bag member function 48
detachLeft Container member function 61
PriorityQueue member function 89 Object member function 85
Dictionary class 69 free
example program 34 MemBlocks member function 83
direct and indirect data structures fundamental data structure
14 class templates 17
directories fundamental data structures
container class library 31 class library and 13
DIRECTRY (container class library Object-based classes 20
example program) 34
DoubleList class 70
DoubleListIterator class 73 G
get
PriorityQueue member function 89
E Queue member function 92
elements getItemsInContainer
ordering definition 19 Bag member function 48
Error class 7, 74 Container member function 61
examples directory Deques member function 68
container class library 34 PriorityQueue member function 89
Stacks member function 99
getLeft
F Deque member function 68
FDS getRight
header files 22 Deque member function 68
FDS (fundamental data structures)
13
findmember H
Bag member function 47 hash table
Btree member function 54 iterators 78
Collection member function 58 HashTable class 75
Index 109
HashTableIterator class 78 instance classes 4
hashValue isA
Association member function 44 Array member function 43
Basedate member function 49 Association member function 44
Basetime member function 51 Bag member function 48
Btree member function 54 Basedate member function 50
Container member function 61 Basetime member function 52
HashTable member function 77 Btree member function 54
List member function 80 Container member function 62
Object member function 85 Date member function 66
PriorityQueue member function 89 Deque member function 68
Sortable member function 95 Dictionary member function 70
String member function 100 DoubleList member function 72
hasMember Error member function 75
Bag member function 48 HashTable member function 78
Btree member function 54 List member function 80
Collection member function 59 Object member function 85
PriorityQueue member function 89 PriorityQueue member function 89
hour Queue member function 92
Basetime member function 51 Set member function 93
hundredths Sortable member function 95
Basetime member function 51 Stack member function 99
String member function 100
Time member function 103
I isAssociation
i_add Association member function 44
Btree member function 54 Object member function 85
I prefix isEmpty
class names 19 Bag member function 48
Imp suffix Container member function 62
class names 19 Deques member function 68
INCLUDE directory PriorityQueue member function 90
container class library 32 Stack member function 99
incrNofKeys isEqual
Btree member function 54 AbstractArray member function 39
initIterator Association member function 45
AbstractArray member function 39 Basedate member function 50
Bag member function 48 Basetime member function 52
Btree member function 54 Btree member function 54
Container member function 61 Container member function 62
Deque member function 68 Error member function 75
DoubleList member function 72 Object member function 86
HashTable member function 77 Sortable member function 95
List member function 80 String member function 100
PriorityQueue member function 89 isLessThan
Stacks member function 99 Basedate member function 50
InnerNode Basetime member function 52
Btree friend class 53 Sortable member function 95
- 110 -
String member function 101 M
isSortable member functions
Object member function 86 virtual
Sortable member function 95 pure 4
Item MemBlocks class 82
Btree friend class 53 memory models
itemsInContainer container class library and 32
Container data member 60 MemStack class 83
iterators minute
DoubleList 73 Basetime member function 52
internal and external 11 Month
iterFuncType definition 61 Basedate member function 50
K N
key nameOf
Association class 44 Arrays member function 43
Association member function 45 Association member function 45
Bag member function 49
Basedate member function 50
L Basetime member function 52
Last-In-First-Out (LIFO) 14 Btree member function 54
lastElementIndex Container member function 62
AbstractArray data member 37 Date member function 66
lastThat Deque member function 68
Bag member function 48 Dictionary member function 70
Container member function 62 DoubleList member function 72
Object member function 86 Error member function 75
LeafNode HashTable member function 78
Btree friend class 53 List member function 80
lib directory Object member function 86
container class library 34 PriorityQueue member function 90
List class 79 Set member function 93
iterators 81 Sortable member function 95
ListElement class 79 Stacks member function 99
ListIterator class 81 String member function 101
lists Time member function 103
classes for 70 new
linked Object member function 86
traversing 81 Node
lookup Btree friend 55
Dictionary member function 70 Btree friend class 53
LOOKUP (container class library non-container classes 6
example program) 34
lowerBound
AbstractArray member function 39 O
lowerbound O prefix 21
AbstractArray data member 37 class names 19
Index 111
Object class 4, 84 operator char *
Object container class library String member function 101
version 3.0 changes to 1 operator int
objectAt ArrayIterator member function 43
AbstractArray member function 39 BtreeIterator member function 56
objects ContainerIterator member function
automatic 11 64
detaching 10 DoubleListIterator member
heap 11 function 74
in containers HashTableIterator member function
counting 59 78
displaying 60 ListIterator member function 81
iterating 60 order
ownership 59 Btree member function 55
ownership 9 ordered collections 7, 13
sortable 93 ownsElements 9
operator < Bag member function 49
overloaded 96 TShouldDelete member function 105
operator =
String member function 101
operator > P
overloaded 96 peekAtHead
operator != DoubleList member function 72
overloaded 88 peekAtTail
operator ++ DoubleList member function 72
ArrayIterator member function 43 peekHead
BtreeIterator member function 56 List member function 80
ContainerIterator member function peekLeft
64 Deque member function 69
DoubleListIterator member PriorityQueue member function 90
function 73 peekRight
HashTableIterator member function Deque member function 69
79 pop
ListIterator member function 81 Stacks member function 99
operator << PRECONDITION macro 35
Object friends 87 printContentsOn
operator <= AbstractArray member function 39
overloaded 96 printHeader
operator == Container member function 62
overloaded 87 printOn
operator >= Association member function 45
overloaded 96 Basedate member function 50
operator [] Basetime member function 52
AbstractArray member function 39 Btree member function 55
Btree member function 55 Container member function 62
operator - - Date member function 66
DoubleListIterator member Error member function 75
function 73 Object member function 87
- 112 -
Sortable member function 96 restart
String member function 101 ArrayIterator member function 44
Time member function 103 BtreeIterator member function 56
printSeparator ContainerIterator member function
Container member function 63 65
printTrailer DoubleListIterator member
Container member function 63 function 74
priority queues 88 HashTableIterator member function
PriorityQueue class 88 79
project files ListIterator member function 81
container class libraries and 32 REVERSE (container class library
ptrAt example program) 34
AbstractArray member function 40
ptrToRef
Object member function 87 S
push S prefix
Stacks member function 99 class names 19
put second
PriorityQueue member function 90 Basetime member function 52
Queue member function 92 Set class 92
putLeft setData
Deque member function 69 AbstractArray member function 40
putRight SetDay
Deque member function 69 Basedate member function 50
setHour
Basetime member function 52
Q setHundredths
Queue class 90 Basetime member function 52
example program 34 setMinute
queues 90 Basetime member function 52
double-ended 66 SetMonth
QUEUETST (container class library Basedate member function 50
example program) 34 setSecond
Basetime member function 52
SetYear
R Basedate member function 50
rank Sortable class 7, 93
Btree member function 55 ordered collections 13
reallocate SortedArray class 97
AbstractArray member function 40 example program 34
MemBlocks member function 83 sorts
removeEntry ascending 97
AbstractArray member function 40 source directory
reset container class library 32
Timer member function 104 squeezeEntry
resolution AbstractArray member function 40
Timer member function 104 Stack class 97
example program 34
Index 113
start top
Timer member function 104 Stacks member function 99
status TShouldDelete class 105
Timer member function 104
stdtempl.h 22
stop U
Timer member function 104 unordered collections 13
String class 100 Bag class 47
example program 34 Dictionary class 69
strings DoubleList class 70
classes for 100 HashTable class 75
STRNGMAX (container class library List class 79
example program) 34 Set class 92
upperBound
AbstractArray member function 40
T upperbound
TC prefix 21 AbstractArray data member 38
class names 19
template-based container library 13
TEMPLATES V
conditional compilation 32 value
Templates Association class 44
Arrays example 30 Association member function 45
Deques example 30
templates
approach to class library 3, 15 Y
container classes and 14 Year
instantiating 19 Basedate member function 50
time
Timer member function 105
Time class 102 Z
example program 34 ZERO
Timer class 104 Object data member 84
- 114 -