00001
00002
00008 #if !defined(__ArrayIndexingBase1_h__)
00009 #error This file is an implementation detail of the class ArrayIndexingBase.
00010 #endif
00011
00012 #include "../defs.h"
00013
00014 BEGIN_NAMESPACE_ADS
00015
00017 template <>
00018 class ArrayIndexingBase<1> {
00019
00020
00021
00022
00023 public:
00024
00026
00032 typedef int size_type;
00033
00035 typedef FixedArray<1,int> index_type;
00037 typedef IndexRange<1,int> range_type;
00038
00039
00040
00041
00042
00043 private:
00044
00045
00046 range_type _range;
00047
00048 protected:
00049
00050
00052
00053
00055 ArrayIndexingBase() :
00056 _range()
00057 {}
00058
00060 ArrayIndexingBase(const ArrayIndexingBase& x) :
00061 _range(x._range)
00062 {}
00063
00065 ArrayIndexingBase&
00066 operator=(const ArrayIndexingBase& x) {
00067 if (&x != this) {
00068 _range = x._range;
00069 }
00070 return *this;
00071 }
00072
00074 explicit
00075 ArrayIndexingBase(const index_type& extent) :
00076 _range(0, extent[0])
00077 {}
00078
00080 void
00081 rebuild(const index_type& extent) {
00082 _range.set_lbound(0);
00083 _range.set_ubound(extent[0]);
00084 }
00085
00087 explicit
00088 ArrayIndexingBase(const size_type size) :
00089 _range(0, size)
00090 {}
00091
00093 void
00094 rebuild(const size_type size) {
00095 _range.set_lbound(0);
00096 _range.set_ubound(size);
00097 }
00098
00100 explicit
00101 ArrayIndexingBase(const range_type& range) :
00102 _range(range)
00103 {}
00104
00106 void
00107 rebuild(const range_type& range) {
00108 _range = range;
00109 }
00110
00112 void
00113 swap(ArrayIndexingBase& x) {
00114 _range.swap(x._range);
00115 }
00116
00118 ~ArrayIndexingBase()
00119 {}
00120
00121
00122
00123 public:
00124
00125
00127
00128
00130 static
00131 int
00132 rank() {
00133 return 1;
00134 }
00135
00136
00137
00139
00140
00142 index_type
00143 extents() const {
00144 return index_type(_range.ubound() - _range.lbound());
00145 }
00146
00148 #ifdef DEBUG_ArrayIndexingBase
00149 size_type
00150 extent(const int i) const {
00151 assert(i == 0);
00152 return _range.ubound() - _range.lbound();
00153 }
00154 #else
00155 size_type
00156 extent(const int) const {
00157 return _range.ubound() - _range.lbound();
00158 }
00159 #endif
00160
00162 const range_type&
00163 ranges() const {
00164 return _range;
00165 }
00166
00168 const index_type&
00169 lbounds() const {
00170 return _range.lbounds();
00171 }
00172
00174 const index_type&
00175 ubounds() const {
00176 return _range.ubounds();
00177 }
00178
00180 int
00181 lbound(const int i) const {
00182 return _range.lbound(i);
00183 }
00184
00186 int
00187 ubound(const int i) const {
00188 return _range.ubound(i);
00189 }
00190
00192 index_type
00193 strides() const {
00194 return index_type(1);
00195 }
00196
00197
00198
00200
00201
00203 const range_type&
00204 range() const {
00205 return _range;
00206 }
00207
00209 int
00210 lbound() const {
00211 return _range.lbound();
00212 }
00213
00215 int
00216 ubound() const {
00217 return _range.ubound();
00218 }
00219
00220
00221
00223
00224
00226 int
00227 index(const index_type& mi) const {
00228 return mi[0] - lbound();
00229 }
00230
00232 int
00233 index(const int i0) const {
00234 return i0 - lbound();
00235 }
00236
00238 void
00239 index_to_indices(int index, int& i) const {
00240 i = index + lbound();
00241 }
00242
00244 void
00245 index_to_indices(int index, ads::FixedArray<1,int>& multi_index) const {
00246 multi_index[0] = index + lbound();
00247 }
00248
00249
00250
00252
00253
00255 void
00256 put(std::ostream& out) const {
00257 out << range() << '\n';
00258 }
00259
00261 void
00262 write(std::ostream& out) const {
00263 out.write(reinterpret_cast<const char*>(&_range),
00264 sizeof(range_type));
00265 }
00266
00267
00268
00270
00271
00273 bool
00274 operator==(const ArrayIndexingBase& x) const {
00275 return ranges() == x.ranges();
00276 }
00277
00278
00279 };
00280
00281 END_NAMESPACE_ADS