Main Page | Class Hierarchy | Class List | File List | Class Members

FluVectorClass.h

00001 // $Id: FluVectorClass.h,v 1.2 2004/10/13 20:05:52 jbryan Exp $
00002 
00003 /***************************************************************
00004  *                FLU - FLTK Utility Widgets 
00005  *  Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
00006  *
00007  * This file and its content is protected by a software license.
00008  * You should have received a copy of this license with this file.
00009  * If not, please contact the Ohio Supercomputer Center immediately:
00010  * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
00011  * 
00012  ***************************************************************/
00013 
00014 
00015 
00016 #ifndef _FLU_VECTOR_CLASS_H
00017 #define _FLU_VECTOR_CLASS_H
00018 
00019 // hackish macro way of making a template class for compilers that don't support templates well
00020 #define FluMakeVectorClass( T, C ) \
00021 class C \
00022 { \
00023 public: \
00024  \
00025   C() { _array = NULL; _size = 0; } \
00026  \
00027   ~C() { clear(); } \
00028  \
00029   inline void add( const T& item ) { insert( size(), item ); } \
00030  \
00031   inline T& operator [](int i) { return _array[i]; } \
00032  \
00033   inline T operator [](int i) const { return _array[i]; } \
00034  \
00035   inline unsigned int size() const { return _size; } \
00036  \
00037   C& operator =( const C &v ) \
00038   { \
00039     clear(); \
00040     if( v.size() ) \
00041       { \
00042         _array = new T[v.size()]; \
00043         for( unsigned int i = 0; i < v.size(); i++ ) \
00044           _array[i] = v._array[i]; \
00045       } \
00046     return *this; \
00047   } \
00048  \
00049   void insert( unsigned int pos, const T &item ) \
00050   { \
00051     if( pos > _size ) \
00052       pos = _size; \
00053     if( _size == 0 ) \
00054       { \
00055         _array = new T[1]; \
00056       } \
00057     else \
00058       { \
00059         if( !( _size & (_size-1) ) ) \
00060           { \
00061             T* temp = new T[_size*2]; \
00062             for( unsigned int i = 0; i < _size; i++ ) \
00063               temp[i] = _array[i]; \
00064             delete[] _array; \
00065             _array = temp; \
00066           } \
00067         for( unsigned int s = _size; s > pos; s-- ) \
00068           _array[s] = _array[s-1]; \
00069       } \
00070     _size++; \
00071     _array[pos] = item; \
00072   } \
00073  \
00074   void erase( unsigned int pos ) \
00075   { \
00076     if( pos >= _size ) \
00077       return; \
00078     _size--; \
00079     if( _size == 0 ) \
00080       { \
00081         delete[] _array; \
00082         _array = NULL; \
00083       } \
00084     else \
00085       { \
00086         for( ; pos < _size; pos++ ) \
00087           _array[pos] = _array[pos+1]; \
00088       } \
00089   } \
00090  \
00091   void clear() \
00092   { \
00093     if( _array ) \
00094       delete[] _array; \
00095     _array = NULL; \
00096     _size = 0; \
00097   } \
00098  \
00099 protected: \
00100   T *_array; \
00101   unsigned int _size; \
00102 }
00103 
00104 #endif

Generated on Fri Nov 5 12:41:32 2004 for FLTK Utility Library and Widget Collection (FLU) by doxygen 1.3.5