Borland Turbo C++ v1

This commit is contained in:
davidly 2024-07-02 07:34:51 -07:00
parent ff1b2da987
commit 0791b7a9e6
307 changed files with 35987 additions and 0 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#ifndef MWC
#include <string.h>
#include <stdlib.h>
#endif
#define DIGITS_TO_FIND 200 /*9009*/
int main() {
int N = DIGITS_TO_FIND;
int x = 0;
int a[ DIGITS_TO_FIND ];
int n;
for (n = N - 1; n > 0; --n) {
a[n] = 1;
}
a[1] = 2, a[0] = 0;
while (N > 9) {
n = N--;
while (--n) {
a[n] = x % n;
x = 10 * a[n-1] + x/n;
}
printf("%d", x);
}
printf( "\ndone\n" );
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,35 @@
/* sieve.c */
/* Eratosthenes Sieve Prime Number Program in C from Byte Jan 1983
to compare the speed. */
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define SIZE 8190
typedef int bool;
char flags[SIZE+1];
int main()
{
int i,k;
int prime,count,iter;
for (iter = 1; iter <= 10; iter++) { /* do program 10 times */
count = 0; /* initialize prime counter */
for (i = 0; i <= SIZE; i++) /* set all flags TRUE */
flags[i] = TRUE;
for (i = 0; i <= SIZE; i++) {
if (flags[i]) { /* found a prime */
prime = i + i + 3; /* twice index + 3 */
for (k = i + prime; k <= SIZE; k += prime)
flags[k] = FALSE; /* kill all multiples */
count++; /* primes found */
}
}
}
printf("%d primes.\n",count); /*primes found in 10th pass */
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,169 @@
#include <stdio.h>
#ifdef AZTEC86
#include <stdlib.h>
#endif
#ifdef HISOFTC
#include <stdlib.h>
#endif
#ifdef INTELC
#include <stdlib.h>
#endif
#ifdef WATCOM
#include <malloc.h>
#include <process.h>
#endif
#ifdef powerc
#define allocs 50
#else
#ifdef HISOFTC
#define allocs 66 /* not enough RAM with hisoft to go higher */
#else
/* most c runtimes work up to 69, but use 66 to have a consistent benchmark */
#define allocs 66
#endif
#endif
int logging = 1;
char * memset_x( p, v, c ) char * p; int v; int c;
{
unsigned char * pc = (unsigned char *) p;
unsigned char val = (unsigned char) ( v & 0xff );
int i;
if ( 0 == p )
{
printf( "request to memset a null pointer\n" );
exit( 1 );
}
if ( logging )
#ifdef CPMTIME
printf( " memset p %u, v %d, val %x, c %d\n", p, v, val, c );
#else
#ifdef HISOFTC
printf( " memset p %u, v %d, val %x, c %d\n", p, v, val, c );
#else
printf( " memset p %p, v %d, val %x, c %d\n", p, v, val, c );
#endif
#endif
for ( i = 0; i < c; i++ )
*pc++ = val;
return p;
}
void chkmem( p, v, c ) char * p; int v; int c;
{
unsigned char * pc = (unsigned char *) p;
unsigned char val = (unsigned char) ( v & 0xff );
int i;
if ( 0 == p )
{
printf( "request to chkmem a null pointer\n" );
exit( 1 );
}
for ( i = 0; i < c; i++ )
{
if ( *pc != val )
{
#ifdef CPMTIME
printf( "memory isn't as expected! p %u, v %d, c %d, *pc %d\n",p, v, c, *pc );
#else
printf( "memory isn't as expected! p %p, v %d, c %d, *pc %d\n",p, v, c, *pc );
#endif
exit( 1 );
}
pc++;
}
}
int main( argc, argv ) int argc; char * argv[];
{
int i, cb, c_cb, j;
char * pc;
char * ap[ allocs ];
logging = ( argc > 1 );
pc = argv[ 0 ]; /* evade compiler warning */
for ( j = 0; j < 10; j++ )
{
if ( logging )
printf( "in alloc mode\n" );
for ( i = 0; i < allocs; i++ )
{
cb = 8 + ( i * 10 );
c_cb = cb + 5;
if ( logging )
printf( " i, cb: %d %d\n", i, cb );
pc = (char *) calloc( c_cb, 1 );
chkmem( pc, 0, c_cb );
memset_x( pc, 0xcc, c_cb );
ap[ i ] = (char *) malloc( cb );
memset_x( ap[ i ], 0xaa, cb );
chkmem( pc, 0xcc, c_cb );
free( pc );
}
if ( logging )
printf( "in free mode, even first\n" );
for ( i = 0; i < allocs; i += 2 )
{
cb = 8 + ( i * 10 );
c_cb = cb + 3;
if ( logging )
printf( " i, cb: %d %d\n", i, cb );
pc = (char *) calloc( c_cb, 1 );
chkmem( pc, 0, c_cb );
memset_x( pc, 0xcc, c_cb );
chkmem( ap[ i ], 0xaa, cb );
memset_x( ap[ i ], 0xff, cb );
free( ap[ i ] );
chkmem( pc, 0xcc, c_cb );
free( pc );
}
if ( logging )
printf( "in free mode, now odd\n" );
for ( i = 1; i < allocs; i += 2 )
{
cb = 8 + ( i * 10 );
c_cb = cb + 7;
if ( logging )
printf( " i, cb: %d %d\n", i, cb );
pc = (char *) calloc( c_cb, 1 );
chkmem( pc, 0, c_cb );
memset_x( pc, 0xcc, c_cb );
chkmem( ap[ i ], 0xaa, cb );
memset_x( ap[ i ], 0xff, cb );
free( ap[ i ] );
chkmem( pc, 0xcc, c_cb );
free( pc );
}
}
printf( "success\n" );
return 0;
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,527 @@
/*
This version builds with old compilers including:
Aztec C 1.06 for 8080 & Z80 on CP/M.
Microsoft C Compiler V1.04 for 8086 on DOS. (This is Lattice C)
Microsoft C Compiler V2.03 for 8086 on DOS. (Still Lattice C)
Microsoft C Compiler V3.00 for 8086 on DOS.
QuickC 1.0
Turbo C 2.0
The syntax is old and reminds me of 7th grade summer vacation.
Much of this code is awkward to satisfy the lowest common denominator of many compilers.
unsigned long isn't supported in many older compilers, so long is used instead.
Early DOS and CP/M require register variabes to be int, not char or other types.
The perf improvement of using register-int instead of stack-char is worth it.
*/
#define LINT_ARGS
#include <stdio.h>
#ifdef DOSTIME
#include <time.h>
#include <dos.h>
#endif
#define true 1
#define false 0
/* Function Pointers are the fastest implementation for almost every compiler */
#define UseFunPointers 1
#define UseWinner2 2
#define UseLookForWinner 3
#define WinMethod UseFunPointers
#define ABPrune true /* alpha beta pruning */
#define WinLosePrune true /* stop early on win/lose */
#define ScoreWin 6
#define ScoreTie 5
#define ScoreLose 4
#define ScoreMax 9
#define ScoreMin 2
#define DefaultIterations 10
#define PieceX 1
#define PieceO 2
#define PieceBlank 0
typedef char ttype; /* 8-bit and 16-bit cpus do best with char aside from register in locals */
int g_Iterations = DefaultIterations;
ttype g_board[ 9 ];
#if WinMethod == UseFunPointers
ttype pos0func()
{
/* using "register int" instead of "ttype" for x is faster on 8086 and Z80 */
register int x = g_board[0];
if ( ( x == g_board[1] && x == g_board[2] ) ||
( x == g_board[3] && x == g_board[6] ) ||
( x == g_board[4] && x == g_board[8] ) )
return x;
return PieceBlank;
}
ttype pos1func()
{
register int x = g_board[1];
if ( ( x == g_board[0] && x == g_board[2] ) ||
( x == g_board[4] && x == g_board[7] ) )
return x;
return PieceBlank;
}
ttype pos2func()
{
register int x = g_board[2];
if ( ( x == g_board[0] && x == g_board[1] ) ||
( x == g_board[5] && x == g_board[8] ) ||
( x == g_board[4] && x == g_board[6] ) )
return x;
return PieceBlank;
}
ttype pos3func()
{
register int x = g_board[3];
if ( ( x == g_board[4] && x == g_board[5] ) ||
( x == g_board[0] && x == g_board[6] ) )
return x;
return PieceBlank;
}
ttype pos4func()
{
register int x = g_board[4];
if ( ( x == g_board[0] && x == g_board[8] ) ||
( x == g_board[2] && x == g_board[6] ) ||
( x == g_board[1] && x == g_board[7] ) ||
( x == g_board[3] && x == g_board[5] ) )
return x;
return PieceBlank;
}
ttype pos5func()
{
register int x = g_board[5];
if ( ( x == g_board[3] && x == g_board[4] ) ||
( x == g_board[2] && x == g_board[8] ) )
return x;
return PieceBlank;
}
ttype pos6func()
{
register int x = g_board[6];
if ( ( x == g_board[7] && x == g_board[8] ) ||
( x == g_board[0] && x == g_board[3] ) ||
( x == g_board[4] && x == g_board[2] ) )
return x;
return PieceBlank;
}
ttype pos7func()
{
register int x = g_board[7];
if ( ( x == g_board[6] && x == g_board[8] ) ||
( x == g_board[1] && x == g_board[4] ) )
return x;
return PieceBlank;
}
ttype pos8func()
{
register int x = g_board[8];
if ( ( x == g_board[6] && x == g_board[7] ) ||
( x == g_board[2] && x == g_board[5] ) ||
( x == g_board[0] && x == g_board[4] ) )
return x;
return PieceBlank;
}
typedef ttype pfunc_t();
pfunc_t * winner_functions[9] =
{
pos0func,
pos1func,
pos2func,
pos3func,
pos4func,
pos5func,
pos6func,
pos7func,
pos8func
};
#endif
#if WinMethod == UseWinner2
ttype winner2( move ) ttype move;
{
register int x; /* faster than ttype x on the stack */
switch( move ) /* msc v3 from 1985 generates a jump table! */
{
case 0:
{
x = g_board[ 0 ];
if ( ( ( x == g_board[1] ) && ( x == g_board[2] ) ) ||
( ( x == g_board[3] ) && ( x == g_board[6] ) ) ||
( ( x == g_board[4] ) && ( x == g_board[8] ) ) )
return x;
break;
}
case 1:
{
x = g_board[ 1 ];
if ( ( ( x == g_board[0] ) && ( x == g_board[2] ) ) ||
( ( x == g_board[4] ) && ( x == g_board[7] ) ) )
return x;
break;
}
case 2:
{
x = g_board[ 2 ];
if ( ( ( x == g_board[0] ) && ( x == g_board[1] ) ) ||
( ( x == g_board[5] ) && ( x == g_board[8] ) ) ||
( ( x == g_board[4] ) && ( x == g_board[6] ) ) )
return x;
break;
}
case 3:
{
x = g_board[ 3 ];
if ( ( ( x == g_board[4] ) && ( x == g_board[5] ) ) ||
( ( x == g_board[0] ) && ( x == g_board[6] ) ) )
return x;
break;
}
case 4:
{
x = g_board[ 4 ];
if ( ( ( x == g_board[0] ) && ( x == g_board[8] ) ) ||
( ( x == g_board[2] ) && ( x == g_board[6] ) ) ||
( ( x == g_board[1] ) && ( x == g_board[7] ) ) ||
( ( x == g_board[3] ) && ( x == g_board[5] ) ) )
return x;
break;
}
case 5:
{
x = g_board[ 5 ];
if ( ( ( x == g_board[3] ) && ( x == g_board[4] ) ) ||
( ( x == g_board[2] ) && ( x == g_board[8] ) ) )
return x;
break;
}
case 6:
{
x = g_board[ 6 ];
if ( ( ( x == g_board[7] ) && ( x == g_board[8] ) ) ||
( ( x == g_board[0] ) && ( x == g_board[3] ) ) ||
( ( x == g_board[4] ) && ( x == g_board[2] ) ) )
return x;
break;
}
case 7:
{
x = g_board[ 7 ];
if ( ( ( x == g_board[6] ) && ( x == g_board[8] ) ) ||
( ( x == g_board[1] ) && ( x == g_board[4] ) ) )
return x;
break;
}
case 8:
{
x = g_board[ 8 ];
if ( ( ( x == g_board[6] ) && ( x == g_board[7] ) ) ||
( ( x == g_board[2] ) && ( x == g_board[5] ) ) ||
( ( x == g_board[0] ) && ( x == g_board[4] ) ) )
return x;
break;
}
}
return PieceBlank;
} /*winner2*/
#endif
#if WinMethod == UseLookForWinner
ttype LookForWinner()
{
register int p = g_board[0]; /* faster as register int than ttype on 8086 and Z80 */
if ( PieceBlank != p )
{
if ( p == g_board[1] && p == g_board[2] )
return p;
if ( p == g_board[3] && p == g_board[6] )
return p;
}
p = g_board[3];
if ( PieceBlank != p && p == g_board[4] && p == g_board[5] )
return p;
p = g_board[6];
if ( PieceBlank != p && p == g_board[7] && p == g_board[8] )
return p;
p = g_board[1];
if ( PieceBlank != p && p == g_board[4] && p == g_board[7] )
return p;
p = g_board[2];
if ( PieceBlank != p && p == g_board[5] && p == g_board[8] )
return p;
p = g_board[4];
if ( PieceBlank != p )
{
if ( ( p == g_board[0] ) && ( p == g_board[8] ) )
return p;
if ( ( p == g_board[2] ) && ( p == g_board[6] ) )
return p;
}
return PieceBlank;
} /*LookForWinner*/
#endif
int g_IMoves = 0;
ttype MinMax( alpha, beta, depth, move ) ttype alpha; ttype beta; ttype depth; ttype move;
{
ttype pieceMove, score; /* better perf with char than int. out of registers so use stack */
register int p, value; /* better perf with these as an int on Z80, 8080, and 8086 */
g_IMoves++;
if ( depth >= 4 )
{
#if WinMethod == UseFunPointers
p = ( * winner_functions[ move ] )();
#endif
#if WinMethod == UseWinner2
p = winner2( move );
#endif
#if WinMethod == UseLookForWinner
p = LookForWinner();
#endif
if ( PieceBlank != p )
{
if ( PieceX == p )
return ScoreWin;
return ScoreLose;
}
if ( 8 == depth )
return ScoreTie;
}
if ( depth & 1 )
{
value = ScoreMin;
pieceMove = PieceX;
}
else
{
value = ScoreMax;
pieceMove = PieceO;
}
for ( p = 0; p < 9; p++ )
{
if ( PieceBlank == g_board[ p ] )
{
g_board[p] = pieceMove;
score = MinMax( alpha, beta, depth + 1, p );
g_board[p] = PieceBlank;
if ( depth & 1 )
{
#if WinLosePrune /* #if statements must be in first column for MS C 1.0 */
if ( ScoreWin == score )
return ScoreWin;
#endif
if ( score > value )
{
value = score;
#if ABPrune
if ( value >= beta )
return value;
if ( value > alpha )
alpha = value;
#endif
}
}
else
{
#if WinLosePrune
if ( ScoreLose == score )
return ScoreLose;
#endif
if ( score < value )
{
value = score;
#if ABPrune
if ( value <= alpha )
return value;
if ( value < beta )
beta = value;
#endif
}
}
}
}
return value;
} /*MinMax*/
long g_Moves = 0;
int FindSolution( position ) ttype position;
{
register int i;
for ( i = 0; i < 9; i++ )
g_board[ i ] = PieceBlank;
g_board[ position ] = PieceX;
for ( i = 0; i < g_Iterations; i++ )
{
g_IMoves = 0;
MinMax( ScoreMin, ScoreMax, 0, position );
g_Moves += g_IMoves; /* do the 4-byte long addition once per loop to save work */
}
return 0;
} /*FindSolution*/
#ifdef CPMTIME
struct CPMTimeValue
{
int h, m, s, l;
};
void print_time_now()
{
/* This CP/M BDOS call of 105 is only implemented in NTVCM -- it's not a standard CP/M 2.2 call */
struct CPMTimeValue t;
t.h = t.m = t.s = t.l = 0;
bdos( 105, &t );
printf( "current time: %02d:%02d:%02d.%02d\n", t.h, t.m, t.s, t.l );
} /*print_time_now*/
long get_ms()
{
/* This CP/M BDOS call of 105 is only implemented in NTVCM -- it's not a standard CP/M 2.2 call */
long h, m, s, l;
struct CPMTimeValue t;
t.h = t.m = t.s = t.l = 0;
bdos( 105, &t );
h = t.h;
m = t.m;
s = t.s;
l = t.l;
return h * 3600000 + m * 60000 + s * 1000 + l * 10;
} /*get_ms*/
#else /* no elif with old compilers */
#ifdef DOSTIME
void print_time_now()
{
/* Make a DOS interrupt call to get the time */
union REGS wrIn, wrOut;
wrIn.h.ah = 0x2c;
intdos( &wrIn, &wrOut );
printf( "current time: %02d:%02d:%02d.%02d\n", wrOut.h.ch, wrOut.h.cl, wrOut.h.dh, wrOut.h.dl );
fflush( stdout );
} /*print_time_now*/
long get_ms()
{
/* this function takes about 3 milliseconds on the original IBM PC */
long h, m, s, l;
union REGS wrIn, wrOut;
wrIn.h.ah = 0x2c;
intdos( &wrIn, &wrOut );
h = wrOut.h.ch;
m = wrOut.h.cl;
s = wrOut.h.dh;
l = wrOut.h.dl;
return h * 3600000 + m * 60000 + s * 1000 + l * 10;
} /*get_ms*/
#else
/* must do this on actual CP/M machines */
int print_time_now() { return 0; }
long get_ms() { return 0; }
#endif
#endif
int main( argc, argv ) int argc; char * argv[];
{
long start_time, end_time;
if ( 2 == argc )
sscanf( argv[ 1 ], "%d", &g_Iterations ); /* no atoi in MS C 1.0 */
start_time = get_ms();
FindSolution( 0 );
FindSolution( 1 );
FindSolution( 4 );
end_time = get_ms();
printf( "runtime in ms: %ld\n", end_time - start_time );
printf( "move count: %ld\n", g_Moves ); /* 6493 * g_Iterations */
printf( "iteration count: %d\n", g_Iterations );
printf( "method: %s\n",
( WinMethod == UseFunPointers ) ? "function pointers" :
( WinMethod == UseWinner2 ) ? "winner2" :
( WinMethod == UseLookForWinner ) ? "look for winner" :
"invalid method" );
return 0;
} /*main*/

View File

@ -0,0 +1,2 @@
-IC:\NTVDM\TCPP1\INCLUDE
-LC:\NTVDM\TCPP1\LIB

Binary file not shown.

View File

@ -0,0 +1,7 @@
@echo off
ntvdm -r:.. tcc -DDOSTIME -ms -Z -O -G -I..\include -L..\lib -e%1.exe %1.c
rem ntvdm -r:.. tcc -DDOSTIME -ms -Z -O -G -I..\include -L..\lib -c %1.c
rem ntvdm -r:.. tlink -L..\lib ..\lib\c0s.obj+%1.obj, %1.exe, /x, ..\lib\CS.LIB+..\lib\EMU.LIB+..\lib\maths.lib

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,194 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Directory::Directory constructor
// Directory::addFile
//
// Description
//
// Implementation of class Directory member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __DIR_H
#include <dir.h>
#define __DIR_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __DIRECTRY_H
#include "directry.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __FILEDATA_H
#include "filedata.h"
#endif
// End Implementation Dependencies -------------------------------------------
// Constructor //
Directory::Directory( char *pathName, sortOrder sortBy ) :
SortedArray( 10, 0, 5 ), mask( pathName )
// Summary -----------------------------------------------------------------
//
// Constructs a directory object. A directory object contains
// a sorted array of the file names which are in the directory.
//
// Parameters
//
// pathName
//
// Character pointer to the pathname for the directory. This
// pathname may include wildcard characters.
//
// sortBy
//
// The order by which we are to sort the directory entries.
//
// Functional Description
//
// We walk through the directory, adding each of the file names to
// our directory object.
//
// End ---------------------------------------------------------------------
{
struct ffblk fileBlock;
int morePathNames = !findfirst( mask, &fileBlock, 0 );
while( morePathNames )
{
addFile( fileBlock, sortBy );
morePathNames = !findnext( &fileBlock );
} // end while more files.
}
// End Constructor Directory::Directory //
// Member Function //
void Directory::addFile( ffblk& fileBlock, sortOrder sortBy )
// Summary -----------------------------------------------------------------
//
// Adds a file to a directory object.
//
// Parameters
//
// fileBlock
//
// The DOS file block we are to add to this directory object.
//
// sortBy
//
// The order in which files are to be sorted.
//
// Functional Description
//
// Depending upon the sort order, we add a new object to the
// sorted array.
//
// End ---------------------------------------------------------------------
{
switch( sortBy )
{
case byName:
add( *(new FilesByName( fileBlock )) );
break;
case byDate:
add( *(new FilesByDate( fileBlock )) );
break;
case bySize:
add( *(new FilesBySize( fileBlock )) );
break;
} // end switch on sort order.
}
// End Member Function Directory::addFile //
// Member Function //
void Directory::printHeader( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays the directory mask for the directory listing
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the header.
//
// Functional Description
//
// We print the directory mask
//
// End ---------------------------------------------------------------------
{
outputStream << "Directory: " << mask << "\n ";
}
// End Member Function Directory::printHeader //
// Member Function //
void Directory::printSeparator( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Starts a new line for the next directory entry.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the separator.
//
// End ---------------------------------------------------------------------
{
outputStream << "\n ";
}
// End Member Function Directory::printSeparator //
// Member Function //
void Directory::printTrailer( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays a new line for the trailer.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the trailer.
//
// End ---------------------------------------------------------------------
{
outputStream << "\n";
}
// End Member Function Directory::printTrailer //

View File

@ -0,0 +1,126 @@
#ifndef __DIRECTRY_H
#define __DIRECTRY_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// directoryClass
//
// Directory
//
// Description
//
// Defines class Directory.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __DIR_H
#include <dir.h>
#define __DIR_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __SORTARRY_H
#include <sortarry.h>
#endif
#ifndef __FILEDATA_H
#include "filedata.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Macro //
// Summary -----------------------------------------------------------------
//
// Defines a value for the directory class. We use the next available
// number after the class which sorts files by date.
//
// End ---------------------------------------------------------------------
#define directoryClass (filesBySizeClass+1)
// Class //
class Directory: public SortedArray
{
public:
virtual ~Directory() {}
enum sortOrder { byName, byDate, bySize };
Directory( char *, sortOrder );
virtual classType isA() { return directoryClass; }
virtual char *nameOf() { return "Directory"; }
virtual hashValueType hashValue() { return 0; }
virtual void printHeader( ostream& ) const;
virtual void printSeparator( ostream& ) const;
virtual void printTrailer( ostream& ) const;
private:
void addFile( ffblk&, sortOrder );
String mask;
};
// Description -------------------------------------------------------------
//
// Defines a directory class. Class Directory is derived from the
// class SortedArray, which is part of the class library.
//
// Constructor
//
// Directory
//
// Constructs a directory object from the given name and sorting
// order.
//
// Destructor
//
// ~Directory
//
// Public Members
//
// sortOrder
//
// Enumerated order for sorting directories.
//
// isA
//
// Returns the class type of Directory.
//
// nameOf
//
// Returns a pointer to the character string "Directory."
//
// hashValue
//
// Returns a pre-defined hash value for a directory object.
//
// Private Members
//
// addFile
//
// Adds a file to the directory structure.
//
// End ---------------------------------------------------------------------
#endif // __DIRECTRY_H

Binary file not shown.

View File

@ -0,0 +1,223 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// FileData::FileData constructor
//
// Description
//
// Class FileData member function implementation.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __IOMANIP_H
#include <iomanip.h>
#define __IOMANIP_H
#endif
#ifndef __DIR_H
#include <dir.h>
#define __DIR_H
#endif
#ifndef __CSLTYPES_H
#include <clstypes.h>
#endif
#ifndef __FILEDATA_H
#include "filedata.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Constructor //
FileData::FileData( ffblk& blk ) :
fileName( blk.ff_name ),
fileDate( (blk.ff_fdate >> 5) & 0x000F,
blk.ff_fdate & 0x0001F,
(blk.ff_fdate >> 9) + 1980 ),
fileSize( blk.ff_fsize ),
fileTime( blk.ff_ftime >> 11,
(blk.ff_ftime >> 5) & 0x3F,
blk.ff_ftime & 0x1F )
// Summary -----------------------------------------------------------------
//
// Constructor for a file data object. Constructs the file name
// file data, and file size objects.
//
// Parameters
//
// blk
//
// The DOS file block structure we are to use to construct the
// file data object.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor //
// Member Function //
void FileData::printOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays the contents of a file data object on the given stream.
//
// Parameters
//
// outputStream
//
// The stream on which we are to display.
//
// End ---------------------------------------------------------------------
{
outputStream << setw( 14 ) << setiosflags( ios::left ) << fileName
<< setw( 18 ) << fileDate
<< setw( 17 ) << resetiosflags( ios::left ) << fileTime
<< setw( 10 ) << fileSize << " bytes";
}
// End Member Function printOn //
// Member Function //
int FilesByName::isEqual( const Object& testFile ) const
// Summary -----------------------------------------------------------------
//
// Determines whether two files are equal by comparing their names.
//
// Return Value
//
// Returns 1 if the files have the same name, 0 otherwise.
//
// End ---------------------------------------------------------------------
{
return fileName == ( (FilesByName&)testFile ).fileName;
}
// End Member Function FilesByName::isEqual //
// Member Function //
int FilesByName::isLessThan( const Object& testFile ) const
// Summary -----------------------------------------------------------------
//
// Determines the ordering of two files by comparing their names.
//
// Return Value
//
// Returns 1 if this file is less than the given file, 0 otherwise.
//
// End ---------------------------------------------------------------------
{
return fileName < ( (FilesByName&)testFile ).fileName;
}
// End Member Function FilesByName::isLessThan //
// Member Function //
int FilesByDate::isEqual( const Object& testFile ) const
// Summary -----------------------------------------------------------------
//
// Determines whether two files by are equal by comparing their dates.
//
// Return Value
//
// Returns 1 if the files have the same date, 0 otherwise.
//
// End ---------------------------------------------------------------------
{
return fileDate == ( (FilesByDate&)testFile ).fileDate &&
fileTime == ( (FilesByDate&)testFile ).fileTime;
}
// End Member Function FilesByDate::isEqual //
// Member Function //
int FilesByDate::isLessThan( const Object& testFile ) const
// Summary -----------------------------------------------------------------
//
// Determines the ordering of two files by comparing their names.
//
// Return Value
//
// Returns 1 if this file is less than the given file, 0 otherwise.
//
// End ---------------------------------------------------------------------
{
if( fileDate == ( (FilesByDate&)testFile ).fileDate )
return fileTime < ( (FilesByDate&)testFile ).fileTime;
else
return fileDate < ( (FilesByDate&)testFile ).fileDate;
}
// End Member Function FilesByDate::isLessThan //
// Member Function //
int FilesBySize::isEqual( const Object& testFile ) const
// Summary -----------------------------------------------------------------
//
// Determines the whether two files are equal by comparing their
// sizes.
//
// Return Value
//
// Returns 1 if this file is less than the given file, 0 otherwise.
//
// End ---------------------------------------------------------------------
{
return fileSize == ( (FilesBySize&)testFile ).fileSize;
}
// End Member Function FilesBySize::isEqual //
// Member Function //
int FilesBySize::isLessThan( const Object& testFile ) const
// Summary -----------------------------------------------------------------
//
// Determines the ordering of two files by comparing their sizes.
//
// Return Value
//
// Returns 1 if this file is less than the given file, 0 otherwise.
//
// End ---------------------------------------------------------------------
{
return fileSize < ( (FilesBySize&)testFile ).fileSize;
}
// End Member Function FilesBySize::isLessThan //

View File

@ -0,0 +1,310 @@
#ifndef __FILEDATA_H
#define __FILEDATA_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// fileDataClass
// filesByNameClass
// filesByDateClass
// filesBySizeClass
//
// FileData
//
// FilesByName
// FilesByName::isEqual
// FilesByName::isLessThan
//
// FilesByDate
// FilesByDate::isEqual
// FilesByDate::isLessThan
//
// FilesBySize
// FilesBySize::isEqual
// FilesBySize::isLessThan
//
// Description
//
// Defines file data classes. These classes are used by DIRECTRY.CPP,
// which is part of the directory listing example program for the
// Turbo C++ class library.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __DIR_H
#include <dir.h>
#define __DIR_H
#endif
#ifndef __CLSDEFS_H
#include <clsdefs.h>
#endif
#ifndef __SORTABLE_H
#include <sortable.h>
#endif
#ifndef __STRNG_H
#include <strng.h>
#endif
#ifndef __LDATE_H
#include <ldate.h>
#endif
#ifndef __LTIME_H
#include <ltime.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Macro //
// Summary -----------------------------------------------------------------
//
// Defines a values for the file classes. We start from the first
// available user class number. The class numbers are defined
// in CLSDEFS.H, in the class library INCLUDE directory.
//
// End ---------------------------------------------------------------------
#define fileDataClass __firstUserClass
#define filesByNameClass (fileDataClass+1)
#define filesByDateClass (filesByNameClass+1)
#define filesBySizeClass (filesByDateClass+1)
// Class //
class FileData: public Sortable
{
public:
FileData( ffblk& );
virtual classType isA() const { return fileDataClass; }
virtual char *nameOf() const { return "FileData"; }
virtual int isEqual( const Object& ) const = 0;
virtual int isLessThan( const Object& ) const = 0;
virtual hashValueType hashValue() const { return 0; }
virtual void printOn( ostream& ) const;
protected:
String fileName;
Date fileDate;
Time fileTime;
long fileSize;
};
// Description -------------------------------------------------------------
//
// Defines a base file class. Class FileData is derived from the
// class Sortable, which is part of the class library.
//
// Constructor
//
// FileData
//
// Constructs a FileData object from the DOS file block.
//
// Public Members
//
// isA
//
// Returns the class type of FileData.
//
// nameOf
//
// Returns a pointer to the character string "FileData."
//
// isEqual
//
// Determines whether two file data objects are equal.
// Redeclared as pure virtual.
//
// isLessThan
// Determines whether one file data object is less than another.
// Redeclared as pure virtual.
//
// hashValue
//
// Returns a pre-defined hash value for a FileData object.
//
// printOn
//
// Prints the contents of a file data object.
//
// End ---------------------------------------------------------------------
// Class //
class FilesByName: public FileData
{
public:
FilesByName( ffblk& blk ) : FileData( blk ) {}
virtual classType isA() const { return filesByNameClass; }
virtual char *nameOf() const { return "FilesByName"; }
virtual int isEqual( const Object& ) const;
virtual int isLessThan( const Object& ) const;
};
// Description -------------------------------------------------------------
//
// Defines a file class which is sorted by name. Class FilesByName
// is derived from the class FileData, which is a user-defined
// base class.
//
// Constructor
//
// FilesByName
//
// Constructs a FilesByName object from the DOS file block.
//
// Public Members
//
// isA
//
// Returns the class type of FilesByName.
//
// nameOf
//
// Returns a pointer to the character string "FilesByName."
//
// isEqual
//
// Determines whether two file data objects are equal.
//
// isLessThan
// Determines whether one file data object is less than another.
//
// Inherited Members
//
// hashValue
//
// Inherited from FileData.
//
// printOn
//
// Inherited from FileData.
//
// End ---------------------------------------------------------------------
// Class //
class FilesByDate: public FileData
{
public:
FilesByDate( ffblk& blk ) : FileData( blk ) {}
virtual classType isA() const { return filesByDateClass; }
virtual char *nameOf() const { return "FilesByDate"; }
virtual isEqual( const Object& ) const;
virtual isLessThan( const Object& ) const;
};
// Description -------------------------------------------------------------
//
// Defines a file class which is sorted by date. Class FilesByDate
// is derived from the class FileData, which is a user-defined
// base class.
//
// Constructor
//
// FilesByDate
//
// Constructs a FilesByDate object from the DOS file block.
//
// Public Members
//
// isA
//
// Returns the class type of FilesByDate.
//
// nameOf
//
// Returns a pointer to the character string "FilesByDate."
//
// isEqual
//
// Determines whether two file data objects are equal.
//
// isLessThan
// Determines whether one file data object is less than another.
//
// Inherited Members
//
// hashValue
//
// Inherited from FileData.
//
// printOn
//
// Inherited from FileData.
//
// End ---------------------------------------------------------------------
// Class //
class FilesBySize: public FileData
{
public:
FilesBySize( ffblk& blk ) : FileData( blk ) {}
virtual classType isA() const { return filesBySizeClass; }
virtual char *nameOf() const { return "FilesBySize"; }
virtual isEqual( const Object& ) const;
virtual isLessThan( const Object& ) const;
};
// Description -------------------------------------------------------------
//
// Defines a file class which is sorted by size. Class FilesBySize
// is derived from the class FileData, which is a user-defined
// base class.
//
// Constructor
//
// FilesBySize
//
// Constructs a FilesBySize object from the DOS file block.
//
// Public Members
//
// isA
//
// Returns the class type of FilesBySize.
//
// nameOf
//
// Returns a pointer to the character string "FilesBySize."
//
// isEqual
//
// Determines whether two file data objects are equal.
//
// isLessThan
// Determines whether one file data object is less than another.
//
// Inherited Members
//
// hashValue
//
// Inherited from FileData.
//
// printOn
//
// Inherited from FileData.
//
// End ---------------------------------------------------------------------
#endif // __FILEDATA_H //

View File

@ -0,0 +1,202 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// CLASSDEFINITIONS
// classNames
// classDefs
//
// main
//
// Description
//
// C++ class library example program. Creates a dictionary from
// the descriptions of each of the classes in the class Object
// hierarchy.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h> // stream i/o
#define __IOSTREAM_H
#endif
#ifndef __DICT_H
#include <dict.h> // class Dictionary
#endif
#ifndef __ASSOC_H
#include <assoc.h> // class Association
#endif
#ifndef __STRNG_H
#include <strng.h> // class String
#endif
// End Implementation Dependencies -------------------------------------------
// Macro //
#define CLASSDEFINITIONS 23
// Description -------------------------------------------------------------
//
// Defines the number of definitions in the dictionary.
//
// End ---------------------------------------------------------------------
// Variable //
static char *classNames[CLASSDEFINITIONS] =
{
"Object",
"Error",
"Sortable",
"Association",
"String",
"Container",
"Stack",
"Queue",
"Deque",
"Collection",
"HashTable",
"Bag",
"Set",
"Dictionary",
"AbstractArray",
"Array",
"SortedArray",
"List",
"DoubleList",
"ContainerIterator",
"ArrayIterator",
"ListIterator",
"DoubleListIterator"
};
// Description -------------------------------------------------------------
//
// Used by the main routine to create the dictionary.
//
// End ---------------------------------------------------------------------
// Variable //
static char *classDefs[CLASSDEFINITIONS] =
{
"The abstract base class of the hierarchy.\n",
"Used to indicate the presence of no object reference.\n",
"Used in ordered collections.\n",
"A key/value pair, used by the class Dictionary.\n",
"An example of an instance class, derived from class Sortable.\n",
"An abstract base class for all classes which contain other objects.\n",
"A LIFO container class.\n",
"A FIFO container class.\n",
"A double-ended container class, allowing both FIFO and LIFO access.\n",
"An abstract base class for classes which may be tested for membership.\n",
"A fast lookup implementation of a collection.\n",
"A collection class implemented by a hash table.\n",
"A collection in which there may be only one copy of each member.\n",
"A set of association object, with a lookup function.\n",
"An abstract base class for arrays.\n",
"A fixed or expandable array.\n",
"An array in which objects at successive indices are in order.\n",
"A collection class in which objects are linked together.\n",
"A collection of objects which are part of two lists.\n",
"A class which, when instantiated, is used to iterate over a collection.\n",
"An iterator which is used on array objects.\n",
"An iterator which is used on list objects.\n",
"An iterator which is used on double list objects.\n"
};
// Description -------------------------------------------------------------
//
// Used by the main routine to create the dictionary.
//
// End ---------------------------------------------------------------------
// Function //
int main( int argc, char *argv[] )
// Summary -----------------------------------------------------------------
//
// Dictionary example program. This program creates a dictionary
// and inserts strings into the dictionary, then looks up a given
// string.
//
// Parameters
//
// argc
//
// The number of arguments passed to our program from the command line.
//
// argv
//
// The array of character pointers which was given on the command line.
//
// Functional Description
//
// A dictionary object is a container class for association objects.
// An association is an object which keeps together a key and
// a value. In our example, both the key and the value will be
// String objects.
//
// We make a dictionary object on the heap, then add associations
// to the dictionary. When these associations have been added, we
// look up the given string in the dictionary and display its
// definition.
//
// End ---------------------------------------------------------------------
{
if ( argc != 2 )
{
cerr << "Usage: lookup classname\n";
return 1;
}
Dictionary& classDefinitions = *( new Dictionary );
for ( int i = 0; i < CLASSDEFINITIONS; i++ )
{
String& className = *( new String( classNames[i] ) );
String& classDef = *( new String( classDefs[i] ) );
Association& entry = *(new Association( className, classDef ) );
classDefinitions.add( entry );
} // end for all class definitions
Association& definition =
classDefinitions.lookup ( *(new String ( argv[1] ) ) );
if ( definition == NOOBJECT )
{
cout << "A definition for " << argv[1] << " was not found in the dictionary.\n";
}
else
{
cout << definition;
}
}
// End Function main //

Binary file not shown.

View File

@ -0,0 +1,108 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents -----------------------------------------------------------------
//
// main
//
// Description
//
// Contains a simple example program for class Queue.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
// None
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __DOS_H
#include <dos.h>
#define __DOS_H
#endif
#ifndef __STDLIB_H
#include <stdlib.h>
#define __STDLIB_H
#endif
#ifndef __LTIME_H
#include <ltime.h>
#endif
#ifndef __QUEUE_H
#include <queue.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Function //
int main()
// Summary -----------------------------------------------------------------
//
// Illustrates a use of the Queue class. Saves
// the current time in a queue, then waits for a random length of
// time before saving the current time in a queue. After 7 samplings
// have been entered in the queue, the queue is printed.
//
// Usage: queuetst
//
// Return Value
//
// noError
//
// Returns a 0 if no error occurs during execution, a 1 otherwise.
//
// End ---------------------------------------------------------------------
{
Queue timeLine;
cout << "\nSampling";
for ( int i = 0; i < 7; i++ )
{
struct time snapShot;
gettime( &snapShot );
Time sample( snapShot.ti_hour,
snapShot.ti_min,
snapShot.ti_sec,
snapShot.ti_hund );
timeLine.put ( *(new Time( sample )) );
cout << ".";
delay( rand() % 5000 );
}
cout << "\nThe timing samples are:\n\n";
while( !timeLine.isEmpty() )
{
Time& sampleTime = (Time&)timeLine.get();
cout << sampleTime << "\n";
delete &sampleTime;
} // end for all element in the queue.
return 0;
}
// End Function main //


Binary file not shown.

View File

@ -0,0 +1,94 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// main
//
// Description
//
// Contains a simple example program for class Stack.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
// None
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h> // stream i/o
#define __IOSTREAM_H
#endif
#ifndef __STACK_H
#include <stack.h> // Stack class.
#endif
#ifndef __STRNG_H
#include <strng.h> // String class. Note that this is not <string.h>!
#endif
// End Implementation Dependencies -------------------------------------------
// Function //
int main()
// Summary -----------------------------------------------------------------
//
// Illustrates a use of the Stack class. Reads in strings until
// you enter the string "reverse," then prints out the strings
// in reverse order. Returns the number of strings read in, not
// including "reverse."
//
// Usage: reverse
//
// End ---------------------------------------------------------------------
{
Stack theStack;
String reverse("reverse");
cout << "\nEnter some strings. Reverse will collect the strings\n";
cout << "for you until you enter the string \"reverse.\" Reverse\n";
cout << "will then print out the strings you have entered, but in\n";
cout << "reverse order. Begin entering strings now.\n";
for(;;)
{
char inputString[255];
cin >> inputString;
String& newString = *( new String( inputString ) );
if ( newString != reverse )
{
theStack.push( newString );
}
else // "reverse" was entered.
{
break;
}
} // end for loop until "reverse" is entered.
cout << "\nThe strings you entered (if any) are:\n";
while( !(theStack.isEmpty()) )
{
String oldString = (String&)theStack.pop();
cout << oldString << "\n";
}
return 0;
}
// End Function main //

Binary file not shown.

View File

@ -0,0 +1,100 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// main
//
// Description
//
// Contains a simple example program for class String.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
// None
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __STRNG_H
#include <strng.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Function //
int main( int argc, char *argv[] )
// Summary -----------------------------------------------------------------
//
// Illustrates a use of the String class. Displays the alphabetically
// last string out of the given command line and returns the position
// of that string.
//
// Usage: strngmax string1 [string2 ...]
//
// Parameters
//
// argc
//
// The number of arguments passed on the command line. There must
// be at least 1 argument other than the command name.
//
// argv
//
// A vector of character strings which are the arguments to the
// command line.
//
// Return Value
//
// maxPosition
//
// The position on the command line of the last string. Returns
// 1 if an error occurs.
//
// End ---------------------------------------------------------------------
{
if ( argc < 2 )
{
cerr << "Usage: strngmax string1 [string2 ...]\n";
return 1;
}
String theLargestString( argv[1] );
int maxPosition = 1;
int nextArg = 2;
while ( nextArg < argc )
{
String argListString ( argv[nextArg++] );
if ( argListString > theLargestString )
{
theLargestString = argListString;
maxPosition = nextArg - 1;
}
} // end while more arguments on the command line.
cout << theLargestString << "\n";
return maxPosition;
}
// End Function main //

Binary file not shown.

View File

@ -0,0 +1,133 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// main
//
// Description
//
// Directory listing program. Lists directories in the given sorting
// order.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
// None
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __STDLIB_H
#include <stdlib.h>
#define __STDLIB_H
#endif
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __DIRECTRY_H
#include "directry.h"
#endif
// End Implementation Dependencies -------------------------------------------
// Function //
int main( int argc, char *argv[] )
// Summary -----------------------------------------------------------------
//
// directry [options] template
//
// Displays a sorted listing of the given pathnames. The template
// may contain wildcard characters.
//
// options: One of the following
//
// -sn Sort by name
//
// -sd Sort by date
//
// -ss Sort by size
//
// Parameters
//
// argc
//
// The number of arguments passed on the command line. There must
// be at least 1 argument other than the command name.
//
// argv
//
// A vector of character strings which are the arguments to the
// command line.
//
// End ---------------------------------------------------------------------
{
if ( argc < 2 || argc > 3 )
{
cerr << "Usage: directry [options] template\n";
exit(1);
}
sortOrder sorting; // Defines the sorting order for the
// pathnames.
int path; // Defines the argument at which the
// pathname occurs.
if ( argc != 3 )
{
sorting = Directory::byName;
path = 1;
}
else // the optional sort argument was specified.
{
String sortArg( argv[1] );
String sortByName( "-sn" );
String sortByDate( "-sd" );
String sortBySize( "-ss" );
path = 2;
if ( sortArg == sortByName )
{
sorting = Directory::byName;
}
else if ( sortArg == sortByDate )
{
sorting = Directory::byDate;
}
else if ( sortArg == sortBySize )
{
sorting = Directory::bySize;
}
}
// Body Comment
//
// At this point, we will have established our sorting order.
// We now construct a directory list of the given sort order
// and display that list.
//
// End
Directory sortedDirectory( argv[path], sorting );
sortedDirectory.printContentsOn( cout );
}
// End Function main //

View File

@ -0,0 +1,322 @@
#ifndef __ABSTARRY_H
#define __ABSTARRY_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// AbstractArray
// AbstractArray::arraySize
//
// ArrayIterator
// ArrayIterator::ArrayIterator
//
// Description
//
// Defines the class AbstractArray. An array object implies
// indexability. Defines the class ArrayIterator.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __COLLECT_H
#include <collect.h>
#endif
// End Interface Dependencies ------------------------------------------------
class AbstractArray: public Collection
{
public:
AbstractArray( int upper, int lower = 0, sizeType aDelta = 0 );
virtual ~AbstractArray();
int lowerBound() const { return lowerbound; }
int upperBound() const { return upperbound; }
sizeType arraySize() const;
virtual ContainerIterator& initIterator() const;
virtual void add( Object& ) = 0;
void destroy( int i ) { detach( i, 1 ); }
void detach( int, int = 0 );
virtual void detach( const Object&, int = 0 );
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual int isEqual( const Object& ) const;
virtual hashValueType hashValue() const;
virtual void printContentsOn( ostream& ) const;
protected:
Object& objectAt( int i ) const
{ return *theArray[ i - lowerbound ]; }
void reallocate( sizeType );
sizeType delta;
int lowerbound;
int upperbound;
int whereToAdd;
Object **theArray;
friend class ArrayIterator;
};
// Description -------------------------------------------------------------
//
// Defines the class AbstractArray. The AbstractArray class is
// used as a base class for random-access and sorted arrays.
// The size of the array, i.e. the maximum number of elements
// which may be put into the array, is calculated from the bounds
// given at the construction of the array object.
//
// Constructor
//
// AbstractArray
//
// Constructor. Parameter upper specifies the upper bound for the
// index of the array. Parameter lower specifies a lower bound for
// the index of the array. Paramter aDelta specifies the number of
// array elements by which the array will grow if an element is added
// to an array which has no more space for elements. Specify aDelta = 0
// if the array should not be allowed to grow.
//
// Public Members
//
// lowerBound
//
// Returns the current lower bound of the array. The lower bound is
// fixed when the array is constructed.
//
// upperBound
//
// Returns the upper bound of the array. The upper bound is initially
// set when the array is constructed but may increase is more elements
// are added. The amount by which the upper bound will increase is
// a parameter to the constructor for the array.
//
// arraySize
//
// Returns the size of the array, in elements, as determined by the
// lower bound and the current upper bound.
//
// initIterator
//
// Array iterator initializer.
//
// add
//
// Pure virtual function.
//
// destroy
//
// Removes an object reference from the array at the given index and
// destroys the object.
//
// detach
//
// Removes all references to the object at the given index in the array.
// Does not delete the object. Use this function when the array elements
// are not owned by the array.
//
// detach
//
// Removes a reference to the given object from the array.
//
// hashValue
//
// Returns a pre-defined value as the hash value of an array.
//
// isEqual
//
// Determines whether two arrays are equal.
//
// printContentsOn
//
// Displays the non-ZERO elements of the array.
//
// Inherited Members
//
// hasMember
//
// Inherited from Collection
//
// isEmpty
//
// Inherited from Collection.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// printOn
//
// Inherited from Container.
//
// destroy
//
// Inherited from Collection.
//
// Protected Members
//
// objectAt
//
// Returns a reference to the object at the given index.
//
// reallocate
//
// Expands the pointer array to a new size.
//
// delta
//
// Defines the number of elements by which we are to expand the
// array, if needed.
//
// lowerbound
//
// Defines the smallest value for an index in this array.
//
// upperbound
//
// Defines the largest index in the array which, if referenced,
// will not cause an array expansion to take place.
//
// theArray
//
// Points to the area in which array element references are located.
//
// End ---------------------------------------------------------------------
// Member Function //
inline sizeType AbstractArray::arraySize() const
// Summary -----------------------------------------------------------------
//
// Returns the current size of the array.
//
// End ---------------------------------------------------------------------
{
return sizeType( upperbound - lowerbound + 1 );
}
// End Member Function AbstractArray::arraySize //
// Class //
class ArrayIterator: public ContainerIterator
{
public:
ArrayIterator( const AbstractArray& );
virtual ~ArrayIterator();
virtual operator int();
virtual operator Object&();
virtual Object& operator ++();
virtual void restart();
private:
int currentIndex;
const AbstractArray& beingIterated;
};
// Description -------------------------------------------------------------
//
// Defines the array iterator class. Upon initialization, we set up
// an internal pointer to our current position in the array. As
// the increment operator is called, we update this current position.
//
// Constructor
//
// ArrayIterator( const AbstractArray& )
//
// Constructor for an iterator. Note that this isn't a copy
// constructor, since it takes an object from a different class.
//
// Destructor
//
// ~ArrayIterator
//
// Public Members
//
// operator int
//
// We are allowed one cast operator to a predefined type. This
// operator defines an explicit or an implicit cast from a
// ArrayIterator to an integer.
//
// operator Object&
//
// Conversion to Object operator.
//
// operator ++
//
// The increment operator.
//
// restart
//
// Restarts an array iterator.
//
// Private Members
//
// currentIndex
//
// Maintains the position information for this iterator.
//
// beingIterated
//
// Maintains a pointer to the array being iterated.
//
// End ---------------------------------------------------------------------
// Constructor //
inline ArrayIterator::ArrayIterator( const AbstractArray& toIterate ) :
beingIterated( toIterate ), currentIndex( toIterate.lowerbound )
// Summary -----------------------------------------------------------------
//
// Constructor for a array iterator object.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor ArrayIterator::ArrayIterator //
#endif // ifndef __ABSTARRY_H //

View File

@ -0,0 +1,233 @@
#ifndef __ARRAY_H
#define __ARRAY_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Array
// Array::operator []
//
// Description
//
// Defines the class Array. An array object implies indexability.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __ABSTARRY_H
#include <abstarry.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Array: public AbstractArray
{
public:
Array( int upper, int lower = 0, sizeType aDelta = 0 ) :
AbstractArray( upper, lower, aDelta ) {}
virtual ~Array();
Object& operator []( int ) const;
virtual void add( Object& );
void addAt( Object&, int );
virtual classType isA() const;
virtual char *nameOf() const;
};
// Description -------------------------------------------------------------
//
// Defines the class Array. The Array class is made up of Objects
// which can be indexed with the given operator. The size of the
// array, i.e. the maximum number of elements which may be put
// into the array, is calculated from the bounds given at the
// construction of the array object.
//
// Constructor
//
// Array
//
// Constructor. Parameter upper specifies the upper bound for the
// index of the array. Parameter lower specifies a lower bound for
// the index of the array. Paramter aDelta specifies the number of
// array elements by which the array will grow if an element is added
// to an array which has no more space for elements. Specify aDelta = 0
// if the array should not be allowed to grow.
//
// Public Members
//
// operator []
//
// Subscript operator. Returns a reference to the element at the
// given index. The subscript operator will report an index out of
// bounds if the index is not in the current range.
//
// lowerBound
//
// Returns the current lower bound of the array. The lower bound is
// fixed when the array is constructed.
//
// upperBound
//
// Returns the upper bound of the array. The upper bound is initially
// set when the array is constructed but may increase is more elements
// are added. The amount by which the upper bound will increase is
// a parameter to the constructor for the array.
//
// arraySize
//
// Returns the size of the array, in elements, as determined by the
// lower bound and the current upper bound.
//
// addAt
//
// Places an object in the array of the specified idnex, growing the
// array as needed if the index exceeds the upper bound.
//
// destroy
//
// Removes an object reference from the array at the given index and
// destroys the object.
//
// detach
//
// Removes all references to the object at the given index in the array.
// Does not delete the object. Use this function when the array elements
// are not owned by the array.
//
// add
//
// Appends an object to the array, expanding the array if necessary.
// Overrides add member function inherited from Collection.
//
// destroy
//
// Destroys the given object.
//
// detach
//
// Removes a reference to the given object from the array.
//
// hashValue
//
// Returns a pre-defined value as the hash value of an array.
//
// isA
//
// Returns the class type of an array.
//
// nameOf
//
// Returns a pointer to the character string "Array."
//
// isEqual
//
// Determines whether two arrays are equal.
//
// Inherited Members
//
// hasMember
//
// Inherited from Collection
//
// isEmpty
//
// Inherited from Collection.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// printOn
//
// Inherited from Container.
//
// printHeader
//
// Inherited from Object.
//
// printTrailer
//
// Inherited from Object.
//
// printSeparator
//
// Inherited from Object.
//
// Protected Members
//
// delta
//
// Defines the number of elements by which we are to expand the
// array, if needed.
//
// lowerbound
//
// Defines the smallest value for an index in this array.
//
// upperbound
//
// Defines the largest index in the array which, if referenced,
// will not cause an array expansion to take place.
//
// theArray
//
// Points to the area in which array element references are located.
//
// End ---------------------------------------------------------------------
// Member Function //
inline Object& Array::operator []( int atIndex ) const
// Summary -----------------------------------------------------------------
//
// Subscript operator for arrays.
//
// Return Value
//
// objectAt
//
// Reference to the object at the given index.
//
// End ---------------------------------------------------------------------
{
return objectAt( atIndex );
}
#endif // ifndef __ARRAY_H //

View File

@ -0,0 +1,108 @@
#ifndef __ASSOC_H
#define __ASSOC_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Association
// Association::Association
// Association::Association copy constructor
//
// Description
//
// Defines the class Association, which is an object that can
// be stored in a Dictionary. An Association contains references
// to two Objects, a Key and a Value.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#define __CLSTYPES_H
#endif
#ifndef __OBJECT_H
#include <object.h>
#define __OBJECT_H
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Association : public Object
{
public:
Association( Object& k, Object& v ) : aKey( k ), aValue( v ) {}
Association( const Association& a ) :
aKey( a.key() ), aValue( a.value() ) {}
virtual ~Association();
Object& key() const { return aKey; }
Object& value() const { return aValue; }
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
virtual int isEqual( const Object& ) const;
virtual int isAssociation() const;
virtual void printOn( ostream& ) const;
private:
Object& aKey;
Object& aValue;
};
// Description -------------------------------------------------------------
//
// Defines an association class. An association keeps two objects
// together and treats them as a single object.
//
// Constructors
//
// Association( Object& k, Object& v )
//
// Constructor from two objects.
//
// Association( Association& a )
//
// Copy constructor.
//
// Public Members
//
// key
//
// Returns a reference to the key
//
// value
//
// Returns a reference to the value of the association.
//
// Private Members
//
// aKey
//
// aValue
//
// End ---------------------------------------------------------------------
#endif // ifndef __ASSOC_H //

View File

@ -0,0 +1,132 @@
#ifndef __BAG_H
#define __BAG_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Bag
// Bag::Bag
//
// Description
//
// Defines the class Bag. A bag is a collection of objects which
// can contain more than one of the same object.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include "clstypes.h"
#endif
#ifndef __RESOURCE_H
#include "resource.h"
#endif
#ifndef __OBJECT_H
#include "object.h"
#endif
#ifndef __HASHTBL_H
#include "hashtbl.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Bag: public HashTable
{
public:
Bag( sizeType bagSize = DEFAULT_BAG_SIZE ) : HashTable( bagSize ) {}
virtual ~Bag();
virtual classType isA() const;
virtual char *nameOf() const;
};
// Description -------------------------------------------------------------
//
// Defines the class Bag. A bag is a collection of objects which
// can contain more than one of the same object.
//
// Constructors
//
// Bag( sizeType )
//
// Constructs a bag of the given size.
//
// Public Members
//
// isA
//
// Inherited from Object.
//
// nameOf
//
// Inherited from Object.
//
// Inherited Members
//
// add
//
// Inherited from HashTable
//
// destroy
//
// Inherited from HashTable
//
// detach
//
// Inherited from HashTable
//
// hasMember
//
// Inherited from HashTable
//
// isEmpty
//
// Inherited from HashTable
//
// firstThat
//
// Inherited from HashTable
//
// lastThat
//
// Inherited from HashTable
//
// hashValue
//
// Inherited from Object.
//
// operator ==
//
// Inherited from Object.
//
// printOn
//
// Inherited from Object.
//
// End ---------------------------------------------------------------------
#endif // ifndef __BAG_H //

View File

@ -0,0 +1,78 @@
#ifndef __CLSDEFS_H
#define __CLSDEFS_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// ERROR_CLASS_HASH_VALUE
//
// __EEXPAND
// __ENOMEM
// __ENOTSORT
// __ENOTASSOC
//
// Description
//
// Definitions for the C++ class library.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __CLSTYPES_H
#include "clstypes.h"
#endif
// End Interface Dependencies ------------------------------------------------
// LiteralSection ----------------------------------------------------------
//
// hash values
//
// Description
//
// For some classes it doesn't make sense to use any particular hash
// function on an object of that class to get a hash value, so we
// provide some default ones instead. These are returned by member
// functions hashValue.
//
// End ---------------------------------------------------------------------
#define ERROR_CLASS_HASH_VALUE (hashValueType)0
// End LiteralSection hash values //
// LiteralSection ----------------------------------------------------------
//
// error codes
//
// Description
//
// Defines run time error codes generated by the class libraries.
//
// End ---------------------------------------------------------------------
#define __EEXPAND 2
#define __ENOMEM 3
#define __ENOTSORT 4
#define __ENOTASSOC 5
// End LiteralSection error codes //
#endif // ifndef __CLSDEFS_H //

View File

@ -0,0 +1,206 @@
#ifndef __CLSTYPES_H
#define __CLSTYPES_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Green Hills Road
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// classType
// hashValueType
// sizeType
// iterFuncType
// condFuncType
// countType
//
// objectClass
// errorClass
// sortableClass
// stringClass
// listElementClass
// doubleListElementClass
// containerClass
// stackClass
// queueClass
// dequeClass
// collectionClass
// hashTableClass
// bagClass
// setClass
// dictionaryClass
// associationClass
// arrayClass
// sortedArrayClass
// listClass
// doubleListClass
// timeClass
// dateClass
// longClass
//
// __lastLibClass
// __firstUserClass
//
// directoryClass
//
// __lastClass
//
// Description
//
// Defines types for the class library.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __LIMITS_H
#include <limits.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Section -----------------------------------------------------------------
// types //
// End ---------------------------------------------------------------------
// Type //
typedef unsigned int classType;
// Description -------------------------------------------------------------
//
// Defines the type of a class.
//
// End ---------------------------------------------------------------------
// Type //
typedef unsigned int hashValueType;
// Description -------------------------------------------------------------
//
// Defines a returned hash value.
//
// End ---------------------------------------------------------------------
// Type //
typedef unsigned int sizeType;
// Description -------------------------------------------------------------
//
// Defines the size of a storage area.
//
// End ---------------------------------------------------------------------
// Type //
class Object;
typedef void ( *iterFuncType )( class Object&, void * );
// Description -------------------------------------------------------------
//
// Defines a pointer to an iteration function. The iteration function
// takes an Object reference and a point to a list of parameters to
// the function. The parameter list pointer may be NULL.
//
// End ---------------------------------------------------------------------
// Type //
typedef int ( *condFuncType )( const class Object&, void * );
// Description -------------------------------------------------------------
//
// Defines a pointer to a function which implements a conditional test
// and returns 0 if the condition was met, non-zero otherwise. The
// non-zero values are defined by the individual function.
//
// End ---------------------------------------------------------------------
// End Section types //
// Type //
typedef int countType;
// Description -------------------------------------------------------------
//
// Defines a container for counting things in the class library.
//
// End ---------------------------------------------------------------------
// End Section types //
// Section -----------------------------------------------------------------
// defines //
// End ---------------------------------------------------------------------
// LiteralSection ----------------------------------------------------------
//
// class type codes
//
// Description
//
// Defines codes for the class types in the class library.
// The ranges for the codes and their use are defined below.
//
// 0 . . __lastLibClass: Reserved for class provided
// in the library.
// __firstUserClass . . __lastClass Available for general use.
//
// End ---------------------------------------------------------------------
#define objectClass 0
#define errorClass (objectClass+1)
#define sortableClass (errorClass+1)
#define stringClass (sortableClass+1)
#define listElementClass (stringClass+1)
#define doubleListElementClass (listElementClass+1)
#define containerClass (doubleListElementClass+1)
#define stackClass (containerClass+1)
#define queueClass (stackClass+1)
#define dequeClass (queueClass+1)
#define collectionClass (dequeClass+1)
#define hashTableClass (collectionClass+1)
#define bagClass (hashTableClass+1)
#define setClass (bagClass+1)
#define dictionaryClass (setClass+1)
#define associationClass (dictionaryClass+1)
#define arrayClass (associationClass+1)
#define sortedArrayClass (arrayClass+1)
#define listClass (sortedArrayClass+1)
#define doubleListClass (listClass+1)
#define timeClass (doubleListClass+1)
#define dateClass (timeClass+1)
#define longClass (dateClass+1)
#define __lastLibClass 255
#define __firstUserClass __lastLibClass+1
#define __lastClass UINT_MAX
// End LiteralSection class type codes //
// End Section defines //
#endif // ifndef __CLSTYPES_H //

View File

@ -0,0 +1,153 @@
#ifndef __COLLECT_H
#define __COLLECT_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Collection
//
// Description
//
// Defines the abstract class Collection. Collections group objects
// together and specify operations.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Collection: public Container
{
public:
virtual ~Collection();
virtual void add( Object& ) = 0;
virtual void detach( const Object&, int = 0 ) = 0;
virtual int hasMember( const Object& ) const;
virtual Object& findMember( const Object& ) const;
virtual ContainerIterator& initIterator() const = 0;
void destroy( const Object& o ) { detach( o, 1 ); }
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual hashValueType hashValue() const = 0;
};
// Description -------------------------------------------------------------
//
// Defines the abstract class Collection. A Collection is a
// grouping of objects on which addition and deletion of objects
// may occur. In addition, a Collection supports a membership test.
//
// Public Members
//
// add
//
// Adds an object to the collection.
//
// destroy
//
// Removes an object reference from the collection and
// destroys the object.
//
// detach
//
// Removes all references to the object in the collection.
// Does not delete the object. Use this function when the collection
// elements are not owned by the collection.
//
// hasMember
//
// Test whether an object is part of the collection. Returns 1 if
// the object reference is found in the array.
//
// findMember
//
// Test whether an object is part of the collection. Returns a
// reference to the object in the collection if the object is found.
//
// initIterator
//
// Iterator initializer. Redeclared as pure virtual.
//
// isA
//
// Redeclared as pure virtual.
//
// nameOf
//
// Redeclared as pure virtual.
//
// hashValue
//
// Redeclared as pure virtual.
//
// Inherited Members
//
// isEmpty
//
// Inherited from Container.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// printOn
//
// Inherited from Container.
//
// isEqual
//
// Inherited from Container.
//
// isSortable
//
// Inherited from Object.
//
// isAssociation
//
// Inherited from Object.
//
// End ---------------------------------------------------------------------
#endif // ifndef __COLLECT_H //

View File

@ -0,0 +1,220 @@
#ifndef __CONTAIN_H
#define __CONTAIN_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Container
// ContainerIterator
//
// Description
//
// Defines the abstract class Container. Containers operate
// on groups of other objects.
// Defines the ContainerIterator class. Container iterators are
// use to step through the objects in a container class without
// knowing the internals of the container class.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
// End Interface Dependencies ------------------------------------------------
// ForwardReference //
class ContainerIterator;
// Class //
class Container: public Object
{
public:
Container() { itemsInContainer = 0; }
Container( const Container& );
virtual ~Container();
virtual ContainerIterator& initIterator() const = 0;
virtual void forEach( iterFuncType, void * );
virtual Object& firstThat( condFuncType, void * ) const;
virtual Object& lastThat( condFuncType, void * ) const;
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual hashValueType hashValue() const = 0;
virtual int isEqual( const Object& ) const;
virtual void printOn( ostream& ) const;
virtual void printHeader( ostream& ) const;
virtual void printSeparator( ostream& ) const;
virtual void printTrailer( ostream& ) const;
int isEmpty() const { return (itemsInContainer == 0); }
countType getItemsInContainer() const { return itemsInContainer; }
protected:
countType itemsInContainer;
private:
friend class ContainerIterator;
};
// Description -------------------------------------------------------------
//
// Defines the abstract class Container. A Container is an object
// which groups some number of other objects together. This is
// an abstract class and provides no method for adding and
// removing objects from the container. Those functions are
// provided by derived classes.
//
// Constructor
//
// Container
//
// Copy constructor
//
// Public Members
//
// isEmpty
//
// Returns a 1 if the container has no members. Returns a 0
// otherwise.
//
// initIterator
//
// Initializes an iterator for this container.
//
// firstThat
//
// Returns the first object that satisfies the given condition.
//
// lastThat
//
// Returns the last object that satisfies the given condition.
//
// isA
//
// Inherited from Object and redeclared as pure virtual.
//
// hashValue
//
// Inherited from Object and redeclared as pure virtual.
//
// nameOf
//
// Inherited from Object and redeclared as pure virtual.
//
// isEqual
//
// A deep-comparison equality operator.
//
// getItemsInContainer
//
// Returns the current number of objects in any container.
//
// printOn
//
// Displays each of the objects which make up a container.
//
// printHeader
//
// Displays a standard header.
//
// printSeparator
//
// Displays a standard trailer.
//
// printTrailer
//
// Displays a standard trailer.
//
// Inherited Members
//
// operator new
//
// Inherited from Object.
//
// Protected Members
//
// itemsInContainer
//
// A count of the number of items in currently in the container.
//
// Private Members
//
// The class ContainerIterator is made a friend of class Object so that
// objects can be iterated without knowing the internals of each class.
//
// End ---------------------------------------------------------------------
// Class //
class ContainerIterator
{
public:
virtual ~ContainerIterator();
virtual operator int() = 0;
virtual operator Object&() = 0;
virtual Object& operator ++() = 0;
virtual void restart() = 0;
};
// Description -------------------------------------------------------------
//
// Defines a container iterator object.
//
// Destructor
//
// ~ContainerIterator
//
// Public Members
//
// operator int
//
// We are allowed one cast operator to a predefined type. This
// operator defines an explicit or an implicit cast from a
// ContainerIterator to an integer.
//
// operator Object&
//
// Conversion from ContainerIterator to Object.
//
// operator ++
//
// The increment operator.
//
// restart
//
// Restarts an iterator without destroying it.
//
// End ---------------------------------------------------------------------
#endif // ifndef __CONTAIN_H //

View File

@ -0,0 +1,378 @@
#ifndef __DBLLIST_H
#define __DBLLIST_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// DoubleList
// DoubleList::destroyFromHead
// DoubleList::destroyFromTail
//
// DoubleListIterator
// DoubleListIterator::DoubleListIterator constructor
//
// Description
//
// Defines the class DoubleList.
// Defines the class DoubleListIterator. A list iterator visits each
// of the items in a list.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __DLSTELEM_H
#include <dlstelem.h>
#endif
#ifndef __COLLECT_H
#include <collect.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class DoubleList: public Collection
{
public:
DoubleList() { head = tail = 0; }
virtual ~DoubleList();
Object& peekAtHead() const { return *(head->data); }
Object& peekAtTail() const { return *(tail->data); }
virtual void add( Object& );
virtual void detach( const Object&, int = 0 );
void addAtHead( Object& );
void addAtTail( Object& );
void destroyFromHead( const Object& );
void destroyFromTail( const Object& );
void detachFromHead( const Object&, int = 0 );
void detachFromTail( const Object&, int = 0 );
virtual ContainerIterator& initIterator() const;
ContainerIterator& initReverseIterator() const;
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
private:
DoubleListElement *head;
DoubleListElement *tail;
friend class DoubleListIterator;
};
// Description -------------------------------------------------------------
//
// Defines the container class DoubleList.
//
// Constructor
//
// DoubleList
//
// Default constructor
//
// Destructor
//
// ~DoubleList
//
// Public Members
//
// peekAtHead
//
// Returns a reference to the object at the head of the list.
//
// peekAtTail
//
// Returns a reference to the object at the tail of the list.
//
// add
//
// Adds an element to the list. By default, the element is
// added to the head of the list.
//
// addAtHead
//
// Adds an element at the head of the list.
//
// addAtTail
//
// Adds an element to the tail of the list.
//
// destroyFromHead
//
// Destroys the given element, searching forward from the head of the
// list.
//
// destroyFromTail
//
// Destroys the given element, searching forward from the head of the
// list.
//
// detach
//
// Detaches the given element. By default, the element is searched
// for from the head of the list.
//
// detachFromHead
//
// Detachs the given element, searching forward from the head of the
// list.
//
// detachFromTail
//
// Detachs the given element, searching forward from the head of the
// list.
//
// isA
//
// Returns the class type of class DoubleList.
//
// nameOf
//
// Returns a pointer to the character string "DoubleList."
//
// hashValue
//
// Inherited from Object.
//
// initIterator
//
// Initializes a double list iterator for a forward traversal of the
// list.
//
// initReverseIterator
//
// Initializes a double list iterator for a reverse traversal of the list.
//
// Inherited Members
//
// printOn
//
// Inherited from Container.
//
// isEqual
//
// Inherited from Container.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// isSortable
//
// Inherited from Object.
//
// isAssociation
//
// Inherited from Object.
//
// End ---------------------------------------------------------------------
// Member Function //
inline void DoubleList::destroyFromHead( const Object& toDestroy )
// Summary -----------------------------------------------------------------
//
// Destroys an object from the head of a double list. We remove
// the object from the list and call that object's destructor.
//
// Parameter
//
// toDestroy
//
// The object we are to search for and destroy from the DoubleList.
//
// Functional Description
//
// Inline wrap of detach which deleteObjectToo parameter set to 1.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't on the double list.
//
// End ---------------------------------------------------------------------
{
detachFromHead( toDestroy, 1 );
}
// End Member Function DoubleList::destroyFromHead //
// Member Function //
inline void DoubleList::destroyFromTail( const Object& toDestroy )
// Summary -----------------------------------------------------------------
//
// Destroys an object from the tail of a double list. We remove
// the object from the list and call that object's destructor.
//
// Parameter
//
// toDestroy
//
// The object we are to search for and destroy from the DoubleList.
//
// Functional Description
//
// Inline wrap of detach which deleteObjectToo parameter set to 1.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't on the double list.
//
// End ---------------------------------------------------------------------
{
detachFromTail( toDestroy, 1 );
}
// End Member Function DoubleList::destroyFromTail //
// Class //
class DoubleListIterator: public ContainerIterator
{
public:
DoubleListIterator( const DoubleList&, int = 1 );
virtual ~DoubleListIterator();
virtual operator int();
virtual operator Object&();
virtual Object& operator ++();
Object& operator --();
virtual void restart();
private:
DoubleListElement *currentElement;
DoubleListElement *startingElement;
};
// Description -------------------------------------------------------------
//
// Defines the double list iterator class. Upon initialization, we
// set up an internal pointer to our current position in the list. When
// an increment or decrement operator is called, we update this
// current position.
//
// Constructor
//
// DoubleListIterator( const DoubleList&, int = 1 )
//
// Constructor for an iterator. Note that this isn't a copy
// constructor, since it takes an object from a different class.
//
// Destructor
//
// ~DoubleListIterator
//
// Public Members
//
// operator int
//
// We are allowed one cast operator to a predefined type. This
// operator defines an explicit or an implicit cast from a
// DoubleListIterator to an integer.
//
// operator Object&
//
// Converts a double list iterator to an Object reference.
//
// operator ++
//
// The increment operator.
//
// operator --
//
// The decrement operator. This makes sense for double lists.
//
// restart
//
// DoubleList iterator restart mechanism.
//
// Private Members
//
// currentElement
//
// The current position in the iteration sequence.
//
// startingElement
//
// The starting position in the iteration sequence.
//
// End ---------------------------------------------------------------------
// Constructor //
inline DoubleListIterator::DoubleListIterator( const DoubleList& toIterate, int atHead )
// Summary -----------------------------------------------------------------
//
// Constructor for a list iterator object.
//
// Parameters
//
// toIterate
//
// The double list we are to iterate.
//
// atHead
//
// Indicates whether we are to start at the head of the list. If this is
// not 1, we will start at the tail.
//
// End ---------------------------------------------------------------------
{
if ( atHead == 1 )
{
startingElement = currentElement = toIterate.head;
}
else
{
startingElement = currentElement = toIterate.tail;
}
}
// End Constructor DoubleListIterator::DoubleListIterator //
#endif // ifndef __DBLLIST_H //

View File

@ -0,0 +1,186 @@
#ifndef __DEQUE_H
#define __DEQUE_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Deque
//
// Description
//
// Defines the class Deque.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __DBLLIST_H
#include <dbllist.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Deque: public Container
{
public:
virtual ~Deque();
Object& peekLeft() const { return theDeque.peekAtHead(); }
Object& peekRight() const { return theDeque.peekAtTail(); }
Object& getLeft();
Object& getRight();
void putLeft( Object& o )
{ theDeque.addAtHead( o ); itemsInContainer++; }
void putRight( Object& o )
{ theDeque.addAtTail( o ); itemsInContainer++; }
virtual ContainerIterator& initIterator() const;
ContainerIterator& initReverseIterator() const;
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
private:
DoubleList theDeque;
};
// Description -------------------------------------------------------------
//
// Defines the container class Deque. A deque is a double-ended queue.
// You may inspect, add, and remove elements at either end of the
// deque.
//
// Public Members
//
// peekLeft
//
// Returns a reference to the object at the left end of the deque.
// The object is still owned by the deque.
//
// peekRight
//
// Returns a reference to the object at the right end of the deque.
// The object is still owned by the deque.
//
// putLeft
//
// Enqueues an object at the left end.
//
// putRight
//
// Enqueues an object at the right end.
//
// getLeft
//
// Dequeues an object from the left end.
//
// getRight
//
// Dequeues an object from the right end.
//
// initIterator
//
// Left-to-right Deque iterator initializer.
//
// initReverseIterator
//
// Right-to-left Deque iterator initializer.
//
// isA
//
// Returns the class type for a deque.
//
// nameOf
//
// Returns a pointer to the character string "Deque."
//
// hashValue
//
// Returns a pre-defined value for deques.
//
// Inherited Members
//
// Deque( Deque& )
//
// Copy constructor. Inherited from Container.
//
// isEmpty
//
// Inherited from Container.
//
// isEqual
//
// Inherited from Container.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// getItemsInContainer
//
// Inherited from Container.
//
// printOn
//
// Inherited from Container.
//
// printHeader
//
// Inherited from Container.
//
// printSeparator
//
// Inherited from Container.
//
// printTrailer
//
// Inherited from Container.
//
// Private Members
//
// theDeque
//
// The implementation of the deque.
//
// End ---------------------------------------------------------------------
#endif // ifndef __DEQUE_H //

View File

@ -0,0 +1,159 @@
#ifndef __DICT_H
#define __DICT_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Dictionary
//
// Description
//
// Defines the class Dictionary. Dictionary holds a set of objects
// of type Association, which each contain a key and a value.
// Dictionary uses the key to look up the associated value.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __STDLIB_H
#include <stdlib.h>
#define __STDLIB_H
#endif
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __CLSDEFS_H
#include <clsdefs.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __ASSOC_H
#include <assoc.h>
#endif
#ifndef __SET_H
#include <set.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Dictionary : public Set
{
public:
Dictionary() {}
Dictionary( Dictionary& );
virtual ~Dictionary();
virtual void add( Object& );
Association& lookup( const Object& ) const;
virtual classType isA() const;
virtual char *nameOf() const;
};
// Description -------------------------------------------------------------
//
// Defines the class Dictionary. Dictionary holds a set of objects
// of type Association, which each contain a key and a value.
// Dictionary uses the key to look up the associated value.
//
// Constructor
//
// Dictionary
//
// Default constructor.
//
// Destructor
//
// ~Dictionary
//
// Public Members
//
// add
//
// Adds an object to the collection.
//
// lookup
//
// Converts an object to an association with no value, then finds
// that association in the dictionary.
//
// isA
//
// Returns the class type of dictionary.
//
// nameOf
//
// Returns a character pointer to the string "Dictionary."
//
// hashValue
//
// Inherited from Object.
//
// Inherited Members
//
// destroy
//
// Removes an object reference from the collection and
// destroys the object.
//
// detach
//
// Removes all references to the object in the collection.
// Does not delete the object. Use this function when the collection
// elements are not owned by the collection.
//
// lookup
//
// Inherited from HashTable.
//
// hasMember
//
// Test whether an object is part of the collection. Returns 1 if
// the object reference is found in the array.
//
// initIterator
//
// Inherited from HashTable.
//
// isEmpty
//
// Returns a 1 if the collection has no members. Returns a 0
// otherwise.
//
// firstThat
//
// Returns the first object that satisfies the given condition.
//
// lastThat
//
// Returns the last object that satisfies the given condition.
//
// End ---------------------------------------------------------------------
#endif // ifndef __DICT_H //

View File

@ -0,0 +1,102 @@
#ifndef _DLSTELEM_H
#define _DLSTELEM_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Green Hills Road
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// DoubleListElement
//
// Description
//
// Defines the class DoubleListElement. Objects of this class may
// be part of lists which can be traversed in forward and reverse
// order.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef _IOSTREAM_H
#include <iostream.h>
#define _IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class DoubleListElement
{
public:
DoubleListElement( Object *o ) { data = o; next = previous = 0; }
~DoubleListElement() { delete data; }
private:
DoubleListElement *next;
DoubleListElement *previous;
Object *data;
friend class DoubleList;
friend class DoubleListIterator;
};
// Description -------------------------------------------------------------
//
// Defines the abstract class DoubleListElement.
//
// Constructor
//
// DoubleListElement
//
// Constructor based on ListElement constructor which makes a
// list element from an object reference.
//
// Destructor
//
// ~DoubleListElement
//
// We delete the data.
//
//
// Private Members
//
// next
//
// The next double list element.
//
// previous
//
// The previous double list element.
//
// data
//
// Pointer to the double list element's data.
//
// Friends
//
// class DoubleList
//
// class DoubleListIterator
//
// End ---------------------------------------------------------------------
#endif // ifndef _DLSTELEM_H //

View File

@ -0,0 +1,322 @@
#ifndef __HASHTBL_H
#define __HASHTBL_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// HashTable
// HashTable::HashTable
// HashTable::getHashValue
//
// Description
//
// Defines the abstract class HashTable and associated inline
// functions. A hash table is a "container-container," that is,
// it contains a number of container objects.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __RESOURCE_H
#include <resource.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __COLLECT_H
#include <collect.h>
#endif
#ifndef __LIST_H
#include <list.h>
#endif
#ifndef __ARRAY_H
#include <array.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class HashTable: public Collection
{
public:
HashTable( sizeType = DEFAULT_HASH_TABLE_SIZE );
virtual ~HashTable();
virtual void add( Object& );
virtual void detach( const Object&, int = 0 );
virtual ContainerIterator& initIterator() const;
virtual Object& findMember( const Object& ) const;
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
private:
hashValueType getHashValue( const Object& ) const;
sizeType size;
Array table;
};
// Description -------------------------------------------------------------
//
// Defines the class HashTable.
//
// Constructors
//
// HashTable( sizeType )
//
// Constructs a hash table of the given size.
//
// Destructors
//
// ~HashTable()
//
// We provide the destructor for the sole purpose of forcing a call
// to the destructor for the private member objects of the class.
//
// Public Members
//
//
// initIterator
//
// Initializes an iterator for a hash table.
//
// add
//
// Adds an object to the hash table.
//
// destroy
//
// Removes an object reference from the hash table and
// destroys the object.
//
// detach
//
// Removes all references to the object in the hash table.
// Does not delete the object. Use this function when the hash table
// elements are not owned by the hash table.
//
// findMember
//
// Returns a reference to the object which is associated with the
// given key.
//
// hashValue
//
// Returns a pre-defined value for a hash table.
//
// isA
//
// Returns the class type of class HashTable.
//
// nameOf
//
// Returns a pointer to the character string "HashTable."
//
// Inherited Members
//
// hasMember
//
// Inherited from Collection.
//
// isEmpty
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// printOn
//
// Inherited from Container.
//
// Protected Members
//
// itemsInCollection
//
// Inherited from Container.
//
// Private Members
//
// getHashValue
//
// Private member function to return the hash value of an object.
//
// size
//
// Container for the size of the hash table.
//
// table
//
// An array of lists which implements the hash table.
//
// End ---------------------------------------------------------------------
// Constructor //
inline HashTable::HashTable( sizeType aPrime ) : size( aPrime ), table( aPrime )
// Summary -----------------------------------------------------------------
//
// Construct a hash table of the given size.
//
// Parameters
//
// aPrime
//
// The size of the hash table. To make the hashing algorithm work
// efficiently, you should make this a prime number.
//
// Functional Description
//
// We store the passed size and create an array object of that size.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor //
// Member Function //
inline sizeType HashTable::getHashValue( const Object& ofObject ) const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of the given object.
//
// Parameters
//
// ofObject
//
// The object we are to hash.
//
// Functional Description
//
// We ask the object to hash itself, then modulo that value by the
// size of our hash table.
//
// End ---------------------------------------------------------------------
{
return ofObject.hashValue() % size;
}
// End Member Function //
// Class //
class HashTableIterator: public ContainerIterator
{
public:
HashTableIterator( const Array& );
virtual operator int();
virtual Object& operator ++();
virtual operator Object&();
virtual void restart();
private:
int preIterate();
ArrayIterator *indexIterator;
ListIterator *listIterator;
const Array& beingIterated;
};
// Description -------------------------------------------------------------
//
// Defines the hash table iterator class. Upon initialization, we set up
// an internal pointer to our current position in the hash table. As
// the increment operator is called, we update this current position.
//
// Constructor
//
// HashTableIterator( const Array& )
//
// Constructor for an iterator. Note that this isn't a copy
// constructor, since it takes an object from a different class.
//
// Destructor
//
// ~HashTableIterator
//
// Public Members
//
// operator int
//
// We are allowed one cast operator to a predefined type. This
// operator defines an explicit or an implicit cast from a
// HashTableIterator to an integer.
//
// operator Object&
//
// Conversion operator from HashTableIterator to Object.
//
// operator ++
//
// The increment operator.
//
// restart
//
// Restarts an hash table iterator.
//
// Private Members
//
// preIterate
//
// Begins a step in the iteration.
//
// indexIterator
//
// Maintains the position information in the array for this iterator.
//
// listIterator
//
// Maintains the position information in the lists of the array
// for this iterator.
//
// beingIterated
//
// A reference to the array hash table which is being iterated. Used
// when restarting the iteration.
//
// End ---------------------------------------------------------------------
#endif // ifndef __HASHTBL_H //

View File

@ -0,0 +1,140 @@
#ifndef __LDATE_H
#define __LDATE_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// BaseDate
//
// Description
//
/* Provides BaseDate as an abstract base class for handling date */
/* storage and formatting */
//
/* Provides the Date class for storing dates and converting them */
/* to an ASCII string of the form */
/* */
/* January 1, 1990 */
//
// End ---------------------------------------------------------------------
#include <assert.h>
#include <dos.h>
#include "strng.h"
class BaseDate : public Sortable
{
public:
unsigned Month() const;
unsigned Day() const;
unsigned Year() const;
void SetMonth( unsigned char );
void SetDay( unsigned char );
void SetYear( unsigned );
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual hashValueType hashValue() const;
virtual int isEqual( const Object& ) const;
virtual int isLessThan( const Object& ) const;
virtual void printOn( ostream& ) const = 0;
protected:
BaseDate();
BaseDate( unsigned char, unsigned char, unsigned );
BaseDate( const BaseDate& );
~BaseDate();
private:
unsigned char MM;
unsigned char DD;
unsigned int YY;
};
inline BaseDate::BaseDate()
{
struct date d;
getdate( &d );
MM = d.da_mon - 1;
DD = d.da_day;
YY = d.da_year + 1980;
}
inline BaseDate::BaseDate( unsigned char M, unsigned char D, unsigned Y )
{
SetMonth( M );
SetDay( D );
SetYear( Y );
}
inline BaseDate::BaseDate( const BaseDate& B ) :
MM(B.MM), DD(B.DD), YY(B.YY)
{
}
inline unsigned BaseDate::Month() const
{
return MM;
}
inline unsigned BaseDate::Day() const
{
return DD;
}
inline unsigned BaseDate::Year() const
{
return YY;
}
inline void BaseDate::SetMonth( unsigned char M )
{
assert( M > 0 && M < 13 );
MM = M - 1;
}
inline void BaseDate::SetDay( unsigned char D )
{
assert( D < 32 );
DD = D;
}
inline void BaseDate::SetYear( unsigned Y )
{
YY = Y;
}
class Date : public BaseDate
{
public:
Date();
Date( unsigned char, unsigned char, unsigned );
Date( const Date& );
~Date();
virtual classType isA() const;
virtual char *nameOf() const;
virtual void printOn( ostream& ) const;
};
inline Date::Date()
{
}
inline Date::Date( unsigned char M, unsigned char D, unsigned Y ) : BaseDate( M, D, Y )
{
}
inline Date::Date( const Date& D ) : BaseDate( D )
{
}
#endif // ifndef __LDATE_H //

View File

@ -0,0 +1,262 @@
#ifndef __LIST_H
#define __LIST_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// List
//
// ListIterator
// ListIterator::ListIterator constructor
//
// Description
//
// Defines the class List. Lists are used to link other objects
// together.
// Defines the ListIterator class. A list iterator visits each
// of the items in a list.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __LSTELEM_H
#include <lstelem.h>
#endif
#ifndef __COLLECT_H
#include <collect.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class List: public Collection
{
public:
List() { head = 0; }
virtual ~List();
Object& peekHead() const { return *(head->data); }
void add( Object& );
void detach( const Object&, int = 0 );
void destroy( const Object& l ) { detach( l, 1 ); }
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
virtual ContainerIterator& initIterator() const;
private:
ListElement *head;
friend class ListIterator;
};
// Description -------------------------------------------------------------
//
// Defines the container class List.
//
// List objects, i.e. objects instantiated of classes derived from
// List, are used in sequences where insertions and deletions
// are defined. They operate soley on objects derived from
// class ListElement.
//
// Constructor
//
// List
//
// Constructor.
//
// Public Members
//
// peekHead
//
// Returns a reference to the object at the head of the list.
//
// add
//
// Adds an object to the list.
//
// destroy
//
// Detaches an object from the list and calls that object's destructor.
//
// detach
//
// Removes a reference to an object from the list.
//
// hasMember
//
// Determines whether the list has a given list element.
//
// isA
//
// Returns the class type of class list.
//
// nameOf
//
// Returns a pointer to the character string "List."
//
// hashValue
//
// Returns a pre-defined value for a list object.
//
// Inherited Members
//
// printOn
//
// Inherited from Container.
//
// isEmpty
//
// Inherited from Container.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// isEqual
//
// Inherited from Container.
//
// isSortable
//
// Inherited from Object.
//
// isAssociation
//
// Inherited from Object.
//
// Private Members
//
// head
//
// Maintains a pointer to the list element at the head of the list.
//
// End ---------------------------------------------------------------------
// Class //
class ListIterator: public ContainerIterator
{
public:
ListIterator( const List& );
virtual ~ListIterator();
virtual operator int();
virtual operator Object&();
virtual Object& operator ++();
virtual void restart();
private:
ListElement *currentElement;
ListElement *startingElement;
};
// Description -------------------------------------------------------------
//
// Defines the list iterator class. Upon initialization, we set up
// an internal pointer to our current position in the list. As
// the increment operator is called, we update this current position.
//
// Constructor
//
// ListIterator( const List& )
//
// Constructor for an iterator. Note that this isn't a copy
// constructor, since it takes an object from a different class.
//
// Destructor
//
// ~ListIterator
//
// Public Members
//
// operator int
//
// We are allowed one cast operator to a predefined type. This
// operator defines an explicit or an implicit cast from a
// ListIterator to an integer.
//
// operator Object&
//
// Conversion to Object reference operator.
//
// operator ++
//
// The increment operator.
//
// restart
//
// List iterator restart mechanism.
//
// Private Members
//
// currentElement
//
// The current position in the iteration sequence.
//
// startingElement
//
// The starting position in the iteration sequence.
//
// End ---------------------------------------------------------------------
// Constructor //
inline ListIterator::ListIterator( const List& toIterate )
// Summary -----------------------------------------------------------------
//
// Constructor for a list iterator object.
//
// End ---------------------------------------------------------------------
{
currentElement = toIterate.head;
}
// End Constructor ListIterator::ListIterator //
#endif // ifndef __LIST_H //

View File

@ -0,0 +1,91 @@
#ifndef __LSTELEM_H
#define __LSTELEM_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// ListElement
//
// Description
//
// Defines the class ListElement. ListElements are used in objects
// which link other objects together and nowhere else.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include "clstypes.h"
#endif
#ifndef __OBJECT_H
#include "object.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class ListElement
{
public:
ListElement( Object *o ) { data = o; next = 0; }
~ListElement() { delete data; }
private:
ListElement *next;
Object *data;
friend class List;
friend class ListIterator;
};
// Description -------------------------------------------------------------
//
// Defines the abstract class ListElement.
//
// ListElement objects, i.e. objects instantiated of classes derived from
// ListElement, are used in sequences where insertions and deletions
// are defined.
//
// Public Members
//
// none
//
// Private Members
//
// next
//
// Pointer to the next list element.
//
// data
//
// Pointer to the list element's data.
//
// Friends
//
// class List
//
// The class which uses class ListElement, class List, is declared
// as a friend.
//
// End ---------------------------------------------------------------------
#endif // ifndef __LSTELEM_H //

View File

@ -0,0 +1,483 @@
#ifndef __LTIME_H
#define __LTIME_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// BaseTime
// BaseTime::BaseTime default constructor
// BaseTime::BaseTime copy constructor
// BaseTime::BaseTime constructor
// BaseTime::hour
// BaseTime::minute
// BaseTime::second
// BaseTime::hundreths
//
// BaseTime::setHour
// BaseTime::setMinute
// BaseTime::setSecond
// BaseTime::setHundreths
//
// Time
// Time::Time default constructor
// Time::Time copy constructor
// Time::Time constructor
//
// Description
//
// Provides the class BaseTime as an abstract base class for
// storing and formatting times.
// times.
//
// Provides the Time class for storing times and converting them
// to ASCII strings of the form "1:23:45.67 pm"
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __ASSERT_H
#include <assert.h>
#define __ASSERT_H
#endif
#ifndef __DOS_H
#include <dos.h>
#define __DOS_H
#endif
#ifndef __STRNG_H
#include <strng.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class BaseTime : public Sortable
{
public:
unsigned hour() const;
unsigned minute() const;
unsigned second() const;
unsigned hundredths() const;
void setHour( unsigned char );
void setMinute( unsigned char );
void setSecond( unsigned char );
void setHundredths( unsigned char );
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual hashValueType hashValue() const;
virtual int isEqual( const Object& ) const;
virtual int isLessThan( const Object& ) const;
virtual void printOn( ostream& ) const = 0;
protected:
BaseTime();
BaseTime( const BaseTime& );
BaseTime( unsigned char, unsigned char = 0, unsigned char = 0, unsigned char = 0 );
private:
unsigned char HH;
unsigned char MM;
unsigned char SS;
unsigned char HD;
};
// Description -------------------------------------------------------------
//
// Defines a base time class. This class provides a starting place
// for deriving usuable time classes.
//
// Constructors
//
// BaseTime()
//
// Default constructor
//
// BaseTime( BaseTime& )
//
// Copy constructor
//
// BaseTime( H, . . . )
//
// Constructs a base time object from a parameter list.
//
// Public Members
//
// hour
//
// Returns the hour portion of the base time object.
//
// minute
//
// Returns the hour portion of the base time object.
//
// second
//
// Returns the second portion of the base time object.
//
// hundreths
//
// Returns the hundreths portion of the base time object.
//
// setHour
//
// Sets the hour portion of the base time object.
//
// setMinute
//
// Sets the minute portion of the base time object.
//
// setHundreths
//
// Sets the hundreths portion of the base time object.
//
// operator String()
//
// Conversion operator to type string.
//
// Private Members
//
// HH
//
// The hour portion of the base time object.
//
// MM
//
// The minute portion of the base time object.
//
// SS
//
// The second portion of the base time object.
//
// HD
//
// The hundreths portion of the base time object.
//
// End ---------------------------------------------------------------------
// Constructor //
inline BaseTime::BaseTime()
// Summary -----------------------------------------------------------------
//
// Default constructor. Constructs a base time object.
//
// End ---------------------------------------------------------------------
{
struct time t; // From dos.h
gettime( &t );
HH = t.ti_hour;
MM = t.ti_min;
SS = t.ti_sec;
HD = t.ti_hund;
}
// End Constructor BaseTime::BaseTime //
// Constructor //
inline BaseTime::BaseTime( const BaseTime& B ) :
HH(B.HH), MM(B.MM), SS(B.SS), HD(B.HD)
// Summary -----------------------------------------------------------------
//
// Copy constructor. Constructs a base time object from another
// base time object.
//
// Functional Description
//
// We initialized each of the private data members of the class in
// the prototype, hence the function body is null.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor BaseTime::BaseTime //
// Constructor //
inline BaseTime::BaseTime( unsigned char H, unsigned char M, unsigned char S, unsigned char D )
// Summary -----------------------------------------------------------------
//
// Constructor. Constructs a base time object from the given
// parameters.
//
// End ---------------------------------------------------------------------
{
setHour( H );
setMinute( M );
setSecond( S );
setHundredths( D );
}
// End Constructor BaseTime::BaseTime //
// Member Function //
inline unsigned BaseTime::hour() const
// Summary -----------------------------------------------------------------
//
// Returns the hours portion of a base time object.
//
// End ---------------------------------------------------------------------
{
return HH;
}
// End Member Function BaseTime::hour //
// Member Function //
inline unsigned BaseTime::minute() const
// Summary -----------------------------------------------------------------
//
// Returns the minutes portion of a base time object.
//
// End ---------------------------------------------------------------------
{
return MM;
}
// End Member Function BaseTime::minute //
// Member Function //
inline unsigned BaseTime::second() const
// Summary -----------------------------------------------------------------
//
// Returns the seconds portion of a base time object.
//
// End ---------------------------------------------------------------------
{
return SS;
}
// End Member Function BaseTime::second //
// Member Function //
inline unsigned BaseTime::hundredths() const
// Summary -----------------------------------------------------------------
//
// Returns the hundreths portion of a base time object.
//
// End ---------------------------------------------------------------------
{
return HD;
}
// End Member Function BaseTime::hundreths //
// Member Function //
inline void BaseTime::setHour( unsigned char anHour )
// Summary -----------------------------------------------------------------
//
// Sets the hour portion of a base time object.
//
// End ---------------------------------------------------------------------
{
assert( anHour < 24 );
HH = anHour;
}
// End Member Function BaseTime::setHour //
// Member Function //
inline void BaseTime::setMinute( unsigned char M )
// Summary -----------------------------------------------------------------
//
// Sets the minute portion of a base time object.
//
// End ---------------------------------------------------------------------
{
assert( M < 60 );
MM = M;
}
// End Member Function BaseTime::setMinute //
// Member Function //
inline void BaseTime::setSecond( unsigned char S )
// Summary -----------------------------------------------------------------
//
// Sets the second portion of a base time object.
//
// End ---------------------------------------------------------------------
{
assert( S < 60 );
SS = S;
}
// End Member Function BaseTime::setSecond //
// Member Function //
inline void BaseTime::setHundredths( unsigned char D )
// Summary -----------------------------------------------------------------
//
// Sets the hunderths portion of a base time object.
//
// End ---------------------------------------------------------------------
{
assert( D < 100 );
HD = D;
}
// End Member Function BaseTime::setHundreths //
// Class //
class Time: public BaseTime
{
public:
Time();
Time( const Time& );
Time( unsigned char, unsigned char = 0, unsigned char = 0,
unsigned char = 0 );
virtual classType isA() const;
virtual char *nameOf() const;
virtual void printOn( ostream& ) const;
};
// Description -------------------------------------------------------------
//
// Defines a usable time class.
//
// Constructors
//
// Time()
//
// Default constructor
//
// Time( Time& )
//
// Copy constructor
//
// Time( H, . . . )
//
// Constructs a time object from a parameter list.
//
// Public Members
//
// operator String()
//
// Conversion operator to type string.
//
// Inherited Members
//
// hour
//
// Inherited from BaseTime
//
// minute
//
// Inherited from BaseTime
//
// second
//
// Inherited from BaseTime
//
// hundreths
//
// Inherited from BaseTime
//
// setHour
//
// Inherited from BaseTime
//
// setMinute
//
// Inherited from BaseTime
//
// setHundreths
//
// Inherited from BaseTime
//
// End ---------------------------------------------------------------------
// Constructor //
inline Time::Time() : BaseTime()
// Summary -----------------------------------------------------------------
//
// Default constructor.
//
// Functional Description
//
// We construct the Time object using the constructor for BaseTime,
// hence the body of the constructor is null.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor Time::Time //
// Constructor //
inline Time::Time( const Time& T ) : BaseTime( T )
// Summary -----------------------------------------------------------------
//
// Copy constructor.
//
// Functional Description
//
// We construct the Time object using the constructor for BaseTime,
// hence the body of the constructor is null.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor Time::Time //
// Constructor //
inline Time::Time( unsigned char H, unsigned char M, unsigned char S,
unsigned char D ) : BaseTime( H, M, S, D )
// Summary -----------------------------------------------------------------
//
// Constructor from parameter list.
//
// Functional Description
//
// We construct the Time object using the constructor for BaseTime,
// hence the body of the constructor is null.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor Time::Time //
#endif // ifndef __LTIME_H //

View File

@ -0,0 +1,355 @@
#ifndef __OBJECT_H
#define __OBJECT_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Object
// NOOBJECT
// Object::Object constructor
// Object::Object copy constructor
//
// Error
//
// operator <<
// operator ==
// operator !=
//
// Description
//
// Defines the abstract base class Object. Object is the class
// at the root of the class library hierarchy. Also defines the
// instance class Error, which is used to indicate the presence of
// no object reference.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __STDDEF_H
#include <stddef.h>
#define __STDDEF_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __CLSDEFS_H
#include <clsdefs.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Object
{
public:
Object();
Object( Object& );
virtual ~Object();
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual hashValueType hashValue() const = 0;
virtual int isEqual( const Object& ) const = 0;
virtual int isSortable() const;
virtual int isAssociation() const;
void *operator new( size_t s );
virtual void forEach( iterFuncType, void * );
virtual Object& firstThat( condFuncType, void * ) const;
virtual Object& lastThat( condFuncType, void * ) const;
virtual void printOn( ostream& ) const = 0;
static Object *ZERO;
protected:
friend ostream& operator <<( ostream&, const Object& );
};
// Description -------------------------------------------------------------
//
// Defines the abstract base class Object. Object is the root of the
// hierarchy, as most classes within the hierarchy are derived from it.
// To create an class as part of this hierarchy, derive that class
// from Object and provide the required functions. You may then
// use the derived class anywhere Object is called for.
//
// Constructors
//
// Object()
//
// Vanilla constructor. Forces each derived class to provide one,
// even if it's one that the compiler has to generate.
//
// Object( Object& )
//
// Copy constructor. Constructs an object, then copies the contents
// of the given object onto the new object.
//
// Destructors
//
// ~Object
//
// Run-of-the-mill destructor. Turns out to be a useful place to set
// breakpoints sometimes.
//
// Public Members
//
// isA
//
// Returns an unique identifying quantity of type classType. You may
// test this quantity to make sure that the object is of the class
// desired.
//
// nameOf
//
// Returns a pointer to the character string which is the class name.
//
// hashValue
//
// Returns a unique key based on the value of an object. The method
// used in obtaining the key depends upon the implementation of the
// function for each class.
//
// isEqual
//
// Returns 1 if the objects are the same type and the elements of the
// object are equal, 0 otherwise.
//
// operator new
//
// Returns ZERO if the allocation of a new object fails.
//
// forEach
//
// Performs a function on each of the subobjects in an object. If
// an object has no subobject, forEach operates on that object.
//
// firstThat
//
// Returns a reference to the first object for which the given
// conditional function returns a 1. For object of non-container
// classes, this will always be a reference to the object.
//
// lastThat
//
// Returns a reference to the last object for which the given
// conditional function returns a 1. For object of non-container
// classes, this will always be a reference to the object.
//
// ZERO
//
// A reference to an error object. Note that this differs from a
// reference to a null object. This is used by the Error class
// to handle problems when the operator new cannot allocate space
// for an object.
//
// printOn
//
// Displays the contents of an object. The format of the output
// is dictated by the implementation of the printOn function for
// each class.
//
// Remarks
//
// Friends:
// The operator << is overloaded and made of friend of the class Object
// so that invocations of << may call the protected member function,
// printOn.
//
// End ---------------------------------------------------------------------
// Macro //
#define NOOBJECT *(Object::ZERO)
// Summary -----------------------------------------------------------------
//
// Provides an easy reference to theErrorObject
//
// End ---------------------------------------------------------------------
// Constructor //
inline Object::Object()
// Summary -----------------------------------------------------------------
//
// Default constructor for an object. Not useful for much, but it
// does provide a good place for setting breakpoints, because every
// time an object gets created, this function must be called.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor Object::Object //
// Constructor //
inline Object::Object( Object& )
// Summary -----------------------------------------------------------------
//
// Copy constructor for an object. Again, not useful for much except
// breakpoints. This function will be called every time one object
// is copied to another.
//
// End ---------------------------------------------------------------------
{
}
// End Constructor Object::Object //
// Class //
class Error: private Object
{
public:
virtual ~Error();
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
virtual int isEqual( const Object& ) const;
virtual void printOn( ostream& ) const;
void operator delete( void * );
};
// Description -------------------------------------------------------------
//
// Defines the class Error. The is exactly one instantiation of
// class Error, namely theErrorObject. The static object pointer
// Object::ZERO points to this object. The define NOOBJECT
// redefines Object::ZERO (see CLSDEFS.H). The operator Object::new
// returns a pointer to theErrorObject if an attempt to allocate
// an object fails. You may test the return value of the new
// operator against NOOBJECT to see whether the allocation failed.
//
// Public Members
//
// isA
//
// Returns the correct value for the Error class.
//
// nameOf
//
// Returns a pointer to the character string "Error".
//
// hashValue
//
// Returns a pre-defined value for the Error class. All objects
// of class Error (there is usually only one, theErrorObject) have
// the same hash value. This makes them hard to distinguish from
// each other, but since there's only one, it doesn't matter.
//
// isEqual
//
// Determines whether the given object is theErrorObject.
//
// printOn
//
// Overrides the default printOn function since the Error class is
// an instance class.
//
// End ---------------------------------------------------------------------
// Friend //
inline ostream& operator <<( ostream& outputStream, const Object& anObject )
// Summary -----------------------------------------------------------------
//
// Write an object value to an output stream.
//
// Parameters
//
// outputStream
// The stream on which to display the formatted contents of the object.
//
// anObject
// The object to display.
//
// End ---------------------------------------------------------------------
{
anObject.printOn( outputStream );
return outputStream;
}
// End Friend operator << //
// Function //
inline int operator ==( const Object& test1, const Object& test2 )
// Summary -----------------------------------------------------------------
//
// Determines whether the first object is equal to the second. We
// do type checking on the two objects (objects of different
// classes can't be equal, even if they're derived from each other).
//
// Parameters
//
// test1
//
// The first object we are testing.
//
// test2
//
// The second object we are testing.
//
// End ---------------------------------------------------------------------
{
return ( (test1.isA() == test2.isA()) && test1.isEqual( test2 ) );
}
// End Function operator == //
// Function //
inline int operator !=( const Object& test1, const Object& test2 )
// Summary -----------------------------------------------------------------
//
// Determines whether the given object is not equal to this. We
// just reverse the condition returned from operator ==.
//
// Parameters
//
// test1
//
// The first object we are testing.
//
// test2
//
// The second object we are testing.
//
// End ---------------------------------------------------------------------
{
return ( !( test1 == test2 ) );
}
// End Function operator != //
#endif // ifndef __OBJECT_H //

View File

@ -0,0 +1,175 @@
#ifndef __QUEUE_H
#define __QUEUE_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Queue
//
// Description
//
// Defines the class Queue.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include "clstypes.h"
#endif
#ifndef __OBJECT_H
#include "object.h"
#endif
#ifndef __CONTAIN_H
#include "contain.h"
#endif
#ifndef __DBLLIST_H
#include "dbllist.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Queue: public Container
{
public:
virtual ~Queue();
Object& peekLeft() const { return theQueue.peekAtHead(); }
Object& peekRight() const { return theQueue.peekAtTail(); }
Object& get();
void put( Object& o ) { theQueue.addAtHead( o ); itemsInContainer++; }
virtual ContainerIterator& initIterator() const;
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
private:
DoubleList theQueue;
};
// Description -------------------------------------------------------------
//
// Defines the container class Queue. A queue is a FIFO object.
// You may inspect elements at either end of the queue, however,
// you may only remove objects at one end and add objects at the
// other. The left end is the end at which objects are enqueued.
// The right end is where objects may be retrieved.
//
// Public Members
//
// peekLeft
//
// Returns a reference to the object at the left end of the queue.
// The object is still owned by the queue.
//
// peekRight
//
// Returns a reference to the object at the right end of the queue.
// The object is still owned by the queue.
//
// put
//
// Enqueues an object.
//
// get
//
// Dequeues an object.
//
// initIterator
//
// Left-to-right Queue iterator initializer.
//
// isA
//
// Returns the class type for a queue.
//
// nameOf
//
// Returns a pointer to the character string "Queue."
//
// hashValue
//
// Returns a pre-defined value for queues.
//
// Inherited Members
//
// Queue( Queue& )
//
// Copy constructor. Inherited from Container.
//
// isEmpty
//
// Inherited from Container.
//
// operator ==
//
// Inherited from Container.
//
// forEach
//
// Inherited from Container.
//
// firstThat
//
// Inherited from Container.
//
// lastThat
//
// Inherited from Container.
//
// getItemsInContainer
//
// Inherited from Container.
//
// itemsInContainer
//
// Inherited from Container.
//
// printOn
//
// Inherited from Container.
//
// printHeader
//
// Inherited from Container.
//
// printSeparator
//
// Inherited from Container.
//
// printTrailer
//
// Inherited from Container.
//
// Private Members
//
// theQueue
//
// The implementation of the queue.
//
// End ---------------------------------------------------------------------
#endif // ifndef __QUEUE_H //

View File

@ -0,0 +1,102 @@
#ifndef __RESOURCE_H
#define __RESOURCE_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// DESIGN_LIMIT_ON_DEFAULT_HASH_TABLE_SIZE
// DEFAULT_HASH_TABLE_SIZE
//
// DESIGN_LIMIT_ON_DEFAULT_BAG_SIZE
// DEFAULT_BAG_SIZE
//
// DESIGN_LIMIT_ON_DEFAULT_SET_SIZE
// DEFAULT_SET_SIZE
//
// Description
//
// Defines resource constants for C++ class library.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __LIMITS_H
#include <limits.h>
#define __LIMITS_H
#endif
// End Interface Dependencies ------------------------------------------------
// LiteralSection ----------------------------------------------------------
//
// hash table size
//
// Description
//
// Defines the limit on a hash table's size and the default size.
// Also defines limits and defaults for derived types of class HashTable.
//
// End ---------------------------------------------------------------------
#define DESIGN_LIMIT_ON_DEFAULT_HASH_TABLE_SIZE UINT_MAX
//
// The hash table size is defined as a sizeType, which is an
// unsigned int.
//
#define DEFAULT_HASH_TABLE_SIZE 111
//
// We make a fair size default hash table. If you care to change
// the default size, you may do so without harm, as long as your
// default value does not exceed the design limit on the maximum
// size for a hash table. Keep in mind that a hash table is more
// efficient if the size is a prime number.
//
#define DESIGN_LIMIT_ON_DEFAULT_BAG_SIZE (\
DESIGN_LIMIT_ON_DEFAULT_HASH_TABLE_SIZE \
)
//
// Class Bag is derived from class HashTable and therefore gets the
// same design limit.
//
#define DEFAULT_BAG_SIZE 29
//
// Bags are usually smaller than hash tables. Of course, if this
// were a grocery bag, the default would be much smaller.
//
#define DESIGN_LIMIT_ON_DEFAULT_SET_SIZE (\
DESIGN_LIMIT_ON_DEFAULT_BAG_SIZE \
)
//
// Class Set is derived from class Bag and therefore gets the
// same design limit.
//
#define DEFAULT_SET_SIZE 29
//
// Bags and sets are usually the same size.
//
// End LiteralSection hash table size //
#endif // ifndef __RESOURCE_H //

View File

@ -0,0 +1,127 @@
#ifndef __SET_H
#define __SET_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Set
// Set::Set constructor
// Set::add
//
// Description
//
// Defines the abstract class Set.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include "clstypes.h"
#endif
#ifndef __RESOURCE_H
#include "resource.h"
#endif
#ifndef __OBJECT_H
#include "object.h"
#endif
#ifndef __BAG_H
#include "bag.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Set: public Bag
{
public:
Set( sizeType setSize = DEFAULT_SET_SIZE ) : Bag( setSize ) {}
virtual ~Set();
virtual void add( Object& );
virtual classType isA() const;
virtual char *nameOf() const;
};
// Description -------------------------------------------------------------
//
// Defines the class Set.
//
// Public Members
//
// isA
//
// Inherited from Object.
//
// nameOf
//
// Inherited from Object.
//
// Inherited Members
//
// add
//
// Inherited from HashTable
//
// destroy
//
// Inherited from HashTable
//
// detach
//
// Inherited from HashTable
//
// hasMember
//
// Inherited from HashTable
//
// isEmpty
//
// Inherited from HashTable
//
// firstThat
//
// Inherited from HashTable
//
// lastThat
//
// Inherited from HashTable
//
// hashValue
//
// Inherited from Object.
//
// operator ==
//
// Inherited from Object.
//
// printOn
//
// Inherited from Object.
//
// End ---------------------------------------------------------------------
#endif // ifndef __SET_H //

View File

@ -0,0 +1,252 @@
#ifndef _SORTABLE_H
#define _SORTABLE_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Sortable
// operator >
// operator >=
// operator <=
//
// Description
//
// Defines the abstract class Sortable and inline member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include "clstypes.h"
#endif
#ifndef __OBJECT_H
#include "object.h"
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Sortable: public Object
{
public:
virtual ~Sortable();
virtual int isEqual( const Object& ) const = 0;
virtual int isLessThan( const Object& ) const = 0;
virtual int isSortable() const;
virtual classType isA() const = 0;
virtual char *nameOf() const = 0;
virtual hashValueType hashValue() const = 0;
protected:
virtual void printOn( ostream& ) const = 0;
};
// Description -------------------------------------------------------------
//
// Defines the abstract class Sortable. Sortable implies that ordering
// operations can be performed up pairs of Sortable objects. The
// relational operations depend upon the implementation of the
// classes derived from the class Sortable.
//
// Sortable objects, i.e. objects instantiated of classes derived from
// Sortable, are used in ordered collections.
//
// Public Members
//
// isEqual
//
// Returns 1 if two objects are equivalent, 0 otherwise.
// Determines equivalence by comparing the contents of the two objects.
// Perpetuates the pure virtual function inherited from Object.
//
// operator <
//
// Returns 1 if this is less than a test object.
//
// operator >
//
// Returns 1 if this is greater than a test object.
//
// operator <=
//
// Returns 1 if this is less than or equal to a test object.
//
// operator >=
//
// Returns 1 if this is greater than or equal to a test object.
//
// isA()
//
// Inherited from Object and redeclared as a pure virtual function.
//
// nameOf
//
// Inherited from Object and redeclared as a pure virtual function.
//
// hashValue
//
// Inherited from Object and redeclared as a pure virtual function.
//
// Inherited Members
//
// operator new
//
// Inherited from Object.
//
// operator !=
//
// Inherited from Object.
//
// forEach
//
// Inherited from Object.
//
// firstThat
//
// Inherited from Object.
//
// lastThat
//
// Inherited from Object.
//
// Protected Members
//
// printOn
//
// Inherited from Object a redeclared as a pure virtual function.
//
// End ---------------------------------------------------------------------
int operator < ( const Sortable&, const Sortable& );
int operator > ( const Sortable&, const Sortable& );
int operator <=( const Sortable&, const Sortable& );
int operator >=( const Sortable&, const Sortable& );
// Function //
inline int operator < ( const Sortable& test1, const Sortable& test2 )
// Summary -----------------------------------------------------------------
//
// Determines whether the first object is less than the second. We
// do type checking on the two objects (objects of different
// classes can't be compared, even if they're derived from each other).
//
// Parameters
//
// test1
//
// The first object we are testing.
//
// test2
//
// The second object we are testing.
//
// End ---------------------------------------------------------------------
{
return ( (test1.isA() == test2.isA()) && test1.isLessThan( test2 ) );
}
// EndFunction operator < //
// Function //
inline int operator > ( const Sortable& test1, const Sortable& test2 )
// Summary -----------------------------------------------------------------
//
// Determines whether the first object is greater than the second. We
// just reverse the condition returned from operator < and test for
// inequality.
//
// Parameters
//
// test1
//
// The first object we are testing.
//
// test2
//
// The second object we are testing.
//
// End ---------------------------------------------------------------------
{
return !( test1 < test2 ) && test1 != test2;
}
// EndFunction operator > //
// Function //
inline int operator >=( const Sortable& test1, const Sortable& test2 )
// Summary -----------------------------------------------------------------
//
// Determines whether the first object is greater than or equal to
// the second. We just reverse the condition returned from operator <.
//
// Parameters
//
// test1
//
// The first object we are testing.
//
// test2
//
// The second object we are testing.
//
// End ---------------------------------------------------------------------
{
return ( !( test1 <( test2 ) ) );
}
// EndFunction operator >= //
// Function //
inline int operator <=( const Sortable& test1, const Sortable& test2 )
// Summary -----------------------------------------------------------------
//
// Determines whether test1 is less than or equal to test2.
// We just combine the less than and equal to operators.
//
// Parameters
//
// test1
//
// The first object we are testing.
//
// test2
//
// The second object we are testing.
//
// End ---------------------------------------------------------------------
{
return ( test1 < test2 || test1 == test2 );
}
// EndFunction Sortable::operator <= //
#endif // ifndef _SORTABLE_H //

View File

@ -0,0 +1,203 @@
#ifndef __SORTARRY_H
#define __SORTARRY_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// SortedArray
// SortedArray::SortedArray constructor
// SortedArray::operator []
//
// Description
//
// Defines the class SortedArray.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __SORTABLE_H
#include <sortable.h>
#endif
#ifndef __ABSTARRY_H
#include <abstarry.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class SortedArray: public AbstractArray
{
public:
SortedArray( int upper, int lower = 0, sizeType aDelta = 0 );
virtual ~SortedArray();
const Sortable& operator []( int ) const;
virtual void add( Object& );
virtual void detach( const Object&, int = 0 );
virtual classType isA() const;
virtual char *nameOf() const;
private:
int lastElementIndex;
};
// Description -------------------------------------------------------------
//
// Defines the class SortedArray. The SortedArray class is an
// array in which any elements which are added are added in sorted
// order.
//
// Constructor
//
// SortedArray
//
// Constructor. Uses the AbstractArray class constructor.
//
// Public Members
//
// operator []
//
// Subscript operator. The subscript operator for sorted array
// returns a constant object. Allowing assignments to an object
// at a particular index might violate the sorting of the array.
//
// add
//
// Appends an object to the array, keeping the array elements sorted
// and expanding the array if necessary.
//
// detach
//
// Removes a reference to the object from the array.
//
// isA
//
// Returns the class type of a sorted array.
//
// nameOf
//
// Returns a character pointer to the string "SortedArray."
//
// Inherited Members
//
// lowerBound
//
// Inherited from class AbstractArray.
//
// upperBound
//
// Inherited from class AbstractArray.
//
// arraySize
//
// Inherited from class AbstractArray.
//
// destroy
//
// Removes an object reference from the array.
//
// hashValue
//
// Inherited from AbstractArray.
//
// isEqual
//
// Inherited from AbstractArray.
//
// printOn
//
// Inherited from Container.
//
// Protected Members
//
// delta
//
// Inherited from Array and made protected.
//
// lowerbound
//
// Inherited from Array and made protected.
//
// upperbound
//
// Inherited from Array and made protected.
//
// array
//
// Inherited from Array and made protected.
//
// Private Members
//
// lastElementIndex
//
// The index of the last element in the sorted array.
//
// End ---------------------------------------------------------------------
// Constructor //
inline SortedArray::SortedArray( int upper, int lower, sizeType aDelta ) :
AbstractArray( upper, lower, aDelta )
// Summary -----------------------------------------------------------------
//
// Constructor for a sorted array object.
//
// End ---------------------------------------------------------------------
{
lastElementIndex = lowerbound - 1;
}
// End Constructor SortedArray::SortedArray //
// Member Function //
inline const Sortable& SortedArray::operator []( int atIndex ) const
// Summary -----------------------------------------------------------------
//
// Subscript operator for sorted arrays.
//
// Return Value
//
// sortableAt
//
// Reference to the sortable object at the given index.
//
// End ---------------------------------------------------------------------
{
return (Sortable&)objectAt( atIndex );
}
// End Member Function SortedArray::operator [] //
#endif // ifndef __SORTARRY_H //

View File

@ -0,0 +1,116 @@
#ifndef __STACK_H
#define __STACK_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Stack
//
// Description
//
// Defines the class Stack.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __LIST_H
#include <list.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class Stack: public Container
{
public:
virtual ~Stack();
void push( Object& );
Object& pop();
Object& top() const;
virtual int isEmpty() const;
virtual ContainerIterator& initIterator() const;
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
private:
List theStack;
};
// Description -------------------------------------------------------------
//
// Defines the container class Stack.
//
// Public Members
//
// push
//
// Pushes an object on the stack.
//
// pop
//
// Pops an object from the stack and delivers that object into the
// ownership of the receiver.
//
// top
//
// Returns a refrence to the object on the top of the stack. The
// object remains in the ownership of the stack. You must make
// sure not to destroy this object while it is still owned by the stack.
//
// initIterator
//
// Stack iterator initializer.
//
// isA
//
// Returns the class type for a stack.
//
// nameOf
//
// Returns a pointer to the character string "Stack."
//
// hashValue
//
// Returns a pre-defined value for stacks.
//
// isEmpty
//
// Returns whether the stack is empty.
//
// End ---------------------------------------------------------------------
#endif // __STACK_H

View File

@ -0,0 +1,219 @@
#ifndef _STRNG_H
#define _STRNG_H
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Green Hills Road
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// String
// String::isEqual
// String::isLessThan
// String::printOn
// String::operator char*
//
// Description
//
// Defines the instance class String and inline member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __STRING_H
#include <string.h>
#define __STRING_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __SORTABLE_H
#include <sortable.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Class //
class String: public Sortable
{
public:
String( const char * );
String( const String& );
virtual ~String();
virtual int isEqual( const Object& ) const;
virtual int isLessThan( const Object& ) const;
virtual classType isA() const;
virtual char *nameOf() const;
virtual hashValueType hashValue() const;
virtual void printOn( ostream& ) const;
String& operator =( const String& );
operator const char *() const;
private:
sizeType len;
char *theString;
};
// Description -------------------------------------------------------------
//
// Defines the instance class String. String objects may be used
// anywhere an instance object is called for. A string object
// is always terminated by a null.
//
// Constructor
//
// String
//
// Constructs a String object from a given character string.
//
// Destructor
//
// ~String
//
// String destructor.
//
// Public Members
//
// isEqual
//
// Returns 1 if two strings are equivalent, 0 otherwise.
// Determines equivalence by calling strcmp().
//
// isLessThan
//
// Returns 1 if this is less than a test String.
//
// isA
//
// Returns the class type of class String.
//
// nameOf
//
// Returns a pointer to the character string "String."
//
// hashValue
//
// Returns the hash value of a string object.
//
// printOn
//
// Prints the contents of the string.
//
// operator char*
//
// Character pointer conversion operator.
//
// operator =
//
// Assignment operator for two string objects.
//
// Inherited Members
//
// operator new
//
// Inherited from Object.
//
// forEach
//
// Inherited from Object.
//
// firstThat
//
// Inherited from Object.
//
// lastThat
//
// Inherited from Object.
//
// isSortable
//
// Inherited from Sortable.
//
// isAssociation
//
// Inherited from Object.
//
// End ---------------------------------------------------------------------
// Constructor //
inline String::String( const char *aPtr )
// Summary -----------------------------------------------------------------
//
// Constructor for a string object.
//
// Parameters
//
// aPtr
//
// Pointer to the characters out of which we are to construct a
// String object.
//
// Functional Description
//
// We assign the string's length to len, then allocate space into
// which we will store the string's characters. You may construct
// String objects out of local character strings.
//
// End ---------------------------------------------------------------------
{
if ( aPtr && *aPtr )
{
len = strlen( aPtr ) + 1;
theString = new char[ len ];
(void)strcpy( theString, aPtr );
}
else // make a null string String object.
{
len = 0;
theString = 0;
}
}
// End Constructor //
// Member Function //
inline String::operator const char *() const
// Summary -----------------------------------------------------------------
//
// Converts a string object to a character pointer.
//
// Remarks
//
// warnings:
// You may not modifiy the returned string.
//
// End ---------------------------------------------------------------------
{
return theString;
}
// End Member Function String::operator char* //
#endif // ifndef _STRNG_H //

Binary file not shown.

View File

@ -0,0 +1,544 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// AbstractArray::AbstractArray constructor
// AbstractArray::~AbstractArray destructor
// AbstractArray::detach Object
// AbstractArray::detach int
// AbstractArray::hashValue
// AbstractArray::reallocate
// AbstractArray::isEqual
// AbstractArray::initIterator
// AbstractArray::printContentsOn
//
// ArrayIterator::operator int
// ArrayIterator::operator Object
// ArrayIterator::restart
// ArrayIterator::operator ++
//
// Description
//
// Implementation of class AbstractArray and class ArrayIterator member
// functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __STDLIB_H
#include <stdlib.h>
#define __STDLIB_H
#endif
#ifndef __ASSERT_H
#include <assert.h>
#define __ASSERT_H
#endif
#ifndef __CLSDEFS_H
#include <clsdefs.h>
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __ABSTARRY_H
#include <abstarry.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Constructor //
AbstractArray::AbstractArray( int anUpper, int aLower, sizeType aDelta )
// Summary -----------------------------------------------------------------
//
// Constructor for an abstract array. An abstract array can be made
// to be either of a fixed or expanding size. In an expanding array,
// when a reference is made to an index greater than the current upper
// bound of the array, the array will grow to allow the given index
// to reference a valid array object. The number of elements by
// which this growth is performed is given by the parameter aDelta.
//
// Parameters
//
// anUpper
//
// The upper bound for the array.
//
// aLower
//
// The lower bound for the array. The initial size of the array is
// calculated from the upper and lower bounds.
//
// aDelta
//
// The growth factor for the array.
//
// Functional Description
//
// We set up the private parts of the array, allocate space for the
// pointers, then set all the allocated pointers to point to the
// error object.
//
// End ---------------------------------------------------------------------
{
lowerbound = whereToAdd = aLower;
upperbound = anUpper;
delta = aDelta;
theArray = new Object *[ arraySize() ];
for( int i = 0; i < arraySize(); i++ )
{
theArray[ i ] = ZERO;
} // end for
}
// End Constructor AbstractArray::AbstractArray //
// Destructor //
AbstractArray::~AbstractArray()
// Summary -----------------------------------------------------------------
//
// Destructor for a AbstractArray object.
//
// End ---------------------------------------------------------------------
{
for( int i = 0; i < arraySize(); i++ )
if( theArray[ i ] != ZERO )
delete theArray[ i ];
delete [ arraySize() ] theArray;
}
// End Destructor //
// Member Function //
void AbstractArray::detach( const Object& toDetach, int deleteObjectToo )
// Summary -----------------------------------------------------------------
//
// Detaches an object from the array.
//
// Parameter
//
// toDetach
//
// The object we are to search for and detach from the AbstractArray.
//
// deleteObjectToo
//
// Specifies whether we are to delete the object.
//
// Functional Description
//
// If the object specified is at the lower bound of the array, we remove
// the reference right away. Otherwise, we iterate through the array until
// we find it, then remove the reference.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't in the array.
//
// End ---------------------------------------------------------------------
{
if ( toDetach == NOOBJECT )
return;
for ( int i = 0; i < arraySize(); i++ )
{
if ( ( theArray[ i ] != ZERO ) && ( *theArray[ i ] == toDetach ) )
{
if ( deleteObjectToo )
{
delete theArray[ i ];
}
theArray[ i ] = ZERO;
itemsInContainer--;
break;
}
} // end for //
}
// End Member Function AbstractArray::detach //
// Member Function //
void AbstractArray::detach( int atIndex, int deleteObjectToo )
// Summary -----------------------------------------------------------------
//
// Detaches an object from the array at the given index.
//
// Parameter
//
// toIndex
//
// The index from which we are to detach the object.
//
// deleteObjectToo
//
// Specifies whether we are to delete the object.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't in the array.
//
// End ---------------------------------------------------------------------
{
if ( theArray[ atIndex - lowerbound ] != ZERO )
{
if ( deleteObjectToo )
{
delete ( theArray[ atIndex - lowerbound ] );
}
theArray[ atIndex - lowerbound ] = ZERO;
itemsInContainer--;
} // end if there was an element already there in the array.
}
// End Member Function AbstractArray::detach //
// Member Function //
hashValueType AbstractArray::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a array.
//
// End ---------------------------------------------------------------------
{
return hashValueType(0);
}
// End Member Function AbstractArray::hashValue //
// Member Function //
void AbstractArray::reallocate( sizeType newSize )
// Summary -----------------------------------------------------------------
//
// Reallocates the array's pointer vector to a new size.
//
// Parameters
//
// newSize
//
// The number of pointers which is to be in the new vector.
//
// Functional Description
//
// We allocate space for a new pointer vector of the given size,
// adjusted to take into account the growth factor. We then copy
// the old vector into the new one and fix up the pointer in the
// array object.
//
// Remarks
//
// assumptions
// Asserts that the new size of the pointer vector is greater than
// the current size. We do "expanding-only" arrays, not accordions.
//
// End ---------------------------------------------------------------------
{
if ( delta == 0 )
{
cerr << "Error: Attempting to expand a fixed size array.";
exit(__EEXPAND);
}
int i; // Loop counter for moving the pointers from the old vector
// to the new one.
// Body Comment
//
// We assume that the new pointer vector size is greater than the
// current vector size.
//
// End
assert ( newSize > arraySize() );
sizeType adjustedSize = newSize + ( delta - ( newSize % delta ) );
Object **newArray = new Object *[ adjustedSize ];
if ( newArray == 0 )
{
cerr << "Error: Out of Memory";
exit(__ENOMEM);
}
for ( i = 0; i < arraySize(); i++ )
{
newArray[i] = theArray[i];
}
for (; i < adjustedSize; i++ )
{
newArray[i] = ZERO;
}
delete [ arraySize() ] theArray;
theArray = newArray;
upperbound = adjustedSize + lowerbound - 1;
}
// End Member Function AbstractArray::reallocate //
// Member Function //
int AbstractArray::isEqual( const Object& testObject ) const
// Summary -----------------------------------------------------------------
//
// Tests for equality of two arrays. Two arrays are equal if they
// have the same dimensions and the same objects at the same indices.
//
// Parameters
//
// testObject
//
// The array which we will be testing against this.
//
// End ---------------------------------------------------------------------
{
if ( lowerbound != ((AbstractArray&)testObject).lowerbound ||
upperbound != ((AbstractArray&)testObject).upperbound )
{
return 0;
}
for ( int i = 0; i < arraySize(); i++ )
{
// Body Comment
//
// The two array elements can be null, so check that first.
// If there are really objects there, compare them for equality.
//
// End
if ( theArray[i] != ZERO )
{
if ( ((AbstractArray&)testObject).theArray[i] != ZERO )
{
if ( *theArray[i] !=
*( ((AbstractArray &)testObject).theArray[i] ) )
{
return 0; // objects weren't equal.
}
}
else // the first pointer wasn't ZERO but the second was
{
return 0;
}
}
else
if ( ((AbstractArray&)testObject).theArray[i] != ZERO )
{
return 0; // first pointer was ZERO but the second wasn't
}
} // end for each element in the array.
return 1;
}
// End Member Function AbstractArray::isEqual //
// Member Function //
ContainerIterator& AbstractArray::initIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a list.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new ArrayIterator( *this ) );
}
// End Member Function AbstractArray::initIterator //
// Member Function //
void AbstractArray::printContentsOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays the non-ZERO contents of an array on the given stream.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the contents.
//
// Functional Description
//
// We initialize an iterator, then iterator through each object,
// asking the objects to print themselves if they are not the
// error object.
//
// Remarks
//
// warnings:
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator& printIterator = initIterator();
printHeader( outputStream );
while( int(printIterator) != 0 )
{
Object& arrayObject = printIterator++;
if ( arrayObject != NOOBJECT )
{
arrayObject.printOn( outputStream );
if ( int(printIterator) != 0 )
{
printSeparator( outputStream );
}
else // there are no more objects in the array.
{
break;
}
} // end if the array object is NOOBJECT.
} // end while //
printTrailer( outputStream );
delete &printIterator;
}
// End Member Function AbstractArray::printContentsOn //
// Destructor //
ArrayIterator::~ArrayIterator()
// Summary -----------------------------------------------------------------
//
// Destructor for a ArrayIterator object.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
ArrayIterator::operator int()
// Summary -----------------------------------------------------------------
//
// Integer conversion for an array iterator.
//
// End ---------------------------------------------------------------------
{
return currentIndex <= beingIterated.upperbound;
}
// End Member Function operator int //
// Member Function //
ArrayIterator::operator Object&()
// Summary -----------------------------------------------------------------
//
// Object reference conversion for an array iterator.
//
// End ---------------------------------------------------------------------
{
if ( currentIndex <= beingIterated.upperbound )
{
return ( (Object&)( beingIterated.objectAt( currentIndex ) ) );
}
else // no more elements in the array.
{
return NOOBJECT;
}
}
// End Member Function operator Object& //
// Member Function //
void ArrayIterator::restart()
// Summary -----------------------------------------------------------------
//
// ArrayIterator restart.
//
// End ---------------------------------------------------------------------
{
currentIndex = beingIterated.lowerbound;
}
// End Member Function ArrayIterator::restart //
// Member Function //
Object& ArrayIterator::operator ++()
// Summary -----------------------------------------------------------------
//
// Increments the array iterator and returns the next object.
//
// End ---------------------------------------------------------------------
{
if ( currentIndex <= beingIterated.upperbound )
{
currentIndex++;
return ( (Object&)( beingIterated.objectAt( currentIndex - 1 ) ) );
}
else // no more elements in the array.
{
return NOOBJECT;
}
}
// End Member Function ArrayIterator::operator ++//

View File

@ -0,0 +1,177 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Array::isA
// Array::nameOf
// Array::add
// Array::addAt
//
// Description
//
// Implementation of class Array member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __ARRAY_H
#include <array.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Member Function //
Array::~Array()
// Summary -----------------------------------------------------------------
//
// Destructor for an Array object.
//
// We don't do anything here, because the destructor for AbstractArray
// will take care of destroying the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType Array::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of an array.
//
// End ---------------------------------------------------------------------
{
return arrayClass;
}
// End Member Function Array::isA //
// Member Function //
char *Array::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Array."
//
// End ---------------------------------------------------------------------
{
return "Array";
}
// End Member Function Array::nameOf //
// Member Function //
void Array::add( Object& toAdd )
// Summary -----------------------------------------------------------------
//
// Adds the given object to the array.
//
// Parameters
//
// toAdd
//
// The object we are to add to the array. Once the object is
// added, it is owned by the array.
//
// End ---------------------------------------------------------------------
{
// Body Comment
//
// We search for the first available space for an array element.
// Since the user may have inserted an element with addAt or
// with the subscript operator, we check first before overwriting
// anything.
//
// End
while( theArray[ whereToAdd ] != ZERO && whereToAdd <= upperbound )
{
whereToAdd++;
} // end while an array index already has an element.
if( whereToAdd > upperbound )
{
reallocate( whereToAdd - lowerbound + 1 );
}
theArray[ whereToAdd++ ] = &toAdd;
itemsInContainer++;
}
// End Member Function Array::add //
// Member Function //
void Array::addAt( Object& toAdd, int atIndex )
// Summary -----------------------------------------------------------------
//
// Adds the given object to the array at the given index. If there
// is an object already at that index, destroys the object.
//
// Parameters
//
// toAdd
//
// The object we are to add to the array. Once the object is
// added, it is owned by the array.
//
// atIndex
//
// The index at which to add the object.
//
// End ---------------------------------------------------------------------
{
if( atIndex > upperbound )
{
reallocate( atIndex - lowerbound + 1 );
}
if ( theArray[ atIndex ] != ZERO )
{
delete theArray[ atIndex ];
itemsInContainer--;
}
theArray[ atIndex ] = &toAdd;
itemsInContainer++;
}
// End Member Function Array::addAt //

View File

@ -0,0 +1,165 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Association::isA
// Association::nameOf
// Association::printOn
// Association::hashValue
// Association::isEqual
// Association::isAssociation
//
// Description
//
// Implementation of member functions for class Association.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __ASSOC_H
#include <assoc.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Member Function //
Association::~Association()
// Summary -----------------------------------------------------------------
//
// Destructor for an Association object.
//
// We don't do anything here, because the key and value fields will
// be destroyed automatically.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType Association::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a association.
//
// End ---------------------------------------------------------------------
{
return associationClass;
}
// End Member Function Association::isA //
// Member Function //
char *Association::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Association."
//
// End ---------------------------------------------------------------------
{
return "Association";
}
// End Member Function Association::isA //
// Member Function //
void Association::printOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays the contents of this association object.
//
// Parameters
//
// outputStream
//
// The stream on which we are to display the association.
//
// End ---------------------------------------------------------------------
{
outputStream << " " << nameOf() << " { ";
aKey.printOn( outputStream );
outputStream << ", ";
aValue.printOn( outputStream );
outputStream << " }\n";
}
// End Member Function //
// Member Function //
hashValueType Association::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of an association. We use the key's
// hash value.
//
// End ---------------------------------------------------------------------
{
return aKey.hashValue();
}
// End Member Function Association::hashValue //
// Member Function //
int Association::isEqual( const Object& toObject ) const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of an association. We use the key's
// hash value.
//
// End ---------------------------------------------------------------------
{
return aKey == ( (Association&)toObject ).key();
}
// End Member Function Association::isEqual //
// Member Function //
int Association::isAssociation() const
// Summary -----------------------------------------------------------------
//
// Indicates that the given object is an association.
//
// End ---------------------------------------------------------------------
{
return 1;
}
// End Member Function Association::isEqual //

View File

@ -0,0 +1,82 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
//
// Description
//
// Implementation of member functions for class Bag.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __BAG_H
#include <bag.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Member Function //
Bag::~Bag()
// Summary -----------------------------------------------------------------
//
// Destructor for a Bag object.
//
// We don't do anything here, because the destructor for Container
// will take care of destroying the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType Bag::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a bag.
//
// End ---------------------------------------------------------------------
{
return bagClass;
}
// End Member Function Bag::isA //
// Member Function //
char *Bag::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Bag".
//
// End ---------------------------------------------------------------------
{
return "Bag";
}
// End Member Function Bag::nameOf //

View File

@ -0,0 +1,38 @@
echo off
if %1.==. goto usage
if %1.==all. build s c m l h
if %1.==ALL. build s c m l h
:loop
if %1.==s. goto ok
if %1.==S. goto ok
if %1.==c. goto ok
if %1.==C. goto ok
if %1.==m. goto ok
if %1.==M. goto ok
if %1.==l. goto ok
if %1.==L. goto ok
if %1.==h. goto ok
if %1.==H. goto ok
if %1.==. goto done
goto error
:ok
tcc -P -c -m%1 -n..\lib -I..\include *.cpp
cd ..\lib
if exist tclass%1.lib del tclass%1.lib
tlib tclass%1.lib @..\source\classlib.rsp
del *.obj
cd ..\source
shift
goto loop
:error
echo Error: bad argument %1
goto done
:usage
echo Usage: BUILD model or all
echo where model is any combination of [s c m l h]
echo Example: BUILD s l builds small and large models
echo BUILD all builds all of the memory models
:done

View File

@ -0,0 +1,20 @@
+ARRAY &
+DBLLIST &
+LIST &
+SORTARRY &
+CONTAIN &
+OBJECT &
+STACK &
+QUEUE &
+DEQUE &
+HASHTBL &
+ABSTARRY &
+ASSOC &
+COLLECT &
+LDATE &
+LTIME &
+DICT &
+STRNG &
+SORTABLE &
+SET &
+BAG

View File

@ -0,0 +1,118 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Collection::findMember
// Collection::hasMember
//
// Description
//
// Implementation of class Collection member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __COLLECT_H
#include <collect.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __CONTAIN_H
#include <contain.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Member Function //
Collection::~Collection()
// Summary -----------------------------------------------------------------
//
// Destructor for a Collection object.
//
// We don't have to do anything here. The derived class will
// destroy all objects in the container.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
Object& Collection::findMember( const Object& testObject ) const
// Summary -----------------------------------------------------------------
//
// Functional Description
//
// We initialize an iterator, then iterate through each object,
// doing a comparison of objects. Note that the iteration is
// a shallow one, that is, if our collection is made up of
// container objects, we don't check to see whether those containers
// contain the object we are looking for.
//
// Remarks
//
// warnings:
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator& containerIterator = initIterator();
while( int(containerIterator) != 0 )
{
Object& listObject = containerIterator++;
if ( listObject == testObject )
{
delete &containerIterator;
return listObject;
}
} // end while //
delete &containerIterator;
return NOOBJECT;
}
// End Member Function Collection::findMember //
// Member Function //
int Collection::hasMember( const Object& testObject ) const
// Summary ----------------------------------------------------------------
//
// Collection
//
// Description
//
// Defines the abstract class Collection. Collections group objects
// together and specify operations.
//
// End ---------------------------------------------------------------------
{
return findMember( testObject ) != NOOBJECT;
}
// End Member Function Collection::hasMember //

View File

@ -0,0 +1,476 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Container::Container copy constructor
// Container::forEach
// Container::firstThat
// Container::lastThat
// Container::isEqual
// Container::printOn
// Container::printHeader
// Container::printSeparator
// Container::printTrailer
//
// Description
//
// Implementation of class Container member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Constructor //
Container::Container( const Container& toCopy )
// Summary -----------------------------------------------------------------
//
// Constructors a container and copies the given container into it.
//
// Parameters
//
// toCopy
//
// The container which we are to copy.
//
// Functional Description
//
// We initialize an iterator, then iterate through each object in the
// container we are copying, constructing and copying as we go.
//
// Remarks
//
// warnings:
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator &copyIterator = toCopy.initIterator();
while( int(copyIterator) != 0 )
{
} // end while //
delete &copyIterator;
}
// End Constructor Container::Container //
// Member Function //
Container::~Container()
// Summary -----------------------------------------------------------------
//
// Destructor for a Container object.
//
// We don't do anything here, because the derived class will have
// taken care of deleting all the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
void Container::forEach( iterFuncType actionPtr, void *paramListPtr )
// Summary -----------------------------------------------------------------
//
// Calls the given iterator function on each object in this container.
//
// Parameters
//
// actionPtr
//
// Pointer to the action routine which is to be called for each object.
//
// paramListPtr
//
// Pointer to the list of parameters which will be passed along to
// the action routine.
//
// Functional Description
//
// We initialize an iterator, then iterator through each object,
// asking the objects to perform the forEach function on themselves.
//
// Remarks
//
// warnings:
// The action routine must have a prototype of the form:
// void action( Object&, void * );
//
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator& containerIterator = initIterator();
while( int(containerIterator) != 0 )
{
containerIterator++.forEach( actionPtr, paramListPtr );
}
delete &containerIterator;
}
// End Member Function Container::forEach //
// Member Function //
Object& Container::firstThat( condFuncType testFuncPtr, void *paramListPtr ) const
// Summary -----------------------------------------------------------------
//
// Finds the first object in the container which satisfies the
// given condition function.
//
// Parameters
//
// testFuncPtr
//
// Pointer to the conditional test routine which is to be called
// for this container.
//
// paramListPtr
//
// Pointer to the list of parameters which will be passed along to
// the conditional test routine.
//
// Return Value
//
// Returns the first object in the container which satisfies the
// condition. Returns NOOBJECT otherwise.
//
// Functional Description
//
// We initialize an iterator, then iterator through each object,
// asking the objects to perform the firstThat function on themselves.
//
// Remarks
//
// warnings:
// The conditional test routine must have a prototype of the form:
// int test( Object&, void * );
//
// The conditional test routine must return 1 if the given object
// satisfies the condition.
//
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator &containerIterator = initIterator();
while( int(containerIterator) != 0 )
{
Object& testResult =
containerIterator++.firstThat( testFuncPtr, paramListPtr );
if ( testResult != NOOBJECT )
{
delete &containerIterator;
return testResult;
}
} // end while //
delete &containerIterator;
return NOOBJECT;
}
// End Member Function Container::firstThat //
// Member Function //
Object& Container::lastThat( condFuncType testFuncPtr, void *paramListPtr ) const
// Summary -----------------------------------------------------------------
//
// Finds the last object in the container which satisfies the
// given condition function.
//
// Parameters
//
// testFuncPtr
//
// Pointer to the conditional test routine which is to be called
// for this object.
//
// paramListPtr
//
// Pointer to the list of parameters which will be passed along to
// the conditional test routine.
//
// Functional Description
//
// We initialize an iterator, then iterator through each object,
// asking the objects to perform the lastThat function on themselves.
// As we iterate, if we find an object which satisfies the condition,
// we make that object the last object which met the condition. Note
// that there is no short-circuiting the search, since we must search
// through every object in the container to find the last one.
//
// Remarks
//
// warnings:
// The conditional test routine must have a prototype of the form:
// int test( Object&, void * );
//
// The conditional test routine must return 1 if the given object
// satisfies the condition.
//
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator& containerIterator = initIterator();
Object *lastMet = &(containerIterator++.lastThat( testFuncPtr, paramListPtr ));
while( int(containerIterator) != 0 )
{
Object& testResult =
containerIterator++.lastThat( testFuncPtr, paramListPtr );
if ( testResult != NOOBJECT )
{
lastMet = &testResult;
}
} // end while //
delete &containerIterator;
return *lastMet;
}
// End Member Function Container::lastThat //
// Member Function //
int Container::isEqual( const Object& testContainer ) const
// Summary -----------------------------------------------------------------
//
// Determines whether the given container is equal to this.
//
// Parameters
//
// testContainer
//
// The container which we will be testing for equality with this.
//
// Return Value
//
// Returns 1 if the two containers have the same objects in them
// in the same order.
//
// Functional Description
//
// We initialize an iterator, then iterator through each object,
// asking the objects to perform an equality test. As we iterate,
// if we find an object which fails the test, we return 0. If every
// object is equal and there are the same number of objects in both
// containers, we return 1.
//
// Remarks
//
// warnings:
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator& thisIterator = initIterator();
ContainerIterator& testContainerIterator =
((Container &)(testContainer)).initIterator();
while( int(thisIterator) != 0 && int(testContainerIterator) != 0 )
{
int objectsAreNotEqual =
(thisIterator++ != testContainerIterator++);
if ( objectsAreNotEqual )
{
delete &testContainerIterator;
delete &thisIterator;
return 0;
}
} // end while //
if ( int(thisIterator) !=0 || int(testContainerIterator) != 0 )
{
delete &testContainerIterator;
delete &thisIterator;
return 0;
}
else // one of the containers has more objects than the other.
{
delete &testContainerIterator;
delete &thisIterator;
return 1;
}
}
// End Member Function Container::isEqual //
// Member Function //
void Container::printOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays the contents of a container on the given stream.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the container contents.
//
// Functional Description
//
// We initialize an iterator, then iterator through each object,
// asking the objects to print themselves.
//
// Remarks
//
// warnings:
// We must be sure to delete the container iterator, since it was
// allocated on the heap.
//
// End ---------------------------------------------------------------------
{
ContainerIterator& printIterator = initIterator();
printHeader( outputStream );
while( int(printIterator) != 0 )
{
printIterator++.printOn( outputStream );
if ( int(printIterator) != 0 )
{
printSeparator( outputStream );
}
else // there are no more objects in the container.
{
break;
}
} // end while //
printTrailer( outputStream );
delete &printIterator;
}
// End Member Function Container::printOn //
// Member Function //
void Container::printHeader( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays a standard header for a container on the given stream.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the header.
//
// Functional Description
//
// We print the string returned by nameOf() and an opening brace.
//
// End ---------------------------------------------------------------------
{
outputStream << nameOf() << " { ";
}
// End Member Function Container::printHeader //
// Member Function //
void Container::printSeparator( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays a standard separator for a container on the given stream.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the separator.
//
// End ---------------------------------------------------------------------
{
outputStream << ",\n ";
}
// End Member Function Container::printSeparator //
// Member Function //
void Container::printTrailer( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays a standard trailer for a container on the given stream.
//
// Parameters
//
// outputStream
//
// The stream on which we will be writing the trailer.
//
// End ---------------------------------------------------------------------
{
outputStream << " }\n";
}
// End Member Function Container::printTrailer //
// Member Function //
ContainerIterator::~ContainerIterator()
// Summary -----------------------------------------------------------------
//
// Destructor for a ContainerIterator object.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //

View File

@ -0,0 +1,603 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// DoubleList::isA
// DoubleList::nameOf
// DoubleList::add
// DoubleList::addAtHead
// DoubleList::addAtTail
// DoubleList::detach
// DoubleList::detachFromHead
// DoubleList::detachFromTail
// DoubleList::initIterator
// DoubleList::initReverseIterator
// DoubleList::hashValue
//
// DoubleListIterator::operator int
// DoubleListIterator::operator Object&
// DoubleListIterator::operator ++
// DoubleListIterator::restart
// DoubleListIterator::operator --
//
// Description
//
// Implementation of class DoubleList member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __DLSTELEM_H
#include <dlstelem.h>
#endif
#ifndef __DBLLIST_H
#include <dbllist.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Member Function //
DoubleList::~DoubleList()
// Summary -----------------------------------------------------------------
//
// Destructor for a DoubleList object.
//
// End ---------------------------------------------------------------------
{
while( head != 0 )
{
DoubleListElement *temp = head;
head = head->next;
delete temp;
}
}
// End Destructor //
// Member Function //
classType DoubleList::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a double list.
//
// End ---------------------------------------------------------------------
{
return doubleListClass;
}
// End Member Function DoubleList::isA //
// Member Function //
char *DoubleList::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "DoubleList."
//
// End ---------------------------------------------------------------------
{
return "DoubleList";
}
// End Member Function DoubleList::nameOf //
// Member Function //
void DoubleList::add( Object& toAdd )
// Summary -----------------------------------------------------------------
//
// Adds the given object on the double list at the head of the list.
//
// Parameters
//
// toAdd
//
// The object we are to add to the head of the list. Once the object is
// added, it is owned by the double list.
//
// Functional Description
//
// Wrap of addAtHead.
//
// End ---------------------------------------------------------------------
{
addAtHead( toAdd );
}
// End Member Function DoubleList::add //
// Member Function //
void DoubleList::addAtHead( Object& toAdd )
// Summary -----------------------------------------------------------------
//
// Adds the given object on the double list at the head of the list.
//
// Parameters
//
// toAdd
//
// The object we are to add to the head of the list. Once the object is
// added, it is owned by the double list.
//
// End ---------------------------------------------------------------------
{
DoubleListElement *newElement = new DoubleListElement( &toAdd );
if ( head )
{
head->previous = newElement;
newElement->next = head;
head = newElement;
}
else
{
tail = head = newElement;
}
itemsInContainer++;
}
// End Member Function DoubleList::addAtHead //
// Member Function //
void DoubleList::addAtTail( Object& toAdd )
// Summary -----------------------------------------------------------------
//
// Adds the given object on the double list at the tail of the list.
//
// Parameters
//
// toAdd
//
// The object we are to add to the tail of the list. Once the object is
// added, it is owned by the double list.
//
// End ---------------------------------------------------------------------
{
DoubleListElement *newElement = new DoubleListElement( &toAdd );
if ( tail )
{
tail->next = newElement;
newElement->previous = tail;
tail = newElement;
}
else
{
head = tail = newElement;
}
itemsInContainer++;
}
// End Member Function DoubleList::addAtTail //
// Member Function //
void DoubleList::detach( const Object& toDetach, int destroyToo )
// Summary -----------------------------------------------------------------
//
// Detaches an object from a double list. By default the object
// is searched for starting at the head of the list.
//
// Parameter
//
// toDetach
//
// The object we are to search for and destroy from the DoubleList.
//
// destroyToo
//
// Indicates whether we are also to destroy the object.
//
// Functional Description
//
// Wrap of detachFromHead.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't on the double list.
//
// End ---------------------------------------------------------------------
{
detachFromHead( toDetach, destroyToo );
}
// End Member Function DoubleList::detach //
// Member Function //
void DoubleList::detachFromHead( const Object& toDetach, int deleteToo )
// Summary -----------------------------------------------------------------
//
// Detaches an object from the head of a double list.
//
// Parameter
//
// toDetach
//
// The object we are to search for and detach from the DoubleList.
//
// deleteToo
//
// Specifies whether we are to delete the object.
//
// Functional Description
//
// If the object specified is at the head of the double list, we remove
// the reference right away. Otherwise, we iterate through the double list until
// we find it, then remove the reference.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't on the double list.
//
// End ---------------------------------------------------------------------
{
DoubleListElement *cursor = head;
if ( *(head->data) == toDetach )
{
if( head->next == 0 )
tail = 0;
head = head->next;
}
else // the object isn't at the head of the list.
{
// Body Comment
//
// Normally we would do this iteration with a list iterator.
// Since we need to keep track of not only the objects in the
// list but also the list elements, i.e. the pointer nodes,
// we don't use the iterator.
//
// End
while ( cursor != 0 )
{
if ( *(cursor->data) == toDetach )
{
cursor->previous->next = cursor->next;
cursor->next->previous = cursor->previous;
break;
}
else // the object isn't the one we want.
{
cursor = cursor->next;
}
} // end while
} // end else the object wasn't at the head of the list.
// Body Comment
//
// Now cursor points to the object that we've found
//
// End
if( cursor != 0 )
{
itemsInContainer--;
if ( deleteToo )
{
delete cursor->data;
}
else
{
cursor->data = 0; // insure that we don't delete the data
}
delete cursor;
}
}
// End Member Function DoubleList::detachFromHead //
// Member Function //
void DoubleList::detachFromTail( const Object& toDetach, int deleteToo )
// Summary -----------------------------------------------------------------
//
// Detaches an object from the tail of a double list.
//
// Parameter
//
// toDetach
//
// The object we are to search for and detach from the DoubleList.
//
// deleteToo
//
// Specifies whether we are to delete the object.
//
// Functional Description
//
// If the object specified is at the tail of the double list, we remove
// the reference right away. Otherwise, we iterate backwards through
// the double list until we find it, then remove the reference.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't on the double list.
//
// End ---------------------------------------------------------------------
{
DoubleListElement *cursor = tail;
if ( *(tail->data) == toDetach )
{
if( tail->previous == 0 )
head = 0;
tail = tail->previous;
}
else // the object isn't at the tail of the list.
{
// Body Comment
//
// Normally we would do this iteration with a list iterator.
// Since we need to keep track of not only the objects in the
// list but also the list elements, i.e. the pointer nodes,
// we don't use the iterator.
//
// End
while ( cursor != 0 )
{
if ( *(cursor->data) == toDetach )
{
cursor->previous->next = cursor->next;
cursor->next->previous = cursor->previous;
break;
}
else // the object isn't the one we want.
{
cursor = cursor->previous;
}
} // end while
} // end else the object wasn't at the tail of the list.
// Body Comment
//
// Now cursor points to the object that we've found
//
// End
if( cursor != 0 )
{
itemsInContainer--;
if ( deleteToo )
{
delete cursor->data;
}
else
{
cursor->data = 0; // insure that we don't delete the data
}
delete cursor;
}
}
// End Member Function DoubleList::detachFromTail //
// Member Function //
ContainerIterator& DoubleList::initIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a double list.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new DoubleListIterator( *this ) );
}
// End Member Function DoubleList::initIterator //
// Member Function //
ContainerIterator& DoubleList::initReverseIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a double list.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new DoubleListIterator( *this, 0 ) );
}
// End Member Function DoubleList::initReverseIterator //
// Member Function //
hashValueType DoubleList::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a double list.
//
// End ---------------------------------------------------------------------
{
return hashValueType(0);
}
// End Member Function DoubleList::hashValue //
// Member Function //
DoubleListIterator::operator int()
// Summary -----------------------------------------------------------------
//
// Integer conversion operator for a Double List iterator.
//
// End ---------------------------------------------------------------------
{
return ( currentElement != 0 );
}
// End Member Function DoubleListIterator::operator int //
// Member Function //
DoubleListIterator::operator Object&()
// Summary -----------------------------------------------------------------
//
// Object conversion operator for a Double List iterator.
//
// End ---------------------------------------------------------------------
{
return ( (Object&)(*(currentElement->data)) );
}
// End Member Function DoubleListIterator::operator Object& //
// Member Function //
Object& DoubleListIterator::operator ++()
// Summary -----------------------------------------------------------------
//
// Increments the list iterator and returns the next object.
//
// Return Value
//
// listObject
//
// A reference to the object which is after the current object
// in the iterator sequence.
//
// End ---------------------------------------------------------------------
{
DoubleListElement *trailer = currentElement;
if ( currentElement != 0 )
{
currentElement = currentElement->next;
return ( (Object&)(*(trailer->data)) );
}
else // no more elements in the list.
{
return NOOBJECT;
}
}
// End Member Function DoubleListIterator::operator ++ //
// Member Function //
void DoubleListIterator::restart()
// Summary -----------------------------------------------------------------
//
// Restart function for a list iterator object.
//
// End ---------------------------------------------------------------------
{
currentElement = startingElement;
}
// End Member Function DoubleListIterator::restart //
// Member Function //
Object& DoubleListIterator::operator --()
// Summary -----------------------------------------------------------------
//
// Decrements the list iterator and returns the previous object.
//
// Return Value
//
// listObject
//
// A reference to the object which is before the current object
// in the iterator sequence.
//
// End ---------------------------------------------------------------------
{
DoubleListElement *trailer = currentElement;
if ( currentElement != 0 )
{
currentElement = currentElement->previous;
return ( (Object&)(*(trailer->data)) );
}
else // no more elements in the list.
{
return NOOBJECT;
}
}
// End Member Function DoubleListIterator::operator -- //
// Destructor //
DoubleListIterator::~DoubleListIterator()
// Summary -----------------------------------------------------------------
//
// Destructor for a DoubleListIterator object.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //

View File

@ -0,0 +1,191 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Deque::isA
// Deque::nameOf
// Deque::getLeft
// Deque::getRight
// Deque::initIterator
// Deque::initReverseIterator
// Deque::hashValue
//
// Description
//
// Implementation of class Deque member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __DEQUE_H
#include <deque.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __DBLLIST_H
#include <dbllist.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Member Function //
Deque::~Deque()
// Summary -----------------------------------------------------------------
//
// Destructor for a Deque object.
//
// We don't do anything here, because the destructor for theDeque
// will destroy all the objects in the Deque.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType Deque::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a double-ended queue.
//
// End ---------------------------------------------------------------------
{
return dequeClass;
}
// End Member Function Deque::isA //
// Member Function //
char *Deque::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Deque."
//
// End ---------------------------------------------------------------------
{
return "Deque";
}
// End Member Function Deque::nameOf //
// Member Function //
Object& Deque::getLeft()
// Summary -----------------------------------------------------------------
//
// Gets an object from the left end of the deque. The object becomes
// the ownership of the receiver.
//
// End ---------------------------------------------------------------------
{
Object& temp = theDeque.peekAtHead();
if( temp != NOOBJECT )
{
theDeque.detachFromHead( temp );
itemsInContainer--;
}
return temp;
}
// End Member Function Deque::getLeft //
// Member Function //
Object& Deque::getRight()
// Summary -----------------------------------------------------------------
//
// Gets an object from the right end of the deque. The object becomes
// the ownership of the receiver.
//
// End ---------------------------------------------------------------------
{
Object& temp = theDeque.peekAtTail();
if( temp != NOOBJECT )
{
theDeque.detachFromTail( temp );
itemsInContainer--;
}
return temp;
}
// End Member Function Deque::getLeft //
// Member Function //
ContainerIterator& Deque::initIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a deque.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new DoubleListIterator( this->theDeque ) );
}
// End Member Function Deque::initIterator //
// Member Function //
ContainerIterator& Deque::initReverseIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes a right to left iterator for a deque.
//
// End ---------------------------------------------------------------------
{
return *((ContainerIterator *)new DoubleListIterator( this->theDeque, 0 ));
}
// End Member Function Deque::initReverseIterator //
// Member Function //
hashValueType Deque::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a deque.
//
// End ---------------------------------------------------------------------
{
return hashValueType(0);
}
// End Member Function Deque::hashValue //

View File

@ -0,0 +1,150 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Dictionary::isA
// Dictionary::nameOf
// Dictionary::lookup
// Dictionary::add
//
// Description
//
// Implementation of member functions for class Dictionary.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __DICT_H
#include <dict.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __ASSOC_H
#include <assoc.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Member Function //
Dictionary::~Dictionary()
// Summary -----------------------------------------------------------------
//
// Destructor for a Dictionary object.
//
// We don't do anything here, because the destructor for HashTable
// will take care of destroying the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType Dictionary::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a dictionary.
//
// End ---------------------------------------------------------------------
{
return dictionaryClass;
}
// End Member Function Dictionary::isA //
// Member Function //
char *Dictionary::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Dictionary."
//
// End ---------------------------------------------------------------------
{
return "Dictionary";
}
// End Member Function Dictionary::nameOf //
// Member Function //
Association& Dictionary::lookup( const Object& toLookUp ) const
// Summary -----------------------------------------------------------------
//
// Looks up an object in the dictionary.
//
// Parameters
//
// toLookUp
//
// The object to be searched for in the dictionary.
//
// End ---------------------------------------------------------------------
{
Association toFind( (Object&)toLookUp, NOOBJECT );
// OK to cast to non-const object here, since it doesn't get
// put into a dictionary, but is only used for comparisons.
Association& found = (Association&)findMember( toFind );
return found;
}
// End Member Function Dictionary::lookup //
// Member Function //
void Dictionary::add( Object& objectToAdd )
// Summary -----------------------------------------------------------------
//
// Adds an object of type Association to the dictionary.
//
// Parameters
//
// objectToAdd
//
// The object to be added to the dictionary.
//
// End ---------------------------------------------------------------------
{
if( !objectToAdd.isAssociation() )
{
cerr << "Error: Object must be association type.";
exit( __ENOTASSOC );
}
else
{
Set::add( objectToAdd );
}
}
// End Member Function Dictionary::add //

View File

@ -0,0 +1,401 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// HashTable::isA
// HashTable::nameOf
// HashTable::add
// HashTable::detach
// HashTable::hashValue
// HashTable::findMember
// HashTable::initIterator
//
// HashTableIterator::HashTableIterator constructor
// HashTableIterator::operator ++
// HashTableIteartor::preIterate
// HashTableIterator::operator int
// HashTableIterator::restart
//
// Description
//
// Class HashTable member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __HASHTBL_H
#include <hashtbl.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __LIST_H
#include <list.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Member Function //
HashTable::~HashTable()
// Summary -----------------------------------------------------------------
//
// Destructor for a HashTable object.
//
// We don't do anything here, because the destructor for Array
// will take care of destroying the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType HashTable::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of an hash table.
//
// End ---------------------------------------------------------------------
{
return hashTableClass;
}
// End Member Function HashTable::isA //
// Member Function //
char *HashTable::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "HashTable."
//
// End ---------------------------------------------------------------------
{
return "HashTable";
}
// End Member Function HashTable::nameOf //
// Member Function //
void HashTable::add( Object& objectToAdd )
// Summary -----------------------------------------------------------------
//
// Adds an element to a hash table.
//
// Parameters
//
// objectToAdd
//
// The object we are to put in the hash table.
//
// End ---------------------------------------------------------------------
{
hashValueType index = getHashValue( objectToAdd );
// Body Comment
//
// Check to see if there is any List object at the given index.
// If there isn't an object already there, then we use the
// table's addAt() function to put a new List object there.
// If there is a List object already there, then we can use its member
// functions (note that it would be a run-time error to use the member
// functions of theErrorObject) to add our object to the list.
//
// EndComment
if( table[ index ] == NOOBJECT )
{
table.addAt( *(new List), index );
}
((List&)table[ index ]).add( objectToAdd );
}
// End Member Function HashTable::add //
// Member Function //
void HashTable::detach( const Object& objectToDetach, int deleteObjectToo )
// Summary -----------------------------------------------------------------
//
// Detaches an element in a hash table.
//
// Parameters
//
// objectToDetach
//
// The object we are to detach from the hash table.
//
// deleteObjectToo
//
// Indicates whether we are to call the object's destructor
//
// Functional Description
//
// If there is a list of objects at the given hash table entry,
// detach our object in the list.
//
// End ---------------------------------------------------------------------
{
hashValueType index = getHashValue( objectToDetach );
if( table[ index ] != NOOBJECT )
{
((List&)table[ index ]).detach( objectToDetach, deleteObjectToo );
}
}
// End Member Function HashTable::detach //
// Member Function //
hashValueType HashTable::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a list.
//
// End ---------------------------------------------------------------------
{
return hashValueType(0);
}
// End Member Function HashTable::hashValue //
// Member Function //
Object& HashTable::findMember( const Object& testObject ) const
// Summary -----------------------------------------------------------------
//
// Looks up the given object in the hash table and returns a
// reference to the object in the hash table, if the hash table
// contains an object which is equal to the given object.
//
// Parameters
//
// testObject
//
// The object for which we will be searching in this
// hash table.
//
// Return Value
//
// Returns NOOBJECT if this hash table does not have the given
// object. Returns a reference to the object otherwise.
//
// Functional Description
//
// Check to see if there is any List object at the given index.
// If there isn't an object already there, then we don't have
// the object in our hash table.
// If there is a List object already there, then we can use its member
// functions (note that it would be a run-time error to use the member
// functions of theErrorObject) to search for our object in the list.
//
// End ---------------------------------------------------------------------
{
hashValueType index = getHashValue( testObject );
if( table[ index ] == NOOBJECT )
{
return NOOBJECT;
}
return ((List&)table[ index ]).findMember( testObject );
}
// End Member Function HashTable::findMember //
// Member Function //
ContainerIterator& HashTable::initIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a hash table.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new HashTableIterator( this->table ) );
}
// End Member Function HashTable::initIterator //
// Constructor //
HashTableIterator::HashTableIterator( const Array& toIterate ) :
beingIterated( toIterate )
// Summary -----------------------------------------------------------------
//
// Constructor for a hash table iterator object.
//
// Functional Description
//
// We initialize the list iterator to a dummy list's iterator, then
// initialize the array iterator. Finally, we invoke operator ++()
// on the iterator to finish the initialization.
//
// End ---------------------------------------------------------------------
{
List dummy;
listIterator = (ListIterator *)&dummy.initIterator();
indexIterator = (ArrayIterator *)&toIterate.initIterator();
(void)preIterate();
}
// End Constructor HashTableIterator::HashTableIterator //
// Member Function //
Object& HashTableIterator::operator ++()
// Summary -----------------------------------------------------------------
//
// Increments a hash table iterator.
//
// End ---------------------------------------------------------------------
{
if ( preIterate() )
return (*listIterator)++;
else
return NOOBJECT;
}
// End Member Function HashTableIterator::operator ++ //
// Member Function //
int HashTableIterator::preIterate()
// Summary -----------------------------------------------------------------
//
// Prepares a hash table iterator for the next iteration step.
//
// Functional Description
//
// If our current list iterator is finished, we bump the array
// iterator up. If the element at that index is a valid list,
// we set up an iterator using that list.
//
//
// End ---------------------------------------------------------------------
{
while ( *listIterator == NOOBJECT )
{
delete listIterator;
while ( *indexIterator && *indexIterator == NOOBJECT )
(*indexIterator)++;
if ( *indexIterator == 0 )
return 0;
else // the array iteration isn't over.
{
Object& l = *indexIterator;
List& l1 = (List&)l;
listIterator = (ListIterator *)&l1.initIterator();
do {
(*indexIterator)++;
} while ( *indexIterator && *indexIterator == NOOBJECT );
}
}
return 1;
}
// End Member Function preIterate //
// Member Function //
HashTableIterator::operator int()
// Summary -----------------------------------------------------------------
//
// Implements a hash table iterator integer conversion operator.
// This is used to test for the end of iteration sequence.
//
// End ---------------------------------------------------------------------
{
return *indexIterator != 0;
}
// End Member Function HashTableIterator::operator int //
// Member Function //
HashTableIterator::operator Object&()
// Summary -----------------------------------------------------------------
//
// Conversion to Object operator.
//
// End ---------------------------------------------------------------------
{
return *listIterator;
}
// End Member Function HashTableIterator::operator Object& //
// Member Function //
void HashTableIterator::restart()
// Summary -----------------------------------------------------------------
//
// Restarts the iteration process.
//
// End ---------------------------------------------------------------------
{
delete indexIterator;
delete listIterator;
List dummy;
listIterator = (ListIterator *)&dummy.initIterator();
indexIterator = (ArrayIterator *)&beingIterated.initIterator();
operator ++();
}
// End Member Function HashTableIterator::restart //

View File

@ -0,0 +1,179 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
#ifndef __STRSTREAM_H
#include <strstream.h>
#endif
#ifndef __STDIO_H
#include <stdio.h>
#endif
#ifndef __STRNG_H
#include <strng.h>
#endif
#ifndef __LDATE_H
#include <ldate.h>
#endif
const BufSize = 20;
static char *MonthNames[] =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
// Member Function //
BaseDate::~BaseDate()
// Summary -----------------------------------------------------------------
//
// Destructor for a BaseDate object.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
int BaseDate::isEqual( const Object& testDate ) const
// Summary -----------------------------------------------------------------
//
// Determines whether two BaseDate objects are equal.
//
// End ---------------------------------------------------------------------
{
return MM == ((BaseDate&)testDate).MM &&
DD == ((BaseDate&)testDate).DD &&
YY == ((BaseDate&)testDate).YY;
}
// End Function BaseDate::isEqual //
// Member Function //
int BaseDate::isLessThan( const Object& testDate ) const
// Summary -----------------------------------------------------------------
//
// Determines whether the current BaseDate is less than the BaseDate
// passed as an argument.
//
// End ---------------------------------------------------------------------
{
if( YY != ((BaseDate&)testDate).YY )
return YY < ((BaseDate&)testDate).YY;
if( MM != ((BaseDate&)testDate).MM )
return MM < ((BaseDate&)testDate).MM;
return DD < ((BaseDate&)testDate).DD;
}
// End BaseDate::isLessThan //
// Member Function //
hashValueType BaseDate::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a string object.
//
// End ---------------------------------------------------------------------
{
return hashValueType( YY + MM + DD );
}
// End Member Function BaseDate::hashValue //
// Member Function //
Date::~Date()
// Summary -----------------------------------------------------------------
//
// Destructor for a Date object.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
void Date::printOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays this object on the given stream.
//
// Parameters
//
// outputStream
//
// The stream where we are to display the object.
//
// End ---------------------------------------------------------------------
{
char temp[BufSize];
ostrstream( temp, BufSize ) << MonthNames[ Month() ] << " " <<
Day() << "," << Year() << ends;
outputStream << temp;
}
// End Member Function Date::printOn //
// Member Function //
classType Date::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a Date.
//
// End ---------------------------------------------------------------------
{
return dateClass;
}
// End Member Function Date::isA //
// Member Function //
char *Date::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Date."
//
// End ---------------------------------------------------------------------
{
return "Date";
}
// End Member Function Date::nameOf //

View File

@ -0,0 +1,360 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// List::add
// List::destroy
// List::detach
// List::initIterator
// List::hashValue
//
// ListIterator::operator int
// ListIterator::operator Object&
// ListIterator::operator ++
// ListIterator::restart
//
// Description
//
// Implementation of class List member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __IOSTREAM_H
#include <iostream.h>
#define __IOSTREAM_H
#endif
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __CONTAIN_H
#include <contain.h>
#endif
#ifndef __LIST_H
#include <list.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __LSTELEM_H
#include <lstelem.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Member Function //
List::~List()
// Summary -----------------------------------------------------------------
//
// Destructor for a List object.
//
// End ---------------------------------------------------------------------
{
while( head != 0 )
{
ListElement *temp = head;
head = head->next;
delete temp;
}
}
// End Destructor //
// Member Function //
void List::add( Object& toAdd )
// Summary -----------------------------------------------------------------
//
// Adds the given object on the list.
//
// Parameters
//
// toAdd
//
// The object we are to add to the list. Once the object is
// added, it is owned by the list.
//
// End ---------------------------------------------------------------------
{
ListElement *newElement = new ListElement( &toAdd );
newElement->next = head;
head = newElement;
itemsInContainer++;
}
// End Member Function List::add //
// Member Function //
void List::detach( const Object& toDetach, int deleteObjectToo )
// Summary -----------------------------------------------------------------
//
// Detaches an object from the list.
//
// Parameter
//
// toDetach
//
// The object we are to search for and detach from the List.
//
// deleteObjectToo
//
// Specifies whether we are to delete the object.
//
// Functional Description
//
// If the object specified is at the head of the list, we remove
// the reference right away. Otherwise, we iterate through the list until
// we find it, then remove the reference.
//
// Remarks
//
// warnings:
// No error condition is generated if the object which was specified
// isn't in the list.
//
// End ---------------------------------------------------------------------
{
ListElement *cursor = head;
if ( *(head->data) == toDetach )
{
head = head->next;
}
else // the object isn't at the head of the list.
{
// Body Comment
//
// Normally we would do this iteration with a list iterator.
// Since we need to keep track of not only the objects in the
// list but also the list elements, i.e. the pointer nodes,
// we don't use the iterator.
//
// End
ListElement *trailer = head;
while ( cursor != 0 )
{
cursor = cursor->next;
if ( *(trailer->data) == toDetach )
{
trailer->next = cursor->next;
break;
}
else // the object isn't the one we want.
{
trailer = trailer->next;
}
} // end while
} // end else the object wasn't at the head of the list.
// Body Comment
//
// Now cursor points to the object that we've found
//
// End
if( cursor != 0 )
{
itemsInContainer--;
if ( deleteObjectToo )
{
delete cursor->data;
}
else
{
cursor->data = 0; // insure that we don't delete the data
}
delete cursor;
}
}
// End Member Function List::detach //
// Member Function //
classType List::isA() const
// Summary -----------------------------------------------------------------
//
// Returns a predefined value for the class List.
//
// Parameters
//
// none
//
// End ---------------------------------------------------------------------
{
return listClass;
}
// End Member Function List::isA //
// Member Function //
char *List::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns the string "List".
//
// Parameters
//
// none
//
// End ---------------------------------------------------------------------
{
return "List";
}
// End Member Function List::nameOf //
// Member Function //
hashValueType List::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a list.
//
// End ---------------------------------------------------------------------
{
return hashValueType(0);
}
// End Member Function List::hashValue //
// Member Function //
ContainerIterator& List::initIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a list.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new ListIterator( *this ) );
}
// End Member Function List::initIterator //
// Member Function //
ListIterator::~ListIterator()
// Summary -----------------------------------------------------------------
//
//
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
ListIterator::operator int()
// Summary -----------------------------------------------------------------
//
// Returns an integer value indicating whether the iteration is complete.
//
// 1 indicates not complete, 0 indicates complete.
//
// End ---------------------------------------------------------------------
{
return currentElement != 0;
}
// End Member Function ListIterator::operator int //
// Member Function //
ListIterator::operator Object&()
// Summary -----------------------------------------------------------------
//
// Object reference conversion operator.
//
// End ---------------------------------------------------------------------
{
if ( currentElement == 0 )
{
return NOOBJECT;
}
else
{
return ( (Object&)(*(currentElement->data)) );
}
}
// End Member Function ListIterator::operator Object& //
// Member Function //
Object& ListIterator::operator ++()
// Summary -----------------------------------------------------------------
//
// Increments the list iterator and returns the next object.
//
// End ---------------------------------------------------------------------
{
ListElement *trailer = currentElement;
if ( currentElement != 0 )
{
currentElement = currentElement->next;
return ( (Object&)(*(trailer->data)) );
}
else // no more elements in the list.
{
return NOOBJECT;
}
}
// End Member Function ListIterator::operator ++ //
// Member Function //
void ListIterator::restart()
// Summary -----------------------------------------------------------------
//
// Restart function for a list iterator object.
//
// End ---------------------------------------------------------------------
{
currentElement = startingElement;
}
// End Member Function ListIterator::restart //

View File

@ -0,0 +1,181 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// BaseTime::operator String()
//
// Description
//
// Implementation of class BaseTime member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __STRNG_H
#include <strng.h>
#endif
#ifndef __LTIME_H
#include <ltime.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __IOMANIP_H
#include <iomanip.h>
#endif
#ifndef __STRSTREAM_H
#include <strstream.h>
#endif
#ifndef __STDIO_H
#include <stdio.h>
#define __STDIO_H
#endif
// End Implementation Dependencies -------------------------------------------
const BufSize = 20;
// Member Function //
BaseTime::isEqual( const Object& testTime ) const
// Summary -----------------------------------------------------------------
//
// Determines whether two times are equal. Times are assumed to be
// normalized.
//
// Parameters
//
// testTime
//
// The time we are testing against this.
//
// End ---------------------------------------------------------------------
{
return HH == ((BaseTime&)testTime).HH &&
MM == ((BaseTime&)testTime).MM &&
SS == ((BaseTime&)testTime).SS &&
HD == ((BaseTime&)testTime).HD;
}
// End Member Function Time::isEqual //
// Member Function //
BaseTime::isLessThan( const Object& testTime ) const
// Summary -----------------------------------------------------------------
//
// Determines whether this time is less than the time passed as
// an argument. Times are assumed to be normalized.
//
// Parameters
//
// testTime
//
// The time we are testing against this.
//
// End ---------------------------------------------------------------------
{
if( HH != ((BaseTime&)testTime).HH )
return HH < ((BaseTime&)testTime).HH;
if( MM != ((BaseTime&)testTime).MM )
return MM < ((BaseTime&)testTime).MM;
if( SS != ((BaseTime&)testTime).SS )
return SS < ((BaseTime&)testTime).SS;
if( HD == ((BaseTime&)testTime).HD )
return HD < ((BaseTime&)testTime).HD;
}
// End Member Function Time::isEqual //
// Member Function //
hashValueType BaseTime::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a string object.
//
// End ---------------------------------------------------------------------
{
return hashValueType( HH + MM + SS + HD );
}
// End Member Function BaseTime::hashValue //
// Member Function //
void Time::printOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Displays this object on the given stream.
//
// Parameters
//
// outputStream
//
// The stream where we are to display the object.
//
// End ---------------------------------------------------------------------
{
char temp[16];
ostrstream( temp, BufSize ) <<
((hour()%12 == 0) ? 12 : hour()%12) << ":"
<< setfill( '0' )
<< setw( 2 ) << minute() << ":"
<< setw( 2 ) << second() << "."
<< setw( 2 ) << hundredths() << " "
<< ((hour() > 11) ? "p" : "a") << "m" << ends;
outputStream << temp;
}
// End Member Function Time::printOn //
// Member Function //
classType Time::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a Time object.
//
// End ---------------------------------------------------------------------
{
return timeClass;
}
// End Member Function Time::isA //
// Member Function //
char *Time::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Time."
//
// End ---------------------------------------------------------------------
{
return "Time";
}
// End Member Function Time::nameOf //

View File

@ -0,0 +1,418 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Object::~Object
// Object::isSortable
// Object::isAssociation
// Object::operator new
// Object::forEach
// Object::firstThat
// Object::lastThat
// Object::operator delete
//
// Error::~Error
// Error::isA
// Error::nameOf
// Error::printOn
// Error::hashValue
// Error::isEqual
//
// theErrorObject
// Object::ZERO initializer
//
// Description
//
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __OBJECT_H
#include <object.h>
#endif
// End Interface Dependencies ------------------------------------------------
Object::~Object()
// Summary -----------------------------------------------------------------
//
// Default destructor for an object. Doesn't do much, but it
// forces all classes derived from Object to have virtual
// destructors, which is essential for proper cleanup. It also
// provides a good place for setting breakpoints, because every
// time an object gets destroyed, this function will be called.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor Object::~Object //
// Member Function //
int Object::isSortable() const
// Summary -----------------------------------------------------------------
//
// indicates whether the object defines comparison operators
//
// Parameters
//
// none
//
// Remarks
//
// A basic Object is not sortable
//
// End ---------------------------------------------------------------------
{
return 0;
}
// End Member Function Object::isSortable //
// Member Function //
int Object::isAssociation() const
// Summary -----------------------------------------------------------------
//
// indicates whether the object is derived from class Association
//
// Parameters
//
// none
//
// Remarks
//
// A basic Object is not derived from class Association
//
// End ---------------------------------------------------------------------
{
return 0;
}
// End Member Function Object::isAssociation //
// Member Function //
void *Object::operator new( size_t s )
// Summary -----------------------------------------------------------------
//
// replacement for the standard operator new(). Returns ZERO
// if attempted allocation fails.
//
// Parameters
//
// s
//
// number of bytes to allocate
//
// Functional Description
//
// we call the global operator new() and check whether it succeeded.
// If it succeeded, we return the block that it allocated. If it
// failed, we return ZERO.
//
// End ---------------------------------------------------------------------
{
void *allocated = ::operator new( s );
if( allocated == 0 )
return ZERO;
else
return allocated;
}
// End Member Function Object::operator new //
// Member Function //
void Object::forEach( iterFuncType actionPtr, void *paramListPtr )
// Summary -----------------------------------------------------------------
//
// Calls the given iterator function on this object.
//
// Parameters
//
// actionPtr
//
// Pointer to the action routine which is to be called for this object.
//
// paramListPtr
//
// Pointer to the list of parameters which will be passed along to
// the action routine.
//
// Functional Description
//
// We call the given function, passing our object and the list of
// parameters that was given to us.
//
// Remarks
//
// warnings:
// The action routine must have a prototype of the form:
// void action( Object&, void * );
//
// End ---------------------------------------------------------------------
{
( *actionPtr )( *this, paramListPtr );
}
// End Member Function Object::forEach //
// Member Function //
Object& Object::firstThat( condFuncType testFuncPtr, void *paramListPtr ) const
// Summary -----------------------------------------------------------------
//
// Calls the given conditional test function on this object.
//
// Parameters
//
// testFuncPtr
//
// Pointer to the conditional test routine which is to be called
// for this object.
//
// paramListPtr
//
// Pointer to the list of parameters which will be passed along to
// the conditional test routine.
//
// Return Value
//
// Returns this if the this satisfies the condition. Returns
// NOOBJECT otherwise.
//
// Functional Description
//
// We call the given function, passing our object and the list of
// parameters that was given to us. If the function returns
// a 1, we return this object, otherwise we return NOOBJECT.
//
// Remarks
//
// warnings:
// The conditional test routine must have a prototype of the form:
// int test( Object&, void * );
// The conditional test routine must return 1 if the given object
// satisfies the condition.
//
// End ---------------------------------------------------------------------
{
if( ( *testFuncPtr )( *this, paramListPtr ) )
{
return( *this );
}
else // our object doesn't satisfy the condition //
{
return( NOOBJECT );
}
}
// End Member Function Object::firstThat //
// Member Function //
Object& Object::lastThat( condFuncType testFuncPtr, void *paramListPtr ) const
// Summary -----------------------------------------------------------------
//
// Calls the given conditional test function on this object. For
// non-container objects, lastThat is the same as firstThat.
//
// Parameters
//
// testFuncPtr
//
// Pointer to the conditional test routine which is to be called
// for this object.
//
// paramListPtr
//
// Pointer to the list of parameters which will be passed along to
// the conditional test routine.
//
// Functional Description
//
// We call the firstThat function.
//
// Remarks
//
// warnings:
// The conditional test routine must have a prototype of the form:
// int test( Object&, void * );
// The conditional test routine must return 1 if the given object
// satisfies the condition.
//
// End ---------------------------------------------------------------------
{
return Object::firstThat( testFuncPtr, paramListPtr );
}
// End Member Function Object::lastThat //
// Destructor //
Error::~Error()
// Description -------------------------------------------------------------
//
// We can't really destroy theErrorObject.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor Error::~Error //
// Member Function //
void Error::operator delete( void * )
// Summary -----------------------------------------------------------------
//
// Can't delete an Error object... so we pretend that we did.
//
// End ---------------------------------------------------------------------
{
}
// End Member Function Error::operator delete //
// Member Function //
classType Error::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of the error object.
//
// End ---------------------------------------------------------------------
{
return errorClass;
}
// End Member Function Error::isA //
// Member Function //
char *Error::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Error."
//
// End ---------------------------------------------------------------------
{
return "Error";
}
// End Member Function Error::nameOf //
// Member Function //
void Error::printOn( ostream& outputStream ) const
// Summary -----------------------------------------------------------------
//
// Error class override of the usual printOn. Since there isn't
// really any object to print, we emit an appropriate message.
//
// Parameters
//
// outputStream
// The stream on which to display the formatted contents of the object.
//
// End ---------------------------------------------------------------------
{
outputStream << "Error\n";
}
// End Member Function Error::printOn //
// Member Function //
hashValueType Error::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the value for use when hashing an error object.
// There should be only one object of class Error, so it's ok
// to return the same value every time.
//
// End ---------------------------------------------------------------------
{
return ERROR_CLASS_HASH_VALUE;
}
// End Member Function Error::hashValue //
// Member Function //
int Error::isEqual ( const Object& testObject ) const
// Summary -----------------------------------------------------------------
//
// Determines whether the given object is theErrorObject.
//
// Parameters
//
// testObject
//
// The object we are testing against theErrorObject.
//
// Return Value
//
// Returns 1 if the given object is theErrorObject, 0 otherwise.
//
// Functional Description
//
// The only way we get called here is if this is a pointer to
// theErrorObject. We test the address of our given object to see
// if it is the address of theErrorObject.
//
// End ---------------------------------------------------------------------
{
return &testObject == this;
}
// End Member Function Error::isEqual //
// Variable //
Error theErrorObject;
// Description -------------------------------------------------------------
//
// Defines a dummy object to which Object::ZERO will point. We only
// need this so we don't ever try to dereference a null pointer.
//
// End ---------------------------------------------------------------------
// Initializer //
Object *Object::ZERO = (Object *)&theErrorObject;
// Description -------------------------------------------------------------
//
// Initializes Object::ZERO. We wait to do this here because we
// have to get theErrorObject defined before we initialize Object::ZERO.
//
// End ---------------------------------------------------------------------

View File

@ -0,0 +1,160 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
// Queue::get
// Queue::initIterator
// Queue::hashValue
//
// Description
//
// Implementation of class Queue member functions.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __OBJECT_H
#include <object.h>
#endif
#ifndef __QUEUE_H
#include <queue.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
#ifndef __DBLLIST_H
#include <dbllist.h>
#endif
// End Implementation Dependencies -------------------------------------------
// Member Function //
Queue::~Queue()
// Summary -----------------------------------------------------------------
//
// Destructor for a Queue object.
//
// We don't do anything here, because the destructor for theQueue
// will take care of destroying the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
Object& Queue::get()
// Summary -----------------------------------------------------------------
//
// Gets an object from the queue. The object becomes the ownership
// of the receiver.
//
// Return Value
//
// firstIn
//
// We return the element which is a the tail of the queue, i.e. the
// first element in to the queue.
//
// End ---------------------------------------------------------------------
{
Object& temp = theQueue.peekAtTail();
if ( temp != NOOBJECT )
{
theQueue.detachFromTail( temp );
itemsInContainer--;
}
return temp;
}
// End Member Function Queue::get //
// Member Function //
classType Queue::isA() const
// Summary -----------------------------------------------------------------
//
// Returns a predefined value for the class Queue.
//
// Parameters
//
// none
//
// End ---------------------------------------------------------------------
{
return queueClass;
}
// End Member Function Queue::isA //
// Member Function //
char *Queue::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns the string "Queue".
//
// Parameters
//
// none
//
// End ---------------------------------------------------------------------
{
return "Queue";
}
// End Member Function Queue::nameOf //
// Member Function //
hashValueType Queue::hashValue() const
// Summary -----------------------------------------------------------------
//
// Returns the hash value of a queue.
//
// End ---------------------------------------------------------------------
{
return hashValueType(0);
}
// End Member Function Queue::hashValue //
// Member Function //
ContainerIterator& Queue::initIterator() const
// Summary -----------------------------------------------------------------
//
// Initializes an iterator for a queue.
//
// End ---------------------------------------------------------------------
{
return *( (ContainerIterator *)new DoubleListIterator( theQueue ) );
}
// End Member Function Queue::initIterator //

View File

@ -0,0 +1,107 @@
//
// This file contains proprietary information of Borland International.
// Copying or reproduction without prior written approval is prohibited.
//
// Copyright (c) 1990
// Borland International
// 1800 Scotts Valley Dr.
// Scotts Valley, CA 95066
// (408) 438-8400
//
// Contents ----------------------------------------------------------------
//
//
// Description
//
// Implementation of member functions for class Set.
//
// End ---------------------------------------------------------------------
// Interface Dependencies ---------------------------------------------------
#ifndef __CLSTYPES_H
#include <clstypes.h>
#endif
#ifndef __SET_H
#include <set.h>
#endif
// End Interface Dependencies ------------------------------------------------
// Implementation Dependencies ----------------------------------------------
// End Implementation Dependencies -------------------------------------------
// Member Function //
Set::~Set()
// Summary -----------------------------------------------------------------
//
// Destructor for a Set object.
//
// We don't do anything here, because the destructor for HashTable
// will take care of destroying the contained objects.
//
// End ---------------------------------------------------------------------
{
}
// End Destructor //
// Member Function //
classType Set::isA() const
// Summary -----------------------------------------------------------------
//
// Returns the class type of a set.
//
// End ---------------------------------------------------------------------
{
return setClass;
}
// End Member Function Set::isA //
// Member Function //
char *Set::nameOf() const
// Summary -----------------------------------------------------------------
//
// Returns a pointer to the character string "Set".
//
// End ---------------------------------------------------------------------
{
return "Set";
}
// End Member Function Set::isA //
// Member Function //
void Set::add( Object& objectToAdd )
// Summary -----------------------------------------------------------------
//
// Adds an object to the set. Sets may have only one copy of an object
// in the set at any time.
//
// Parameters
//
// objectToAdd
//
// End ---------------------------------------------------------------------
{
if ( !(Bag::hasMember( objectToAdd )) )
{
Bag::add( objectToAdd );
}
}
// End Member Function Set::add //

Some files were not shown because too many files have changed in this diff Show More