home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftptest.leeds.ac.uk
/
2015.02.ftptest.leeds.ac.uk.tar
/
ftptest.leeds.ac.uk
/
bionet
/
CAE-GROUP
/
SCL-WIN3x
/
SCL.EXE
/
GENNODEA.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-04
|
3KB
|
117 lines
/*
* NIST Utils Class Library
* clutils/gennodearray.h
* February, 1994
* David Sauder
* K. C. Morris
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
/* $Id: gennodearray.cc,v 2.0.1.2 1994/04/05 16:44:43 sauderd Exp $ */
#include <gennode.h>
#include <gennodel.h>
#include <gennodei.h>
#include <gennodea.h>
#include <string.h>
void bcopy (register char *src,register char *dest,register int len);
void bcopy (register char *src,register char *dest,register int len)
{
if (dest < src)
while (len--)
*dest++ = *src++;
else
{
char *lasts = src + (len-1);
char *lastd = dest + (len-1);
while (len--)
*(char *)lastd-- = *(char *)lasts--;
}
}
void
GenNodeArray::Check (int index)
{
GenericNode** newbuf;
if (index >= _bufsize) {
int oldBufSize = _bufsize;
_bufsize=_bufsize+1024; //= (index+1) * 2;
newbuf = new GenericNode*[_bufsize];
memset(newbuf, 0, _bufsize);
// memset(newbuf[oldBufSize], 0,
// (_bufsize - oldBufSize)*sizeof(GenericNode*) );
bcopy((char*)_buf, (char*)newbuf, _count*sizeof(GenericNode*));
//memcpy((void*)newbuf,(void*) _buf, _count*sizeof(GenericNode*));
delete [] _buf;
_buf = newbuf;
}
}
int
GenNodeArray::Insert (GenericNode* gn, int index)
{
const GenericNode** spot;
index = (index < 0) ? _count : index;
if (index < _count) {
Check(_count+1);
spot = (const GenericNode**)&_buf[index];
strcpy((char*)spot+1, (char*)spot);
} else {
Check(index);
spot = (const GenericNode**) &_buf[index];
}
*spot = gn;
++_count;
return index;
}
void
GenNodeArray::Remove (int index)
{
if (0 <= index && index < _count) {
--_count;
const GenericNode** spot = (const GenericNode**)&_buf[index];
strcpy((char*)spot+1, (char*)spot);
_buf[_count] = 0;
}
}
void GenNodeArray::ClearEntries ()
{
// if(debug_level >= PrintFunctionTrace)
// cout << "GenNodeArray::Clear()\n";
int i;
for(i = 0 ; i < _count; i++)
_buf[i] = 0;
_count = 0;
}
void GenNodeArray::DeleteEntries()
{
// if(debug_level >= PrintFunctionTrace)
// cout << "GenNodeArray::DeleteEntries()\n";
int i;
for(i = 0 ; i < _count; i++)
delete (_buf[i]);
_count = 0;
}
int GenNodeArray::Index (GenericNode* gn)
{
// if(debug_level >= PrintFunctionTrace)
// cout << "GenNodeArray::Index()\n";
for (register int i = 0; i < _count; ++i) {
if (_buf[i] == gn) {
return i;
}
}
return -1;
}