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