Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development 00002 // Laboratory (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_OPT_ELEMENT_HH 00028 # define MLN_OPT_ELEMENT_HH 00029 00033 00034 # include <mln/core/concept/image.hh> 00035 # include <mln/trait/images.hh> 00036 00037 namespace mln 00038 { 00039 00040 namespace opt 00041 { 00042 00043 template <typename I> 00044 inline 00045 mln_rvalue(I) element(const Image<I>& ima, unsigned index); 00046 00047 template <typename I> 00048 inline 00049 mln_lvalue(I) element(Image<I>& ima, unsigned index); 00050 00051 template <typename I> 00052 inline 00053 unsigned nelements(const Image<I>& ima); 00054 00055 00056 # ifndef MLN_INCLUDE_ONLY 00057 00058 namespace impl 00059 { 00060 00061 template <typename I> 00062 inline 00063 mln_rvalue(I) element_impl(trait::image::category::domain_morpher, 00064 const Image<I>& ima, unsigned index) 00065 { 00066 (void) index; 00067 return element(*exact(ima).delegatee_()); 00068 } 00069 00070 template <typename I> 00071 inline 00072 mln_rvalue(I) element_impl(trait::image::category::any, 00073 const Image<I>& ima, unsigned index) 00074 { 00075 mlc_and(mlc_is(mln_trait_image_value_storage(I), 00076 trait::image::value_storage::one_block), 00077 mlc_is(mln_trait_image_value_access(I), 00078 trait::image::value_access::direct))::check(); 00079 00080 return exact(ima).element(index); 00081 } 00082 00083 00084 template <typename I> 00085 inline 00086 mln_lvalue(I) element_impl(trait::image::category::domain_morpher, 00087 Image<I>& ima, unsigned index) 00088 { 00089 (void) index; 00090 return element(*exact(ima).delegatee_()); 00091 } 00092 00093 template <typename I> 00094 inline 00095 mln_lvalue(I) element_impl(trait::image::category::any, 00096 Image<I>& ima, unsigned index) 00097 { 00098 mlc_and(mlc_is(mln_trait_image_value_storage(I), 00099 trait::image::value_storage::one_block), 00100 mlc_is(mln_trait_image_value_access(I), 00101 trait::image::value_access::direct))::check(); 00102 00103 return exact(ima).element(index); 00104 } 00105 00106 00107 00108 00109 template <typename I> 00110 inline 00111 unsigned nelements_impl(trait::image::category::domain_morpher, 00112 const Image<I>& ima) 00113 { 00114 return nelements(*exact(ima).delegatee_()); 00115 } 00116 00117 template <typename I> 00118 inline 00119 unsigned nelements_impl(trait::image::category::any, 00120 const Image<I>& ima) 00121 { 00122 mlc_is(mln_trait_image_value_storage(I), 00123 trait::image::value_storage::one_block)::check(); 00124 00125 return exact(ima).nelements(); 00126 } 00127 00128 00129 00130 00131 00132 00133 } // end of namespace mln::opt::impl 00134 00135 00136 template <typename I> 00137 inline 00138 mln_rvalue(I) element(const Image<I>& ima, unsigned index) 00139 { 00140 return impl::element_impl(mln_trait_image_category(I)(), ima, index); 00141 } 00142 00143 template <typename I> 00144 inline 00145 mln_lvalue(I) element(Image<I>& ima, unsigned index) 00146 { 00147 return impl::element_impl(mln_trait_image_category(I)(), ima, index); 00148 } 00149 00150 00151 template <typename I> 00152 inline 00153 unsigned nelements(const Image<I>& ima) 00154 { 00155 return impl::nelements_impl(mln_trait_image_category(I)(), ima); 00156 } 00157 00158 # endif // ! MLN_INCLUDE_ONLY 00159 00160 } // end of namespace mln::opt 00161 00162 } // end of namespace mln 00163 00164 00165 #endif // ! MLN_OPT_ELEMENT_HH