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
00027 #ifndef MLN_ACCU_LABEL_USED_HH
00028 # define MLN_ACCU_LABEL_USED_HH
00029
00033
00034 # include <mln/accu/internal/base.hh>
00035 # include <mln/core/concept/meta_accumulator.hh>
00036 # include <mln/math/max.hh>
00037 # include <mln/value/next.hh>
00038 # include <mln/fun/i2v/array.hh>
00039
00040
00041 namespace mln
00042 {
00043
00044 namespace accu
00045 {
00046
00051
00052 template <typename L>
00053 struct label_used : public mln::accu::internal::base< const fun::i2v::array<bool>& , label_used<L> >
00054 {
00055 typedef L argument;
00056
00057 label_used();
00058
00060 void init();
00061
00064 void take(const argument&);
00065 void take(const label_used<L>& other);
00067
00069 const fun::i2v::array<bool>& to_result() const;
00070
00073 bool is_valid() const;
00074
00075 protected:
00077 fun::i2v::array<bool> label_used_;
00078 };
00079
00080
00081 namespace meta
00082 {
00083
00085 struct label_used : public Meta_Accumulator< label_used >
00086 {
00087 template <typename L>
00088 struct with
00089 {
00090 typedef accu::label_used<L> ret;
00091 };
00092 };
00093
00094 }
00095
00096
00097
00098 # ifndef MLN_INCLUDE_ONLY
00099
00100 template <typename L>
00101 inline
00102 label_used<L>::label_used()
00103 {
00104 init();
00105 }
00106
00107 template <typename L>
00108 inline
00109 void
00110 label_used<L>::init()
00111 {
00112 label_used_.resize(1, true);
00113 }
00114
00115 template <typename L>
00116 inline
00117 void
00118 label_used<L>::take(const argument& l)
00119 {
00120 if (label_used_.size() <= l)
00121 label_used_.resize(value::next(l), false);
00122
00123 label_used_(l) = true;
00124 }
00125
00126 template <typename L>
00127 inline
00128 void
00129 label_used<L>::take(const label_used<L>& other)
00130 {
00131 unsigned
00132 max_size = mln::math::max(other.to_result().size(), label_used_.size());
00133
00134 label_used_.resize(max_size, false);
00135 for (unsigned i = 1; i < label_used_.size(); ++i)
00136 label_used_(i) = label_used_(i) || other.to_result()(i);
00137 }
00138
00139 template <typename L>
00140 inline
00141 const fun::i2v::array<bool>&
00142 label_used<L>::to_result() const
00143 {
00144 return label_used_;
00145 }
00146
00147 template <typename L>
00148 inline
00149 bool
00150 label_used<L>::is_valid() const
00151 {
00152 return true;
00153 }
00154
00155 # endif // ! MLN_INCLUDE_ONLY
00156
00157 }
00158
00159 }
00160
00161
00162 #endif // ! MLN_ACCU_LABEL_USED_HH