#ifndef Int_H #define Int_H //#include "Integer.H" #include #include #include #include //#include "Complex.H" #include // enable_if #include namespace Integer { //! Choose int32_t or int64_t given # of bits template struct integer { BOOST_STATIC_ASSERT (bits < sizeof(int64_t)*8); typedef typename boost::mpl::if_c< (bits > sizeof(int)*8), int64_t, int32_t >::type type; static const type max = ~(type(-1) << (bits-1)); static const type min = (type(-1) << (bits-1)); }; //! Choose uint32_t or uint64_t given # of bits template struct uinteger { BOOST_STATIC_ASSERT (bits < sizeof(uint64_t)*8); typedef typename boost::mpl::if_c< (bits > sizeof(int)*8), uint64_t, uint32_t >::type type; }; } template struct noop { int_t static Apply (int_t x) { return x; } }; template struct sat { int_t static Apply (int_t x) { if (x > Integer::integer::max) return Integer::integer::max; else if (x < Integer::integer::min) return Integer::integer::min; else return x; } }; template class policy, typename int_t=typename Integer::integer::type> class SInt { public: explicit SInt (int_t x) : val (Check (x)) {} // template class otherpolicy> // explicit SInt (SInt x) : // val (Check (int_t(x))) {} static int_t Check (int_t x) { return policy::Apply (x); } int_t operator= (int_t x) { val = Check (x); } operator int_t() { return val; } private: int_t val; }; #endif