home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
FlexArray.hxx
< prev
next >
Wrap
Text File
|
1996-05-31
|
2KB
|
81 lines
/*---------------------------------------------------------------------------
*
* (c) Westmount Technology 1990
*
* File : @(#)FlexArray.hxx 1.3
* Description : Generic relocatable arrays
*
*---------------------------------------------------------------------------
*/
#ifndef FLEXARRAY_HXX
#define FLEXARRAY_HXX
#ifndef TEMPLCONF_HXX
#include "TemplConf.hxx"
#endif
#if !HAS_TEMPLATES
#ifndef GENERICH
# include <generic.h>
#endif
#endif /* HAS_TEMPLATES */
extern const int DEFAULT_ARRAY_SIZE; // == 16
class GenFlexArray {
public:
GenFlexArray (unsigned size = DEFAULT_ARRAY_SIZE);
GenFlexArray (const GenFlexArray&);
~GenFlexArray ();
GenFlexArray& operator=(const GenFlexArray&);
void clear(void* e= 0);
void reSize(unsigned);
unsigned capacity() const { return sz; }
void*& at(int i) const { return v[i]; }
void*& operator[](int i) const
{ return v[i]; }
protected:
void** v;
unsigned sz;
};
#if HAS_TEMPLATES
template<class T>
class FlexArray : private GenFlexArray {
public:
FlexArray(unsigned s=DEFAULT_ARRAY_SIZE): GenFlexArray(s) {}
void clear(T e =0) { GenFlexArray::clear(e); }
unsigned capacity() const { return sz; }
void reSize(unsigned s) { GenFlexArray::reSize(s); }
T& at(int i) const { return (T&)v[i]; }
T& operator[](int i) const
{ return (T&)GenFlexArray::operator[](i); }
};
#else
#define FlexArray(t) name2(t,_FlexArray)
#define FlexArraydeclare(t) \
class FlexArray(t) : private GenFlexArray { \
public: \
FlexArray(t) (unsigned s=DEFAULT_ARRAY_SIZE): GenFlexArray(s) {} \
void clear(t e =0) { GenFlexArray::clear(e); } \
unsigned capacity() const { return sz; } \
void reSize(unsigned s) { GenFlexArray::reSize(s); } \
t& at(int i) const { return (t&)v[i]; } \
t& operator[](int i) const \
{ return (t&)GenFlexArray::operator[](i); } \
}
#endif /* HAS_TEMPLATES */
#endif /* FLEXARRAY_HXX */