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

classical_window_base.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_INTERNAL_CLASSICAL_WINDOW_BASE_HH
00027 # define MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH
00028 
00039 # include <mln/core/window.hh>
00040 # include <mln/core/dpsites_piter.hh>
00041 
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   namespace internal
00048   {
00049 
00053     template <typename D, typename E>
00054     class classical_window_base : public window_base<D, E>
00055     {
00056     public:
00057 
00058 
00060       typedef window<D> regular;
00061 
00062 
00064       typedef dpsites_fwd_piter<E> fwd_qiter;
00065 
00067       typedef dpsites_fwd_piter<E> bkd_qiter;
00068 
00070       typedef fwd_qiter qiter;
00071 
00072 
00074       unsigned size() const;
00075 
00077       bool is_empty() const;
00078 
00079 
00081       bool is_centered() const;
00082 
00084       bool is_symmetric() const;
00085 
00087       void sym();
00088 
00089 
00092       unsigned delta() const;
00093 
00094 
00096       bool has(const D& dp) const;
00097 
00099       const D& dp(unsigned i) const;
00100 
00102       const std::vector<D>& vect() const;
00103 
00105       const std::vector<D>& std_vector() const;
00106 
00108       void print(std::ostream& ostr) const;
00109 
00110     protected:
00111 
00112       classical_window_base();
00113 
00114       void insert(const D& d);
00115       unsigned delta_() const;               // Default implementation based on win_.
00116       void print_(std::ostream& ostr) const; // Default implementation based on win_.
00117 
00118       mln::window<D> win_;
00119     };
00120 
00121 
00122 
00123 # ifndef MLN_INCLUDE_ONLY
00124 
00125     template <typename D, typename E>
00126     inline
00127     classical_window_base<D,E>::classical_window_base()
00128     {
00129     }
00130 
00131     template <typename D, typename E>
00132     inline
00133     unsigned
00134     classical_window_base<D,E>::size() const
00135     {
00136       return win_.size();
00137     }
00138 
00139     template <typename D, typename E>
00140     inline
00141     bool
00142     classical_window_base<D,E>::is_empty() const
00143     {
00144       return win_.is_empty();
00145     }
00146 
00147     template <typename D, typename E>
00148     inline
00149     bool
00150     classical_window_base<D,E>::is_centered() const
00151     {
00152       mln_invariant(win_.is_centered());
00153       return true;
00154     }
00155 
00156     template <typename D, typename E>
00157     inline
00158     bool
00159     classical_window_base<D,E>::is_symmetric() const
00160     {
00161       mln_invariant(win_.is_symmetric());
00162       return true;
00163     }
00164 
00165     template <typename D, typename E>
00166     inline
00167     void
00168     classical_window_base<D,E>::sym()
00169     {
00170       mln_invariant(win_.is_symmetric());
00171       // No-op.
00172     }
00173 
00174     template <typename D, typename E>
00175     inline
00176     unsigned
00177     classical_window_base<D,E>::delta() const
00178     {
00179       //       void *v = (void*)(& classical_window_base<D,E>::delta_);
00180       //       void *w = (void*)(& E::delta_);
00181       //       std::cout << v << ' ' << w << std::endl;
00182       return exact(this)->delta_();
00183     }
00184 
00185     template <typename D, typename E>
00186     inline
00187     unsigned
00188     classical_window_base<D,E>::delta_() const
00189     {
00190       return win_.delta();
00191     }
00192 
00193     template <typename D, typename E>
00194     inline
00195     const D&
00196     classical_window_base<D,E>::dp(unsigned i) const
00197     {
00198       mln_precondition(i < size());
00199       return win_.dp(i);
00200     }
00201 
00202     template <typename D, typename E>
00203     inline
00204     const std::vector<D>&
00205     classical_window_base<D,E>::std_vector() const
00206     {
00207       return win_.std_vector();
00208     }
00209 
00210     template <typename D, typename E>
00211     inline
00212     const std::vector<D>&
00213     classical_window_base<D,E>::vect() const
00214     {
00215       return std_vector();
00216     }
00217 
00218     template <typename D, typename E>
00219     inline
00220     bool
00221     classical_window_base<D,E>::has(const D& dp) const
00222     {
00223       return win_.has(dp);
00224     }
00225 
00226     template <typename D, typename E>
00227     inline
00228     void
00229     classical_window_base<D,E>::insert(const D& d)
00230     {
00231       win_.insert(d);
00232     }
00233 
00234     template <typename D, typename E>
00235     inline
00236     void
00237     classical_window_base<D,E>::print(std::ostream& ostr) const
00238     {
00239       exact(this)->print_(ostr);
00240     }
00241 
00242     template <typename D, typename E>
00243     inline
00244     void
00245     classical_window_base<D,E>::print_(std::ostream& ostr) const
00246     {
00247       ostr << win_;
00248     }
00249 
00250 # endif // ! MLN_INCLUDE_ONLY
00251 
00252   } // end of namespace internal
00253 
00254 } // end of namespace mln
00255 
00256 
00257 #endif // ! MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH

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