Milena (Olena)
User documentation 2.0a Id
|
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_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 // Implementations. 00051 00052 namespace impl 00053 { 00054 00055 // Generic version. 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 } // end of namespace mln::set::impl::generic 00077 00078 00079 // A single specialization. 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 } // end of namespace mln::set::impl 00092 00093 00094 00095 // Dispatch. 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 // Dispatch facade. 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 } // end of namespace mln::set::internal 00127 00128 00129 00130 // Facade. 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 } // end of namespace mln::set 00148 00149 } // end of namespace mln 00150 00151 00152 #endif // ! MLN_SET_CARD_HH