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

multi_site.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_UTIL_MULTI_SITE_HH
00027 # define MLN_UTIL_MULTI_SITE_HH
00028 
00031 
00032 # include <cstddef>
00033 
00034 # include <algorithm>
00035 # include <vector>
00036 
00037 # include <mln/core/concept/object.hh>
00038 
00039 # include <mln/util/ord.hh>
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   namespace util
00046   {
00047 
00048     template <typename P>
00049     struct multi_site : public mln::Object< multi_site<P> >
00050     {
00051       // The type of a single site, called a location.
00052       typedef P location;
00053       /* FIXME: We should not need to define this typedef
00054          (see. mln::internal::image_base's site `coord' typedef).  */
00055       typedef mln_coord(P) coord;
00056 
00057       typedef std::vector<P> container;
00058       typedef typename container::size_type size_type;
00059       typedef typename container::reference reference;
00060       typedef typename container::const_reference const_reference;
00061 
00064       void push_back(const P& p);
00065 
00066       void reserve(size_type n);
00067 
00068       size_type size() const;
00069 
00070       reference operator[](size_type n);
00071       const_reference operator[](size_type n) const;
00072 
00073       const_reference front() const;
00074       reference front();
00076 
00077       container sites;
00078     };
00079 
00080 
00081     /* FIXME: Required by an assertion in mln::p_queue_fast<P>::has();
00082        shouldn't there be no requirements on sites?  */
00083     template <typename P>
00084     bool
00085     operator==(const multi_site<P>& lhs, const multi_site<P>& rhs);
00086 
00087     /* FIXME: Required (indirectly) by a postcondition in
00088        mln::morpho::dilation.  */
00089     template <typename P>
00090     bool
00091     operator< (const multi_site<P>& lhs, const multi_site<P>& rhs);
00092 
00093 
00094 
00095 # ifndef MLN_INCLUDE_ONLY
00096 
00097     template <typename P>
00098     void 
00099     multi_site<P>::push_back(const P& p)
00100     {
00101       sites.push_back(p);
00102     }
00103 
00104     template <typename P>
00105     void 
00106     multi_site<P>::reserve(size_type n)
00107     {
00108       sites.reserve(n);
00109     }
00110 
00111     template <typename P>
00112     typename multi_site<P>::size_type 
00113     multi_site<P>::size() const
00114     {
00115       return sites.size();
00116     }
00117 
00118     template <typename P>
00119     typename multi_site<P>::reference
00120     multi_site<P>::operator[](size_type n)
00121     {
00122       return sites[n];
00123     }
00124 
00125     template <typename P>
00126     typename multi_site<P>::const_reference
00127     multi_site<P>::operator[](size_type n) const
00128     {
00129       return sites[n];
00130     }
00131 
00132     template <typename P>
00133     typename multi_site<P>::const_reference
00134     multi_site<P>::front() const
00135     {
00136       mln_precondition(!sites.empty());
00137       return sites[0];
00138     }
00139 
00140     template <typename P>
00141     typename multi_site<P>::reference
00142     multi_site<P>::front()
00143     {
00144       mln_precondition(!sites.empty());
00145       return sites[0];
00146     }
00147 
00148 
00149     template <typename P>
00150     bool
00151     operator==(const multi_site<P>& lhs, const multi_site<P>& rhs)
00152     {
00153       return lhs.sites == rhs.sites;
00154     }
00155 
00156     template <typename P>
00157     bool
00158     operator< (const multi_site<P>& lhs, const multi_site<P>& rhs)
00159     {
00160       // FIXME: This comparison is meaningless, since LHS and RHS are
00161       // not sorted!
00162       return std::lexicographical_compare(lhs.sites.begin(), lhs.sites.end(),
00163                                           rhs.sites.begin(), rhs.sites.end(),
00164                                           util::ord<P>());
00165     }
00166 
00167 # endif // ! MLN_INCLUDE_ONLY
00168 
00169   } // end of mln::util
00170 
00171 } // end of mln
00172 
00173 
00174 #endif // ! MLN_UTIL_MULTI_SITE_HH

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