Milena (Olena)
User documentation 2.0a Id
|
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_VALUE_INTERNAL_ITERABLE_SET_HH 00027 # define MLN_VALUE_INTERNAL_ITERABLE_SET_HH 00028 00034 # include <mln/core/concept/value_set.hh> 00035 # include <mln/trait/value_.hh> 00036 # include <mln/value/builtin/all.hh> 00037 # include <mln/value/internal/convert.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 namespace value 00044 { 00045 00046 // Fwd decls. 00047 template <typename S> struct fwd_viter_; 00048 template <typename S> struct bkd_viter_; 00049 00050 00051 namespace internal 00052 { 00053 00057 template <typename T, typename E> 00058 struct iterable_set : public Value_Set<E> 00059 { 00061 typedef T value; 00062 00064 typedef fwd_viter_<E> fwd_viter; 00065 00067 typedef bkd_viter_<E> bkd_viter; 00068 00070 bool has(const T& v) const; 00071 00073 T operator[](unsigned i) const; 00074 00076 unsigned index_of(const T& v) const; 00077 00079 unsigned nvalues() const; 00080 00081 }; 00082 00083 00084 00085 # ifndef MLN_INCLUDE_ONLY 00086 00087 template <typename T, typename E> 00088 inline 00089 bool 00090 iterable_set<T,E>::has(const T&) const 00091 { 00092 return true; 00093 } 00094 00095 template <typename T, typename E> 00096 inline 00097 T 00098 iterable_set<T,E>::operator[](unsigned i) const 00099 { 00100 mln_precondition(i < nvalues()); 00101 return mln::value::internal::convert_<T>::value_at_index(i); 00102 } 00103 00104 template <typename T, typename E> 00105 inline 00106 unsigned 00107 iterable_set<T,E>::index_of(const T& v) const 00108 { 00109 return mln::value::internal::convert_<T>::index_of_value(v); 00110 } 00111 00112 template <typename T, typename E> 00113 inline 00114 unsigned 00115 iterable_set<T,E>::nvalues() const 00116 { 00117 return mln_card(T); 00118 } 00119 00120 # endif // ! MLN_INCLUDE_ONLY 00121 00122 } // end of namespace mln::value::internal 00123 00124 } // end of namespace mln::value 00125 00126 } // end of namespace mln 00127 00128 00129 # include <mln/value/viter.hh> 00130 00131 00132 #endif // ! MLN_VALUE_INTERNAL_ITERABLE_SET_HH