ivl 679
ivl/details/core/loops/loop_on.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_LOOPS_LOOP_ON_HPP
00025 #define IVL_CORE_DETAILS_LOOPS_LOOP_ON_HPP
00026 
00027 namespace ivl {
00028 
00029 namespace loops {
00030 
00031 template <
00032         template <typename, typename> class F,
00033         class A,
00034         class B,
00035         class A_IS_ARRAY,
00036         class B_IS_ARRAY,
00037         class OP_IS_WW
00038 >
00039 struct loop_on_resolve { };
00040 
00041 template <
00042         template <typename, typename> class F,
00043         class A,
00044         class B
00045 >
00046 struct loop_on_resolve<F, A, B, types::t_true, types::t_true, types::t_false>
00047 {
00048         static inline void operate(A& a, const B& b)
00049         {
00050                 loops::loop<F<typename A::reference,
00051                         typename B::const_reference> >(a, b);
00052         }
00053 };
00054 
00055 template <
00056         template <typename, typename> class F,
00057         class A,
00058         class B
00059 >
00060 struct loop_on_resolve<F, A, B, types::t_true, types::t_true, types::t_true>
00061 {
00062         static inline void operate(A& a, const B& b)
00063         {
00064                 loops::loop_ww<F<typename A::reference, typename B::reference> >(a, b);
00065         }
00066 };
00067 
00068 template <
00069         template <typename, typename> class F,
00070         class A,
00071         class B
00072 >
00073 struct loop_on_resolve<F, A, B, types::t_true, types::t_false, types::t_false>
00074 {
00075         static inline void operate(A& a, const B& b)
00076         {
00077                 typename array_details::scalar_to_array<B, A>::
00078                         type v(a.size(), b); // must be derived() as
00079                         // scalar_to_array works this way (at least for now).
00080                 loops::loop<F<typename A::reference, const B&> >(a, v);
00081         }
00082 };
00083 
00084 
00085 template <
00086         template <typename, typename> class F,
00087         class A,
00088         class B
00089 >
00090 struct loop_on_resolve<F, A, B, types::t_false, types::t_false, types::t_false>
00091 {
00092         static inline void operate(A& a, const B& b)
00093         {
00094                 // trivial loop element = element. ...
00095                 // allowed.
00096                 a = b;
00097         }
00098 };
00099 
00100 template <
00101         template <typename, typename> class F,
00102         class A,
00103         class B
00104 >
00105 struct loop_on_resolve<F, A, B, types::t_false, types::t_true, types::t_false>
00106 {
00107         // loop element = array.
00108         // not allowed.
00109         /*static inline void operate(A& a, const B& b)
00110         {
00111                 a.unsupported_method();
00112                 CHECK(false, ecomp());
00113         }*/
00114 };
00115 
00116 } /* namespace loops */
00117 
00118 template<template <typename, typename> class F, class A, class B>
00119 void loop_on(A& a, const B& b) 
00120 {
00121         loops::loop_on_resolve<F, A, B,
00122                 typename types::is_ivl_array<A>::type,
00123                 typename types::is_ivl_array<B>::type,
00124                 typename types::is_base<types::loop_ww_identifier,
00125                         F<typename types::get_value<A>::type,
00126                                 typename types::get_value<B>::type>
00127                         >::type
00128         >::operate(a, b);
00129 }
00130 
00131 } /* namespace ivl */
00132 
00133 #endif // IVL_CORE_DETAILS_LOOPS_LOOP_ON_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations