00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_CORE_INTERNAL_IMAGE_MORPHER_HH
00027 # define MLN_CORE_INTERNAL_IMAGE_MORPHER_HH
00028 
00034 
00035 # include <mln/core/internal/image_base.hh>
00036 # include <mln/metal/const.hh>
00037 # include <mln/metal/is_const.hh>
00038 # include <mln/metal/is_not_const.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace internal
00045   {
00046 
00050     
00051     template <typename I, typename T, typename S, typename E>
00052     class image_morpher : public image_base<T, S, E>
00053     {
00054     public:
00055 
00057       typedef I delegatee;
00058 
00060       mlc_const(I)* delegatee_() const;
00061 
00063       I* delegatee_();
00064 
00065 
00066 
00068       typedef I unmorph;
00069 
00071       I& unmorph_();
00072 
00074       mlc_const(I)& unmorph_() const;
00075 
00076 
00077       
00078 
00079 
00080 
00081 
00082 
00083       bool is_valid() const;
00084 
00085 
00088       E& rw();
00089 
00090 
00091     protected:
00092       image_morpher();
00093     };
00094 
00095   } 
00096 
00097 
00098 
00099   namespace impl
00100   {
00101 
00102     
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112     template <typename Subject, typename T,
00113               typename J>
00114     void init_(Subject s, T& target, const Image<J>& model);
00115 
00116   } 
00117 
00118 
00119 
00120 # ifndef MLN_INCLUDE_ONLY
00121 
00122   namespace internal
00123   {
00124 
00125     template <typename I, typename T, typename S, typename E>
00126     inline
00127     image_morpher<I, T, S, E>::image_morpher()
00128     {
00129     }
00130 
00131     template <typename I, typename T, typename S, typename E>
00132     inline
00133     mlc_const(I)*
00134     image_morpher<I, T, S, E>::delegatee_() const
00135     {
00136       return this->data_ == 0 ? 0 : & this->data_->ima_;
00137     }
00138 
00139     template <typename I, typename T, typename S, typename E>
00140     inline
00141     I*
00142     image_morpher<I, T, S, E>::delegatee_()
00143     {
00144       return this->data_ == 0 ? 0 : & this->data_->ima_;
00145     }
00146 
00147     template <typename I, typename T, typename S, typename E>
00148     inline
00149     I&
00150     image_morpher<I, T, S, E>::unmorph_()
00151     {
00152       I* ptr = delegatee_();
00153       mln_assertion(ptr != 0);
00154       return *ptr;
00155     }
00156 
00157     template <typename I, typename T, typename S, typename E>
00158     inline
00159     mlc_const(I)&
00160     image_morpher<I, T, S, E>::unmorph_() const
00161     {
00162       mlc_const(I)* ptr = delegatee_();
00163       mln_assertion(ptr != 0);
00164       return *ptr;
00165     }
00166 
00167     template <typename I, typename T, typename S, typename E>
00168     inline
00169     bool
00170     image_morpher<I, T, S, E>::is_valid() const
00171     {
00172       return
00173         this->data_ != 0 &&
00174         this->delegatee_() != 0 &&
00175         this->delegatee_()->is_valid();
00176     }
00177 
00178     template <typename I, typename T, typename S, typename E>
00179     inline
00180     E&
00181     image_morpher<I, T, S, E>::rw()
00182     {
00183       mlc_is_not_const(I)::check();
00184       mlc_equal(mln_trait_image_value_io(I),
00185                 mln::trait::image::value_io::read_write)::check();
00186       
00187       return exact(*this);
00188     }
00189 
00190   } 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204     template <typename Subject, typename T,
00205               typename J>
00206     inline
00207     void init_(Subject s, T& target, const Image<J>& model_)
00208     {
00209       mlc_is(mln_trait_image_category(J),
00210              trait::image::category::morpher)::check();
00211       const J& model = exact(model_);
00212       init_(s, target, * model.delegatee_());
00213     }
00214 
00215 # endif // ! MLN_INCLUDE_ONLY
00216 
00217 } 
00218 
00219 
00220 #endif // ! MLN_CORE_INTERNAL_IMAGE_MORPHER_HH