Source: lycad_chargen/Vector.h
|
|
|
|
/***************************************************************************
Vector.h - description
-------------------
begin : Fri May 12 2000
copyright : (C) 2000 by Sheldon Lee Wen
email : sheldonl@linuxstart.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* header file for a generic Vector class. The source is in Vector.cc
*
* A dynamic array implementation of a vector that stores generic (void)
* pointers.
*
* Written by: Rob Boyd rboyd@telusplanet.net
*
*/
#if !defined VECTOR_H
# define VECTOR_H
# include
# if !defined NULL
# define NULL 0x0
# endif
class Vector
{
private:
int sz;
int curSize, numRemoved;
void **data;
int iter; // iterator
public:
// constructor
Vector(int s = 50);
// destructor
~Vector() { delete [] data;}
int capacity() {return sz;} // what is the current limit to the vector
int size() {return curSize;} // how many elements are currently stored
int contains(void *elem); // returns whether elem is in the Vector
int isEmpty() {return ((curSize - numRemoved) == 0);}
int indexOf(void *elem); // returns the index of the element
void *elementAt(int index); // returns the element at index
void *firstElement(); // returns the first element
void *lastElement(); // returns the last element
int insertElementAt(void *elem, int index);
void addElement(void *elem);
int setElementAt(void *elem, int index);
void removeAllElements(); // clear the vector
void removeElementAt(int index);
void removeElement(void *elem);
void setSize(int s); // reset the size of the vector
void trimToSize(); // shrink the vector to it's minimum size
// iterator functions
void iBegin(); // sets the iterator to the beginning
void iEnd(); // sets the iterator to the end
void *getNext(); // returns the next object
void *getPrev(); // returns the previous object
protected:
// protected methods for clean up and space re-use, etc...
};
#endif
Generated by: sheldonl on cr595811-a on Fri Nov 30 10:24:34 2001, using kdoc 2.0a53. |