home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWGVECTOR_H__
- #define __RWGVECTOR_H__
- pragma push_align_members(64);
-
- /*
- * <generic.h> style macro for a generic vector.
- *
- * $Header: E:/vcs/rw/gvector.h_v 1.4 18 Mar 1992 11:27:52 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/gvector.h_v $
- *
- * Rev 1.4 18 Mar 1992 11:27:52 KEFFER
- * Implementation is now V2.1 aware.
- *
- * Rev 1.3 18 Feb 1992 19:23:04 KEFFER
- * Now includes "rw/generic.h".
- * Class tag is now RWExport instead of huge.
- *
- * Rev 1.2 28 Oct 1991 09:08:16 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- * Rev 1.1 09 Oct 1991 18:34:38 keffer
- * Ported to Zortech V3.0
- *
- * Rev 1.0 28 Jul 1991 08:11:24 keffer
- * Tools.h++ V4.0.5 PVCS baseline version
- *
- */
-
- #include "rw/generic.h"
-
- #define GVector(val) name2(val,GVector)
-
- /************************************************
- ************************************************
- * *
- * GVector declaration *
- * *
- ************************************************
- ************************************************/
-
- #ifdef CONST_OVERLOADS
-
- # ifdef CPPV21 /* V2.1 compliant does not allow delete [npts] syntax; V2.0 requires it! */
-
- #define GVectordeclare(val) \
- GPT set_handler(GVector,val,GPT); \
- extern GPT errorhandler(GVector,val); \
- class RWExport GVector(val) { \
- protected: \
- unsigned npts; \
- val* array; \
- public: \
- GVector(val)() \
- {npts = 0; array = 0;} \
- GVector(val)(unsigned n) \
- {npts = n; array = new val[npts];} \
- GVector(val)(unsigned n, val ival); \
- ~GVector(val)() { delete[] array; } \
- GVector(val)(const GVector(val)&); \
- GVector(val)& operator=(const GVector(val)&); \
- const val* data() const {return array;} \
- unsigned length() const { return npts; } \
- void resize(unsigned); \
- val& operator()(int i) { return array[i]; } \
- val operator()(int i) const { return array[i]; } \
- val& operator[](int i) \
- { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range."); \
- return array[i]; } \
- val operator[](int i) const \
- { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range."); \
- return array[i]; } \
- };
-
- # else /* V2.0 compliant */
-
- #define GVectordeclare(val) \
- GPT set_handler(GVector,val,GPT); \
- extern GPT errorhandler(GVector,val); \
- class RWExport GVector(val) { \
- protected: \
- unsigned npts; \
- val* array; \
- public: \
- GVector(val)() \
- {npts = 0; array = 0;} \
- GVector(val)(unsigned n) \
- {npts = n; array = new val[npts];} \
- GVector(val)(unsigned n, val ival); \
- ~GVector(val)() { delete[npts] array; } \
- GVector(val)(const GVector(val)&); \
- GVector(val)& operator=(const GVector(val)&); \
- const val* data() const {return array;} \
- unsigned length() const { return npts; } \
- void resize(unsigned); \
- val& operator()(int i) { return array[i]; } \
- val operator()(int i) const { return array[i]; } \
- val& operator[](int i) \
- { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range."); \
- return array[i]; } \
- val operator[](int i) const \
- { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range."); \
- return array[i]; } \
- };
- # endif /* CPPV21 */
-
- #else /* not CONST_OVERLOADS */
-
- #define GVectordeclare(val) \
- GPT set_handler(GVector,val,GPT); \
- extern GPT errorhandler(GVector,val); \
- class RWExport GVector(val) { \
- protected: \
- unsigned npts; \
- val* array; \
- public: \
- GVector(val)() \
- {npts = 0; array = 0;} \
- GVector(val)(unsigned n) \
- {npts = n; array = new val[npts];} \
- GVector(val)(unsigned n, val val); \
- ~GVector(val)() { delete[npts] array; } \
- GVector(val)(const GVector(val)&); \
- GVector(val)& operator=(const GVector(val)&); \
- const val* data() const {return array;} \
- unsigned length() const { return npts; } \
- void resize(unsigned); \
- val& operator()(int i) { return array[i]; } \
- val& operator[](int i) \
- { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range."); \
- return array[i]; } \
- };
-
- #endif /* CONST_OVERLOADS */
-
-
- /************************************************
- ************************************************
- * *
- * GVector implementation *
- * *
- ************************************************
- ************************************************/
-
- #ifdef CPPV21
-
- #define GVectorimplement(val) \
- GPT errorhandler(GVector,val) = genericerror; \
- GVector(val)::GVector(val)(unsigned n, val ival) \
- { \
- register unsigned i = npts = n; \
- register val* dst = array = new val[i]; \
- while(i--) *dst++ = ival; \
- } \
- \
- GVector(val)::GVector(val)(const GVector(val)& a) \
- { \
- register unsigned i= npts = a.npts; \
- register val* dst = array = new val[i]; \
- register val* src = a.array; \
- while (i--) *dst++ = *src++; \
- } \
- \
- GVector(val)& GVector(val)::operator=(const GVector(val)& a) \
- { \
- if(this != &a){ \
- delete[] array; /* Disconnect from old array */ \
- register unsigned i = npts = a.npts; \
- register val* dst = array = new val[i]; \
- register val* src = a.array; \
- while (i--) *dst++ = *src++; \
- } \
- return *this; \
- } \
- \
- void GVector(val)::resize(unsigned N) \
- { \
- if(N==npts)return; \
- val* newArray = new val[N]; \
- register unsigned i = (N<=npts) ? N:npts; \
- register val* src = array; \
- register val* dst = newArray; \
- while (i--) *dst++ = *src++; \
- delete[] array; \
- array = newArray; \
- npts = N; \
- } \
- \
- GPT set_handler(GVector,val, GPT newHandler) \
- { \
- GPT oldHandler = errorhandler(GVector,val); \
- errorhandler(GVector,val) = newHandler; \
- return oldHandler; \
- }
-
- #else /* Not V2.1 compliant */
-
- #define GVectorimplement(val) \
- GPT errorhandler(GVector,val) = genericerror; \
- GVector(val)::GVector(val)(unsigned n, val ival) \
- { \
- register unsigned i = npts = n; \
- register val* dst = array = new val[i]; \
- while(i--) *dst++ = ival; \
- } \
- \
- GVector(val)::GVector(val)(const GVector(val)& a) \
- { \
- register unsigned i= npts = a.npts; \
- register val* dst = array = new val[i]; \
- register val* src = a.array; \
- while (i--) *dst++ = *src++; \
- } \
- \
- GVector(val)& GVector(val)::operator=(const GVector(val)& a) \
- { \
- if(this != &a){ \
- delete[npts] array; /* Disconnect from old array */ \
- register unsigned i = npts = a.npts; \
- register val* dst = array = new val[i]; \
- register val* src = a.array; \
- while (i--) *dst++ = *src++; \
- } \
- return *this; \
- } \
- \
- void GVector(val)::resize(unsigned N) \
- { \
- if(N==npts)return; \
- val* newArray = new val[N]; \
- register unsigned i = (N<=npts) ? N:npts; \
- register val* src = array; \
- register val* dst = newArray; \
- while (i--) *dst++ = *src++; \
- delete[npts] array; \
- array = newArray; \
- npts = N; \
- } \
- \
- GPT set_handler(GVector,val, GPT newHandler) \
- { \
- GPT oldHandler = errorhandler(GVector,val); \
- errorhandler(GVector,val) = newHandler; \
- return oldHandler; \
- }
-
- #endif
-
- pragma pop_align_members();
- #endif /* __RWGVECTOR_H__ */
-