Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory 00002 // (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_DATA_FILL_WITH_VALUE_HH 00028 # define MLN_DATA_FILL_WITH_VALUE_HH 00029 00038 00039 # include <cstdlib> 00040 00041 # include <mln/core/concept/image.hh> 00042 00043 00044 00045 // Specializations are in: 00046 # include <mln/data/fill_with_value.spe.hh> 00047 00048 00049 namespace mln 00050 { 00051 00052 namespace data 00053 { 00054 00063 template <typename I, typename V> 00064 void fill_with_value(Image<I>& ima, const V& val); 00066 00067 00068 00069 # ifndef MLN_INCLUDE_ONLY 00070 00071 namespace internal 00072 { 00073 00074 template <typename I, typename V> 00075 inline 00076 void fill_with_value_tests(Image<I>& ima, const V&) 00077 { 00078 mlc_converts_to(mln_exact(V), mln_value(I))::check(); 00079 mln_precondition(exact(ima).is_valid()); 00080 00081 // Avoid a warning about an undefined variable when NDEBUG 00082 (void) ima; 00083 } 00084 00085 } // end of namespace mln::data::internal 00086 00087 00088 namespace impl 00089 { 00090 00091 namespace generic 00092 { 00093 00101 // 00102 template <typename I, typename V> 00103 void fill_with_value(Image<I>& ima_, const V& val) 00104 { 00105 trace::entering("data::impl::generic::fill_with_value"); 00106 00107 I& ima = exact(ima_); 00108 00109 internal::fill_with_value_tests(ima, val); 00110 mlc_is(mln_trait_image_pw_io(I), 00111 trait::image::pw_io::read_write)::check(); 00112 00113 mln_value(I) v = static_cast<mln_value(I)>(exact(val)); 00114 mln_piter(I) p(ima.domain()); 00115 for_all(p) 00116 ima(p) = v; 00117 00118 trace::exiting("data::impl::generic::fill_with_value"); 00119 } 00120 00121 } // end if namespace mln::data::impl::generic 00122 00123 } // end of namespace mln::data::impl 00124 00125 00126 // Facade. 00127 00128 template <typename I, typename V> 00129 inline 00130 void fill_with_value(Image<I>& ima, const V& val) 00131 { 00132 trace::entering("data::fill_with_value"); 00133 00134 internal::fill_with_value_tests(ima, val); 00135 internal::fill_with_value_dispatch(ima, val); 00136 00137 trace::exiting("data::fill_with_value"); 00138 } 00139 00140 00141 # endif // ! MLN_INCLUDE_ONLY 00142 00143 } // end of namespace mln::data 00144 00145 } // end of namespace mln 00146 00147 00148 #endif // ! MLN_DATA_FILL_WITH_VALUE_HH