Commit 21d11b8f authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add a label type and labeling.

	* tests/labeling.cc: New.
	* tests/label.cc: New.
	* mln/fun/to_enc.hh: New.
	* mln/level/to_enc.hh: New.
	* mln/level/labeling.hh: New.
	* mln/value/label.hh: New.
	* img/tiny.pgm: New.

	* tests/README: Fix missing CR.
	* doc/Doxyfile.in: Update.
	* mln/core/trait/is_lowq.hh: Remove.
	* mln/core/trait/all.hh: Update.
	* mln/core/macros.hh: Update.
	* mln/value/set.hh: Update.
	* mln/core/concept/value.hh (++, --): New.
	* mln/level/fill.hh (memset): Force cast.
	* mln/value/lut_vec.hh: Fix warning.
	* mln/value/props.hh (card, mln_card): Rename as...
	(card_, mln_card_): ...these.
	(convert_): New.
	* mln/value/int_s.hh (+=, -=): New.
	* mln/value/int_u.hh: Likewise.
	* mln/value/internal/iterable_set.hh: Use convert_.
	* mln/value/internal/encoding.hh: Factor names.
	* mln/value/internal/value_like.hh (to_enc): New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1039 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 2655e8c7
2007-07-25 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add a label type and labeling.
* tests/labeling.cc: New.
* tests/label.cc: New.
* mln/fun/to_enc.hh: New.
* mln/level/to_enc.hh: New.
* mln/level/labeling.hh: New.
* mln/value/label.hh: New.
* img/tiny.pgm: New.
* tests/README: Fix missing CR.
* doc/Doxyfile.in: Update.
* mln/core/trait/is_lowq.hh: Remove.
* mln/core/trait/all.hh: Update.
* mln/core/macros.hh: Update.
* mln/value/set.hh: Update.
* mln/core/concept/value.hh (++, --): New.
* mln/level/fill.hh (memset): Force cast.
* mln/value/lut_vec.hh: Fix warning.
* mln/value/props.hh (card, mln_card): Rename as...
(card_, mln_card_): ...these.
(convert_): New.
* mln/value/int_s.hh (+=, -=): New.
* mln/value/int_u.hh: Likewise.
* mln/value/internal/iterable_set.hh: Use convert_.
* mln/value/internal/encoding.hh: Factor names.
* mln/value/internal/value_like.hh (to_enc): New.
2007-07-25 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add pset and pvec point sets.
......
......@@ -1054,6 +1054,7 @@ PREDEFINED = \
"mln_viter(T)=typename T::viter" \
"mln_fwd_viter(T)=typename T::fwd_viter" \
"mln_bkd_viter(T)=typename T::bkd_viter" \
"mln_enc(T)=typename T::enc" \
"mln_value(T)=typename T::value" \
"mln_qlf_value(T)=typename T::qlf_value" \
"mln_vset(T)=typename T::vset" \
......
P5
64 64
255
煗洑灘`fijjqy~亗亙厖剟厖剛儌剟儊亐~ynw摐槞殬櫄毎缀qtyyy{{||{~湜洑〃^chhhpy}亗們剟儍儍亗亜倐亐zpo墰湝潧殭槥梢巒vyyz{~~^9洔洕い^cighpx|亗倐儍儍倐倎亝剛亐{sk~槧牋潧櫁暚挚vrxy{乗3/湞灒潂\chghox|亖亖們~|~~~倐~~|ulz敓煘潧殭枛沦焢xy{Z2.3灍&潁[bgfgowz}~亖亇zzzy}亗~~~{uny彋潨湜洑棏U蝷py}Y0332煝灍潀Ybgfgowz|}~亗噷垈}|~~~ztnw嫈櫅櫄殫拸惤莓otX/171-牓殟湤瀪X`ggipx{}~亖儗彉ク{}}|ysmu嫄敊棗晵帊対炎扵./54/-ア剙灓爙T\bdhovy{|~儐剦彈々岸季wyyupju寫憯晳悘崒崒册.521//⿻ex牑瀨QYacfkruy{|wyz亙垘洨狈焕亩媘prmhs彅悕悙帍帊帍浀Y*24102-Uy牔瀦P[ccekqtxyxou{剢姇げ附懒牌hifr憵拁~悙悗彁搼R+120257Q媊Vz牔漼R[bdekquy{xnrwx{儐墤⒋阜可我讦_bbq悮杝X儜悘彁昪+04013@Y宩XYy灕漻S\bdekrvyyoousv噵崘煪猜吞送又奦[o憵梫<f帎帍攞6/4131<]垟YZZx湧漼R[cceksv{soqsv~厜寜嫏惹巧滔酉怭j悮榳6C|悕憤F*53124O剶焃[Zx湥瀦RYadekru卝mpsz剦増彯揪久仕掏卧觱a帣榵9+R寳攂-26331>|彍ZWv湥瀧PW_bejm~峠nqv厖億惎抖咐呐巧释献穋寵榵8*g嘉紻.65344l悪煗[][u湧瀥NVacdil憡emrz}~{柂澈冀滥巧商我崍洏p<z窖仲_-4013W彈灋渀b`w湩QZcefln焸dksy{~{挔,泊挡房履戮鞘膛煑拋澞瓮呜d/2.09倵灉洓ccbz湬S[cedimfhnvy{帞敘祷挤好侣霉澀可趟艘裇00/6e敎灉洐cbcz灛RZbccfp眽nipv{審寱潷Ё党富沟挡航粕汕拭芯<0/1P嫎煗湜沘`ay煬S[bbcds硹}imv噴噿摃灓è│Μ钡帛防牌魄柿┖/1.:u枬煘湝渀_`{牜T\bacas禎坢p厔倢嫃敋灍潬牐Жēギ沽寐萌侍瓪‐-11Z悪煖潨湜aad~牜▊QZaab_u咖攝{墕啀悎寠敄攪彙本戮僚商瞎儌/3<|枬潧洓洑ccg仮働Yacc_o掳寎uy唭亝墑{h[乵^ZDB笨寐僚人粯ql焗,0/R彌煘湚殮檊dg~▋QYaccad阜墎r亐倖~ucOG_VT@:vɑ澜苛呕爎i儯f1018s棥牊潧殮榠ff牚▌RX`bbc_灹渵}}z~zhOA4KKTFO档肪紦qx挘琯/511K嫓あ牉湜殬jgcz牜﹨PW`aaeey惊|{|}wXN=C8@=KXx幢将^dy殹\.35/5d帲"潨殬jg`u煬獑PU`abgleu{~uZDM:H>36Jl毝碑搅緖Ql廠*482/Bx挜"煗洏hf_t灛獓QWbdchpiΗqvyvQ>1@DDO,?t彲处浩仁?Q?/7:0/Z嚃煝 潨榞e`s灛獔TYdfdmup帟q|oK:;45=LK;|"绷韧噎J8E4:807t摐棗櫄灋湚梖c^r灜珗U[dgfmtt{厎{O=4?95:?Cs湶ぁ┏燎逃纀0rN6<51J嚋潤搾摃棗ec_r灜瑘TYeffltqh乣BD6?37A:\櫒伯垍敩被疗透`+f[;<33e崬煙檿拸弾ee_p灝瓓UZeediy恘[cKGI8:72=K懘亀l`こ扛恖T0\f<92<w摕湜湝殮殨張caYl灟瑠TXcc_~挄|KGQU<>3B32{楶>BTSz惎纘MD<0Wm>41I嚈湙殮殭槝拲坆^Sg灠畨U\dcUE?CI_5690/T溁璶FMc玱s埗㏎fi0.VsC21a憸殬槝槚搻墕巈_Qe灡睄[bm^f唨IPDDWmD,1,7兂﹣唦v墻抾劰瓈乛;3T{B0:v暃棗櫂枒寠敠砨YK_湶硰Zal{\<FeDB\lL-..aΙr仌洍枮檰儾聶kK3O>/E剺櫀枙攽寠ず窘XRD[湵睅YawjLEc[2:XX\7+D嫰dk剸Ν泴偑龋寎R7I:.X帥櫀晸憣垽谅玖NJ@Y毌瘞Ybrl\PKcI10:8lM)e璽Bs儜牠棆仯散弤L7B傽3m槣槙拺張椊旅鞘LI;U櫖瑣Vj{`bRSkP3,DQxR:嫍7Fo値殻ǎ悆|櫳y?;<丣;洓槙拸媼猜盟翁OI8Q櫗畮YjrW\OUiT3/KcM4n桸/Om姅殶渾惼煁i2>6{WJ帥槚晸悎浟率挝螼J?]洭瘣\aiTWPPfh;<7O3S,6Xo垜枦泭yp偗槄M0@4oeb枤枖搼帀任闲螸JFp灙瘨X]nKOJMdtNW9Uyy~84:`r~啂挋洉嫊┌搕75G7`qz槞枔拹實菲挝醒袵EDr煫皳WcoRP>GRboKN墦nF199^q唽崚晹樀慨峌/:I8R}垯様搼悐懡绦闲乙=@Dq…睊^ijGC?WXTd]枽xP44<9Th~儕媨{亐寫噛91=I:I剱櫁搾憦墦男行以<Ft“睍ihjF8Eh^^[|瀾l613;;J]v}啂倃{墬拡V/1=J@F寱殬枔憪嚈鸵矣杂6Gq澃矓XmWN9Jug`o潏A545;<DNgt墜剙厠憊505=NDH悧殭槙憥儧哉终严1Rt毊皰WcPD9Cntljn扱164369:@Og{唻彆潨廙/67@RGI憴洏棖憣炟终友蜒/0Ov洯瘨TWFD;=bWuyy^63:54269=<Dcy嚁ˇ9595EVLM憯枙晹強~诱油紳0,Am毈瓙pa?B;5nZ^u乹K2@6423::BOdu亸殶煆W;74GXPT峽}儓崒唦怪蜒菕O:O99V敧瑴kQ2A=DXigjkovB>842288Bl~倛帎摠拷榎0FUNX妧ztopsuv叫猩廌;N俲HF崻瑮vD)JJSC\`Yr~eX<86468?@iz垕寳盟艂EJGW帍妳{oenk阂蛺IHUV倫jF幁}41?EC@IHOn僯kD8969;PCiz剨嫃湪埠猛覑??Y悞弻垁x{喪远WQ]c\T枅J幆癁i,558I4@JR`{{a[39398_Ie唻寫殺旧以m0\悜弽妳~啩砸怳`had6帒E嵃皼d/3.BL3:AYYuyYe5=35<eMg倗墝悥灖被切俨2a搾弸噦偓首聁]jc`f,厰E嫲睖Y1./QD514IZu{`:;55OuTl厜垔帗洠盼杂Ug攼帄厎撔诱cl`ea(~橩壇疀Z..7A?607?R|j`SOJ7:ezUs唻増寫櫊┑绿屹卲搹媻厎熝匀協fcabZ&r淪嚡盀^.386:63:ESoeW8;?4GruX~妼妶姀枬グ救兄眬崕帊噧暬哟tc^[c^]$g漒劖瘽f2428<72:LPLPj;1.4Yxca唽帉墘帞櫋畔晕俠q噴憢S焏\U`_^R#a沚5.58;8/4KmTP?0,+EmoMu垕崓妶嫄枮С撂易嘢TQQ^嚊啡sMT\^_]@Fl瑃梋2234:;016Yw^2,)4]qO]剦妼帉墛崜殺刃专bdU?-x姑桮GX^UdV<[}朮0232;@8:>DdR/*,H\OU{厜媽帋寢嫃枱ù猛粤igbUF翍N@R_N[hPAGm朒/587?FQ?BJfM-+1DQfz剤妼帎弽寧摏グ饺研x^gfgz哤KP`ONlcE<7V瓭劕祶=16<<B@]JFGTO.1Kfs{儑墜崗悙悙摍仿陀怸iruoggZZPKepR:91M矾埆磮:1:BBODUSL?BRBDarx}亙唸妼彁憮摃殹ǔ可耀[cs{w|oZUQ]y`:9Q
\ No newline at end of file
......@@ -49,8 +49,14 @@ namespace mln
/*
typedef enc; // encoding type
typedef equiv; // equivalent type
*/
*/
/// Pre-incrementation.
E& operator++();
/// Pre-decrementation.
E& operator--();
protected:
Value();
};
......@@ -65,6 +71,22 @@ namespace mln
typedef mln_equiv(E) equiv;
}
template <typename E>
E&
Value<E>::operator++()
{
exact(this)->operator+=(E::one);
return exact(*this);
}
template <typename E>
E&
Value<E>::operator--()
{
exact(this)->operator-=(E::one);
return exact(*this);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
......
......@@ -152,7 +152,7 @@
# define mln_value_kind(I) typename mln::value::props< mln_value(I) >::kind
/// Shortcut to test if the values of an image with type \c I are lowly quantifized.
# define mln_is_value_lowq(I) typename mln::trait::is_lowq< mln_value(I) >::ret
# define mln_is_value_lowq(I) mln_is_lowq( mln_value(I) )
/// Shortcut to access the type of value set (vset) associated to T.
# define mln_vset(T) typename T::vset
......
......@@ -45,7 +45,6 @@ namespace mln
# include <mln/core/trait/is_fast.hh>
# include <mln/core/trait/is_lowq.hh>
# include <mln/core/trait/pixter.hh>
......
......@@ -25,41 +25,47 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CORE_TRAIT_IS_LOWQ_HH
# define MLN_CORE_TRAIT_IS_LOWQ_HH
#ifndef MLN_FUN_TO_ENC_HH
# define MLN_FUN_TO_ENC_HH
/*! \file mln/core/trait/is_lowq.hh
/*! \file mln/fun/to_enc.hh
*
* \brief Definition of the is_lowq image trait.
* \brief FIXME.
*/
# include <mln/metal/bool.hh>
# include <mln/value/props.hh>
# define mln_is_lowq(T) typename mln::trait::is_lowq< T >::ret
# include <mln/core/concept/function.hh>
namespace mln
{
namespace trait
namespace fun
{
// FIXME: Doc!
template <typename T>
struct is_lowq
template <typename V>
struct to_enc : public Function_v2v< to_enc<V> >
{
typedef typename metal::bool_<( mln_card(T) != 0 )>::type ret;
typedef typename V::enc result;
result operator()(const V& v) const;
};
} // end of namespace mln::trait
# ifndef MLN_INCLUDE_ONLY
template <typename V>
typename V::enc
to_enc<V>::operator()(const V& v) const
{
return v.to_enc();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::fun
} // end of namespace mln
#endif // ! MLN_CORE_TRAIT_IS_LOWQ_HH
#endif // ! MLN_FUN_TO_ENC_HH
......@@ -146,7 +146,7 @@ namespace mln
if (sizeof(mln_value(I)) == 1)
{
std::memset((void*)(ima.buffer()),
value,
*(const int*)(& value), // violent cast
sizeof(mln_value(I)) * ima.ncells());
}
else
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_LEVEL_LABELING_HH
# define MLN_LEVEL_LABELING_HH
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/value/props.hh>
# include <mln/level/fill.hh>
namespace mln
{
namespace level
{
template <typename I, typename N, typename O>
void labeling(const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
namespace impl
{
template <typename I, typename N, typename O>
struct component_labeling
{
typedef mln_point(I) point;
typedef mln_value(I) value;
// in:
const I& input;
const N& nbh;
// out:
O& output;
// aux:
mln_ch_value(I, point) parent;
mln_ch_value(I, bool) deja_vu;
mln_value(O) current_l;
component_labeling(const I& input_, const N& nbh_, O& output_)
: // in
input(input_),
nbh(nbh_),
// out
output(output_),
// aux
parent(input.domain()),
deja_vu(input.domain())
{
}
void run()
{
// init
{
level::fill(deja_vu, false);
current_l = 0;
level::fill(output, 0);
}
// first pass
{
mln_bkd_piter(I) p(input.domain());
mln_niter(N) n(nbh, p);
for_all(p)
if (input(p))
{
parent(p) = p;
for_all(n)
if (input.has(n) && input(n) && deja_vu(n))
{
point r = find_root(n);
if (r != p)
parent(r) = p;
}
deja_vu(p) = true;
}
}
// second pass
{
mln_fwd_piter(I) p(input.domain());
for_all(p)
if (input(p))
if (parent(p) == p)
output(p) = ++current_l;
else
output(p) = output(parent(p));
}
}
point find_root(const point& x)
{
if (parent(x) == x)
return x;
else
return parent(x) = find_root(parent(x));
}
}; // end of component_labeling
template <typename I, typename N, typename O>
void labeling(value::binary_kind,
const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output)
{
impl::component_labeling<I,N,O> f(exact(input), exact(nbh), exact(output));
f.run();
}
/*
template <typename K, typename I, typename N, typename O>
void labeling(K,
const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output)
{
impl::flat_labeling<I,N,O> f(exact(input), exact(nbh), exact(output));
f.run();
}
*/
} // end of namespace mln::level::impl
// facade
template <typename I, typename N, typename O>
void labeling(const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output)
{
mln_assertion(exact(output).domain() == exact(input).domain());
impl::labeling(mln_value_kind(I)(),
exact(input), exact(nbh), exact(output));
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::level
} // end of namespace mln
#endif // ! MLN_LEVEL_LABELING_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_LEVEL_TO_ENC_HH
# define MLN_LEVEL_TO_ENC_HH
/*! \file mln/level/to_enc.hh
*
* \brief Transform with fun::to_enc the contents of an image into
* another one.
*/
# include <mln/level/transform.hh>
# include <mln/fun/to_enc.hh>
namespace mln
{
namespace level
{
/*! Set the \p output image with the encoding values of the image \p input pixels.
*
* \param[in] input The input image.
* \param[out] output The result image.
*
* \pre \p output.domain >= \p input.domain
*/
template <typename I, typename O>
void to_enc(const Image<I>& input, Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename O>
void to_enc(const Image<I>& input, Image<O>& output)
{
mln_precondition(exact(output).domain() >= exact(input).domain());
level::transform(input, fun::to_enc< mln_value(I) >(), output);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::level
} // end of namespace mln
#endif // ! MLN_LEVEL_TO_ENC_HH
......@@ -80,6 +80,7 @@ namespace mln
output(p) = f( input(p) );
}
template <typename I, typename F, typename O>
void transform(metal::true_, // low quantization
const Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_)
......@@ -94,6 +95,7 @@ namespace mln
output(p) = lut(input(p));
}
// template <typename I, typename F, typename O>
// void transform(metal::true_, // low quantization
// const Fast_Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_)
......
......@@ -37,7 +37,6 @@
# include <mln/value/internal/value_like.hh>
# include <mln/value/internal/encoding.hh>
# include <mln/value/props.hh>
# include <mln/value/set.hh>
# include <mln/debug/format.hh>
......@@ -54,11 +53,11 @@ namespace mln
*/
template <unsigned n>
struct int_s
: public internal::value_like_< typename internal::encoding_int_s_<n>::ret,
: public internal::value_like_< typename internal::encoding_signed_<n>::ret,
int_s<n> >
{
protected:
typedef internal::value_like_< typename internal::encoding_int_s_<n>::ret,
typedef internal::value_like_< typename internal::encoding_signed_<n>::ret,
int_s<n> > super;
public:
......@@ -80,6 +79,12 @@ namespace mln
/// Unit value.
static const int_s<n> one;
/// Self addition.
int_s<n>& operator+=(int i);
/// Self subtraction.
int_s<n>& operator-=(int i);
};
......@@ -89,7 +94,7 @@ namespace mln
{
static const int_s<n> max; // = 2^(n-1) - 1
static const int_s<n> min; // = - max
static const std::size_t card = metal::pow<2, n>::value;
static const std::size_t card_ = metal::pow<2, n>::value;
static const unsigned nbits = n;
typedef data_kind kind;
};
......@@ -128,11 +133,32 @@ namespace mln
}
template <unsigned n>
int_s<n> int_s<n>::operator-() const
int_s<n>
int_s<n>::operator-() const
{
return - this->v_;
}
template <unsigned n>
int_s<n>&
int_s<n>::operator+=(int i)
{
mln_precondition(long(this->v_) + i >= mln_min(enc));
mln_precondition(long(this->v_) + i <= mln_max(enc));
this->v_ += i;
return *this;
}
template <unsigned n>
int_s<n>&
int_s<n>::operator-=(int i)
{
mln_precondition(long(this->v_) - i >= mln_min(enc));
mln_precondition(long(this->v_) - i <= mln_max(enc));
this->v_ -= i;
return *this;
}
template <unsigned n>
const int_s<n> int_s<n>::zero = 0;
......
......@@ -37,7 +37,6 @@
# include <mln/value/internal/value_like.hh>
# include <mln/value/internal/encoding.hh>
# include <mln/value/props.hh>
# include <mln/value/set.hh>
# include <mln/debug/format.hh>
......@@ -54,11 +53,11 @@ namespace mln
*/
template <unsigned n>
struct int_u
: public internal::value_like_< typename internal::encoding_int_u_<n>::ret,
: public internal::value_like_< typename internal::encoding_unsigned_<n>::ret,
int_u<n> >
{
protected:
typedef internal::value_like_< typename internal::encoding_int_u_<n>::ret,
typedef internal::value_like_< typename internal::encoding_unsigned_<n>::ret,
int_u<n> > super;
public:
......@@ -77,6 +76,12 @@ namespace mln
/// Unit value.
static const int_u<n> one;
/// Self addition.
int_u<n>& operator+=(int i);
/// Self subtraction.
int_u<n>& operator-=(int i);
};
......@@ -89,9 +94,9 @@ namespace mln
template <unsigned n>
struct props< int_u<n> >
{
static const std::size_t card = metal::pow<2, n>::value;
static const std::size_t card_ = metal::pow<2, n>::value;
static const int_u<n> min; // = 0
static const int_u<n> max; // = card - 1
static const int_u<n> max; // = card_ - 1
static const unsigned nbits = n;
typedef data_kind kind;
};
......@@ -124,6 +129,26 @@ namespace mln
this->v_ = enc(i);
}
template <unsigned n>
int_u<n>&
int_u<n>::operator+=(int i)
{
mln_precondition(long(this->v_) + i >= 0);
mln_precondition(long(this->v_) + i <= mln_max(enc));
this->v_ += i;
return *this;
}
template <unsigned n>
int_u<n>&
int_u<n>::operator-=(int i)
{
mln_precondition(long(this->v_) - i >= 0);
mln_precondition(long(this->v_) - i <= mln_max(enc));
this->v_ -= i;
return *this;
}
template <unsigned n>
const int_u<n> int_u<n>::zero = 0;
......
......@@ -43,36 +43,36 @@ namespace mln
namespace internal
{
template <unsigned n> struct encoding_int_u_;
template <unsigned n> struct encoding_unsigned_;
template <> struct encoding_int_u_<8> { typedef unsigned char ret; };
template <> struct encoding_int_u_<16> { typedef unsigned short ret; };
template <> struct encoding_int_u_<32> { typedef unsigned int ret; }; // FIXME!!!
template <> struct encoding_int_u_<64> { typedef unsigned long ret; }; // FIXME!!!
template <> struct encoding_unsigned_<8> { typedef unsigned char ret; };
template <> struct encoding_unsigned_<16> { typedef unsigned short ret; };
template <> struct encoding_unsigned_<32> { typedef unsigned int ret; }; // FIXME!!!
template <> struct encoding_unsigned_<64> { typedef unsigned long ret; }; // FIXME!!!
template <> struct encoding_int_u_<99> { typedef void ret; }; // stopper
template <> struct encoding_unsigned_<99> { typedef void ret; }; // stopper
template <unsigned n>