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

Generated on Thu Sep 8 2011 18:32:09 for Milena (Olena) by  doxygen 1.7.1