Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_FUN_P2V_TERNARY_HH 00027 # define MLN_FUN_P2V_TERNARY_HH 00028 00034 # include <mln/fun/internal/selector.hh> 00035 00036 00037 namespace mln 00038 { 00039 00040 namespace fun 00041 { 00042 00043 namespace p2v 00044 { 00045 00046 template <typename P, typename T, typename F> 00047 struct ternary_ 00048 : fun::internal::selector_from_result_<mln_result(T), ternary_<P,T,F> >::ret 00049 { 00050 typedef mln_result(T) result; 00051 00052 ternary_(const Function_v2b<P>& f_pred, 00053 const Function_v2v<T>& f_true, 00054 const Function_v2v<F>& f_false); 00055 00056 template <typename Pt> 00057 result operator()(const Pt& p) const; 00058 00059 protected: 00060 const P f_pred_; 00061 const T f_true_; 00062 const F f_false_; 00063 }; 00064 00065 00066 template <typename P, typename T, typename F> 00067 ternary_<P, T, F> 00068 ternary(const Function_v2b<P>& f_pred, 00069 const Function_v2v<T>& f_true, 00070 const Function_v2v<F>& f_false); 00071 00072 00073 # ifndef MLN_INCLUDE_ONLY 00074 00075 template <typename P, typename T, typename F> 00076 inline 00077 ternary_<P,T,F>::ternary_(const Function_v2b<P>& f_pred, 00078 const Function_v2v<T>& f_true, 00079 const Function_v2v<F>& f_false) 00080 : f_pred_(exact(f_pred)), 00081 f_true_(exact(f_true)), 00082 f_false_(exact(f_false)) 00083 { 00084 } 00085 00086 template <typename P, typename T, typename F> 00087 template <typename Pt> 00088 inline 00089 mln_result(T) 00090 ternary_<P,T,F>::operator()(const Pt& p) const 00091 { 00092 return f_pred_(p) ? f_true_(p) : f_false_(p); 00093 } 00094 00095 00096 template <typename P, typename T, typename F> 00097 inline 00098 ternary_<P, T, F> 00099 ternary(const Function_v2b<P>& f_pred, 00100 const Function_v2v<T>& f_true, 00101 const Function_v2v<F>& f_false) 00102 { 00103 ternary_<P, T, F> tmp(exact(f_pred), 00104 exact(f_true), 00105 exact(f_false)); 00106 return tmp; 00107 } 00108 00109 # endif // ! MLN_INCLUDE_ONLY 00110 00111 } // end of namespace mln::fun::p2v 00112 00113 } // end of namespace mln::fun 00114 00115 } // end of namespace mln 00116 00117 00118 #endif // ! MLN_FUN_P2V_TERNARY_HH