00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_DIMENSIONS_INCLUDE
00013 #define MTL_DIMENSIONS_INCLUDE
00014
00015 #include <iostream>
00016 #include <boost/mpl/if.hpp>
00017 #include <boost/utility/enable_if.hpp>
00018
00019 namespace mtl {
00020
00021
00022
00023
00024
00025
00026 namespace fixed
00027 {
00028 template <std::size_t Rows, std::size_t Cols>
00029 struct dimensions
00030 {
00031 typedef std::size_t size_type;
00032
00033 static size_type const Num_Rows= Rows;
00034 static size_type const Num_Cols= Cols;
00035
00036
00037 explicit dimensions(size_type r= Rows, size_type c= Cols)
00038 {
00039 assert(r == Rows); assert(c == Cols);
00040 }
00041
00042 size_type num_rows() const { return Rows; }
00043 size_type num_cols() const { return Cols; }
00044
00045
00046 static bool const is_static= true;
00047
00048 typedef dimensions<Cols, Rows> transposed_type;
00049 transposed_type transpose() const
00050 {
00051 return transposed_type();
00052 }
00053 };
00054
00055 template <std::size_t R, std::size_t C>
00056 inline std::ostream& operator<< (std::ostream& stream, dimensions<R, C>)
00057 {
00058 return stream << R << 'x' << C;
00059 }
00060
00061 }
00062
00063 namespace non_fixed
00064 {
00065 struct dimensions
00066 {
00067 typedef std::size_t size_type;
00068
00069
00070 dimensions(size_type r= 0, size_type c= 0) : r(r), c(c) {}
00071
00072
00073 dimensions& operator=(const dimensions& x)
00074 {
00075 r= x.r; c= x.c; return *this;
00076 }
00077 size_type num_rows() const { return r; }
00078 size_type num_cols() const { return c; }
00079
00080 typedef dimensions transposed_type;
00081 transposed_type transpose()
00082 {
00083 return transposed_type(c, r);
00084 }
00085
00086 static bool const is_static= false;
00087 protected:
00088 size_type r, c;
00089 };
00090
00091 inline std::ostream& operator<< (std::ostream& stream, dimensions d)
00092 {
00093 return stream << d.num_rows() << 'x' << d.num_cols();
00094 }
00095
00096 }
00097
00098
00099 #if 0
00100 template <std::size_t Rows = 0, std::size_t Cols = 0>
00101 struct dimensions
00102 : public boost::mpl::if_c<
00103 Rows != 0 && Cols != 0
00104 , struct fixed::dimensions
00105 , struct non_fixed::dimensions
00106 >::type
00107 {
00108 dimensions(std::size_t r, std::size_t c,
00109 typename boost::enable_if_c<Rows == 0 || Cols == 0>::type* = 0)
00110 : non_fixed::dimensions(r, c) {}
00111 };
00112 #endif
00113
00114
00115 }
00116
00117 #endif // MTL_DIMENSIONS_INCLUDE