ivl 679
ivl/details/core/data/conversions_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_CORE_DETAILS_DATA_CONVERSIONS_ARRAY_HPP
00025 #define IVL_CORE_DETAILS_DATA_CONVERSIONS_ARRAY_HPP
00026 
00027 namespace ivl {
00028 
00029 namespace data {
00030 
00031 
00032 
00033 // The following structs describe the promotions that happen to the data types
00034 // when new arrays are automatically created as function return values.
00035 // Depending in the input array type the following transitions occur.
00036 //
00037 // array_creation: the type of the created array<T, ..> classes
00038 // array_nd_creation: the type of the created array_nd<T, ..> classes
00039 // derived_creation: the type of the classes that are created using the
00040 //      new_derived or similar_derived typedefs, but only when the derived
00041 //      class is below the array_nd class.
00042 //
00043 // similar_type defines the creation when a similar type is requested using
00044 //      the appropriate typedef.
00045 // new_type defines the creation type of a request for a completely new array.
00046 // the difference has to do with the shape of the new array.
00047 // a new_type is supposed to be freely resizable.
00048 // It is also guaranteed to be able to be created, using the constructor
00049 //              new_type(input_array_of_same_level::size_type)
00050 // a similar_type is supposed to be able to hold the exact same size of the
00051 //      input array using strictly the constructor
00052 //              similar_type(input_array_of_same_level::size_type)
00053 // In the cases above, the input_array_of_same_level is an array when
00054 //      the created type is an array, an array_nd when the created type is
00055 //      an array_nd, and a ::derived_type when the created type is of the
00056 //      form ::derived_type<T,...>, so the assumption that there is a valid
00057 //      constructor that takes the ::size_type is always qualified,
00058 //      as long as the conversions below are well-defined.
00059 // Furthermore, is some cases, where both similar_type and new_type
00060 // are resizable, it would be wise for similar_type to be declared to
00061 // a type that could be more easily resized, to the predicted size
00062 // of the initial array. data::little is a that kind of example,
00063 // when we are expecting small input array sizes, but the input size
00064 // is unknown, improving speed in several cases, without dropping
00065 // generalisation.
00066 typedef mem<> normal;
00067 
00068 template <class D>
00069 struct conversion
00070 {
00071         struct array_creation
00072         {
00073                 typedef normal similar_type;
00074                 typedef normal new_type;
00075         };
00076         struct array_nd_creation
00077         {
00078                 typedef normal similar_type;
00079                 typedef normal new_type;
00080         };
00081         struct derived_creation
00082         {
00083                 typedef normal similar_type;
00084                 typedef normal new_type;
00085         };
00086 };
00087 
00088 template <class D>
00089 struct conversion<mem<D> >
00090 {
00091         struct array_creation
00092         {
00093                 typedef normal similar_type;
00094                 typedef normal new_type;
00095         };
00096         struct array_nd_creation
00097         {
00098                 typedef normal similar_type;
00099                 typedef normal new_type;
00100         };
00101         struct derived_creation
00102         {
00103                 typedef normal similar_type;
00104                 typedef normal new_type;
00105         };
00106 };
00107 
00108 template <class D>
00109 struct conversion<empty<D> >
00110 {
00111         struct array_creation
00112         {
00113                 typedef empty<> similar_type;
00114                 typedef normal new_type;
00115         };
00116         struct array_nd_creation : public array_creation {};
00117         struct derived_creation : public array_creation {};
00118 };
00119 
00120 // no need to state this actually, with the new mechanism...
00121 template<class D>
00122 struct conversion<range<D> > : public conversion<normal>
00123 {
00124 };
00125 
00126 
00127 template <int N, bool B1, bool B2, class D>
00128 struct conversion<stack<N, B1, B2, D> >
00129 {
00130         struct array_creation
00131         {
00132                 typedef stack<N> similar_type;
00133                 typedef stack<N + 2> new_type;
00134         };
00135         struct array_nd_creation
00136         {
00137                 typedef stack<N> similar_type;
00138                 typedef stack<N + 8> new_type;
00139         };
00140         struct derived_creation
00141         {
00142                 typedef stack<N> similar_type;
00143                 typedef stack<N + 8> new_type;
00144         };
00145 };
00146 
00147 
00148 template <int N, class NM, class D>
00149 struct conversion<fixed<N, NM, D> >
00150 {
00151         struct array_creation
00152         {
00153                 typedef fixed<N, NM> similar_type;
00154                 typedef stack<N + 2> new_type;
00155         };
00156         struct array_nd_creation
00157         {
00158                 // TODO: why not fixed? probably because it is not yet supporting nd
00159                 // level arrays? or maybe the `standard' is not like this for nd?
00160                 // this question is about the similar_type. new_type is right.
00161                 typedef stack<N> similar_type;
00162                 typedef stack<N + 8> new_type;
00163         };
00164         struct derived_creation
00165         {
00173                 typedef fixed<N, NM> similar_type;
00174                 typedef stack<N + 8> new_type;
00175         };
00176 };
00177 
00178 template <class IT, class CONST_IT, int LENGTH, class D>
00179 struct conversion<ref_iterator<IT, CONST_IT, LENGTH, D> >
00180 {
00181         struct array_creation
00182         {
00183                 typedef fixed<LENGTH> similar_type;
00184                 typedef stack<LENGTH + 2> new_type;
00185         };
00186         struct array_nd_creation
00187         {
00188                 typedef stack<LENGTH> similar_type;
00189                 typedef stack<LENGTH + 8> new_type;
00190         };
00191         struct derived_creation
00192         {
00193                 typedef stack<LENGTH> similar_type;
00194                 typedef stack<LENGTH + 8> new_type;
00195         };
00196 };
00197 
00198 template <class IT, class CONST_IT, class D>
00199 struct conversion<ref_iterator<IT, CONST_IT, 0, D> >
00200 {
00201         struct array_creation
00202         {
00203                 typedef stack<4> similar_type; // having pixel of image<0> in mind.
00204                 typedef normal new_type;
00205         };
00206         struct array_nd_creation
00207         {
00208                 typedef normal similar_type;
00209                 typedef normal new_type;
00210         };
00211         struct derived_creation
00212         {
00213                 typedef normal similar_type;
00214                 typedef normal new_type;
00215         };
00216 };
00217 
00218 template <class A, class ATTR, class D>
00219 struct conversion<wrap_array<A, ATTR, D> >
00220         : public conversion<typename A::data_type> { };
00221 
00222 template<template <typename, typename, typename> class F,
00223         class A1, class A2, bool SWAP_ARGS, class D>
00224 struct conversion<binary_elem_func<F, A1, A2, SWAP_ARGS, D> >
00225 : public conversion<typename A1::data_type> {};
00226 //: public A1::data_type::data_identifier
00227 /*: public conversion<normal>
00228 {
00229         // binary_elem_func inherits conversions from the first of the two operand classes
00230         // however, a conversion to normal is always acceptable, and thus, will be
00231         // used for now.
00232 };*/
00233 
00234 template<template <typename, typename> class F, class A, class D>
00235 struct conversion<unary_elem_func<F, A, D> >
00236 : public conversion<typename A::data_type>
00237 {
00238 };
00239 
00240 
00241 
00242 /* not needed
00243 template<template <typename, typename> class F, class A>
00244 class conversion<unary_elem_func<F, A> : public conversion<normal>
00245 {
00246 };
00247 
00248 
00249 template<class A, class B>
00250 class conversion<mask<A, B> > : public conversion<normal>
00251 {
00252 };
00253 
00254 template<class A, class B>
00255 class indirect_data_id : public normal_data_id
00256 {
00257 };
00258 
00259 
00260 template<class A, class I>
00261 class subarray_data_id
00262 {
00263 
00264 };*/
00265 
00266 } //namespace data
00267 
00268 } //namespace ivl
00269 
00270 #endif // IVL_CORE_DETAILS_DATA_CONVERSIONS_ARRAY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations