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_MORPHO_ATTRIBUTE_CARD_HH
00027 # define MLN_MORPHO_ATTRIBUTE_CARD_HH
00028
00036
00037 # include <mln/accu/internal/base.hh>
00038 # include <mln/util/pix.hh>
00039
00040
00041 namespace mln
00042 {
00043
00044
00045
00046
00047 namespace morpho {
00048 namespace attribute {
00049 template <typename I> class card;
00050 }
00051 }
00052
00053
00054
00055
00056 namespace trait
00057 {
00058
00059 template <typename I>
00060 struct accumulator_< morpho::attribute::card<I> >
00061 {
00062 typedef accumulator::has_untake::no has_untake;
00063 typedef accumulator::has_set_value::no has_set_value;
00064 typedef accumulator::has_stop::no has_stop;
00065 typedef accumulator::when_pix::use_none when_pix;
00066 };
00067
00068 }
00069
00070
00071 namespace morpho
00072 {
00073
00074 namespace attribute
00075 {
00076
00078
00079 template <typename I>
00080 class card : public mln::accu::internal::base< unsigned, card<I> >
00081 {
00082 typedef mln::accu::internal::base< unsigned, card<I> > super_;
00083 public:
00084
00085 typedef mln_psite(I) argument;
00086
00087 card();
00088
00091 void init();
00092
00093 void take();
00094 void take(const argument& s);
00095 void take(const util::pix<I>& px);
00096 void take(const card<I>& other);
00097
00098 void take_as_init();
00099 void take_as_init_(const util::pix<I>& px);
00101
00103 unsigned to_result() const;
00104
00107 bool is_valid() const;
00108
00109 protected:
00111 unsigned c_;
00112 };
00113
00114
00115
00116 # ifndef MLN_INCLUDE_ONLY
00117
00118 template <typename I>
00119 inline
00120 card<I>::card()
00121 {
00122 init();
00123 }
00124
00125 template <typename I>
00126 inline
00127 void
00128 card<I>::init()
00129 {
00130 c_ = 0;
00131 }
00132
00133
00134
00135 template <typename I>
00136 inline
00137 void
00138 card<I>::take()
00139 {
00140 ++c_;
00141 }
00142
00143 template <typename I>
00144 inline
00145 void
00146 card<I>::take(const argument&)
00147 {
00148 take();
00149 }
00150
00151 template <typename I>
00152 inline
00153 void
00154 card<I>::take(const util::pix<I>&)
00155 {
00156 take();
00157 }
00158
00159 template <typename I>
00160 inline
00161 void
00162 card<I>::take(const card<I>& other)
00163 {
00164 c_ += other.c_;
00165 }
00166
00167
00168
00169 template <typename I>
00170 inline
00171 void
00172 card<I>::take_as_init()
00173 {
00174 init();
00175 take();
00176 }
00177
00178 template <typename I>
00179 inline
00180 void
00181 card<I>::take_as_init_(const util::pix<I>&)
00182 {
00183 this->take_as_init();
00184 }
00185
00186 template <typename I>
00187 inline
00188 unsigned
00189 card<I>::to_result() const
00190 {
00191 return c_;
00192 }
00193
00194 template <typename I>
00195 inline
00196 bool
00197 card<I>::is_valid() const
00198 {
00199 return true;
00200 }
00201
00202 # endif // ! MLN_INCLUDE_ONLY
00203
00204 }
00205
00206 }
00207
00208 }
00209
00210
00211 #endif // ! MLN_MORPHO_ATTRIBUTE_CARD_HH