Import backup from 2005-06-02
This commit is contained in:
1 parent
b0132c866e
commit
692cf2fc08
22 files changed
+512
-244
No files matched your search
@@ -102,6 +102,9 @@ static inline bool operator<=(const char *cstring, const string & str)
|
||||
static inline bool operator>=(const char *cstring, const string & str)
|
||||
{ return str <= cstring; }
|
||||
|
||||
static inline string operator+(const char *cstring, const string & str)
|
||||
{ return string(cstring, str); }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
|
||||
// vector.h
|
||||
// implements c++ vector object for HOS
|
||||
// Author: Josh Holtrop
|
||||
// Date: 05/30/05
|
||||
// Modified: 05/30/05
|
||||
|
||||
|
||||
#ifndef __HOS_VECTOR__
|
||||
#define __HOS_VECTOR__ __HOS_VECTOR__
|
||||
|
||||
template<typename type>
|
||||
class vector
|
||||
{
|
||||
protected:
|
||||
/* Pointers to vector elements */
|
||||
type **myData;
|
||||
|
||||
/* How many elements are present */
|
||||
unsigned int mySize;
|
||||
|
||||
/* How many elements there are pointers for */
|
||||
unsigned int myAllocated;
|
||||
|
||||
/* Causes the vector to double in its allocated size */
|
||||
void grow();
|
||||
|
||||
public:
|
||||
/* Constructors/Destructor */
|
||||
vector<type>();
|
||||
vector<type>(unsigned int size);
|
||||
~vector<type>();
|
||||
|
||||
/* Returns the size of the vector */
|
||||
unsigned int size() const;
|
||||
|
||||
/* Add an element to the end of the vector */
|
||||
vector<type> & add(type elem);
|
||||
|
||||
/* Remove an element from the vector */
|
||||
vector<type> & remove(unsigned int index);
|
||||
|
||||
/* Insert an element into a position in the vector */
|
||||
vector<type> & insert(type elem, unsigned int position);
|
||||
|
||||
/* Direct access operators */
|
||||
const type & operator[](unsigned int index) const;
|
||||
type & operator[](unsigned int index);
|
||||
|
||||
};
|
||||
|
||||
template<typename type>
|
||||
vector<type>::vector<type>()
|
||||
{
|
||||
myData = NULL;
|
||||
mySize = 0;
|
||||
myAllocated = 0;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type>::vector<type>(unsigned int size)
|
||||
{
|
||||
myData = new (type *)[size];
|
||||
mySize = 0;
|
||||
myAllocated = size;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type>::~vector<type>()
|
||||
{
|
||||
for (unsigned int i = 0; i < mySize; i++)
|
||||
delete myData[i];
|
||||
delete[] myData;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
u32_t vector<type>::size() const
|
||||
{
|
||||
return mySize;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
const type & vector<type>::operator[](unsigned int index) const
|
||||
{
|
||||
return *myData[index];
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
type & vector<type>::operator[](unsigned int index)
|
||||
{
|
||||
return *myData[index];
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type> & vector<type>::add(type elem)
|
||||
{
|
||||
while (mySize >= myAllocated)
|
||||
grow();
|
||||
myData[mySize++] = new type(elem);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
void vector<type>::grow()
|
||||
{
|
||||
myAllocated <<= 1;
|
||||
if (myAllocated == 0)
|
||||
myAllocated = 1;
|
||||
type **data_new = new (type *)[myAllocated];
|
||||
for (unsigned int i = 0; i < mySize; i++)
|
||||
data_new[i] = myData[i];
|
||||
if (myData)
|
||||
delete[] myData;
|
||||
myData = data_new;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type> & vector<type>::remove(unsigned int index)
|
||||
{
|
||||
if (index < mySize)
|
||||
{
|
||||
delete myData[index];
|
||||
for (unsigned int i = index; i < (mySize - 1); i++)
|
||||
myData[i] = myData[i+1];
|
||||
mySize--;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type> & vector<type>::insert(type elem, unsigned int position)
|
||||
{
|
||||
if (position <= mySize)
|
||||
{
|
||||
if (mySize == myAllocated)
|
||||
grow();
|
||||
for (unsigned int i = mySize; i > position; i--)
|
||||
myData[i] = myData[i-1];
|
||||
myData[position] = new type(elem);
|
||||
mySize++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user