ivl 679
ivl/details/core/data/data_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_DATA_ARRAY_HPP
00025 #define IVL_CORE_DETAILS_DATA_DATA_ARRAY_HPP
00026 
00027 namespace ivl {
00028 
00029 namespace data {
00030 
00031 template <class D = types::term>
00032 struct data_type_base
00033 {
00034         enum { Ch = 0 };
00035 };
00036 
00037 // no arg
00038 template <template<typename> class T, class D>
00039 class data_type_base<T<D> >
00040 : public data_type_base<>
00041 {
00042 public:
00043         template <class DT>
00044         struct change_derived_param
00045         {
00046                 typedef T<DT> type;
00047         };
00048         typedef D derived_param;
00049 };
00050 
00051 // 1 arg, int
00052 template <template<int, typename> class T, int N, class D>
00053 class data_type_base<T<N, D> >
00054 : public data_type_base<>
00055 {
00056 public:
00057         template <class DT>
00058         struct change_derived_param
00059         {
00060                 typedef T<N, DT> type;
00061         };
00062         typedef D derived_param;
00063 };
00064 
00065 // 1 arg template
00066 template <template<typename, typename> class T, class T1, class D>
00067 class data_type_base<T<T1, D> >
00068 : public data_type_base<>
00069 {
00070 public:
00071         template <class DT>
00072         struct change_derived_param
00073         {
00074                 typedef T<T1, DT> type;
00075         };
00076         typedef D derived_param;
00077 };
00078 
00079 // 2 arg template
00080 template <template<typename, typename, typename> class T,
00081         class T1, class T2, class D>
00082 class data_type_base<T<T1, T2, D> >
00083 : public data_type_base<>
00084 {
00085 public:
00086         template <class DT>
00087         struct change_derived_param
00088         {
00089                 typedef T<T1, T2, DT> type;
00090         };
00091         typedef D derived_param;
00092 };
00093 
00094 // 3 arg template
00095 template <template<typename, typename, typename, typename> class T,
00096         class T1, class T2, class T3, class D>
00097 class data_type_base<T<T1, T2, T3, D> >
00098 : public data_type_base<>
00099 {
00100 public:
00101         template <class DT>
00102         struct change_derived_param
00103         {
00104                 typedef T<T1, T2, T3, DT> type;
00105         };
00106         typedef D derived_param;
00107 };
00108 
00109 
00110 // ---------------------------------------------------------------------------
00111 
00112 // this is the definition of the default array data class
00113 template <class DT = types::term>
00114 struct mem : public data_type_base<mem<DT> >
00115 {
00116         // note that these tags may be overwritten by the first array<...>
00117         // object. generally user should use the tags from the array class
00118         // and not from the data class.
00125         typedef seq_optimal_tag optimal_access_tag;
00140         typedef types::t_true has_random_access;
00144         typedef types::t_true is_writeable;
00177         typedef types::t_true is_createable;
00186         typedef types::t_true is_resizeable;
00192         typedef types::t_true has_c_ptr;
00199         typedef types::t_true is_linear;
00214         typedef types::t_false has_specialized_iter;
00224         typedef types::t_false is_referencing_array;
00241         typedef types::number<10> optimal_access_cost;
00242 };
00243 
00244 template<class DT = types::term>
00245 struct empty
00246 : public data_type_base<empty<DT> >
00247 {
00248         typedef random_optimal_tag optimal_access_tag;
00249         typedef types::t_true has_random_access;
00250         typedef types::t_false is_writeable;
00251         typedef types::t_false is_createable;
00252         typedef types::t_false is_resizeable;
00253         typedef types::t_false has_c_ptr;
00254         //is_linear is ambiguous here so the answer is: why optimize an empty array!
00255         typedef types::t_true is_linear;
00256         typedef types::t_false has_specialized_iter;
00257         typedef types::t_false is_referencing_array;
00258         //avoid being absolute here and saying 0 as it could intruduce difficulties.
00259         typedef types::number<1> optimal_access_cost;
00260 };
00261 
00262 template <class T, T V, class DT = types::term>
00263 struct fixed_val_repeat
00264 : public data_type_base<>
00265 {
00266 public:
00267         template <class DERIVED_TYPE>
00268         struct change_derived_param
00269         {
00270                 typedef fixed_val_repeat<T, V, DERIVED_TYPE> type;
00271         };
00272         typedef DT derived_param;
00273 
00274 public:
00275         typedef random_optimal_tag optimal_access_tag;
00276         typedef types::t_true has_random_access;
00277         typedef types::t_false is_writeable;
00278         typedef types::t_false is_createable;
00279         typedef types::t_true is_resizeable;
00280         typedef types::t_false has_c_ptr;
00281         typedef types::t_false is_linear;
00282         typedef types::t_false has_specialized_iter;
00283         typedef types::t_false is_referencing_array;
00284         typedef types::number<5> optimal_access_cost;
00285 };
00286 
00287 template <class DT = types::term>
00288 struct ref_val_repeat
00289 : public data_type_base<ref_val_repeat<DT> >
00290 {
00291         typedef random_optimal_tag optimal_access_tag;
00292         typedef types::t_true has_random_access;
00293         typedef types::t_false is_writeable;
00294         typedef types::t_false is_createable;
00295         typedef types::t_true is_resizeable;
00296         typedef types::t_false has_c_ptr;
00297         typedef types::t_false is_linear;
00298         typedef types::t_false has_specialized_iter;
00299         typedef types::t_false is_referencing_array;
00300         typedef types::number<8> optimal_access_cost;
00301 };
00302 
00303 template <class DT = types::term>
00304 struct val_repeat
00305 : public data_type_base<val_repeat<DT> >
00306 {
00307         typedef random_optimal_tag optimal_access_tag;
00308         typedef types::t_true has_random_access;
00309         typedef types::t_false is_writeable;
00310         typedef types::t_false is_createable;
00311         typedef types::t_true is_resizeable;
00312         typedef types::t_false has_c_ptr;
00313         typedef types::t_false is_linear;
00314         typedef types::t_false has_specialized_iter;
00315         typedef types::t_false is_referencing_array;
00316         typedef types::number<7> optimal_access_cost;
00317 };
00318 
00319 template <class DT = types::term>
00320 struct range
00321 : public data_type_base<range<DT> >
00322 {
00323         typedef seq_optimal_tag optimal_access_tag;
00324         typedef types::t_true has_random_access;
00325         typedef types::t_false is_writeable;
00326         typedef types::t_false is_createable;
00327         typedef types::t_false is_resizeable;
00328         typedef types::t_false has_c_ptr;
00329         typedef types::t_false is_linear;
00330         typedef types::t_false has_specialized_iter;
00331         typedef types::t_false is_referencing_array;
00332         typedef types::number<7> optimal_access_cost;
00333 };
00334 
00335 struct point_naming { };
00336 struct dims_naming { };
00337 struct color_naming { };
00338 
00339 template <int N, class NAMING = types::term, class DT = types::term>
00340 struct fixed
00341 : public data_type_base<>
00342 {
00343 public:
00344         template <class DERIVED_TYPE>
00345         struct change_derived_param
00346         {
00347                 typedef fixed<N, NAMING, DERIVED_TYPE> type;
00348         };
00349         typedef DT derived_param;
00350 
00351 public:
00352         typedef random_optimal_tag optimal_access_tag;
00353         typedef types::t_true has_random_access;
00354         typedef types::t_true is_writeable;
00355         typedef types::t_true is_createable;
00356         typedef types::t_false is_resizeable;
00357         typedef types::t_true has_c_ptr;
00358         typedef types::t_true is_linear;
00359         typedef types::t_false has_specialized_iter;
00360         typedef types::t_false is_referencing_array;
00361         typedef types::number<9> optimal_access_cost;
00362 };
00363 
00364 template <int N = 4, bool USE_REALLOC = false, bool USE_PREALLOC = true,
00365         class DT = types::term>
00366 struct stack
00367 : public data_type_base<>
00368 {
00369 public:
00370         template <class DERIVED_TYPE>
00371         struct change_derived_param
00372         {
00373                 typedef stack<N, USE_REALLOC, USE_PREALLOC, DERIVED_TYPE> type;
00374         };
00375         typedef DT derived_param;
00376 
00377 public:
00378         typedef seq_optimal_tag optimal_access_tag;
00379         typedef types::t_true has_random_access;
00380         typedef types::t_true is_writeable;
00381         typedef types::t_true is_createable;
00382         typedef types::t_true is_resizeable;
00383         typedef types::t_true has_c_ptr;
00384         typedef types::t_true is_linear;
00385         typedef types::t_false has_specialized_iter;
00386         typedef types::t_false is_referencing_array;
00387         typedef types::number<10> optimal_access_cost;
00388 };
00389 
00390 typedef stack<> tiny;
00391 
00392 // for const mode the usage of this is
00393 // ref_iterator<array::const_iterator>
00394 // for read-write mode the usage is
00395 // ref_iterator<array::iterator, array::const_iterator>
00396 // for fixed-length N it is
00397 // wrap_iterator<array::iterator, array::const_iterator, N>
00398 // for write-only access (not encouraged for in-library use) it is
00399 // wrap_iterator<array::iterator>
00400 // IT : the writeable iterator, or the best available iterator,
00401 //      if set to not_a_type means there is only const iterator.
00402 //      if set to types::term means the iterator is T*
00403 // CONST_IT: the readable iterator. if set to types::term then there is
00404 //      either no const iterator, or if IT is set to not_a_type then
00405 //      we only have a const iterator and it is const T*
00406 // LENGTH: 0 means variable length, stored in a size_t. > 0 for fixed length.
00407 // HAS_C_PTR: normally should be t_false, and this doesn't cancel the c_ptr()
00408 //      if it is possible from the given iterator. setting HAS_C_PTR to t_true
00409 //      however, forces the class to have a c_ptr() member that gives as a
00410 //      pointer. Setting this to deletable_c_ptr makes the array behave like
00411 //      a storable_link meaning that it gets one more member, which is bool
00412 //      and, if told so, it sets the bool to true, and at the destructor it
00413 //      frees the iterator begin() which should be a pointer with the
00414 //      standard c free(.); function. This is obviously for cases where the
00415 //      data is temporary.
00416 
00417 class deletable_c_ptr : public types::t_true { };
00418 
00419 template <
00420         class IT = types::not_a_type,
00421         class CONST_IT = types::term,
00422         int LENGTH = 0,
00423         class HAS_C_PTR = types::t_false,
00424         class DT = types::term
00425 >
00426 struct ref_iterator
00427 : public data_type_base<>
00428 {
00429 private:
00430         typedef typename types::t_if<types::t_and<
00431                 types::t_eq<IT, types::term>, types::t_eq<CONST_IT, types::term> >,
00432                 int*, typename types::t_if<types::t_and<
00433                         types::t_eq<IT, types::not_a_type>,
00434                         types::t_eq<CONST_IT, types::term> >,
00435                         const int*, CONST_IT>::type>::
00436                 type const_it_at;
00437 
00438         typedef typename types::t_if<types::t_or<types::t_eq<IT, types::term>,
00439                 types::t_eq<IT, types::not_a_type> >, const_it_at, IT>
00440                 ::type iter_bt;
00441 
00442         typedef typename types::t_if<types::is_ivl_array<iter_bt>,
00443                 typename types::best_iterator<
00444                         typename types::t_if<types::is_ivl_array<iter_bt>, iter_bt,
00445                                 types::term>::type
00446                 >::type, iter_bt>::type iter_t;
00447 
00448         typedef std::iterator_traits<iter_t> it_t;
00449 
00450 public:
00451         template <class DER_TYPE>
00452         struct change_derived_param
00453         {
00454                 typedef ref_iterator<IT, CONST_IT, LENGTH, HAS_C_PTR, DER_TYPE> type;
00455         };
00456         typedef DT derived_param;
00457 
00458 public:
00459         typedef typename types::t_if<
00460                         types::t_eq<typename it_t::iterator_category,
00461                                 std::random_access_iterator_tag>,
00462                         random_optimal_tag, seq_optimal_tag>
00463                                                                                         ::type optimal_access_tag;
00464 
00465         typedef typename types::t_eq<
00466                                 typename it_t::iterator_category,
00467                                 std::random_access_iterator_tag>
00468                                                                                         ::type has_random_access;
00469 
00470         typedef typename types::t_not<
00471                 types::is_const<typename it_t::reference> >
00472                  ::type is_writeable;
00473 
00474         typedef types::t_false is_createable;
00475         typedef types::t_false is_resizeable;
00476         typedef types::t_false has_c_ptr; // overriden.
00477         typedef types::t_false is_linear;
00478         typedef types::t_false has_specialized_iter;
00479         typedef types::t_true is_referencing_array;
00480         typedef types::number<11> optimal_access_cost;
00481 };
00482 
00483 // various link (ref_iterator) data types
00484 typedef ref_iterator<> const_link;
00485 typedef ref_iterator<types::term, types::term> rw_link;
00486 typedef ref_iterator<types::not_a_type, types::term, 0,
00487         deletable_c_ptr> storable_link;
00488 
00489 
00490 
00491 template<template <typename, typename, typename> class F,
00492         class A1, class A2, bool SWAP_ARGS, class DT = types::term>
00493 struct binary_elem_func_ptr
00494 : public data_type_base<>
00495 {
00496 public:
00497         template <class DER_TYPE>
00498         struct change_derived_param
00499         {
00500                 typedef binary_elem_func_ptr<F, A1, A2, SWAP_ARGS, DER_TYPE> type;
00501         };
00502         typedef DT derived_param;
00503 public:
00504 
00505         typedef typename minimum_access_tag<
00506                         typename A1::optimal_access_tag, typename A2::optimal_access_tag>
00507                         ::type optimal_access_tag;
00508 
00509         typedef typename types::t_and<
00510                         typename A1::has_random_access, typename A2::has_random_access>
00511                         ::type has_random_access;
00512 
00513         typedef types::t_false is_writeable;
00514         typedef types::t_false is_createable;
00515         typedef types::t_false is_resizeable;
00516         typedef types::t_false has_c_ptr;
00517         typedef types::t_false is_linear;
00518         typedef types::t_false has_specialized_iter;
00519         typedef types::t_true is_referencing_array;
00520         typedef typename types::t_add_3<
00521                         typename A1::optimal_access_cost,
00522                         typename A2::optimal_access_cost,
00523                         /*typename F<types::term,
00524                                 typename types::t_if<types::t_expr<!SWAP_ARGS>,
00525                                         typename types::get_value<A1>::type,
00526                                         typename types::get_value<A2>::type>::type,
00527                                 typename types::t_if<types::t_expr<!SWAP_ARGS>,
00528                                         typename types::get_value<A2>::type,
00529                                         typename types::get_value<A1>::type>::type>::cost>*/
00530                         typename types::t_max<
00531                                 typename F<
00532                                         typename A1::elem_type,
00533                                         typename A1::elem_type,
00534                                         typename A2::elem_type>::cost,
00535                                 typename F<
00536                                         typename A2::elem_type,
00537                                         typename A1::elem_type,
00538                                         typename A2::elem_type>::cost
00539                         >::type>
00540 
00541                 ::type optimal_access_cost;
00542 };
00543 template<template <typename, typename, typename> class F,
00544         class A1, class A2, bool SWAP_ARGS, class DT = types::term>
00545 struct binary_elem_func
00546 : public data_type_base<>
00547 {
00548 public:
00549         template <class DER_TYPE>
00550         struct change_derived_param
00551         {
00552                 typedef binary_elem_func<F, A1, A2, SWAP_ARGS, DER_TYPE> type;
00553         };
00554         typedef DT derived_param;
00555 public:
00556 
00557         typedef typename minimum_access_tag<
00558                         typename A1::optimal_access_tag, typename A2::optimal_access_tag>
00559                         ::type optimal_access_tag;
00560 
00561         typedef typename types::t_and<
00562                         typename A1::has_random_access, typename A2::has_random_access>
00563                         ::type has_random_access;
00564 
00565         typedef types::t_false is_writeable;
00566         typedef types::t_false is_createable;
00567         typedef types::t_false is_resizeable;
00568         typedef types::t_false has_c_ptr;
00569         typedef types::t_false is_linear;
00570         typedef types::t_false has_specialized_iter;
00571         typedef types::t_true is_referencing_array;
00572         typedef typename types::t_add_3<
00573                         typename A1::optimal_access_cost,
00574                         typename A2::optimal_access_cost,
00575                         /*typename F<types::term,
00576                                 typename types::t_if<types::t_expr<!SWAP_ARGS>,
00577                                         typename types::get_value<A1>::type,
00578                                         typename types::get_value<A2>::type>::type,
00579                                 typename types::t_if<types::t_expr<!SWAP_ARGS>,
00580                                         typename types::get_value<A2>::type,
00581                                         typename types::get_value<A1>::type>::type>::cost>*/
00582                         typename types::t_max<
00583                                 typename F<
00584                                         typename A1::elem_type,
00585                                         typename A1::elem_type,
00586                                         typename A2::elem_type>::cost,
00587                                 typename F<
00588                                         typename A2::elem_type,
00589                                         typename A1::elem_type,
00590                                         typename A2::elem_type>::cost
00591                         >::type>
00592 
00593                 ::type optimal_access_cost;
00594 };
00595 
00596         
00597 
00598 template<template <typename, typename> class F, class A, class DT = types::term>
00599 struct unary_elem_func
00600 : public data_type_base<unary_elem_func<F, A, DT> >
00601 {
00602 public:
00603         template <class DER_TYPE>
00604         struct change_derived_param
00605         {
00606                 typedef unary_elem_func<F, A, DER_TYPE> type;
00607         };
00608         typedef DT derived_param;
00609 public:
00610 
00611         typedef typename A::
00612                         optimal_access_tag optimal_access_tag;
00613 
00614         typedef typename A::
00615                         has_random_access has_random_access;
00616 
00617         typedef types::t_false is_writeable;
00618         typedef types::t_false is_createable;
00619         typedef types::t_false is_resizeable;
00620         typedef types::t_false has_c_ptr;
00621         typedef types::t_false is_linear;
00622         typedef types::t_false has_specialized_iter;
00623         typedef types::t_true is_referencing_array;
00624 
00625         typedef typename types::t_add<
00626                         typename A::optimal_access_cost,
00627                         typename F<
00628                                 typename types::get_value<A>::type,
00629                                 typename types::get_value<A>::type>::cost
00630                 >::type optimal_access_cost;
00631 };
00632 
00633 template<class F, class A, class DT = types::term>
00634 struct row_elem_func_2d
00635 : public data_type_base<row_elem_func_2d<F, A, DT> >
00636 {
00637         typedef seq_optimal_tag optimal_access_tag;
00638         typedef types::t_true has_random_access;
00639         typedef types::t_false is_writeable;
00640         typedef types::t_false is_createable;
00641         typedef types::t_false is_resizeable;
00642         typedef types::t_false has_c_ptr;
00643         typedef types::t_false is_linear;
00644         typedef types::t_false has_specialized_iter;
00645         typedef types::t_true is_referencing_array;
00646         typedef typename types::t_add<
00647                         typename A::optimal_access_cost,
00648                         typename F::cost
00649                 >::type optimal_access_cost;
00650 };
00651 
00652 template<class F, class A, class DT = types::term>
00653 struct row_elem_func_nd
00654 : public data_type_base<row_elem_func_nd<F, A, DT> >
00655 {
00656         typedef nd_seq_optimal_tag optimal_access_tag;
00657         typedef typename A::has_random_access has_random_access;
00658         typedef types::t_false is_writeable;
00659         typedef types::t_false is_createable;
00660         typedef types::t_false is_resizeable;
00661         typedef types::t_false has_c_ptr;
00662         typedef types::t_false is_linear;
00663         typedef types::t_false has_specialized_iter;
00664         typedef types::t_true is_referencing_array;
00665         typedef typename types::t_add<
00666                         typename A::optimal_access_cost,
00667                         typename F::cost
00668                 >::type optimal_access_cost;
00669 };
00670 
00671 // wrap
00672 
00673 struct ice_wrap_array_attr_base_identifier {};
00674 template <class ATTR> struct wrap_identifier {};
00675 
00676 struct force_wrap_array_attr {};
00677 struct ice_wrap_array_attr : public ice_wrap_array_attr_base_identifier {};
00678 struct ices_wrap_array_attr : public ice_wrap_array_attr_base_identifier {};
00679 template <class T>
00680 struct icers_wrap_array_attr : public ice_wrap_array_attr_base_identifier {};
00681 
00682 template<class A, class ATTR = types::term, class DT = types::term>
00683 struct wrap_array
00684 : public data_type_base<wrap_array<A, ATTR, DT> >, public ATTR
00685 {
00686         typedef typename A::optimal_access_tag optimal_access_tag;
00687         typedef typename A::has_random_access has_random_access;
00688         typedef typename types::t_and<
00689                 types::t_not<types::is_const<A> >, typename A::is_writeable>
00690                 ::type is_writeable;
00691 
00692         typedef types::t_false is_createable;
00693         typedef typename A::is_resizeable is_resizeable;
00694         typedef typename A::has_c_ptr has_c_ptr;
00695         typedef typename A::is_linear is_linear;
00696 
00697         // this should actually be typename A::has_specialized_iter;
00698         // note: could fix this: add the specialized_iter calls for this class.
00699         // however this would complicate things, because array_nd level class
00700         // should be specialized too. Another approach is to have special
00701         // treatment for subarrays when force() is used, and apply force on
00702         // the referenced array.
00703         //todo:
00704         // Also, consider that, when specialized_iter stuff is used, the same
00705         // should be done for elem funcs, so if this is fixed, it needs to
00706         // be fixed on elem_funcs as well.
00707         typedef types::t_false has_specialized_iter;
00708         //typedef typename A::has_specialized_iter has_specialized_iter;
00709 
00710         //this is the most important tag for this class. we are faking (on force).
00711         typedef typename types::t_if<types::t_eq<ATTR, force_wrap_array_attr>,
00712                 types::t_false, types::t_true>::type is_referencing_array;
00713 
00714         typedef typename A::optimal_access_cost optimal_access_cost;
00715 };
00716 /*
00717 template<class A>
00718 struct forced
00719 {
00720         typedef typename A::optimal_access_tag optimal_access_tag;
00721         typedef typename A::has_random_access has_random_access;
00722         typedef typename types::t_and<
00723                 types::t_not<types::is_const<A> >, typename A::is_writeable>
00724                 ::type is_writeable;
00725 
00726         typedef types::t_false is_createable;
00727         typedef typename A::is_resizeable is_resizeable;
00728         typedef typename A::has_c_ptr has_c_ptr;
00729         typedef typename A::is_linear is_linear;
00730 
00731         // this should actually be typename A::has_specialized_iter;
00732         // note: could fix this: add the specialized_iter calls for this class.
00733         // however this would complicate things, because array_nd level class
00734         // should be specialized too. Another approach is to have special
00735         // treatment for subarrays when force() is used, and apply force on
00736         // the referenced array.
00737         //todo:
00738         // Also, consider that, when specialized_iter stuff is used, the same
00739         // should be done for elem funcs, so if this is fixed, it needs to
00740         // be fixed on elem_funcs as well.
00741         typedef types::t_false has_specialized_iter;
00742         //typedef typename A::has_specialized_iter has_specialized_iter;
00743 
00744         //this is the most important tag for this class. we are faking.
00745         typedef types::t_false is_referencing_array;
00746 
00747         typedef typename A::optimal_access_cost optimal_access_cost;
00748 };
00749 */
00750 template<class A, class B, class DT = types::term>
00751 struct member
00752 : public data_type_base<member<A, B, DT> >
00753 {
00754         typedef typename A::optimal_access_tag optimal_access_tag;
00755         typedef typename A::has_random_access has_random_access;
00756         typedef typename types::t_and<
00757                 types::t_not<types::is_const<A> >, typename A::is_writeable>
00758                 ::type is_writeable;
00759 
00760         typedef types::t_false is_createable;
00761         typedef typename A::is_resizeable is_resizeable;
00762         typedef types::t_false has_c_ptr;
00763         typedef types::t_false is_linear;
00764         typedef types::t_false has_specialized_iter;
00765         typedef types::t_true is_referencing_array;
00766         typedef typename types::t_add<
00767                 typename A::optimal_access_cost,
00768                          types::number<5>
00769                 >::type optimal_access_cost;
00770 };
00771 
00772 template<class A, class B, class DT = types::term>
00773 struct mask
00774 : public data_type_base<mask<A, B, DT> >
00775 {
00776         typedef data::seq_optimal_tag optimal_access_tag;
00777 
00778         typedef types::t_false has_random_access;
00779 
00780         typedef typename types::t_and<
00781                 types::t_not<types::is_const<A> >, typename A::is_writeable>
00782                 ::type is_writeable;
00783 
00784         typedef types::t_false is_createable;
00785         typedef types::t_false is_resizeable;
00786         typedef types::t_false has_c_ptr;
00787         typedef types::t_false is_linear;
00788         typedef types::t_false has_specialized_iter;
00789         typedef types::t_true is_referencing_array;
00790         typedef typename types::t_add_3<
00791                         typename A::optimal_access_cost,
00792                         types::t_mul<types::number<5>, typename B::optimal_access_cost>,
00793                         types::number<10>
00794                 >::type optimal_access_cost;
00795 };
00796 
00797 template<class A, class B, class DT = types::term>
00798 struct indirect
00799 : public data_type_base<indirect<A, B, DT> >
00800 {
00801 private:
00802         typedef typename types::bare_type<B>::type b_t;
00803 public:
00804         typedef typename minimum_access_tag<
00805                 typename A::optimal_access_tag, typename b_t::optimal_access_tag>
00806                 ::type optimal_access_tag;
00807 
00808         typedef typename types::t_and<
00809                         typename A::has_random_access, typename b_t::has_random_access>
00810                         ::type has_random_access;
00811 
00812         typedef typename types::t_and<
00813                         types::t_not<types::is_const<A> >, typename A::is_writeable>
00814                         ::type is_writeable;
00815 
00816         typedef types::t_false is_createable;
00817         typedef types::t_false is_resizeable;
00818         typedef types::t_false has_c_ptr;
00819         typedef types::t_false is_linear;
00820         typedef types::t_false has_specialized_iter;
00821         typedef types::t_true is_referencing_array;
00822         typedef typename types::t_add_3<
00823                         typename A::optimal_access_cost,
00824                         typename b_t::optimal_access_cost,
00825                         types::number<0>
00826                 >::type optimal_access_cost;
00827 };
00828 
00829 template<class A, class DT = types::term>
00830 struct slice
00831 : public data_type_base<slice<A, DT> >
00832 {
00833         typedef seq_optimal_tag optimal_access_tag;
00834 
00835         typedef types::t_true has_random_access;
00836 
00837         typedef typename types::t_and<
00838                         types::t_not<types::is_const<A> >, typename A::is_writeable>
00839                         ::type is_writeable;
00840 
00841         typedef types::t_false is_createable;
00842         typedef types::t_false is_resizeable;
00843         typedef types::t_false has_c_ptr;
00844         typedef types::t_false is_linear;
00845         typedef types::t_false has_specialized_iter;
00846         typedef types::t_true is_referencing_array;
00847         typedef typename types::t_add<
00848                         typename A::optimal_access_cost,
00849                         types::number<10>
00850                 >::type optimal_access_cost;
00851 };
00852 
00853 template <class A, class I, class DT = types::term>
00854 struct subarray
00855 : public data_type_base<subarray<A, I, DT> >
00856 {
00857         typedef nd_seq_optimal_tag optimal_access_tag;
00858         typedef types::t_false has_random_access;
00859 
00860         typedef typename types::t_if<
00861                 types::t_not<types::is_const<A> >, typename A::is_writeable,
00862                 types::t_false>
00863                 ::type is_writeable;
00864 
00865         typedef types::t_false is_createable;
00866         typedef types::t_false is_resizeable;
00867         typedef types::t_false has_c_ptr;
00868         typedef types::t_false is_linear;
00869         typedef types::number<2> has_specialized_iter;
00870         typedef types::t_true is_referencing_array;
00871         typedef typename types::t_add<
00872                         typename A::optimal_access_cost,
00873                         types::number<70>
00874                 >::type optimal_access_cost;
00875 };
00876 
00877 template <class A1, class A2, int CATDIM = -1, class DT = types::term>
00878 struct catarray
00879 : public data_type_base<>
00880 {
00881 public:
00882         template <class DER_TYPE>
00883         struct change_derived_param
00884         {
00885                 typedef catarray<A1, A2, CATDIM, DER_TYPE> type;
00886         };
00887         typedef DT derived_param;
00888 public:
00889 
00890         typedef nd_seq_optimal_tag optimal_access_tag;
00891         typedef typename types::t_and<
00892                 typename A1::has_random_access, typename A2::has_random_access>
00893                 ::type has_random_access;
00894 
00895         typedef typename types::t_and<types::t_and<
00896                         types::t_not<types::is_const<A1> >, typename A1::is_writeable>,
00897                 types::t_and<
00898                         types::t_not<types::is_const<A2> >, typename A2::is_writeable> >
00899                 ::type is_writeable;
00900 
00901         typedef types::t_false is_createable;
00902         typedef types::t_false is_resizeable;
00903         typedef types::t_false has_c_ptr;
00904         typedef types::t_false is_linear;
00905 
00906         /*
00907         typedef typename types::t_if<types::t_expr<CATDIM == -1>,
00908                 types::number<2>, types::t_false>
00909                 ::type has_specialized_iter;
00910         */
00911         typedef types::t_false has_specialized_iter;
00912 
00913         typedef types::t_true is_referencing_array;
00914         typedef typename types::t_add_3<
00915                         typename A1::optimal_access_cost,
00916                         typename A2::optimal_access_cost,
00917                         types::number<70>
00918                 >::type optimal_access_cost;
00919 };
00920 
00921 } //namespace data
00922 
00923 typedef data::mem<> mem;
00924 using data::fixed_val_repeat;
00925 typedef data::ref_val_repeat<> ref_val_repeat;
00926 typedef data::val_repeat<> val_repeat;
00927 using data::fixed;
00928 using data::stack;
00929 using data::tiny;
00930 using data::ref_iterator;
00931 using data::const_link;
00932 using data::rw_link;
00933 //using data::storable_link;
00934 using data::wrap_array;
00935 //typedef data::empty<> emptydt;
00936 //typedef data::range<> rangedt;
00937 //using data::maskdt;
00938 //using data::indirectdt;
00939 //using data::slicedt;
00940 //using data::subarraydt;
00941 //using data::binary_elem_funcdt;
00942 //using data::unary_elem_funcdt;
00943 //using data::row_elem_func_2ddt;
00944 //using data::row_elem_func_nddt;
00945 
00946 using data::catarray;
00947 
00948 
00949 } //namespace ivl
00950 
00951 
00952 
00953 #endif // IVL_CORE_DETAILS_DATA_DATA_ARRAY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations