Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef SUNDANCE_FIXEDARRAY_H
00043 #define SUNDANCE_FIXEDARRAY_H
00044
00045
00046 #include "SundanceDefs.hpp"
00047 #include <iostream>
00048 #include <algorithm>
00049
00050 namespace Sundance
00051 {
00052
00053
00054
00055
00056 template <int N, class T> class FixedArray
00057 {
00058 public:
00059
00060 FixedArray(){;}
00061
00062
00063 const T& operator[](int i) const
00064 {
00065 TEUCHOS_TEST_FOR_EXCEPT(i<0);
00066 TEUCHOS_TEST_FOR_EXCEPT(i>=N);
00067 return data_[i];
00068 }
00069
00070
00071 T& operator[](int i)
00072 {
00073 TEUCHOS_TEST_FOR_EXCEPT(i<0);
00074 TEUCHOS_TEST_FOR_EXCEPT(i>=N);
00075 return data_[i];
00076 }
00077
00078
00079 int size() const {return N;}
00080
00081
00082 const T* begin() const {return &(data_[0]);}
00083
00084
00085 const T* end() const {return begin()+N;}
00086
00087
00088 T* begin() {return data_;}
00089
00090
00091 T* end() {return data_+N;}
00092
00093
00094 bool operator<(const FixedArray<N, T>& other) const
00095 {
00096 return std::lexicographical_compare(begin(), end(),
00097 other.begin(), other.end());
00098 }
00099
00100 private:
00101 T data_[N];
00102 };
00103
00104
00105
00106
00107 template<class T>
00108 FixedArray<2,T> makeFA(const T& a, const T& b)
00109 {
00110 FixedArray<2,T> rtn;
00111 rtn[0] = a;
00112 rtn[1] = b;
00113 return rtn;
00114 }
00115
00116
00117 template<class T>
00118 FixedArray<3,T> makeFA(const T& a, const T& b, const T& c)
00119 {
00120 FixedArray<3,T> rtn;
00121 rtn[0] = a;
00122 rtn[1] = b;
00123 rtn[2] = c;
00124 return rtn;
00125 }
00126
00127
00128
00129 template<class T>
00130 FixedArray<4,T> makeFA(const T& a, const T& b, const T& c, const T& d)
00131 {
00132 FixedArray<4,T> rtn;
00133 rtn[0] = a;
00134 rtn[1] = b;
00135 rtn[2] = c;
00136 rtn[2] = d;
00137 return rtn;
00138 }
00139
00140 }
00141
00142
00143 namespace std
00144 {
00145
00146 template <int N, class T>
00147 ostream& operator<<(std::ostream& os, const Sundance::FixedArray<N, T>& f)
00148 {
00149 os << "{";
00150 for (int i=0; i<N; i++)
00151 {
00152 if (i>0) os << ", ";
00153 os << f[i];
00154 }
00155 os << "}";
00156 return os;
00157 }
00158
00159 }
00160
00161 #endif