Import backup from 2005-09-11
This commit is contained in:
1 parent
396c5f3452
commit
0521733e20
10 files changed
+1391
-79
No files matched your search
+18
-5
@@ -31,9 +31,12 @@ public:
|
||||
/* Constructors/Destructor */
|
||||
vector<type>();
|
||||
vector<type>(unsigned int size);
|
||||
vector<type>(vector<type> & v1);
|
||||
vector<type>(const vector<type> & v1);
|
||||
~vector<type>();
|
||||
|
||||
/* Assignment operator */
|
||||
vector<type> & operator=(const vector<type> & v1);
|
||||
|
||||
/* Returns the size of the vector */
|
||||
unsigned int size() const;
|
||||
|
||||
@@ -49,7 +52,6 @@ public:
|
||||
/* Direct access operators */
|
||||
const type & operator[](unsigned int index) const;
|
||||
type & operator[](unsigned int index);
|
||||
|
||||
};
|
||||
|
||||
template<typename type>
|
||||
@@ -69,12 +71,12 @@ vector<type>::vector<type>(unsigned int size)
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type>::vector<type>(vector<type> & v1)
|
||||
vector<type>::vector<type>(const vector<type> & v1)
|
||||
{
|
||||
mySize = v1.mySize;
|
||||
myAllocated = v1.myAllocated;
|
||||
myData = new (type *)[myAllocated];
|
||||
for (int i = 0; i < mySize; i++)
|
||||
for (u32_t i = 0; i < mySize; i++)
|
||||
myData[i] = new type(*v1.myData[i]);
|
||||
}
|
||||
|
||||
@@ -86,6 +88,16 @@ vector<type>::~vector<type>()
|
||||
delete[] myData;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type> & vector<type>::operator=(const vector<type> & v1)
|
||||
{
|
||||
mySize = v1.mySize;
|
||||
myAllocated = v1.myAllocated;
|
||||
myData = new (type *)[myAllocated];
|
||||
for (u32_t i = 0; i < mySize; i++)
|
||||
myData[i] = new type(*v1.myData[i]);
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
u32_t vector<type>::size() const
|
||||
{
|
||||
@@ -110,6 +122,7 @@ vector<type> & vector<type>::add(type elem)
|
||||
while (mySize >= myAllocated)
|
||||
grow();
|
||||
myData[mySize++] = new type(elem);
|
||||
kprintf("vector.h: added element %d @ 0x%x\n", mySize-1, myData[mySize-1]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -145,7 +158,7 @@ vector<type> & vector<type>::insert(type elem, unsigned int position)
|
||||
{
|
||||
if (position <= mySize)
|
||||
{
|
||||
if (mySize == myAllocated)
|
||||
if (mySize >= myAllocated)
|
||||
grow();
|
||||
for (unsigned int i = mySize; i > position; i--)
|
||||
myData[i] = myData[i-1];
|
||||
|
||||
Reference in new issue
Block a user