00001
00002
00008 #if !defined(__FixedArray1_h__)
00009 #error This file is an implementation detail of the class FixedArray.
00010 #endif
00011
00012 #include "../defs.h"
00013
00014 BEGIN_NAMESPACE_ADS
00015
00017 template<typename T>
00018 class FixedArray<1,T> {
00019
00020
00021
00022
00023 private:
00024
00025 typedef ArrayTypes<T> Types;
00026
00027
00028
00029
00030
00031 public:
00032
00033
00035
00036
00038 typedef typename Types::value_type value_type;
00040 typedef typename Types::parameter_type parameter_type;
00042 typedef typename Types::pointer pointer;
00044 typedef typename Types::const_pointer const_pointer;
00046 typedef typename Types::iterator iterator;
00048 typedef typename Types::const_iterator const_iterator;
00050 typedef typename Types::reference reference;
00052 typedef typename Types::const_reference const_reference;
00054
00060 typedef typename Types::size_type size_type;
00062 typedef typename Types::difference_type difference_type;
00063
00065
00066
00067
00068
00069
00070 private:
00071
00072 value_type _data;
00073
00074 public:
00075
00076
00078
00079
00081 FixedArray() :
00082 _data()
00083 {}
00084
00086 ~FixedArray()
00087 {}
00088
00090 FixedArray(const FixedArray& other) :
00091 _data(other._data)
00092 {}
00093
00095 template<typename T2>
00096 FixedArray(const FixedArray<1,T2>& x) :
00097 _data(static_cast<value_type>(x[0]))
00098 {}
00099
00101 explicit
00102 FixedArray(parameter_type x) :
00103 _data(x)
00104 {}
00105
00107 FixedArray(const void* vp) :
00108 _data(*static_cast<const_pointer>(vp))
00109 {}
00110
00111
00112
00114
00115
00117 FixedArray&
00118 operator=(const FixedArray& x) {
00119 if (&x != this) {
00120 _data = x._data;
00121 }
00122 return *this;
00123 }
00124
00126 FixedArray&
00127 operator=(parameter_type x) {
00128 _data = x;
00129 return *this;
00130 }
00131
00133 template<typename T2>
00134 FixedArray&
00135 operator=(const FixedArray<1,T2>& x) {
00136 _data = x[0];
00137 return *this;
00138 }
00139
00141 template<typename T2, bool A>
00142 FixedArray&
00143 operator=(const Array<1, T2, A>& x) {
00144 #ifdef DEBUG_FixedArray
00145 assert(size() == x.size());
00146 #endif
00147 _data[0] = x[0];
00148 return *this;
00149 }
00150
00151
00152
00154
00155
00157 static
00158 size_type
00159 size() {
00160 return 1;
00161 }
00162
00164 static
00165 bool
00166 empty() {
00167 return false;
00168 }
00169
00171 static
00172 size_type
00173 max_size() {
00174 return std::numeric_limits<int>::max() / sizeof(value_type);
00175 }
00176
00177
00178
00180
00181
00183 const_iterator
00184 begin() const {
00185 return &_data;
00186 }
00187
00189 const_iterator
00190 end() const {
00191 return &_data + 1;
00192 }
00193
00195 const_pointer
00196 data() const {
00197 return &_data;
00198 }
00199
00201 #ifdef DEBUG_FixedArray
00202 parameter_type
00203 operator()(const int i) const {
00204 assert(i == 0);
00205 return _data;
00206 }
00207 #else
00208 parameter_type
00209 operator()(const int) const {
00210 return _data;
00211 }
00212 #endif
00213
00215 #ifdef DEBUG_FixedArray
00216 parameter_type
00217 operator[](const int i) const {
00218 assert(i == 0);
00219 return _data;
00220 }
00221 #else
00222 parameter_type
00223 operator[](const int) const {
00224 return _data;
00225 }
00226 #endif
00227
00229 template<typename EqualityComparable>
00230 const_iterator
00231 find(const EqualityComparable& x) const {
00232 if (_data == x) {
00233 return begin();
00234 }
00235 return end();
00236 }
00237
00239 template<typename EqualityComparable>
00240 int
00241 find_index(const EqualityComparable& x) const {
00242 if (_data == x) {
00243 return 0;
00244 }
00245 return 1;
00246 }
00247
00249 template<typename EqualityComparable>
00250 bool
00251 has(const EqualityComparable& x) const {
00252 return _data == x;
00253 }
00254
00256 bool
00257 is_sorted() const {
00258 return true;
00259 }
00260
00262 template<class StrictWeakOrdering>
00263 bool
00264 is_sorted(StrictWeakOrdering comp) const {
00265 return true;
00266 }
00267
00269 int
00270 min_index() const {
00271 return 0;
00272 }
00273
00275 template<class StrictWeakOrdering>
00276 int
00277 min_index(StrictWeakOrdering comp) const {
00278 return 0;
00279 }
00280
00282 int
00283 max_index() const {
00284 return 0;
00285 }
00286
00288 template<class StrictWeakOrdering>
00289 int
00290 max_index(StrictWeakOrdering comp) const {
00291 return 0;
00292 }
00293
00294
00295
00297
00298
00300 iterator
00301 begin() {
00302 return &_data;
00303 }
00304
00306 iterator
00307 end() {
00308 return &_data + 1;
00309 }
00310
00312 pointer
00313 data() {
00314 return &_data;
00315 }
00316
00318 reference
00319 operator()(const int i) {
00320 #ifdef DEBUG_FixedArray
00321 assert(i == 0);
00322 #endif
00323 return _data;
00324 }
00325
00327 #ifdef DEBUG_FixedArray
00328 reference
00329 operator[](const int i) {
00330 assert(i == 0);
00331 return _data;
00332 }
00333 #else
00334 reference
00335 operator[](const int) {
00336 return _data;
00337 }
00338 #endif
00339
00341 void
00342 swap(FixedArray& x) {
00343 std::swap(_data, x._data);
00344 }
00345
00347 template<typename EqualityComparable>
00348 iterator
00349 find(const EqualityComparable& x) {
00350 if (_data == x) {
00351 return begin();
00352 }
00353 return end();
00354 }
00355
00357 void
00358 negate() {
00359 _data = - _data;
00360 }
00361
00363 void
00364 fill(parameter_type value) {
00365 _data = value;
00366 }
00367
00369 template<typename InputIterator>
00370 void
00371 copy(InputIterator start, InputIterator finish) {
00372 _data = *start;
00373 #ifdef DEBUG_FixedArray
00374 assert(++start == finish);
00375 #endif
00376 }
00377
00379 void
00380 sort()
00381 {}
00382
00384 template<class StrictWeakOrdering>
00385 void
00386 sort(StrictWeakOrdering comp)
00387 {}
00388
00389
00390
00392
00393
00395 FixedArray&
00396 operator+=(parameter_type x) {
00397 _data += x;
00398 return *this;
00399 }
00400
00402 FixedArray&
00403 operator-=(parameter_type x) {
00404 _data -= x;
00405 return *this;
00406 }
00407
00409 FixedArray&
00410 operator*=(parameter_type x) {
00411 _data *= x;
00412 return *this;
00413 }
00414
00416 FixedArray&
00417 operator/=(parameter_type x) {
00418 #ifdef DEBUG_FixedArray
00419 assert(x != 0);
00420 #endif
00421 _data /= x;
00422 return *this;
00423 }
00424
00426 FixedArray&
00427 operator%=(parameter_type x) {
00428 #ifdef DEBUG_FixedArray
00429 assert(x != 0);
00430 #endif
00431 _data %= x;
00432 return *this;
00433 }
00434
00436 FixedArray&
00437 operator<<=(const int offset) {
00438 _data <<= offset;
00439 return *this;
00440 }
00441
00443 FixedArray&
00444 operator>>=(const int offset) {
00445 _data >>= offset;
00446 return *this;
00447 }
00448
00449
00450
00452
00453
00455 template<typename T2>
00456 FixedArray&
00457 operator+=(const FixedArray<1,T2>& x) {
00458 _data += x[0];
00459 return *this;
00460 }
00461
00463 template<typename T2>
00464 FixedArray&
00465 operator-=(const FixedArray<1,T2>& x) {
00466 _data -= x[0];
00467 return *this;
00468 }
00469
00471 template<typename T2>
00472 FixedArray&
00473 operator*=(const FixedArray<1,T2>& x) {
00474 _data *= x[0];
00475 return *this;
00476 }
00477
00479 template<typename T2>
00480 FixedArray&
00481 operator/=(const FixedArray<1,T2>& x) {
00482 #ifdef DEBUG_FixedArray
00483 assert(x[0] != 0);
00484 #endif
00485 _data /= x[0];
00486 return *this;
00487 }
00488
00490 template<typename T2>
00491 FixedArray&
00492 operator%=(const FixedArray<1,T2>& x) {
00493 #ifdef DEBUG_FixedArray
00494 assert(x[0] != 0);
00495 #endif
00496 _data %= x[0];
00497 return *this;
00498 }
00499
00500
00501 };
00502
00503
00504 END_NAMESPACE_ADS
00505
00506
00507 #define __FixedArray1_ipp__
00508 #include "FixedArray1.ipp"
00509 #undef __FixedArray1_ipp__