• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

violent_cast_image.hh

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

Generated on Tue Oct 4 2011 15:25:07 for Milena (Olena) by  doxygen 1.7.1