Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 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_DATA_CONVERT_HH 00027 # define MLN_DATA_CONVERT_HH 00028 00034 00035 # include <mln/core/routine/duplicate.hh> 00036 # include <mln/fun/v2v/convert.hh> 00037 # include <mln/data/transform.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 namespace data 00044 { 00045 00050 // 00051 template <typename V, typename I> 00052 mln_ch_value(I, V) 00053 convert(const V& v, const Image<I>& input); 00054 00055 00056 00057 # ifndef MLN_INCLUDE_ONLY 00058 00059 namespace internal 00060 { 00061 00062 template <typename V, typename I> 00063 inline 00064 void 00065 convert_tests(const V&, const Image<I>& input) 00066 { 00067 mln_precondition(exact(input).is_valid()); 00068 (void) input; 00069 } 00070 00071 } // using namespace mln::data::internal 00072 00073 namespace impl 00074 { 00075 00076 namespace generic 00077 { 00078 00079 template <typename V, typename I> 00080 inline 00081 mln_ch_value(I, V) 00082 convert(const V& v, const Image<I>& input) 00083 { 00084 trace::entering("data::impl::generic::convert"); 00085 internal::convert_tests(v, input); 00086 00087 fun::v2v::convert<V> f; 00088 mln_ch_value(I, V) output = data::transform(input, f); 00089 00090 trace::exiting("data::impl::generic::convert"); 00091 return output; 00092 } 00093 00094 } // end of namespace mln::data::impl::generic 00095 00096 00097 template <typename V, typename I> 00098 inline 00099 mln_ch_value(I,V) 00100 convert_identity(const V& v, const Image<I>& input) 00101 { 00102 trace::entering("data::impl::convert_identity"); 00103 internal::convert_tests(v, input); 00104 00105 mln_concrete(I) output = duplicate(input); 00106 00107 trace::exiting("data::impl::convert_identity"); 00108 return output; 00109 } 00110 00111 00112 } // end of namespace mln::data::impl 00113 00114 namespace internal 00115 { 00116 00117 template <typename V, typename I> 00118 inline 00119 mln_ch_value(I, V) 00120 convert_dispatch(metal::bool_<true>, 00121 const V& v, const Image<I>& input) 00122 { 00123 return impl::convert_identity(v, input); 00124 } 00125 00126 template <typename V, typename I> 00127 inline 00128 mln_ch_value(I, V) 00129 convert_dispatch(metal::bool_<false>, 00130 const V& v, const Image<I>& input) 00131 { 00132 return impl::generic::convert(v, input); 00133 } 00134 00135 template <typename V, typename I> 00136 inline 00137 mln_ch_value(I, V) 00138 convert_dispatch(const V& v, const Image<I>& input) 00139 { 00140 enum { 00141 test = mlc_equal(V, mln_value(I))::value 00142 }; 00143 return convert_dispatch(metal::bool_<test>(), 00144 v, input); 00145 } 00146 00147 } // end of namespace mln::data::internal 00148 00149 // Facade. 00150 00151 template <typename V, typename I> 00152 inline 00153 mln_ch_value(I, V) 00154 convert(const V& v, const Image<I>& input) 00155 { 00156 trace::entering("data::convert"); 00157 00158 internal::convert_tests(v, input); 00159 00160 mln_ch_value(I, V) output = internal::convert_dispatch(v, input); 00161 00162 trace::exiting("data::convert"); 00163 return output; 00164 } 00165 00166 00167 # endif // ! MLN_INCLUDE_ONLY 00168 00169 } // end of namespace mln::data 00170 00171 } // end of namespace mln 00172 00173 00174 #endif // ! MLN_DATA_CONVERT_HH