image_with_impl.hh

00001 // Copyright (C) 2001, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef OLENA_CORE_ABSTRACT_IMAGE_WITH_IMPL_HH
00029 # define OLENA_CORE_ABSTRACT_IMAGE_WITH_IMPL_HH
00030 
00031 # include <oln/core/abstract/image_with_type_with_dim.hh>
00032 # include <oln/core/impl/image_impl.hh>
00033 
00034 
00035 namespace oln {
00036 
00037   namespace abstract {
00038 
00039     template<class Impl, class Exact>
00040     class image_with_impl; // fwd_decl
00041 
00042   } // end of namespace abstract
00043 
00051   template<class Impl, class Exact>
00052   struct image_traits<abstract::image_with_impl<Impl, Exact> > :
00053     public image_traits<typename abstract::image_with_dim<image_id<Exact>::dim, Exact> >,
00054                                 public image_traits<typename abstract::image_with_type<typename image_id<Exact>::value_type, Exact> >
00055   {
00056     typedef Impl impl_type;
00057   };
00058 
00059 
00060 
00061   namespace abstract {
00062 
00068     template<class Impl, class Exact>
00069     class image_with_impl:
00070       public image_with_type_with_dim_switch<Exact>::ret
00071     {
00072     public:
00073 
00074       typedef typename image_traits<Exact>::point_type point_type;
00080       typedef typename image_traits<Exact>::iter_type iter_type;
00086       typedef typename image_traits<Exact>::fwd_iter_type fwd_iter_type;
00088       typedef typename image_traits<Exact>::bkd_iter_type bkd_iter_type;
00090       typedef typename image_traits<Exact>::value_type value_type;
00094       typedef typename image_traits<Exact>::size_type size_type;
00099       typedef typename image_traits<Exact>::impl_type impl_type ;
00102       typedef image_with_impl<Impl, Exact> self_type;
00103       typedef Exact exact_type;
00104       typedef typename image_with_type_with_dim_switch<Exact>::ret super_type;
00105       friend class image<exact_type>;
00106       friend class image_with_dim<image_id<Exact>::dim, exact_type>;
00107       friend class image_with_type<typename image_id<Exact>::value_type, Exact>;
00108 
00109       // shallow copy
00110 
00119       image_with_impl(self_type& rhs)
00120         : super_type(rhs)
00121       {
00122         assertion(rhs.has_impl());
00123         impl_ = rhs.impl();
00124         impl_->ref();
00125       }
00126 
00134       exact_type&
00135       operator=(self_type rhs)
00136       {
00137         return this->exact().assign(rhs.exact());
00138       }
00139 
00141 
00142       const impl_type*
00143       impl() const
00144       {
00145         return impl_;
00146       }
00147 
00152       const size_type&
00153       size() const
00154       {
00155         assertion(has_impl());
00156         return this->exact().impl()->size();
00157       }
00158 
00160 
00161       impl_type*
00162       impl()
00163       {
00164         return impl_;
00165       }
00166 
00167       static std::string
00168       name()
00169       {
00170         return
00171           std::string("abstract::image_with_impl<")
00172           + Impl::name() + ", "
00173           + Exact::name() + ">";
00174       }
00175 
00180       void
00181       clone_to(impl_type* output_data) const
00182       {
00183         assertion(impl_ != 0);
00184         impl()->clone_to(output_data);
00185       }
00186 
00188 
00189       void
00190       clear()
00191       {
00192         if (impl_ != 0)
00193           {
00194             impl_->unref();
00195             impl_ = 0; // security
00196           }
00197       }
00198 
00199     protected:
00200 
00210       const value_type
00211       at(const point_type& p) const
00212       {
00213         return impl_->at(p);
00214       }
00215 
00216 
00226       value_type&
00227       at(const point_type& p)
00228       {
00229         return impl_->at(p);
00230       }
00231 
00239       exact_type&
00240       assign(exact_type rhs) // shallow assignment
00241       {
00242         assertion(rhs.impl() != 0);
00243         if ( &rhs == this )
00244           return this->exact();
00245         if (this->impl() != 0)
00246           this->impl()->unref();
00247         this->impl_ = rhs.impl();
00248         this->impl()->ref();
00249         return this->exact();
00250       }
00251 
00252       ~image_with_impl()
00253       {
00254         clear();
00255       }
00256 
00261       image_with_impl() : impl_(0)
00262       {}
00263 
00265 
00266       image_with_impl(impl_type* impl) :
00267         super_type(),
00268         impl_(impl)
00269       {
00270         impl_->ref();
00271       }
00272 
00273     private:
00274 
00279       impl_type* impl_;
00280 
00281       image_with_impl(const self_type& rhs); // w/o impl
00282 
00283     };
00284 
00285   } // end of namespace abstract
00286 
00287 } // end of namespace oln
00288 
00289 #endif // ! OLENA_CORE_ABSTRACT_IMAGE_WITH_IMPL_HH

Generated on Thu Apr 15 20:13:12 2004 for Olena by doxygen 1.3.6-20040222