|
JVector
/*
This library was downloaded from: http://www.mike95.com
This library is copyright. It may freely be used for personal
purposes
if the restriction listed below is adhered to.
Author: Michael Olivero
Email: mike95@mike95.com
//===============================
//Start of Restriction Definition
//===============================
Anyone can have full use of the library provided they keep this
complete comment
with the source. Also I would like to ask if any changes are
made to the
code for efficiency reasons, please let me know so I may look into
your change and
likewise incorporate it into library. If a suggestion makes
it into the library,
your credits will be added to this information.
Authors of Computer related books are welcome to include this
source code as part
of their publishing, provided credit the Author and make note of
where the source
code was obtained from: http://www.mike95.com
//=============================
//End of Restriction Definition
//=============================
Description:
Visit http://www.mike95.com/c_plusplus/classes/JVector/
Standard collection class. It's public member functions
are identical to the Java Vector public member functions (except
for any Java specific
Java related functions).
//The following people have contributed to the solution
//of bugs or additional features in this library
//=====================================================
//Carl Pupa, email: pumacat@erols.com
//Adam Doppelt, email: amd@gurge.com
//Dave O'Keefe, email: okeefe@cs.stanford.edu
//George Kerber, email: gek@pobox.com
*/
#ifndef COM_MIKE95_COM_JVECTOR_H
#define COM_MIKE95_COM_JVECTOR_H
#include <iostream>
#include "M95_types.h"
using namespace std;
template <class Etype>
class JVector
{
public:
JVector( UINT initialCapacity = 10, UINT
capacityIncrement = 10 );
JVector( const JVector& rhv );
virtual ~JVector();
//Inspectors (additional exception throwing inspectors
below)
//===========================================================
UINT capacity() const;
bool contains( const Etype& elem ) const;
const Etype& firstElement() const;
int indexOf( const Etype& elem ) const;
bool isEmpty() const;
const Etype& lastElement() const;
int lastIndexOf( const Etype& elem ) const;
UINT size() const;
void copyInto( Etype* array ) const;
//Modifiers (additional exception throwing inspectors
below)
//==========================================================
void addElement( const Etype& obj );
void ensureCapacity( UINT minCapacity );
void removeAllElements();
bool removeElement( const Etype& obj );
void setSize( UINT newSize );
void trimToSize();
//Exceptions are thrown at run time with the following
functions if
//the index parameter is not within a valid range.
If the data
//is uncertain (i.e. user inputed), then you should
wrap these function
//calls with the try/catch blocks and handle them
appropriately.
//===============================================
const Etype& elementAt( UINT index )
const; //inspector
void insertElementAt( const Etype& obj, UINT index
); //modifier
void removeElementAt( UINT index
);
//modifier
void setElementAt( const Etype& obj, UINT index
); //modifier
//C++ specific operations
//=======================
const Etype& operator[]( UINT index ) const;
Etype& operator[]( UINT index );
protected:
void verifyIndex( UINT index ) const;
UINT m_size;
UINT m_capacity;
UINT m_increment;
Etype** m_pData;
};
#endif
|
|
|