Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 102 lines (71 sloc) 1.21 KB
#ifndef com_sleepless_misc_vector_cpp
#define com_sleepless_misc_vector_cpp
// Copyright 1998-2002
// Sleepless Software Inc.
// All Rights Reserved
/*
Similar to java.util.Vector
*/
#include "Shelf.cpp"
class Vector
{
Shelf shelf;
int numItems;
public:
// Return # of items in the vector
int size()
{
return numItems;
}
// Append an item to the end of the vector
bool add(void *p)
{
bool r = shelf.put(numItems, p);
if(r)
numItems++;
return r;
}
// Remove all items from the vector
void clear()
{
numItems = 0;
}
// Return pointer at index 'i'
void *get(int i)
{
return shelf.get(i);
}
// Same as get(int i)
void *elementAt(int i)
{
return get(i);
}
// Remove item from index 'i', size is reduced by 1 and item is returned.
void *remove(int i)
{
void *p = get(i);
for( ; i < numItems - 1; i++)
{
shelf.put(i, shelf.get(i + 1));
}
numItems--;
return p;
}
// Remove item 'p' if found. Size is reduced by 1 and item is returned if found.
void *remove(void *p)
{
for(int i = 0; i < numItems; i++)
{
if(get(i) == p)
{
return remove(i);
}
}
return NULL;
}
Vector()
{
numItems = 0;
}
};
#endif // com_sleepless_misc_vector_cpp
Something went wrong with that request. Please try again.