fixed_2D.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef fixed_2D_h
00014 #define fixed_2D_h
00015
00016 #include <cml/core/common.h>
00017 #include <cml/core/fixed_1D.h>
00018
00019
00020
00021
00022 struct invalid_layout_type_error;
00023
00024
00025
00026
00027 struct negative_array_size_error;
00028
00029 namespace cml {
00030
00060 template<typename Element, int Rows, int Cols, typename Layout>
00061 class fixed_2D
00062 {
00063 public:
00064
00065
00066 CML_STATIC_REQUIRE_M(
00067 (Rows > 0) && (Cols > 0),
00068 negative_array_size_error);
00069
00070
00071 CML_STATIC_REQUIRE_M(
00072 (same_type<Layout,row_major>::is_true
00073 || same_type<Layout,col_major>::is_true),
00074 invalid_layout_type_error);
00075
00076
00077
00078 typedef fixed<Rows,Cols> generator_type;
00079
00080
00081 typedef Element value_type;
00082 typedef Element* pointer;
00083 typedef Element& reference;
00084 typedef const Element& const_reference;
00085 typedef const Element* const_pointer;
00086
00087
00088 typedef Layout layout;
00089
00090
00091 typedef fixed_memory_tag memory_tag;
00092
00093
00094 typedef fixed_size_tag size_tag;
00095
00096
00097 typedef not_resizable_tag resizing_tag;
00098
00099
00100 typedef twod_tag dimension_tag;
00101
00102
00103 typedef fixed_2D<Element,Cols,Rows,Layout> transposed_type;
00104
00105
00106 typedef fixed_1D<Element,Rows> row_array_type;
00107 typedef fixed_1D<Element,Cols> col_array_type;
00108
00109
00110 public:
00111
00112 enum { array_rows = Rows, array_cols = Cols };
00113
00114
00115 public:
00116
00118 size_t rows() const { return size_t(array_rows); }
00119
00121 size_t cols() const { return size_t(array_cols); }
00122
00123
00124 public:
00125
00134 reference operator()(size_t row, size_t col) {
00135
00136 return get_element(row,col,layout());
00137 }
00138
00147 const_reference operator()(size_t row, size_t col) const {
00148
00149 return get_element(row,col,layout());
00150 }
00151
00153 pointer data() { return &m_data[0][0]; }
00154
00156 const_pointer data() const { return &m_data[0][0]; }
00157
00158
00159 public:
00160
00161 fixed_2D() {}
00162
00163
00164 protected:
00165
00166 reference get_element(size_t row, size_t col, row_major) {
00167 return m_data[row][col];
00168 }
00169
00170 const_reference get_element(size_t row, size_t col, row_major) const {
00171 return m_data[row][col];
00172 }
00173
00174 reference get_element(size_t row, size_t col, col_major) {
00175 return m_data[col][row];
00176 }
00177
00178 const_reference get_element(size_t row, size_t col, col_major) const {
00179 return m_data[col][row];
00180 }
00181
00182
00183 protected:
00184
00185
00186 typedef Element row_major_array[Rows][Cols];
00187 typedef Element col_major_array[Cols][Rows];
00188
00189
00190 typedef typename select_switch<
00191 Layout, row_major, row_major_array,
00192 col_major, col_major_array
00193 >::result array_data;
00194
00195
00196 array_data m_data;
00197 };
00198
00199 }
00200
00201 #endif
00202
00203
00204