00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory 00002 // (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 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 } // end of namespace mln::accu::meta 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 } // end of namespace mln::accu 00158 00159 } // end of namespace mln 00160 00161 00162 #endif // ! MLN_ACCU_LABEL_USED_HH