ivl 679
ivl/details/array/impl/fixed_array.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 #ifndef IVL_ARRAY_DETAILS_TUPLE_HPP
00025 #define IVL_ARRAY_DETAILS_TUPLE_HPP
00026 
00027 namespace ivl {
00028 
00029 template <class T, int N>
00030 class fixed_array : public array<T, data::fixed<N, types::term> >
00031 {
00032 public:
00033         typedef fixed_array<T, N> this_type;
00034         typedef array<T, data::fixed<N, types::term> > base_class;
00035 
00036         fixed_array() { }
00037 
00038         fixed_array(const T* data) : base_class(data) { }
00039 
00040         fixed_array(const T& s) : base_class(N, s) { }
00041 
00042         fixed_array(const this_type& t) : base_class(t) { }
00043 
00044         template <class S>
00045         fixed_array(const array<T, S>& a) : base_class(a) { }
00046 
00047         fixed_array& operator=(const fixed_array<T, N>& o)
00048         { base_class::operator=(o); return *this; }
00049 
00050         template<class S>
00051         fixed_array& operator=(const array<T, S>& o)
00052         { base_class::operator=(o); return *this; }
00053 };
00054 
00055 template <class T, int N = 2>
00056 class point : public array<T, fixed<N, data::point_naming> >
00057 {
00058 public:
00059         typedef point<T, N> this_type;
00060         typedef array<T, fixed<N, data::point_naming> > base_class;
00061 
00062         point() { }
00063 
00064         point(const T* data) : base_class(data) { }
00065 
00066         point(const T& s) : base_class(N, s) { }
00067 
00068         point(const this_type& t) : base_class(t) { }
00069 
00070         template <class S>
00071         point(const array<T, S>& a) : base_class(a) { }
00072 
00073         point(T y, T x,
00074                 typename types::t_if<types::t_expr<N == 2>, types::skip, T>::type z = 0)
00075         {
00076                 (*this)[0] = y;
00077                 (*this)[1] = x;
00078                 types::r_if<types::t_expr<N == 2> >(types::skip(), (*this)[N - 1]) = z;
00079         }
00080 
00081         point& operator=(const point<T, N>& o)
00082         { base_class::operator=(o); return *this; }
00083 
00084         template<class S>
00085         point& operator=(const array<T, S>& o)
00086         { base_class::operator=(o); return *this; }
00087 };
00088 
00089 template <class T, int N = 2>
00090 class dims : public array<T, fixed<N, data::dims_naming> >
00091 {
00092 public:
00093         typedef point<T, N> this_type;
00094         typedef array<T, fixed<N, data::dims_naming> > base_class;
00095 
00096         dims() { }
00097 
00098         dims(const T* data) : base_class(data) { }
00099 
00100         dims(const T& s) : base_class(N, s) { }
00101 
00102         dims(const this_type& t) : base_class(t) { }
00103 
00104         template <class S>
00105         dims(const array<T, S>& a) : base_class(a) { }
00106 
00107         dims(T h, T w,
00108                 typename types::t_if<types::t_expr<N == 2>, types::skip, T>::type d = 0)
00109         {
00110                 (*this)[0] = h;
00111                 (*this)[1] = w;
00112                 types::r_if<types::t_expr<N == 2> >(types::skip(), (*this)[N - 1]) = d;
00113         }
00114 
00115         dims& operator=(const dims<T, N>& o)
00116         { base_class::operator=(o); return *this; }
00117 
00118         template<class S>
00119         dims& operator=(const array<T, S>& o)
00120         { base_class::operator=(o); return *this; }
00121 };
00122 
00123 // specializations for point
00124 
00125 template <int N>
00126 class int_point : public point<int, N>
00127 {
00128 public:
00129         typedef int_point this_type;
00130 
00131         typedef point<int, N> base_class;
00132 
00133         int_point() { }
00134 
00135         int_point(const int* data) : base_class(data) { }
00136 
00137         int_point(const int& s) : base_class(s) { }
00138 
00139         int_point(const this_type& t) : base_class(t) { }
00140 
00141         int_point(const typename this_type::array_type& a) : base_class(a) { }
00142 
00143         int_point(int y, int x, int z = 0) : base_class(y, x, z) { }
00144 
00145         int_point& operator=(const int_point<N>& o)
00146         { base_class::operator=(o); return *this; }
00147 
00148         template<class S>
00149         int_point& operator=(const array<int, S>& o)
00150         { base_class::operator=(o); return *this; }
00151 };
00152 
00153 template <int N>
00154 class size_point : public point<size_t, N>
00155 {
00156 public:
00157         typedef size_point this_type;
00158 
00159         typedef point<size_t, N> base_class;
00160 
00161         size_point() { }
00162 
00163         size_point(const size_t* data) : base_class(data) { }
00164 
00165         size_point(const size_t& s) : base_class(s) { }
00166 
00167         size_point(const this_type& t) : base_class(t) { }
00168 
00169         size_point(const typename this_type::array_type& a) : base_class(a) { }
00170 
00171         size_point(size_t y, size_t x, size_t z = 0) : base_class(y, x, z) { }
00172 
00173         size_point& operator=(const size_point<N>& o)
00174         { base_class::operator=(o); return *this; }
00175 
00176         template<class S>
00177         size_point& operator=(const array<size_t, S>& o)
00178         { base_class::operator=(o); return *this; }
00179 };
00180 
00181 template <int N>
00182 class float_point : public point<float, N>
00183 {
00184 public:
00185         typedef float_point this_type;
00186 
00187         typedef point<float, N> base_class;
00188 
00189         float_point() { }
00190 
00191         float_point(const float* data) : base_class(data) { }
00192 
00193         float_point(const float& s) : base_class(s) { }
00194 
00195         float_point(const this_type& t) : base_class(t) { }
00196 
00197         float_point(const typename this_type::array_type& a) : base_class(a) { }
00198 
00199         float_point(float y, float x, float z = 0) : base_class(y, x, z) { }
00200 
00201         float_point& operator=(const float_point<N>& o)
00202         { base_class::operator=(o); return *this; }
00203 
00204         template<class S>
00205         float_point& operator=(const array<float, S>& o)
00206         { base_class::operator=(o); return *this; }
00207 };
00208 
00209 template <int N>
00210 class double_point : public point<double, N>
00211 {
00212 public:
00213         typedef double_point this_type;
00214 
00215         typedef point<double, N> base_class;
00216 
00217         double_point() { }
00218 
00219         double_point(const double* data) : base_class(data) { }
00220 
00221         double_point(const double& s) : base_class(s) { }
00222 
00223         double_point(const this_type& t) : base_class(t) { }
00224 
00225         double_point(const typename this_type::array_type& a) : base_class(a) { }
00226 
00227         double_point(double y, double x, double z = 0) : base_class(y, x, z) { }
00228 
00229         double_point& operator=(const double_point<N>& o)
00230         { base_class::operator=(o); return *this; }
00231 
00232         template<class S>
00233         double_point& operator=(const array<double, S>& o)
00234         { base_class::operator=(o); return *this; }
00235 };
00236 
00237 // specializations for dims
00238 
00239 template <int N>
00240 class int_dims : public dims<int, N>
00241 {
00242 public:
00243         typedef int_dims this_type;
00244 
00245         typedef dims<int, N> base_class;
00246 
00247         int_dims() { }
00248 
00249         int_dims(const int* data) : base_class(data) { }
00250 
00251         int_dims(const int& s) : base_class(s) { }
00252 
00253         int_dims(const this_type& t) : base_class(t) { }
00254 
00255         int_dims(const typename this_type::array_type& a) : base_class(a) { }
00256 
00257         int_dims(int h, int w, int d = 0) : base_class(h, w, d) { }
00258 
00259         int_dims& operator=(const int_dims<N>& o)
00260         { base_class::operator=(o); return *this; }
00261 
00262         template<class S>
00263         int_dims& operator=(const array<int, S>& o)
00264         { base_class::operator=(o); return *this; }
00265 };
00266 
00267 template <int N>
00268 class size_dims : public dims<size_t, N>
00269 {
00270 public:
00271         typedef size_dims this_type;
00272 
00273         typedef dims<size_t, N> base_class;
00274 
00275         size_dims() { }
00276 
00277         size_dims(const size_t* data) : base_class(data) { }
00278 
00279         size_dims(const size_t& s) : base_class(s) { }
00280 
00281         size_dims(const this_type& t) : base_class(t) { }
00282 
00283         size_dims(const typename this_type::array_type& a) : base_class(a) { }
00284 
00285         size_dims(size_t h, size_t w, size_t d = 0) : base_class(h, w, d) { }
00286 
00287         size_dims& operator=(const size_dims<N>& o)
00288         { base_class::operator=(o); return *this; }
00289 
00290         template<class S>
00291         size_dims& operator=(const array<size_t, S>& o)
00292         { base_class::operator=(o); return *this; }
00293 };
00294 
00295 template <int N>
00296 class float_dims : public dims<float, N>
00297 {
00298 public:
00299         typedef float_dims this_type;
00300 
00301         typedef dims<float, N> base_class;
00302 
00303         float_dims() { }
00304 
00305         float_dims(const float* data) : base_class(data) { }
00306 
00307         float_dims(const float& s) : base_class(s) { }
00308 
00309         float_dims(const this_type& t) : base_class(t) { }
00310 
00311         float_dims(const typename this_type::array_type& a) : base_class(a) { }
00312 
00313         float_dims(float h, float w, float d = 0) : base_class(h, w, d) { }
00314 
00315         float_dims& operator=(const float_dims<N>& o)
00316         { base_class::operator=(o); return *this; }
00317 
00318         template<class S>
00319         float_dims& operator=(const array<float, S>& o)
00320         { base_class::operator=(o); return *this; }
00321 };
00322 
00323 template <int N>
00324 class double_dims : public dims<double, N>
00325 {
00326 public:
00327         typedef double_dims this_type;
00328 
00329         typedef dims<double, N> base_class;
00330 
00331         double_dims() { }
00332 
00333         double_dims(const double* data) : base_class(data) { }
00334 
00335         double_dims(const double& s) : base_class(s) { }
00336 
00337         double_dims(const this_type& t) : base_class(t) { }
00338 
00339         double_dims(const typename this_type::array_type& a) : base_class(a) { }
00340 
00341         double_dims(double h, double w, double d = 0) : base_class(h, w, d) { }
00342 
00343         double_dims& operator=(const double_dims<N>& o)
00344         { base_class::operator=(o); return *this; }
00345 
00346         template<class S>
00347         double_dims& operator=(const array<double, S>& o)
00348         { base_class::operator=(o); return *this; }
00349 };
00350 
00351 
00352 /*
00353 template <class T>
00354 class singleton : public fixed_array<T, 1>
00355 {
00356 public:
00357         typedef singleton this_type;
00358         typedef fixed_array<T, 1> base_class;
00359 
00360         singleton() { }
00361 
00362         singleton(const T* data) : base_class(data) { }
00363 
00364         singleton(const T& s) : base_class(s) { }
00365 
00366         singleton(const this_type& a) : base_class(a) {}
00367 
00368         template<class S> inline
00369         explicit singleton(const array<T, S>& a) : base_class(a) { }
00370 
00371         using base_class::operator=;
00372 
00373         this_type& operator=(const this_type& o){ return base_class::operator=(o); }
00374 };
00375 
00376 template <class T>
00377 class pair : public fixed_array<T, 2>
00378 {
00379 public:
00380         typedef pair this_type;
00381         typedef fixed_array<T, 2> base_class;
00382 
00383         pair() { }
00384 
00385         pair(const T* data) : base_class(data) { }
00386 
00387         pair(const T& s) : base_class(s) { }
00388 
00389         pair(const T& s0, const T& s1) { (*this)[0] = s0; (*this)[1] = s1; }
00390 
00391         pair(const this_type& a) : base_class(a) {}
00392 
00393         // this constructor is explicit, because pair is a type
00394         // that needs to be matched exactly to provide type-correctness.
00395         template<class S> inline
00396         explicit pair(const array<T, S>& a) : base_class(a) { }
00397 
00398         using base_class::operator=;
00399 
00400         this_type& operator=(const this_type& o){ return base_class::operator=(o); }
00401 
00402         //const T& x() const { return (*this)[0]; }
00403         //T& x() { return (*this)[0]; }
00404 
00405         //const T& y() const { return (*this)[1]; }
00406         //T& y() { return (*this)[1]; }
00407 };
00408 
00409 template <class T>
00410 class triplet : public fixed_array<T, 3>
00411 {
00412 public:
00413         typedef triplet <T> this_type;
00414         typedef fixed_array<T, 3> base_class;
00415 
00416         triplet() { }
00417 
00418         triplet(const T* data) : base_class(data) { }
00419 
00420         triplet(const T& s) : base_class(s) { }
00421 
00422         triplet(const T& s0, const T& s1, const T& s2)
00423                 { (*this)[0] = s0; (*this)[1] = s1; (*this)[2] = s2; }
00424 
00425         triplet(const this_type& a) : base_class(a) { }
00426 
00427         template<class S> inline
00428         explicit triplet(const array<T, S>& a) : base_class(a) { }
00429 
00430         using base_class::operator=;
00431 
00432         this_type& operator=(const this_type& o){ return base_class::operator=(o); }
00433 
00434         //const T& x() const { return (*this)[0]; }
00435         //T& x() { return (*this)[0]; }
00436 
00437         //const T& y() const { return (*this)[1]; }
00438         //T& y() { return (*this)[1]; }
00439 
00440         //const T& z() const { return (*this)[2]; }
00441         //T& z() { return (*this)[2]; }
00442 
00443 };
00444 
00445 
00446 typedef pair<size_t> size_pair;
00447 
00448 typedef triplet<size_t> size_triplet;
00449 */
00450 
00451 
00452 
00453 /*
00454 template <class T>
00455 point<T, 2> pnt(const T& x, const T& y)
00456 {
00457         return point<T, 2>(x, y);
00458 }
00459 
00460 template <class T>
00461 point<T, 3> pnt(const T& x, const T& y, const T& z)
00462 {
00463         return point<T, 3>(x, y, z);
00464 }
00465 */
00466 
00467 }; /*namespace ivl*/
00468 
00469 #endif // IVL_ARRAY_DETAILS_TUPLE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations