Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 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_CORE_IMAGE_VMORPH_VIOLENT_CAST_IMAGE_HH 00028 # define MLN_CORE_IMAGE_VMORPH_VIOLENT_CAST_IMAGE_HH 00029 00034 00035 # include <mln/core/internal/image_value_morpher.hh> 00036 # include <mln/value/set.hh> 00037 # include <mln/value/cast.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 // Fwd decl. 00044 template <typename T, typename I> struct violent_cast_image; 00045 00046 namespace internal 00047 { 00049 template <typename T, typename I> 00050 struct data< violent_cast_image<T,I> > 00051 { 00052 data(const I& ima); 00053 const I& ima_; 00054 }; 00055 00056 } // end of namespace mln::internal 00057 00058 00059 00060 namespace trait 00061 { 00062 template <typename T, typename I, typename value_io> 00063 struct violent_cast_image_trait_selector : 00064 default_image_morpher< I, T, violent_cast_image<T,I> > 00065 { 00066 typedef trait::image::vw_io::none vw_io; 00067 typedef trait::image::vw_set::none vw_set; 00068 }; 00069 00070 template <typename T, typename I> 00071 struct violent_cast_image_trait_selector<T, I, trait::image::vw_io::read> : 00072 default_image_morpher< I, T, violent_cast_image<T,I> > 00073 { 00074 typedef trait::image::vw_io::read vw_io; 00075 }; 00076 00077 template <typename T, typename I> 00078 struct violent_cast_image_trait_selector<T, I, trait::image::vw_io::read_write> : 00079 default_image_morpher< I, T, violent_cast_image<T,I> > 00080 { 00081 typedef trait::image::vw_io::read vw_io; 00082 }; 00083 00084 template <typename T, typename I> 00085 struct image_< violent_cast_image<T,I> > : 00086 violent_cast_image_trait_selector<T, I, mln_trait_image_vw_io(I)> 00087 { 00088 private: 00089 typedef mlc_equal(mln_trait_value_quant(T), 00090 trait::value::quant::high) is_high_quant_; 00091 public: 00092 typedef mlc_if(is_high_quant_, 00093 trait::image::quant::high, 00094 trait::image::quant::low) quant; 00095 00096 typedef trait::image::value_io::read_only value_io; 00097 typedef trait::image::pw_io::read pw_io; 00098 typedef trait::image::value_access::indirect value_access; 00099 typedef trait::image::category::value_morpher category; 00100 00102 typedef trait::image::ext_domain::none ext_domain; 00103 }; 00104 } // end of namespace mln::trait 00105 00106 00107 00111 // 00112 template <typename T, typename I> 00113 struct violent_cast_image : 00114 public internal::image_value_morpher< I, T, violent_cast_image<T,I> > 00115 { 00117 typedef T value; 00118 00120 typedef T rvalue; 00121 00123 typedef T lvalue; 00124 00126 typedef violent_cast_image< tag::value_<T>, tag::image_<I> > skeleton; 00127 00129 violent_cast_image(const Image<I>& ima); 00130 00132 void init_(const Image<I>& ima); 00133 00135 T operator()(const mln_psite(I)& p) const; 00136 00138 T operator()(const mln_psite(I)& p); 00139 }; 00140 00141 00142 template <typename T, typename I> 00143 violent_cast_image<T,I> 00144 violent_cast_image_(const Image<I>& ima) 00145 { 00146 mln_precondition(exact(ima).is_valid()); 00147 violent_cast_image<T,I> tmp(ima); 00148 return tmp; 00149 } 00150 00151 00152 # ifndef MLN_INCLUDE_ONLY 00153 00154 00155 // internal::data< violent_cast_image<T,I> > 00156 00157 namespace internal 00158 { 00159 00160 template <typename T, typename I> 00161 inline 00162 data< violent_cast_image<T,I> >::data(const I& ima) 00163 : ima_(ima) 00164 { 00165 } 00166 00167 } // end of namespace mln::internal 00168 00169 // violent_cast_image<T,I> 00170 00171 template <typename T, typename I> 00172 inline 00173 violent_cast_image<T,I>::violent_cast_image(const Image<I>& ima) 00174 { 00175 metal::bool_<sizeof(T) == sizeof(typename I::value)>::check(); 00176 mln_precondition(exact(ima).is_valid()); 00177 this->data_ = new internal::data< violent_cast_image<T,I> >(exact(ima)); 00178 } 00179 00180 template <typename T, typename I> 00181 inline 00182 void 00183 violent_cast_image<T,I>::init_(const Image<I>& ima) 00184 { 00185 mln_precondition(exact(ima).is_valid()); 00186 this->data_ = new internal::data<violent_cast_image<T,I> >(exact(ima)); 00187 } 00188 00189 template <typename T, typename I> 00190 inline 00191 T 00192 violent_cast_image<T,I>::operator()(const mln_psite(I)& p) const 00193 { 00194 mln_precondition(this->data_->ima_.has(p)); 00195 return *(T*)(void*)&( this->data_->ima_(p) ); 00196 } 00197 00198 template <typename T, typename I> 00199 inline 00200 T 00201 violent_cast_image<T,I>::operator()(const mln_psite(I)& p) 00202 { 00203 return *(T*)(void*)&( this->data_->ima_(p) ); 00204 } 00205 00206 # endif // ! MLN_INCLUDE_ONLY 00207 00208 } // end of namespace mln 00209 00210 00211 #endif // ! MLN_CORE_IMAGE_VMORPH_VIOLENT_CAST_IMAGE_HH