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_SET_CARD_HH
00027 # define MLN_SET_CARD_HH
00028 
00032 
00033 # include <mln/core/concept/site_set.hh>
00034 
00035 
00036 namespace mln
00037 {
00038 
00039   namespace set
00040   {
00041 
00043     template <typename S>
00044     unsigned card(const Site_Set<S>& s);
00045 
00046 
00047 # ifndef MLN_INCLUDE_ONLY
00048 
00049 
00050     
00051 
00052     namespace impl
00053     {
00054 
00055       
00056 
00057       namespace generic
00058       {
00059 
00060         template <typename S>
00061         unsigned card(const Site_Set<S>& s_)
00062         {
00063           trace::entering("set::impl::generic::card");
00064           const S& s = exact(s_);
00065           mln_precondition(s.is_valid());
00066 
00067           unsigned n = 0;
00068           mln_piter(S) p(s);
00069           for_all(p)
00070             ++n;
00071 
00072           trace::exiting("set::impl::generic::card");
00073           return n;
00074         }
00075 
00076       } 
00077 
00078 
00079       
00080 
00081       template <typename S>
00082       inline
00083       unsigned card_from_method(const Site_Set<S>& s)
00084       {
00085         trace::entering("set::impl::card_from_method");
00086         unsigned n = exact(s).nsites();
00087         trace::exiting("set::impl::card_from_method");
00088         return n;
00089       }
00090 
00091     } 
00092 
00093 
00094 
00095     
00096 
00097     namespace internal
00098     {
00099 
00100       template <typename S>
00101       inline
00102       unsigned card_dispatch(mln::trait::site_set::nsites::any,
00103                              const Site_Set<S>& s)
00104       {
00105         return impl::generic::card(s);
00106       }
00107 
00108       template <typename S>
00109       inline
00110       unsigned card_dispatch(mln::trait::site_set::nsites::known,
00111                              const Site_Set<S>& s)
00112       {
00113         return impl::card_from_method(s);
00114       }
00115 
00116       
00117 
00118       template <typename S>
00119       inline
00120       unsigned card_dispatch(const Site_Set<S>& s)
00121       {
00122         return card_dispatch(mln_trait_site_set_nsites(S)(),
00123                              s);
00124       }
00125 
00126     } 
00127 
00128 
00129 
00130     
00131 
00132     template <typename S>
00133     inline
00134     unsigned card(const Site_Set<S>& s)
00135     {
00136       trace::entering("set::card");
00137       mln_precondition(exact(s).is_valid());
00138 
00139       unsigned n = internal::card_dispatch(s);
00140 
00141       trace::exiting("set::card");
00142       return n;
00143     }
00144 
00145 # endif // ! MLN_INCLUDE_ONLY
00146 
00147   } 
00148 
00149 } 
00150 
00151 
00152 #endif // ! MLN_SET_CARD_HH