Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

VecBase.h

Go to the documentation of this file.
00001 /************************************************************** ggt-head beg
00002  *
00003  * GGT: Generic Graphics Toolkit
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: VecBase.h,v $
00010  * Date modified: $Date: 2003/03/29 22:02:19 $
00011  * Version:       $Revision: 1.14 $
00012  * -----------------------------------------------------------------
00013  *
00014  *********************************************************** ggt-head end */
00015 /*************************************************************** ggt-cpr beg
00016 *
00017 * GGT: The Generic Graphics Toolkit
00018 * Copyright (C) 2001,2002 Allen Bierbaum
00019 *
00020 * This library is free software; you can redistribute it and/or
00021 * modify it under the terms of the GNU Lesser General Public
00022 * License as published by the Free Software Foundation; either
00023 * version 2.1 of the License, or (at your option) any later version.
00024 *
00025 * This library is distributed in the hope that it will be useful,
00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00028 * Lesser General Public License for more details.
00029 *
00030 * You should have received a copy of the GNU Lesser General Public
00031 * License along with this library; if not, write to the Free Software
00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033 *
00034  ************************************************************ ggt-cpr end */
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 // --- Inline members --- //
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    // @todo need compile time assert
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    // @todo need compile time assert
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    // @todo need compile time assert
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 // Setting
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

Generated on Mon Apr 7 15:28:55 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002