00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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       
00052       typedef P location;
00053       
00054 
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     
00082 
00083     template <typename P>
00084     bool
00085     operator==(const multi_site<P>& lhs, const multi_site<P>& rhs);
00086 
00087     
00088 
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       
00161       
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   } 
00170 
00171 } 
00172 
00173 
00174 #endif // ! MLN_UTIL_MULTI_SITE_HH