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

site_set_impl.hh

00001 // Copyright (C) 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_SITE_SET_IMPL_HH
00027 # define MLN_CORE_INTERNAL_SITE_SET_IMPL_HH
00028 
00031 
00032 # include <mln/core/concept/site_set.hh>
00033 # include <mln/accu/shape/bbox.hh>
00034 
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace internal
00041   {
00042 
00045     template <typename Sc>
00046     struct site_set_impl;
00047 
00048 
00049 
00050     // For .nsites()
00051 
00052     template <typename trait_nsites, typename Sc>
00053     struct site_set_impl__nsites
00054     {
00055     protected:
00056       template <typename T>
00057       void update_nsites_(const T&); // No-op.
00058     };
00059 
00060     template <typename Sc>
00061     struct site_set_impl__nsites< trait::site_set::nsites::known, Sc>
00062     {
00063       site_set_impl__nsites();
00064       unsigned nsites() const;
00065     protected:
00066       void update_nsites_(const mln_site(Sc)& p);
00067       template <typename S>
00068       void update_nsites_(const Site_Set<S>& s);
00069       unsigned nsites_;
00070     };
00071 
00072 
00073     // For .bbox()
00074 
00075     template <typename trait_bbox, typename Sc>
00076     struct site_set_impl__bbox
00077     {
00078       typedef const mln::box<mln_site(Sc)>& q_box;
00079       q_box bbox() const;
00080 
00081     protected:
00082       void update_bbox_(const mln_site(Sc)& p);
00083       template <typename S>
00084       void update_bbox_(const Site_Set<S>& s);
00085 
00086       accu::shape::bbox<mln_site(Sc)> bb_;
00087     };
00088 
00089     template <typename Sc>
00090     struct site_set_impl__bbox< trait::site_set::nsites::unknown, Sc >
00091     {
00092     protected:
00093       template <typename T>
00094       void update_bbox_(const T&); // No-op.
00095     };
00096 
00097 
00098     // Facade.
00099 
00100     template <typename Sc>
00101     struct site_set_impl
00102       : site_set_impl__nsites< mln_trait_site_set_nsites(Sc), Sc>,
00103         site_set_impl__bbox  < mln_trait_site_set_bbox(Sc),   Sc>
00104     {
00105     };
00106 
00107 
00108 
00109 
00110 # ifndef MLN_INCLUDE_ONLY
00111 
00112 
00113     // site_set_impl__nsites
00114 
00115     template <typename trait_nsites, typename Sc>
00116     template <typename T>
00117     inline
00118     void
00119     site_set_impl__nsites<trait_nsites, Sc>::update_nsites_(const T&)
00120     {
00121       // No-op.
00122     }
00123 
00124     template <typename Sc>
00125     inline
00126     site_set_impl__nsites<trait::site_set::nsites::known, Sc>::site_set_impl__nsites()
00127       : nsites_(0)
00128     {
00129     }
00130 
00131     template <typename Sc>
00132     inline
00133     unsigned
00134     site_set_impl__nsites<trait::site_set::nsites::known, Sc>::nsites() const
00135     {
00136       return nsites_;
00137     }
00138 
00139     template <typename Sc>
00140     inline
00141     void
00142     site_set_impl__nsites<trait::site_set::nsites::known, Sc>::update_nsites_(const mln_site(Sc)&)
00143     {
00144       ++nsites_;
00145     }
00146 
00147     template <typename Sc>
00148     template <typename S>
00149     inline
00150     void
00151     site_set_impl__nsites<trait::site_set::nsites::known, Sc>::update_nsites_(const Site_Set<S>& s)
00152     {
00153       nsites_ += exact(s).nsites();
00154     }
00155 
00156     // site_set_impl__bbox
00157 
00158     template <typename trait_bbox, typename Sc>
00159     inline
00160     typename site_set_impl__bbox<trait_bbox, Sc>::q_box
00161     site_set_impl__bbox<trait_bbox, Sc>::bbox() const
00162     {
00163       return bb_.to_result();
00164     }
00165 
00166     template <typename trait_bbox, typename Sc>
00167     inline
00168     void
00169     site_set_impl__bbox<trait_bbox, Sc>::update_bbox_(const mln_site(Sc)& p)
00170     {
00171       bb_.take(p);
00172     }
00173 
00174     template <typename trait_bbox, typename Sc>
00175     template <typename S>
00176     inline
00177     void
00178     site_set_impl__bbox<trait_bbox, Sc>::update_bbox_(const Site_Set<S>& s)
00179     {
00180       bb_.take(exact(s).bbox());
00181     }
00182 
00183     template <typename Sc>
00184     template <typename T>
00185     inline
00186     void
00187     site_set_impl__bbox< trait::site_set::nsites::unknown, Sc >::update_bbox_(const T&)
00188     {
00189       // No-op.
00190     }
00191 
00192 # endif // ! MLN_INCLUDE_ONLY
00193 
00194   } // end of namespace mln::internal
00195 
00196 } // end of namespace mln
00197 
00198 
00199 #endif // ! MLN_CORE_INTERNAL_SITE_SET_IMPL_HH

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