home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-28 | 34.0 KB | 1,122 lines |
- Newsgroups: comp.sources.misc
- From: tlhouns@srv.pacbell.com (Lee Hounshell)
- Subject: v33i128: var - C++ class library "var" (v1.1) and "VarMap" (associative arrays), Part02/02
- Message-ID: <1992Nov25.215658.19787@sparky.imd.sterling.com>
- X-Md4-Signature: 4d78e84a407547ae47405dd75ad48e64
- Date: Wed, 25 Nov 1992 21:56:58 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tlhouns@srv.pacbell.com (Lee Hounshell)
- Posting-number: Volume 33, Issue 128
- Archive-name: var/part02
- Environment: C++, G++
- Supersedes: var: Volume 31, Issue 91-92
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: LEGAL_NOTICE Makefile VarMap.3++ VarMap.C VarMap.H demo.C
- # var.H
- # Wrapped by kent@sparky on Tue Nov 24 09:31:38 1992
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 2 (of 2)."'
- if test -f 'LEGAL_NOTICE' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'LEGAL_NOTICE'\"
- else
- echo shar: Extracting \"'LEGAL_NOTICE'\" \(1388 characters\)
- sed "s/^X//" >'LEGAL_NOTICE' <<'END_OF_FILE'
- X
- X Any use of this source code must include, in the user documentation
- X and internal comments to the code, and notices to the end user as
- X follows:
- X
- X Copyright (c) 1992 Lee Hounshell
- X
- X LEE HOUNSHELL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
- X THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS"
- X WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. LEE HOUNSHELL
- X SEVERALLY AND INDIVIDUALLY, DISCLAIM ALL WARRANTIES WITH REGARD
- X TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
- X MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
- X EVENT SHALL LEE HOUNSHELL BE LIABLE FOR ANY SPECIAL, INDIRECT,
- X INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
- X RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- X OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- X OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.
- X
- X Permission to use, copy, modify, and distribute this software
- X and its documentation for any purpose and without fee is hereby
- X granted, provided that the above copyright notice appear in all
- X copies and that both that copyright notice and this permission
- X notice appear in supporting documentation, and that the name of
- X Lee Hounshell not be used in advertising in publicity pertaining
- X to distribution of the software without specific, written prior
- X permission.
- X
- END_OF_FILE
- if test 1388 -ne `wc -c <'LEGAL_NOTICE'`; then
- echo shar: \"'LEGAL_NOTICE'\" unpacked with wrong size!
- fi
- # end of 'LEGAL_NOTICE'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(1475 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X############################################################################
- X# make - compiles the C++ library (libvar.a)
- X# make clean - removes all .o files generated in these procedures
- X# make clobber - removes all libraries, cleans up .o's
- X############################################################################
- X
- X
- X# from the two below, pick the operating system closest to yours:
- X
- X# If you're using g++, define CC and INCDIRS as appropriate for you
- XCC = g++
- XINCDIRS = -I. -I/usr/local/lib/g++-include
- X
- X# If you're using Sun or AT&T C++ version 2.0 or 2.1 use these..
- X#CC = CC
- X#INCDIRS = -I.
- X
- X#SYS = HP
- XSYS = SUN
- X
- X#-----don't change anything after this line-----
- X
- XCFLAGS = -O $(INCDIRS)
- XARFLAGS = rv
- X
- X
- Xis_bsd = test $(SYS) = SUN
- X
- Xall: libvar.a
- X
- XC++FILES = var.C VarMap.C
- XINS_HFILES = var.H VarMap.H
- XHFILES = $(INS_HFILES)
- X
- XOBJECTS = ${C++FILES:.C=.o}
- X
- Xlibvar.a: $(OBJECTS)
- X ar $(ARFLAGS) $@ $?
- X if $(is_bsd) ; then ranlib $@; fi
- X
- X$(OBJECTS): $(HFILES)
- X
- Xdemo: libvar.a demo.C demo2.C
- X $(CC) $(INCDIRS) demo.C -L. -lvar -o demo
- X $(CC) $(INCDIRS) demo2.C -L. -lvar -o demo2
- X
- Xclean:
- X rm -f *.o a.out core $(OBJECTS)
- X cd demo; $(MAKE) clean
- X
- Xclobber: clean
- X rm -fr $(DOTAS)
- X cd demo; $(MAKE) clobber
- X
- X#####
- X#####
- X#.SUFFIXES: .o .C .C~ .c .c~
- X.SUFFIXES: .o .C .C~
- X.C~.C:
- X -cd $(<D); $(GET) $(GFLAGS) $(<F)
- X.C.c:
- X $(CC) $(CFLAGS) -Fc $*.C > $*.c
- X.C.o:
- X $(CC) $(CFLAGS) -c $*.C
- X.C~.o:
- X -cd $(<D); $(GET) $(GFLAGS) $(<F)
- X $(CC) $(CFLAGS) -c $*.C
- X
- END_OF_FILE
- if test 1475 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'VarMap.3++' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'VarMap.3++'\"
- else
- echo shar: Extracting \"'VarMap.3++'\" \(8400 characters\)
- sed "s/^X//" >'VarMap.3++' <<'END_OF_FILE'
- X.po 6
- X.TH VARMAP 3++ "1/92" "Version 1.0" "VAR Associative Array Class Library"
- X
- X.SH CLASS
- XVARMAP \- Variable Base Type Associative Array Class Library
- X.SH SYNOPSIS
- X.B #include <VarMap.H>
- X.PP
- X.nf
- X.ta.5i 1.0i 4.0i
- X\fB
- Xclass VarMap {
- X
- X public:
- X // Standard Interface
- X const var & type(void) const; // who am i
- X
- X // Constructors & Destructor
- X VarMap(int type = VARMAP_FIFO);
- X ~VarMap(void) {remove();}
- X
- X // Operators
- X VarMap & operator = (const VarMap &); // assign VarMaps
- X int operator == (VarMap &) const; // equality
- X int operator != (VarMap &) const; // inequality
- X var & operator [] (const var index); // index/create entry
- X
- X friend ostream & operator << (ostream &, const VarMap &); // output
- X friend TraceStream & operator << (TraceStream &, const VarMap &);
- X
- X // Standard Member Functions
- X void print(ostream &) const; // output
- X
- X // Custom Interface - see VarMap man pages for use
- X int append(var newkey, var newvalue); // append to map
- X int push(var newkey, var newvalue); // push a var
- X var pop(void); // pop a var
- X int empty(void) const; // is map empty
- X int at_start(void) const; // at head of map
- X int at_end(void) const; // at end of map
- X int position(void); // index within map
- X int size(void) const; // length of map
- X void remove(void); // remove all items
- X void delete_here(void); // remove this item
- X int element(const var & index); // test for element
- X var & key(void); // current key
- X var & value(void); // current value
- X void display(ostream & out = cerr); // print the map
- X void first(void); // point to first node
- X void next(void); // point to next node
- X void last(void); // point to last node
- X};
- X.fi
- X\fP
- X
- X.SH DESCRIPTION
- XClass \fBVarMap\fP represents an \fBassociative array\fP object class that allows dynamic
- Xarrays of \fBvar\fP objects to be indexed by another \fBvar\fP object.
- X\fBVarMap\fP, is in many ways a "super-associative-array" class.
- XThe VarMap class does a pretty good job of offering an associative array object with an
- Xindex of virtually \fBany base type\fP. It also provides a base data "container" object
- Xthat can assume its "type" at run time, based on context. VarMap can also function as a "stack"
- Xobject, with both FIFO (first-in-first-out) and LIFO (last-in-last-out) capabilities.
- X
- X.SH PUBLIC CONSTRUCTORS
- X.SS VarMap(int type = VARMAP_FIFO);
- XThis constructor is used to declare a VarMap object. The newly created object will
- Xinitially contain NO data elements. If the paramater \fBVARMAP_LIFO\fP is specified,
- Xthen this object will use LIFO (last-in-first-out) stack operations. If either no
- Xparameter or \fBVARMAP_FIFO\fP is specified, then FIFO (first-in-first-out) stack
- Xoperations will occur on this object. Type of the indexed object
- Xis determined at run-time, based on context of use.
- X
- X.SS ~VarMap(void);
- XThe destructor returns all memory allocated by the object back to the OS.
- X
- X.SH PUBLIC OPERATORS
- X.SS The Assignment Operator
- XThe assignment operator (=) will operate as expected.
- XAs no \fBcopy constructor\fP exists at present for \fBVarMap\fP, you will need
- Xto use this operator to initialize copies of other VarMaps.
- X
- X.SS Relational Operators
- XOnly the \fBequality\fP (==) and \fBinequality\fP (!=) operators are currently implemented.
- XThese operate as expected. The objects must be \fBexactly\fP the same to match.
- X
- X.SS The Indexing Operator []
- XYou can index any \fBvar\fP object inside a \fBVarMap\fP object by using
- Xthe \fB"var & operator [] (const var);"\fP operator. WARNING!! If you attempt
- Xto index an object that does not yet exist, then it will be created automatically.
- XTo test whether or not an object exists without creating it, use the \fBelement(const var)\fP
- Xmember function. A reference to the indexed \fBvar\fP is returned, which can be assigned to.
- X
- X.SS Type Casting
- XThere are no cast operators for \fBVarMap\fP objects; however, you may cast the
- Xindexed \fBvar\fP object to any base type.
- X
- X.SS Output
- XYou can output the contents of an entire \fBVarMap\fP object using the io stream library.
- XObjects can be output using the ">>" operator.
- XFor formatted output, be sure to index and set each \fBvar\fP element's "format template"
- Xprior to calling the ">>" operator. (see \fB"var & format(const char *);"\fP)
- X
- X.SH PUBLIC MEMBER FUNCTIONS
- X
- X.SS Appending a New Element and Key to a VarMap
- XThe \fB"int append(var newkey, var newvalue);\fP function will append a new element
- Xto the VarMap with the index \fBnewkey\fP and the value \fBnewvalue\fP. The size of
- Xthe VarMap is increased by one.
- X
- X.SS Pushing a New Element (and Key) onto a VarMap
- XThe \fB"int push(var newkey, var newvalue);\fP function will push a new element
- Xto the \fBVarMap\fP stack with the index \fBnewkey\fP and the value \fBnewvalue\fP.
- XThe size of the \fBVarMap\fP is increased by one. The order that this element will be
- Xlater \fBpopped\fP is determined by the \fBVarmap\fP object's initial VARMAP_FIFO
- Xor VARMAP_LIFO constructor argument.
- X
- X.SS Poping an Element from a VarMap
- XThe \fB"int pop(void);\fP function will pop the next appropriate element
- Xfrom the \fBVarMap\fP stack. The size of the \fBVarMap\fP is decreased by one.
- XThe order that each element is popped is determined by the \fBVarmap\fP object's
- Xinitial VARMAP_FIFO or VARMAP_LIFO constructor argument.
- X
- X.SS Testing a VarMap Index
- XThe \fB"int element(const var & index) const;"\fP function returns 1 if a \fBVarMap\fP entry
- Xexists for the passed index value, 0 otherwise.
- X
- X.SS Determining if a VarMap is Empty
- XThe \fB"int empty(void) const;"\fP function returns 1 if a \fBVarMap\fP is empty, 0 otherwise.
- X
- X.SS Determining VarMap's Size
- XThe \fB"int size(void) const;"\fP function returns the "size" of a \fBVarMap\fP.
- X
- X.SS Relative "Positions" Inside a VarMap Object
- XSix member functions exist to allow user to "walk" through a \fBVarMap's\fP elements and/or test
- Xwhere (relatively speaking) you are currently positioned within the map. The first two are used
- Xto test if you are at the \fBhead\fP or \fBtail\fP of the \fBVarMap\fP.
- XThe \fB"int at_start(void) const;"\fP function returns 1 if you are at the head of a \fBVarMap\fP, 0 otherwise.
- XThe \fB"int at_end(void) const;"\fP function returns 1 if you are at the tail of a \fBVarMap\fP, 0 otherwise.
- XThe \fB"int position(void) const;"\fP function returns relative \fBnumerical position\fP of the current
- Xnode in a \fBVarMap\fP. Three memeber functions allow you to change the current position.
- XThe \fB"void first(void) const;"\fP function moves the current \fBVarMap\fP pointer to the head of the map.
- XThe \fB"void last(void) const;"\fP function moves the current \fBVarMap\fP pointer to the tail of the map.
- XThe \fB"void next(void) const;"\fP function moves the current \fBVarMap\fP pointer to the next entry of the map.
- X
- X.SS Deleting the current VarMap Entry
- XThe \fB"void delete_here(void) const;"\fP function will destroy the currently \fBpointed to\fP entry.
- XThis is often used in conjunction with the \fBfirst()\fP and \fBnext()\fP function to traverse a
- X\fBVarMap\fP and remove nodes at random. After a \fBdelete_here()\fP call, the \fBVarMap\fP will be
- Xpointing to the \fBnext\fP node (just as if a \fBnext()\fP call had been made).
- X
- X.SS Deleting all VarMap Entries
- XThe \fB"void remove(void) const;"\fP function will destroy every entry in the \fBVarMap\fP. After this
- Xcall, the \fBVarMap's\fP size will be zero.
- X
- X.SS Extracting the Current Entry's Key Value
- XThe \fB"var & key(void);"\fP function will return a reference to the current \fBVarMap\fP element's key.
- X
- X.SS Extracting the Current Entry's Data Value
- XThe \fB"var & value(void);"\fP function will return a reference to the current \fBVarMap\fP element.
- X
- X.SS Displaying a VarMap
- XThe \fB"void display(ostream & out = cerr);"\fP function will output all elements and keys of a \fBVarMap\fP
- Xto the passed ostream. By default, output is sent to \fBcerr\fP.
- X
- X.SH AUTHOR
- XLee Hounshell - 1/92
- X
- X.SH EXAMPLE
- X.nf
- X#include <VarMap.H>
- X
- Xmain ()
- X{
- X VarMap aa; // declare a VarMap
- X var lee = "foobar";
- X if (!aa.element(lee)) {
- X aa[lee] = "hello world"; // create/assign using index "foobar"
- X }
- X aa[42] = "testing 123"; // create/assign using index "42"
- X aa[5] = 123.45; // create/assign using index "5"
- X aa.display(); // display this map to stderr
- X}
- X.fi
- X
- X.SH SUPERCLASSES
- Xnone.
- X
- X.SH SUBCLASSES
- Xvar
- X
- X.SH BUGS
- X
- END_OF_FILE
- if test 8400 -ne `wc -c <'VarMap.3++'`; then
- echo shar: \"'VarMap.3++'\" unpacked with wrong size!
- fi
- # end of 'VarMap.3++'
- fi
- if test -f 'VarMap.C' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'VarMap.C'\"
- else
- echo shar: Extracting \"'VarMap.C'\" \(6346 characters\)
- sed "s/^X//" >'VarMap.C' <<'END_OF_FILE'
- X//
- X// NAME: VarMap.C
- X//
- X// PURPOSE: C++ "Map of Vars" Class Library Source File
- X// VERSION: 1.0
- X// AUTHOR: Lee Hounshell
- X// LAST MOD: Mon Nov 23 13:55:39 PST 1992
- X//
- X
- X#include <stream.h>
- X#include "VarMap.H"
- X
- X// -----------------------------------------------------------------------------
- X
- Xconst var & VarMapNode::type(void) const
- X{
- X static const var objtype = "VarMapNode";
- X return objtype;
- X}
- X
- X
- Xconst var & VarMap::type(void) const
- X{
- X static const var objtype = "VarMap";
- X return objtype;
- X}
- X
- X
- XVarMapNode::VarMapNode(var newkey, var newvalue)
- X{
- X errno = 0;
- X key = newkey;
- X value = newvalue;
- X prev = next = NULL;
- X}
- X
- X
- XVarMap::VarMap(int type)
- X{
- X errno = 0;
- X typeofmap = type;
- X here = head = tail = NULL;
- X _size = 0;
- X}
- X
- X// -----------------------------------------------------------------------------
- X
- XVarMap & VarMap::operator = (const VarMap & map)
- X{
- X if (this != &map) {
- X VarMapNode *vptr;
- X remove();
- X typeofmap = map.typeofmap;
- X for (vptr = map.head; vptr; vptr = vptr->next) {
- X append(vptr->key, vptr->value);
- X }
- X here = map.here;
- X }
- X return *this;
- X}
- X
- X
- Xint VarMap::operator == (VarMap & map) const
- X{
- X if (size() != map.size()) {
- X return 0;
- X }
- X if (empty() && map.empty()) {
- X return 1;
- X }
- X int rc = 1;
- X VarMapNode *tmp1 = head;
- X VarMapNode *tmp2 = map.head;
- X int done = 0;
- X do {
- X if (tmp1 == tail) {
- X done = 1;
- X }
- X if (tmp1->key != tmp2->key) {
- X rc = 0;
- X break;
- X }
- X if (tmp1->value != tmp2->value) {
- X rc = 0;
- X break;
- X }
- X if ((tmp2 == map.tail) && (tmp1 != tail)) {
- X rc = 0;
- X break;
- X }
- X tmp1 = tmp1->next;
- X tmp2 = tmp2->next;
- X } while (!done);
- X return rc;
- X}
- X
- X
- Xint VarMap::operator != (VarMap & map) const
- X{
- X return (!(*this == map));
- X}
- X
- X
- Xvar & VarMap::operator [] (const var index)
- X{
- X for (VarMapNode *vptr = head; vptr; vptr = vptr->next) {
- X if (vptr->key == index) {
- X here = vptr;
- X return vptr->value;
- X }
- X }
- X append(index, "");
- X return here->value;
- X}
- X
- X// -----------------------------------------------------------------------------
- X
- Xint VarMap::append(var newkey, var newvalue)
- X{
- X VarMapNode *newnode = new VarMapNode(newkey, newvalue);
- X if (newnode == NULL) {
- X cerr << "Out of memory.\n";
- X return 0;
- X }
- X if (head == NULL) {
- X // empty map
- X head = newnode;
- X tail = newnode;
- X }
- X else {
- X tail->next = newnode;
- X newnode->prev = tail;
- X tail = newnode;
- X }
- X here = newnode;
- X _size++;
- X return 1;
- X}
- X
- X
- Xint VarMap::push(var newkey, var newvalue)
- X{
- X if (typeofmap == VARMAP_FIFO) {
- X return append(newkey, newvalue);
- X }
- X else if (typeofmap == VARMAP_LIFO) {
- X VarMapNode *newnode = new VarMapNode(newkey, newvalue);
- X if (newnode == NULL) {
- X cerr << "Out of memory.\n";
- X return 0;
- X }
- X if (head == NULL) {
- X // empty map
- X head = newnode;
- X tail = newnode;
- X }
- X else {
- X head->prev = newnode;
- X newnode->next = head;
- X newnode->prev = NULL;
- X head = newnode;
- X }
- X here = newnode;
- X }
- X return 1;
- X}
- X
- X
- Xvar VarMap::pop(void)
- X{
- X var data;
- X VarMapNode *vptr;
- X if (head == NULL) {
- X // empty map
- X return 0;
- X }
- X data = head->value;
- X vptr = head;
- X here = head = head->next;
- X if (head) {
- X head->prev = NULL;
- X }
- X else {
- X tail = NULL;
- X }
- X delete vptr;
- X _size--;
- X return data;
- X}
- X
- X
- Xint VarMap::empty(void) const
- X{
- X return head == NULL;
- X}
- X
- X
- Xint VarMap::at_start(void) const
- X{
- X return here == head;
- X}
- X
- X
- Xint VarMap::at_end(void) const
- X{
- X return here == tail;
- X}
- X
- X
- Xint VarMap::position(void)
- X{
- X int index = 0;
- X VarMapNode *vptr = head;
- X while (vptr && vptr != here) {
- X vptr = vptr->next;
- X ++index;
- X }
- X return index;
- X}
- X
- X
- Xint VarMap::size(void) const
- X{
- X return _size;
- X}
- X
- X
- Xvoid VarMap::remove(void)
- X{
- X VarMapNode *vptr = head;
- X while (vptr) {
- X VarMapNode *tmp = vptr;
- X vptr = vptr->next;
- X delete tmp;
- X }
- X here = head = tail = NULL;
- X _size = 0;
- X}
- X
- X
- Xvoid VarMap::delete_here(void)
- X{
- X if (here) {
- X VarMapNode *vptr = here;
- X if (here->next) {
- X here->next->prev = here->prev;
- X }
- X if (here->prev) {
- X here->prev->next = here->next;
- X }
- X if (here == head && head == tail) {
- X here = head = tail = NULL;
- X }
- X else if (here == head) {
- X head = here->next;
- X here = head;
- X }
- X else if (here == tail) {
- X tail = here->prev;
- X here = tail;
- X }
- X else {
- X here = here->next;
- X }
- X delete vptr;
- X --_size;
- X }
- X}
- X
- X
- Xint VarMap::element(const var & index)
- X{
- X for (VarMapNode *vptr = head; vptr; vptr = vptr->next) {
- X if (vptr->key == index) {
- X return 1; // found it
- X }
- X }
- X return 0; // this index doesn't exist
- X}
- X
- X
- Xvar & VarMap::key(void)
- X{
- X static var vkey = "";
- X if (!here) {
- X return vkey;
- X }
- X return here->key;
- X}
- X
- X
- Xvar & VarMap::value(void)
- X{
- X static var vvalue = "";
- X if (!here) {
- X return vvalue;
- X }
- X return here->value;
- X}
- X
- X
- Xvoid VarMap::display(ostream & out)
- X{
- X out << "Display VarMap\n";
- X for (VarMapNode *vptr = head; vptr; vptr = vptr->next) {
- X out << "\tKey: " << vptr->key << " Value: " << vptr->value << "\n";
- X }
- X}
- X
- X
- X// return value of first node - NULL if invalid
- Xvoid VarMap::first(void)
- X{
- X here = head;
- X}
- X
- X
- X// return value of next node
- Xvoid VarMap::next(void)
- X{
- X if (here == tail) {
- X return;
- X }
- X here = here->next;
- X}
- X
- X
- X// return value of last node
- Xvoid VarMap::last(void)
- X{
- X here = tail;
- X}
- X
- X// -----------------------------------------------------------------------------
- X
- Xostream & operator << (ostream &out, const VarMapNode &d)
- X{
- X d.print(out);
- X return out;
- X}
- X
- X
- Xostream & operator << (ostream &out, const VarMap &d)
- X{
- X d.print(out);
- X return out;
- X}
- X
- X
- Xvoid VarMapNode::print(ostream &out) const
- X{
- X out << "VarMapNode OBJECT: {"
- X << "\n\t<this> = " << (void *) this
- X << "\n\tvar key = " << key
- X << "\n\tvar value = " << value
- X << "\n\tVarMapNode *prev = " << prev
- X << "\n\tVarMapNode *next = " << next
- X << "\n}\n";
- X}
- X
- X
- Xvoid VarMap::print(ostream &out) const
- X{
- X out << "VarMap OBJECT: {"
- X << "\n\tint typeofmap = " << typeofmap
- X << "\n\tVarMapNode *head = " << head
- X << "\n\tVarMapNode *tail = " << tail
- X << "\n\tVarMapNode *here = " << here
- X << "\n\tint _size = '" << _size << "'";
- X int i = 0;
- X for (VarMapNode *ptr = head; ptr; ptr = ptr->next) {
- X ++i;
- X out << "\n\tVarMapNode #" << i << " = " << *ptr;
- X }
- X out << "\n}\n";
- X}
- X
- END_OF_FILE
- if test 6346 -ne `wc -c <'VarMap.C'`; then
- echo shar: \"'VarMap.C'\" unpacked with wrong size!
- fi
- # end of 'VarMap.C'
- fi
- if test -f 'VarMap.H' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'VarMap.H'\"
- else
- echo shar: Extracting \"'VarMap.H'\" \(2602 characters\)
- sed "s/^X//" >'VarMap.H' <<'END_OF_FILE'
- X//
- X// NAME: VarMap.H
- X//
- X// PURPOSE: C++ "Map of Vars" Class Library Header File
- X// VERSION: 1.0
- X// AUTHOR: Lee Hounshell
- X// LAST MOD: Mon Nov 23 13:50:56 PST 1992
- X//
- X
- X#ifndef VARMAP_H
- X#define VARMAP_H
- X
- X#include <stream.h>
- X#include "var.H"
- X
- Xenum {VARMAP_FIFO, VARMAP_LIFO};
- X
- Xclass VarMapNode
- X{
- X public:
- X // Standard Interface
- X const var & type(void) const; // who am i
- X
- X // Operators
- X friend ostream & operator << (ostream &, const VarMapNode &); // output
- X
- X friend class VarMap;
- X
- X // Standard Member Functions
- X void print(ostream &) const; // output
- X
- X int errno; // primitive error control
- X
- X protected:
- X
- X private:
- X VarMapNode(var newkey, var newvalue);
- X var key;
- X var value;
- X VarMapNode *prev;
- X VarMapNode *next;
- X};
- X
- X
- Xclass VarMap
- X{
- X public:
- X // Standard Interface
- X const var & type(void) const; // who am i
- X
- X // Constructors & Destructor
- X VarMap(int type = VARMAP_FIFO);
- X ~VarMap(void) {remove();}
- X
- X // Operators
- X VarMap & operator = (const VarMap &); // assign VarMaps
- X int operator == (VarMap &) const; // equality
- X int operator != (VarMap &) const; // inequality
- X var & operator [] (const var index); // index/create entry
- X
- X friend ostream & operator << (ostream &, const VarMap &); // output
- X
- X // Standard Member Functions
- X void print(ostream &) const; // output
- X
- X // Custom Interface - see VarMap man pages for use
- X int append(var newkey, var newvalue); // append to map
- X int push(var newkey, var newvalue); // push a var
- X var pop(void); // pop a var
- X int empty(void) const; // is map empty
- X int at_start(void) const; // at head of map
- X int at_end(void) const; // at end of map
- X int position(void); // index within map
- X int size(void) const; // length of map
- X void remove(void); // remove all items
- X void delete_here(void); // remove this item
- X int element(const var & index); // test for element
- X var & key(void); // current key
- X var & value(void); // current value
- X void display(ostream & out = cerr); // print the map
- X void first(void); // point to first node
- X void next(void); // point to next node
- X void last(void); // point to last node
- X
- X int errno; // primitive error control
- X
- X protected:
- X
- X private:
- X int typeofmap; // VARMAP_FIFO or VARMAP_LIFO
- X VarMapNode *head; // first node
- X VarMapNode *tail; // last node
- X VarMapNode *here; // current node
- X int _size; // size of Map
- X};
- X
- X#endif
- X
- END_OF_FILE
- if test 2602 -ne `wc -c <'VarMap.H'`; then
- echo shar: \"'VarMap.H'\" unpacked with wrong size!
- fi
- # end of 'VarMap.H'
- fi
- if test -f 'demo.C' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'demo.C'\"
- else
- echo shar: Extracting \"'demo.C'\" \(824 characters\)
- sed "s/^X//" >'demo.C' <<'END_OF_FILE'
- X#include <stdlib.h>
- X#include <stream.h>
- X#include <var.H>
- X
- Xmain ()
- X{
- X var value; // declare an "untyped" var
- X value = "hello world"; // initialize it
- X cout << value << "\n"; // output "hello world"
- X value = value(3, value.length() - 6); // substring example
- X cout << value << "\n"; // output "lo wo"
- X value = 34; // assignment of int
- X value++; // increment
- X value += 42.375; // add 42.375 to present value
- X cout << value << "\n"; // output "77.375"
- X cout << value.format("formatted output example %05d of value\n");
- X cout << value.format("multiple outputs #1=%d, #2=%9.2f of value\n");
- X value.null(2); // truncate string
- X value += " sunset strip"; // concatenate a string
- X cout << value.format("%s\n"); // output "77 sunset strip"
- X cout << value[3] << value[4] << value[5] << "\n"; // output "sun"
- X}
- X
- END_OF_FILE
- if test 824 -ne `wc -c <'demo.C'`; then
- echo shar: \"'demo.C'\" unpacked with wrong size!
- fi
- # end of 'demo.C'
- fi
- if test -f 'var.H' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'var.H'\"
- else
- echo shar: Extracting \"'var.H'\" \(8847 characters\)
- sed "s/^X//" >'var.H' <<'END_OF_FILE'
- X//
- X// NAME: var.H
- X//
- X// PURPOSE: C++ Generic "Universal Variable" Class Library Header File
- X// VERSION: 1.1
- X// AUTHOR: Lee Hounshell
- X// LAST MOD: Mon Nov 23 08:56:24 PST 1992
- X//
- X
- X#ifndef VAR_H
- X#define VAR_H
- X
- X#include <stream.h>
- X#include "string.h"
- X
- X// -----------------------------------------------------------------------------
- X//
- Xclass varsize {
- X // dummy class needed for var constructor of specific size that
- X // doesn't conflict with the var integer type constructor
- X public:
- X // Constructors & Destructors
- X varsize(int sz); // constructor
- X int size; // size of var
- X};
- X
- Xclass subvar;
- X
- X// -----------------------------------------------------------------------------
- X//
- Xclass var {
- X
- X public:
- X // Standard Interface
- X const var & type(void) const; // who am i
- X
- X // Constructors & Destructors
- X var(void); // constructor
- X var(const varsize &); // constructor
- X var(const char *); // constructor
- X var(const char); // constructor
- X var(const short); // constructor
- X var(const unsigned short); // constructor
- X var(const int); // constructor
- X var(const unsigned int); // constructor
- X var(const long); // constructor
- X var(const unsigned long); // constructor
- X var(const double); // constructor
- X var(const var &); // copy constructor
- X ~var(void); // destructor
- X
- X // Operators
- X var & operator = (const char *); // assignment
- X var & operator = (const var &); // assignment
- X char & operator [] (const int); // indexing
- X subvar & operator () (int, int) const; // substring
- X subvar & operator () (const int) const; // substring
- X friend ostream & operator << (ostream &, const var &); // output
- X friend class subvar; // substring
- X
- X // More Operators (used for arithmetic type extension)
- X var & operator = (const char); // assignment
- X var & operator = (const short); // assignment
- X var & operator = (const unsigned short); // assignment
- X var & operator = (const int); // assignment
- X var & operator = (const unsigned int); // assignment
- X var & operator = (const long); // assignment
- X var & operator = (const unsigned long); // assignment
- X var & operator = (const double); // assignment
- X
- X // Casting Operators
- X operator char * (void) const; // type conversion
- X operator double (void) const; // type conversion
- X
- X // Assignment Operators
- X var & operator ++ (void); // increment (pre-index only)
- X var & operator -- (void); // decrement (pre-index only)
- X var operator ! (void) const; // not
- X
- X var operator + (const var &) const; // addition OR concatenation
- X var operator - (const var &) const; // subtraction
- X var operator * (const var &) const; // multiplication
- X var operator / (const var &) const; // division
- X var operator % (const var &) const; // remainder
- X
- X var & operator += (const var &); // addition OR concatenation
- X var & operator -= (const var &); // subtraction
- X var & operator *= (const var &); // multiplication
- X var & operator /= (const var &); // division
- X var & operator %= (const var &); // remainder
- X
- X var & operator += (const char &); // addition OR concatenation
- X var & operator += (const char *); // addition OR concatenation
- X var & operator -= (const char *); // subtraction
- X var & operator *= (const char *); // multiplication
- X var & operator /= (const char *); // division
- X var & operator %= (const char *); // remainder
- X
- X var & operator += (const double); // addition OR concatenation
- X var & operator -= (const double); // subtraction
- X var & operator *= (const double); // multiplication
- X var & operator /= (const double); // division
- X var & operator %= (const double); // remainder
- X
- X friend var operator + (const char *, const var &); // addition OR concatenation
- X friend var operator - (const char *, const var &); // subtraction
- X friend var operator * (const char *, const var &); // multiplication
- X friend var operator / (const char *, const var &); // division
- X friend var operator % (const char *, const var &); // remainder
- X friend var operator + (const var &, const char *); // addition OR concatenation
- X friend var operator - (const var &, const char *); // subtraction
- X friend var operator * (const var &, const char *); // multiplication
- X friend var operator / (const var &, const char *); // division
- X friend var operator % (const var &, const char *); // remainder
- X
- X friend var operator + (const var &, const double); // addition OR concatenation
- X friend var operator - (const var &, const double); // subtraction
- X friend var operator * (const var &, const double); // multiplication
- X friend var operator / (const var &, const double); // division
- X friend var operator % (const var &, const double); // remainder
- X friend var operator + (const double, const var &); // addition OR concatenation
- X friend var operator - (const double, const var &); // subtraction
- X friend var operator * (const double, const var &); // multiplication
- X friend var operator / (const double, const var &); // division
- X friend var operator % (const double, const var &); // remainder
- X
- X // Equality Operators
- X int operator == (const var &) const; // equality
- X int operator != (const var &) const; // inequality
- X int operator < (const var &) const; // less than
- X int operator > (const var &) const; // greater than
- X int operator <= (const var &) const; // less than or equal
- X int operator >= (const var &) const; // greater than or equal
- X
- X friend int operator == (const var &, const char *); // equality
- X friend int operator != (const var &, const char *); // inequality
- X friend int operator < (const var &, const char *); // less than
- X friend int operator > (const var &, const char *); // greater than
- X friend int operator <= (const var &, const char *); // less than or equal
- X friend int operator >= (const var &, const char *); // greater than or equal
- X friend int operator == (const char *, const var &); // equality
- X friend int operator != (const char *, const var &); // inequality
- X friend int operator < (const char *, const var &); // less than
- X friend int operator > (const char *, const var &); // greater than
- X friend int operator <= (const char *, const var &); // less than or equal
- X friend int operator >= (const char *, const var &); // greater than or equal
- X
- X friend int operator == (const var &, const double); // equality
- X friend int operator != (const var &, const double); // inequality
- X friend int operator < (const var &, const double); // less than
- X friend int operator > (const var &, const double); // greater than
- X friend int operator <= (const var &, const double); // less than or equal
- X friend int operator >= (const var &, const double); // greater than or equal
- X friend int operator == (const double, const var &); // equality
- X friend int operator != (const double, const var &); // inequality
- X friend int operator < (const double, const var &); // less than
- X friend int operator > (const double, const var &); // greater than
- X friend int operator <= (const double, const var &); // less than or equal
- X friend int operator >= (const double, const var &); // greater than or equal
- X
- X // Custom Interface
- X void null(int); // "null" out string
- X void changesize(int); // change allocated memory
- X int length(void) const; // length of string
- X const char * vartype(void) const; // name of this var type
- X void change_type(const char *); // change var type
- X int is_string(void) const; // test var type
- X int is_double(void) const; // test var type
- X int is_long(void) const; // test var type
- X int strchr(const char) const; // strchr(char) index
- X int strrchr(const char) const; // strrchr(char) index
- X var & concat(const var &); // concatenation
- X var & format(const char *); // set output format
- X void print(ostream &) const; // output
- X
- X protected:
- X
- X private:
- X int numcheck(const char *) const; // determine is_numeric value
- X
- X short fixed; // 1=fixed data type
- X short is_numeric; // 0=string, 1=short/int/long, 2=float/double
- X int data_str_len; // length of allocated "string"
- X int data_str_end; // index to current "end" of string
- X char *data_str; // for "string" data
- X char *format_str; // the output format string
- X
- X};
- X
- X
- Xclass subvar : public var {
- X public:
- X var & operator = (const var &); // substring replacement
- X var *varptr;
- X unsigned offset;
- X unsigned length;
- X};
- X
- X
- X// global conversion functions
- Xchar *itoa(const int foo);
- Xchar *uitoa(const unsigned int foo);
- Xchar *dtoa(const double foo);
- Xdouble atod(char * foo);
- X
- X#ifdef HP
- X char *ltoa(long foo);
- X char *ultoa(unsigned long foo);
- X#else
- X char *ltoa(const long foo);
- X char *ultoa(const unsigned long foo);
- X#endif
- X
- X
- X#endif
- X
- END_OF_FILE
- if test 8847 -ne `wc -c <'var.H'`; then
- echo shar: \"'var.H'\" unpacked with wrong size!
- fi
- # end of 'var.H'
- fi
- echo shar: End of archive 2 \(of 2\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-