00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 #ifndef _GMTL_VECBASE_H_
00036 #define _GMTL_VECBASE_H_
00037 
00038 #include <gmtl/Util/Assert.h>
00039 
00040 namespace gmtl
00041 {
00042 
00051 template<class DATA_TYPE, unsigned SIZE>
00052 class VecBase
00053 {
00054 public:
00056    typedef DATA_TYPE DataType;
00057 
00059    enum Params { Size = SIZE };
00060 
00061 public:
00068    VecBase() {}
00069 
00075    VecBase(const VecBase<DATA_TYPE, SIZE>& rVec);
00076 
00078 
00081    VecBase(const DATA_TYPE& val0,const DATA_TYPE& val1);
00082    VecBase(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2);
00083    VecBase(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2,const DATA_TYPE& val3);
00085 
00092    inline void set(const DATA_TYPE* dataPtr);
00093 
00095 
00098    inline void set(const DATA_TYPE& val0);
00099    inline void set(const DATA_TYPE& val0,const DATA_TYPE& val1);
00100    inline void set(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2);
00101    inline void set(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2,const DATA_TYPE& val3);
00103 
00105 
00113    inline DATA_TYPE& operator [](const unsigned i)
00114    {
00115       gmtlASSERT(i < SIZE);
00116       return mData[i];
00117    }
00118    inline const DATA_TYPE&  operator [](const unsigned i) const
00119    {
00120       gmtlASSERT(i < SIZE);
00121       return mData[i];
00122    }
00124 
00126 
00131    DATA_TYPE* getData()
00132    { return mData; }
00133    const DATA_TYPE* getData() const
00134    { return mData; }
00136 
00137 public:
00139    DATA_TYPE mData[SIZE];
00140 };
00141 
00142 
00143 template<class DATA_TYPE, unsigned SIZE>
00144 VecBase<DATA_TYPE,SIZE>::VecBase(const VecBase<DATA_TYPE, SIZE>& rVec)
00145 {
00146    for(unsigned i=0;i<SIZE;++i)
00147       mData[i] = rVec.mData[i];
00148 }
00149 
00150 template<class DATA_TYPE, unsigned SIZE>
00151 VecBase<DATA_TYPE,SIZE>::VecBase(const DATA_TYPE& val0,const DATA_TYPE& val1)
00152 {
00153    
00154    gmtlASSERT( SIZE == 2 && "out of bounds element access in VecBase" );
00155    mData[0] = val0;
00156    mData[1] = val1;
00157 }
00158 
00159 template<class DATA_TYPE, unsigned SIZE>
00160 VecBase<DATA_TYPE,SIZE>::VecBase(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2)
00161 {
00162    
00163    gmtlASSERT( SIZE == 3 && "out of bounds element access in VecBase" );
00164    mData[0] = val0;
00165    mData[1] = val1;
00166    mData[2] = val2;
00167 }
00168 
00169 template<class DATA_TYPE, unsigned SIZE>
00170 VecBase<DATA_TYPE,SIZE>::VecBase(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2,const DATA_TYPE& val3)
00171 {
00172    
00173    gmtlASSERT( SIZE == 4 && "out of bounds element access in VecBase" );
00174    mData[0] = val0;
00175    mData[1] = val1;
00176    mData[2] = val2;
00177    mData[3] = val3;
00178 }
00179 
00180 
00181 
00182 template<class DATA_TYPE, unsigned SIZE>
00183 inline void VecBase<DATA_TYPE,SIZE>::set(const DATA_TYPE* dataPtr)
00184 {
00185    for(unsigned i=0;i<SIZE;++i)
00186       mData[i] = dataPtr[i];
00187 }
00188 template<class DATA_TYPE, unsigned SIZE>
00189 inline void VecBase<DATA_TYPE,SIZE>::set(const DATA_TYPE& val0)
00190 {
00191    gmtlASSERT( SIZE >= 1 && "out of bounds element access in VecBase" );
00192    mData[0] = val0;
00193 }
00194 template<class DATA_TYPE, unsigned SIZE>
00195 inline void VecBase<DATA_TYPE,SIZE>::set(const DATA_TYPE& val0,const DATA_TYPE& val1)
00196 {
00197    gmtlASSERT( SIZE >= 2 && "out of bounds element access in VecBase" );
00198    mData[0] = val0;
00199    mData[1] = val1;
00200 }
00201 template<class DATA_TYPE, unsigned SIZE>
00202 inline void VecBase<DATA_TYPE,SIZE>::set(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2)
00203 {
00204    gmtlASSERT( SIZE >= 3 && "out of bounds element access in VecBase" );
00205    mData[0] = val0;
00206    mData[1] = val1;
00207    mData[2] = val2;
00208 }
00209 template<class DATA_TYPE, unsigned SIZE>
00210 inline void VecBase<DATA_TYPE,SIZE>::set(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2,const DATA_TYPE& val3)
00211 {
00212    gmtlASSERT( SIZE >= 4 && "out of bounds element access in VecBase" );
00213    mData[0] = val0;
00214    mData[1] = val1;
00215    mData[2] = val2;
00216    mData[3] = val3;
00217 }
00218 
00219 };
00220 
00221 #endif