?? classlib.doc
字號:
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.
Before we review the differences between the Object and
BIDS models, we'll list the changes to the Object
container library since version 1.0:
o New Btree and PriorityQueue classes.
o New TShouldDelete class gives the programmer control
over container/element ownership. You can control the
fate of objects when they are detached from a
container and when the container is flushed (using
the new flush method) or destroyed.
o New memory management classes, MemBlocks and
MemStack, for efficient memory block and memory stack
(mark-and-release) allocations.
o New PRECONDITION and CHECK macros provide sophisti-
cated assert mechanisms to speed application develop-
ment and debugging.
o New Timer class gives you a stopwatch for timing
program execution.
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?
===========================================================================
The Object container classes have been retained and
enhanced to provide code compatibility with the version
1.0 library. They provide a gentler learning curve than
the template-based BIDS library. The Object container
code offers faster compilation but slightly slower
execution than the template version. The project files
for the example and demo programs are set up to use the
Object version of the container libraries.
BIDS exploits the new exciting templates feature of C++
2.1. It offers you considerable flexibility in choosing
the best underlying data structure for a given
container application. With the Object version, each
container is implemented with a fixed data structure,
chosen to meet the space/speed requirements of most
container applications. For example, a Bag object is
implemented with a hash table, and a Deque object with
a double list. With BIDS you can fine-tune your
application by varying the container implementation
with the minimum recoding--often a single typedef will
suffice. You can switch easily from StackAsList to
StackAsVector and test the results. In fact, you'll see
that by setting appropriate values for <T>, a generic
class parameter, you can implement the Object model
exactly. With BIDS, you can even choose between
polymorphic and non-polymorphic implementations of the
Object container model. Such choices between execution
speed (non-polymorphic) and future flexibility
(polymorphic) can be tested without major recoding.
- 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.
Regardless of which container class model you elect to
use, you should be familiar with container terminology,
the Object class hierarchy, and the functionality
provided for each container type. Although the classes
in the BIDS library have different naming conventions
and special template parameters, the prototypes and
functionality of each class member are the same as
those in the Object library.
===========================================================================
Container basics
===========================================================================
If you are fully We start by describing the Object container class
versed in the hierarchy as enhanced for Turbo C++ version 3.0. This
Turbo C++ 1.0 hierarchy offers a high degree of modularity through
version of the inheritance and polymorphism. You can use these classes
container library, as they are, or you can extend and expand them to pro-
you should first duce an object-oriented software package specific to
check out the your needs.
Object library
enhancements At the top of the class hierarchy is the Object class
before moving to (see Figure 1), an abstract class that cannot be
the templates instantiated (no objects of its type can be declared).
section on page An abstract class serves as an umbrella for related
14. classes. As such, it has few if any data members, and
some or all of its member functions are pure virtual
functions. Pure virtual functions serve as placeholders
for functions of the same name and signature intended
- 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.
Figure 1: Class hierarchies in CLASSLIB
Object穆腅rror
媚Sortable哪哪履String
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -