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

p_set.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_SITE_SET_P_SET_HH
00027 # define MLN_CORE_SITE_SET_P_SET_HH
00028 
00033 
00034 # include <mln/core/site_set/p_array.hh>
00035 # include <mln/util/set.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   // Forward declaration.
00042   template <typename P> class p_set;
00043 
00044 
00045   namespace trait
00046   {
00047 
00048     template <typename P>
00049     struct site_set_< p_set<P> >
00050     {
00051       typedef trait::site_set::nsites::known  nsites;
00052       typedef trait::site_set::bbox::unknown  bbox;
00053       typedef trait::site_set::contents::free contents;
00054       typedef trait::site_set::arity::unique  arity;
00055     };
00056 
00057   } // end of namespace trait
00058 
00059 
00060 
00064 
00069   template <typename P>
00070   class p_set : public internal::site_set_base_< P, p_set<P> >
00071   {
00072     typedef p_set<P> self_;
00073   public:
00074 
00076     typedef P element;
00077 
00079     typedef p_indexed_psite<self_> psite;
00080 
00082     typedef p_indexed_fwd_piter<self_> fwd_piter;
00083 
00085     typedef p_indexed_bkd_piter<self_> bkd_piter;
00086 
00088     typedef fwd_piter piter;
00089 
00090 
00092     p_set();
00093 
00094 
00096     bool has(const psite& p) const;
00097 
00099     bool has(const P& p) const;
00100 
00102     bool has(const util::index& i) const;
00103 
00105     bool is_valid() const;
00106 
00107 
00109     unsigned nsites() const;
00110 
00111 
00113     typedef P i_element;
00114 
00116     void insert(const P& p);
00117 
00119     typedef P r_element;
00120 
00122     void remove(const P& p);
00123 
00125     void clear();
00126 
00127 
00129     const P& operator[](unsigned i) const;
00130 
00131 
00133     std::size_t memory_size() const;
00134 
00136     const std::vector<P>& std_vector() const;
00137 
00139     const util::set<P>& util_set() const;
00140 
00141   protected:
00142 
00143     util::set<P> s_;
00144   };
00145 
00146 
00147 
00148 # ifndef MLN_INCLUDE_ONLY
00149 
00150   template <typename P>
00151   inline
00152   p_set<P>::p_set()
00153   {
00154   }
00155 
00156   template <typename P>
00157   inline
00158   bool
00159   p_set<P>::has(const P& p) const
00160   {
00161     return s_.has(p);
00162   }
00163 
00164   template <typename P>
00165   inline
00166   bool
00167   p_set<P>::has(const psite& p) const
00168   {
00169     mln_precondition(p.target_() == this); // FIXME: Refine.
00170     if (! has(p.index()))
00171       return false;
00172     mln_invariant(p.to_site() == (*this)[p.index()]);
00173     return true;
00174   }
00175 
00176   template <typename P>
00177   inline
00178   bool
00179   p_set<P>::has(const util::index& i) const
00180   {
00181     return i >= 0 && unsigned(i) < nsites();
00182   }
00183 
00184   template <typename P>
00185   inline
00186   bool
00187   p_set<P>::is_valid() const
00188   {
00189     return true;
00190   }
00191 
00192   template <typename P>
00193   inline
00194   unsigned
00195   p_set<P>::nsites() const
00196   {
00197     return s_.nelements();
00198   }
00199 
00200   template <typename P>
00201   inline
00202   void
00203   p_set<P>::insert(const P& p)
00204   {
00205     s_.insert(p);
00206   }
00207 
00208   template <typename P>
00209   inline
00210   void
00211   p_set<P>::remove(const P& p)
00212   {
00213     s_.remove(p);
00214   }
00215 
00216   template <typename P>
00217   inline
00218   void
00219   p_set<P>::clear()
00220   {
00221     s_.clear();
00222   }
00223 
00224   template <typename P>
00225   inline
00226   const P&
00227   p_set<P>::operator[](unsigned i) const
00228   {
00229     mln_precondition(i < nsites());
00230     return s_[i];
00231   }
00232 
00233   template <typename P>
00234   inline
00235   std::size_t
00236   p_set<P>::memory_size() const
00237   {
00238     return s_.memory_size();
00239   }
00240 
00241   template <typename P>
00242   inline
00243   const std::vector<P>&
00244   p_set<P>::std_vector() const
00245   {
00246     return s_.std_vector();
00247   }
00248 
00249   template <typename P>
00250   inline
00251   const util::set<P>&
00252   p_set<P>::util_set() const
00253   {
00254     return s_;
00255   }
00256 
00257 # endif // ! MLN_INCLUDE_ONLY
00258 
00259 } // end of namespace mln
00260 
00261 
00262 #endif // ! MLN_CORE_SITE_SET_P_SET_HH

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