Missing file from previous checkin.

This commit is contained in:
Justin Marshall
2020-06-26 15:04:01 -07:00
parent 28f5f86f91
commit 37b47a8cfe
+79 -79
View File
@@ -52,46 +52,46 @@
#include <stdlib.h>
#include <stddef.h>
// ST - 5/8/1029
//inline void * operator new(size_t , void * pointer) {return(pointer);}
//inline void * operator new[](size_t , void * pointer) {return(pointer);}
// ST - 5/8/1029
//inline void * operator new(size_t , void * pointer) {return(pointer);}
//inline void * operator new[](size_t , void * pointer) {return(pointer);}
/**************************************************************************
** This is a general purpose vector class. A vector is defined by this
** class, as an array of arbitrary objects where the array can be dynamically
** sized. Because is deals with arbitrary object types, it can handle everything.
** As a result of this, it is not terribly efficient for integral objects (such
** as char or int). It will function correctly, but the copy constructor and
** equality operator could be highly optimized if the integral type were known.
** This efficiency can be implemented by deriving an integral vector template
** from this one in order to supply more efficient routines.
*/
/**************************************************************************
** This is a general purpose vector class. A vector is defined by this
** class, as an array of arbitrary objects where the array can be dynamically
** sized. Because is deals with arbitrary object types, it can handle everything.
** As a result of this, it is not terribly efficient for integral objects (such
** as char or int). It will function correctly, but the copy constructor and
** equality operator could be highly optimized if the integral type were known.
** This efficiency can be implemented by deriving an integral vector template
** from this one in order to supply more efficient routines.
*/
template<class T>
class VectorClass
{
public:
VectorClass(NoInitClass const & ) {};
VectorClass(unsigned size=0, T const * array=0);
VectorClass(VectorClass<T> const &); // Copy constructor.
public:
VectorClass(NoInitClass const&) {};
VectorClass(unsigned size = 0, T const* array = 0);
VectorClass(VectorClass<T> const&); // Copy constructor.
virtual ~VectorClass(void);
T & operator[](unsigned index) {return(Vector[index]);};
T const & operator[](unsigned index) const {return(Vector[index]);};
virtual VectorClass<T> & operator =(VectorClass<T> const &); // Assignment operator.
virtual int operator == (VectorClass<T> const &) const; // Equality operator.
virtual int Resize(unsigned newsize, T const * array=0);
T& operator[](unsigned index) { return(Vector[index]); };
T const& operator[](unsigned index) const { return(Vector[index]); };
virtual VectorClass<T>& operator =(VectorClass<T> const&); // Assignment operator.
virtual int operator == (VectorClass<T> const&) const; // Equality operator.
virtual int Resize(unsigned newsize, T const* array = 0);
virtual void Clear(void);
unsigned Length(void) const {return VectorMax;};
virtual int ID(T const * ptr); // Pointer based identification.
virtual int ID(T const & ptr); // Value based identification.
unsigned Length(void) const { return VectorMax; };
virtual int ID(T const* ptr); // Pointer based identification.
virtual int ID(T const& ptr); // Value based identification.
protected:
protected:
/*
** This is a pointer to the allocated vector array of elements.
*/
T * Vector;
T* Vector;
/*
** This is the maximum number of elements allowed in this vector.
@@ -102,7 +102,7 @@ class VectorClass
** Does the vector data pointer refer to memory that this class has manually
** allocated? If so, then this class is responsible for deleting it.
*/
unsigned IsAllocated:1;
unsigned IsAllocated : 1;
};
@@ -118,41 +118,41 @@ class VectorClass
template<class T>
class DynamicVectorClass : public VectorClass<T>
{
public:
DynamicVectorClass(unsigned size=0, T const * array=0);
public:
DynamicVectorClass(unsigned size = 0, T const* array = 0);
// Change maximum size of vector.
virtual int Resize(unsigned newsize, T const * array=0);
virtual int Resize(unsigned newsize, T const* array = 0);
// Resets and frees the vector array.
virtual void Clear(void) {ActiveCount = 0;VectorClass<T>::Clear();};
virtual void Clear(void) { ActiveCount = 0;VectorClass<T>::Clear(); };
// Fetch number of "allocated" vector objects.
int Count(void) const {return(ActiveCount);};
int Count(void) const { return(ActiveCount); };
// Add object to vector (growing as necessary).
int Add(T const & object);
int Add_Head(T const & object);
int Add(T const& object);
int Add_Head(T const& object);
// Delete object just like this from vector.
int Delete(T const & object);
int Delete(T const& object);
// Delete object at this vector index.
int Delete(int index);
// Deletes all objects in the vector.
void Delete_All(void) {ActiveCount = 0;};
void Delete_All(void) { ActiveCount = 0; };
// Set amount that vector grows by.
int Set_Growth_Step(int step) {return(GrowthStep = step);};
int Set_Growth_Step(int step) { return(GrowthStep = step); };
// Fetch current growth step rate.
int Growth_Step(void) {return GrowthStep;};
int Growth_Step(void) { return GrowthStep; };
virtual int ID(T const * ptr) {return(VectorClass<T>::ID(ptr));};
virtual int ID(T const & ptr);
virtual int ID(T const* ptr) { return(VectorClass<T>::ID(ptr)); };
virtual int ID(T const& ptr);
protected:
protected:
/*
** This is a count of the number of active objects in this
@@ -210,22 +210,22 @@ public:
return Count(Active);
}
int Add(T const & object)
int Add(T const& object)
{
return Add(Active, object);
}
int Add_Head(T const & object)
int Add_Head(T const& object)
{
return Add_Head(Active, object);
}
int Delete(T const & object)
int Delete(T const& object)
{
return Delete(Active, object);
}
int Delete_All(T const & object)
int Delete_All(T const& object)
{
int count = 0;
for (int i = FIRST; i < COUNT; ++i)
@@ -235,7 +235,7 @@ public:
return count;
}
int Delete_All_Except(T const & object, int except)
int Delete_All_Except(T const& object, int except)
{
int count = 0;
for (int i = FIRST; i < COUNT; ++i)
@@ -253,12 +253,12 @@ public:
return Delete(Active, index);
}
T & operator[](unsigned index)
T& operator[](unsigned index)
{
return Collection[Active][index];
}
T const & operator[](unsigned index) const
T const& operator[](unsigned index) const
{
return Collection[Active][index];
}
@@ -273,17 +273,17 @@ public:
return Collection[context].Count();
}
int Add(int context, T const & object)
int Add(int context, T const& object)
{
return Collection[context].Add(object);
}
int Add_Head(int context, T const & object)
int Add_Head(int context, T const& object)
{
return Collection[context].Add(object);
}
int Delete(int context, T const & object)
int Delete(int context, T const& object)
{
return Collection[context].Delete(object);
}
@@ -293,12 +293,12 @@ public:
return Collection[context].Delete(index);
}
DynamicVectorClass<T> & Raw()
DynamicVectorClass<T>& Raw()
{
return Collection[Active];
}
DynamicVectorClass<T> & Raw(int context)
DynamicVectorClass<T>& Raw(int context)
{
return Collection[context];
}
@@ -321,18 +321,18 @@ private:
*/
class BooleanVectorClass
{
public:
BooleanVectorClass(unsigned size=0, unsigned char * array=0);
BooleanVectorClass(BooleanVectorClass const & vector);
public:
BooleanVectorClass(unsigned size = 0, unsigned char* array = 0);
BooleanVectorClass(BooleanVectorClass const& vector);
// Assignment operator.
BooleanVectorClass & operator =(BooleanVectorClass const & vector);
BooleanVectorClass& operator =(BooleanVectorClass const& vector);
// Equivalency operator.
int operator == (BooleanVectorClass const & vector);
int operator == (BooleanVectorClass const& vector);
// Fetch number of boolean objects in vector.
int Length(void) {return BitCount;};
int Length(void) { return BitCount; };
// Set all boolean values to false;
void Reset(void);
@@ -347,11 +347,11 @@ class BooleanVectorClass
int Resize(unsigned size);
// Fetch reference to specified index.
bool const & operator[](int index) const {
bool const& operator[](int index) const {
if (LastIndex != index) Fixup(index);
return(Copy);
};
bool & operator[](int index) {
bool& operator[](int index) {
if (LastIndex != index) Fixup(index);
return(Copy);
};
@@ -390,8 +390,8 @@ class BooleanVectorClass
return(-1);
}
private:
void Fixup(int index=-1) const;
private:
void Fixup(int index = -1) const;
/*
** This is the number of boolean values in the vector. This value is
@@ -447,7 +447,7 @@ class BooleanVectorClass
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
DynamicVectorClass<T>::DynamicVectorClass(unsigned size, T const * array)
DynamicVectorClass<T>::DynamicVectorClass(unsigned size, T const* array)
: VectorClass<T>(size, array)
{
GrowthStep = 10;
@@ -475,7 +475,7 @@ DynamicVectorClass<T>::DynamicVectorClass(unsigned size, T const * array)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int DynamicVectorClass<T>::Resize(unsigned newsize, T const * array)
int DynamicVectorClass<T>::Resize(unsigned newsize, T const* array)
{
if (VectorClass<T>::Resize(newsize, array)) {
if (Length() < (unsigned)ActiveCount) ActiveCount = Length();
@@ -504,7 +504,7 @@ int DynamicVectorClass<T>::Resize(unsigned newsize, T const * array)
* 03/13/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int DynamicVectorClass<T>::ID(T const & object)
int DynamicVectorClass<T>::ID(T const& object)
{
for (int index = 0; index < Count(); index++) {
if ((*this)[index] == object) return(index);
@@ -531,7 +531,7 @@ int DynamicVectorClass<T>::ID(T const & object)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int DynamicVectorClass<T>::Add(T const & object)
int DynamicVectorClass<T>::Add(T const& object)
{
if (ActiveCount >= (int)Length()) {
if ((IsAllocated || !VectorMax) && GrowthStep > 0) {
@@ -578,7 +578,7 @@ int DynamicVectorClass<T>::Add(T const & object)
* 09/21/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int DynamicVectorClass<T>::Add_Head(T const & object)
int DynamicVectorClass<T>::Add_Head(T const& object)
{
if (ActiveCount >= (int)Length()) {
if ((IsAllocated || !VectorMax) && GrowthStep > 0) {
@@ -631,7 +631,7 @@ int DynamicVectorClass<T>::Add_Head(T const & object)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int DynamicVectorClass<T>::Delete(T const & object)
int DynamicVectorClass<T>::Delete(T const& object)
{
return(Delete(ID(object)));
}
@@ -700,7 +700,7 @@ int DynamicVectorClass<T>::Delete(int index)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
VectorClass<T>::VectorClass(unsigned size, T const * array) :
VectorClass<T>::VectorClass(unsigned size, T const* array) :
Vector(0),
VectorMax(size),
IsAllocated(false)
@@ -759,7 +759,7 @@ VectorClass<T>::~VectorClass(void)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
VectorClass<T>::VectorClass(VectorClass<T> const & vector) :
VectorClass<T>::VectorClass(VectorClass<T> const& vector) :
Vector(0),
VectorMax(0),
IsAllocated(false)
@@ -784,7 +784,7 @@ VectorClass<T>::VectorClass(VectorClass<T> const & vector) :
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
VectorClass<T> & VectorClass<T>::operator =(VectorClass<T> const & vector)
VectorClass<T>& VectorClass<T>::operator =(VectorClass<T> const& vector)
{
if (this != &vector) {
Clear();
@@ -824,7 +824,7 @@ VectorClass<T> & VectorClass<T>::operator =(VectorClass<T> const & vector)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int VectorClass<T>::operator == (VectorClass<T> const & vector) const
int VectorClass<T>::operator == (VectorClass<T> const& vector) const
{
if (VectorMax == vector.Length()) {
for (int index = 0; index < (int)VectorMax; index++) {
@@ -857,9 +857,9 @@ int VectorClass<T>::operator == (VectorClass<T> const & vector) const
* 03/13/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
inline int VectorClass<T>::ID(T const * ptr)
inline int VectorClass<T>::ID(T const* ptr)
{
return(((INT_PTR)ptr - (INT_PTR)&(*this)[0]) / sizeof(T));
return(((INT_PTR)ptr - (INT_PTR) & (*this)[0]) / sizeof(T));
}
@@ -880,7 +880,7 @@ inline int VectorClass<T>::ID(T const * ptr)
* 03/13/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int VectorClass<T>::ID(T const & object)
int VectorClass<T>::ID(T const& object)
{
for (int index = 0; index < (int)VectorMax; index++) {
if ((*this)[index] == object) {
@@ -939,7 +939,7 @@ void VectorClass<T>::Clear(void)
* 03/10/1995 JLB : Created. *
*=============================================================================================*/
template<class T>
int VectorClass<T>::Resize(unsigned newsize, T const * array)
int VectorClass<T>::Resize(unsigned newsize, T const* array)
{
if (newsize) {
@@ -947,7 +947,7 @@ int VectorClass<T>::Resize(unsigned newsize, T const * array)
** Allocate a new vector of the size specified. The default constructor
** will be called for every object in this vector.
*/
T * newptr;
T* newptr;
if (!array) {
newptr = new T[newsize];
}