blitz/tinyveciter.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  * blitz/tinyveciter.h   Declaration of TinyVectorIter<T,N,stride>
00004  *
00005  * $Id: tinyveciter.h,v 1.6 2005/05/07 04:17:56 julianc Exp $
00006  *
00007  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License
00011  * as published by the Free Software Foundation; either version 2
00012  * of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * Suggestions:          blitz-dev@oonumerics.org
00020  * Bugs:                 blitz-bugs@oonumerics.org
00021  *
00022  * For more information, please see the Blitz++ Home Page:
00023  *    http://oonumerics.org/blitz/
00024  *
00025  ***************************************************************************/
00026 
00027 
00028 #ifndef BZ_TINYVECITER_H
00029 #define BZ_TINYVECITER_H
00030 
00031 #ifndef BZ_TINYVEC_H
00032  #include <blitz/tinyvec.h>
00033 #endif
00034 
00035 #ifndef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00036  #error "Debug in tinyveciter.h (this line shouldn't be here)"
00037 #endif
00038 
00039 BZ_NAMESPACE(blitz)
00040 
00041 // N_stride has default 1, in forward declaration in <blitz/tinyvec.h>
00042 template<typename P_numtype, int N_length, int N_stride>
00043 class TinyVectorIter {
00044 public:
00045     typedef P_numtype T_numtype;
00046 
00047     explicit TinyVectorIter(TinyVector<T_numtype, N_length>& x)
00048         : data_(x.data())
00049     { }
00050 
00051 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00052     TinyVectorIter(const TinyVectorIter<T_numtype, N_length, N_stride>& iter)
00053         : data_(iter.data_)
00054     {
00055     }
00056 #endif
00057 
00058     T_numtype operator[](int i) const
00059     {
00060         BZPRECONDITION(i >= 0 && i < N_length);
00061         return data_[i * N_stride];
00062     }
00063 
00064     T_numtype& restrict operator[](int i)
00065     {
00066         BZPRECONDITION(i >= 0 && i < N_length);
00067         return data_[i * N_stride];
00068     }
00069 
00070     T_numtype operator()(int i) const
00071     {
00072         BZPRECONDITION(i >= 0 && i < N_length);
00073         return data_[i * N_stride];
00074     }
00075 
00076     T_numtype& restrict operator()(int i)
00077     {
00078         BZPRECONDITION(i >= 0 && i < N_length);
00079         return data_[i * N_stride];
00080     }
00081 
00082     int length(int) const
00083     { return N_length; }
00084 
00085     static const int _bz_staticLengthCount = 1,
00086                      _bz_dynamicLengthCount = 0,
00087                      _bz_staticLength = 0;
00088 
00089     bool _bz_hasFastAccess() const
00090     { return true; }
00091 
00092     T_numtype _bz_fastAccess(int i) const
00093     { return data_[i * N_stride]; }
00094 
00095     T_numtype& _bz_fastAccess(int i)
00096     { return data_[i * N_stride]; }
00097 
00098     int _bz_suggestLength() const
00099     { return N_length; }
00100 
00101 private:
00102     T_numtype * restrict data_;
00103 };
00104 
00105 // N_stride has default 1, in forward declaration in <blitz/tinyvec.h>
00106 template<typename P_numtype, int N_length, int N_stride>
00107 class TinyVectorIterConst {
00108 public:
00109     typedef P_numtype T_numtype;
00110 
00111     explicit TinyVectorIterConst(const TinyVector<T_numtype, N_length>& x)
00112         : data_(x.data())
00113     { }
00114 
00115 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00116     TinyVectorIterConst(const TinyVectorIterConst<T_numtype, N_length, 
00117         N_stride>& iter)
00118         : data_(iter.data_)
00119     {
00120     }
00121 
00122     void operator=(const TinyVectorIterConst<T_numtype, N_length, N_stride>& 
00123         iter)
00124     {
00125         data_ = iter.data_;
00126     }
00127 #endif
00128 
00129     T_numtype operator[](int i) const
00130     {
00131         BZPRECONDITION(i >= 0 && i < N_length);
00132         return data_[i * N_stride];
00133     }
00134 
00135     T_numtype operator()(int i) const
00136     {
00137         BZPRECONDITION(i >= 0 && i < N_length);
00138         return data_[i * N_stride];
00139     }
00140 
00141     int length(int) const
00142     { return N_length; }
00143 
00144     static const int _bz_staticLengthCount = 1,
00145                      _bz_dynamicLengthCount = 0,
00146                      _bz_staticLength = 0;
00147 
00148     bool _bz_hasFastAccess() const
00149     { return true; }
00150 
00151     T_numtype _bz_fastAccess(int i) const
00152     { return data_[i * N_stride]; }
00153 
00154     int _bz_suggestLength() const
00155     { return N_length; }
00156 
00157 private:
00158     const T_numtype * restrict data_;
00159 };
00160 
00161 BZ_NAMESPACE_END
00162 
00163 #endif // BZ_TINYVECITER_H

Generated on Wed Oct 17 17:44:29 2007 for blitz by  doxygen 1.5.2