DGtal  1.4.beta
DGtal::IntegerConverter< dim, DGtal::int64_t > Struct Template Reference

#include <DGtal/kernel/IntegerConverter.h>

Public Types

typedef DGtal::int64_t Integer
 

Static Public Member Functions

static DGtal::int64_t cast (DGtal::int32_t i)
 
static PointVector< dim, DGtal::int64_tcast (PointVector< dim, DGtal::int32_t > p)
 
static DGtal::int64_t cast (DGtal::int64_t i)
 
static PointVector< dim, DGtal::int64_tcast (PointVector< dim, DGtal::int64_t > p)
 
static DGtal::int64_t cast (DGtal::BigInteger i)
 
static PointVector< dim, DGtal::int64_tcast (PointVector< dim, DGtal::BigInteger > p)
 

Detailed Description

template<DGtal::Dimension dim>
struct DGtal::IntegerConverter< dim, DGtal::int64_t >

Allows seamless conversion of integral types and lattice points, while checking for errors when going from a more precise to a less precise type.

Specialized version for int64_t.

Template Parameters
dimstatic constant of type DGtal::Dimension that specifies the static dimension of the space and thus the number of elements of the Point or Vector.

Definition at line 235 of file IntegerConverter.h.

Member Typedef Documentation

◆ Integer

template<DGtal::Dimension dim>
typedef DGtal::int64_t DGtal::IntegerConverter< dim, DGtal::int64_t >::Integer

Definition at line 236 of file IntegerConverter.h.

Member Function Documentation

◆ cast() [1/6]

template<DGtal::Dimension dim>
static DGtal::int64_t DGtal::IntegerConverter< dim, DGtal::int64_t >::cast ( DGtal::BigInteger  i)
inlinestatic
Parameters
iany integer
Returns
the same integer

Definition at line 280 of file IntegerConverter.h.

281  {
282  DGtal::int64_t r = detail::mpz_get_sll( i.get_mpz_t() );
283  DGtal::BigInteger tmp;
284  detail::mpz_set_sll( tmp.get_mpz_t(), r );
285  if ( tmp != i )
286  trace.warning() << "Bad integer conversion: " << i << " -> " << r
287  << std::endl;
288  return r;
289  }
std::ostream & warning()
static void mpz_set_sll(mpz_t n, long long sll)
----------— GMP SPECIALIZED SERVICES -------------------------—
static long long mpz_get_sll(mpz_t n)
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Trace trace
Definition: Common.h:153
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition: BasicTypes.h:79

References DGtal::detail::mpz_get_sll(), DGtal::detail::mpz_set_sll(), DGtal::trace, and DGtal::Trace::warning().

◆ cast() [2/6]

template<DGtal::Dimension dim>
static DGtal::int64_t DGtal::IntegerConverter< dim, DGtal::int64_t >::cast ( DGtal::int32_t  i)
inlinestatic
Parameters
iany integer
Returns
the same integer

Definition at line 240 of file IntegerConverter.h.

241  {
242  return i;
243  }

◆ cast() [3/6]

template<DGtal::Dimension dim>
static DGtal::int64_t DGtal::IntegerConverter< dim, DGtal::int64_t >::cast ( DGtal::int64_t  i)
inlinestatic
Parameters
iany integer
Returns
the same integer

Definition at line 261 of file IntegerConverter.h.

262  {
263  return i;
264  }

◆ cast() [4/6]

template<DGtal::Dimension dim>
static PointVector< dim, DGtal::int64_t > DGtal::IntegerConverter< dim, DGtal::int64_t >::cast ( PointVector< dim, DGtal::BigInteger p)
inlinestatic

Conversion of a lattice point.

Parameters
pany point
Returns
the same point

Definition at line 297 of file IntegerConverter.h.

298  {
299  PointVector< dim, DGtal::int64_t > q;
300  for ( DGtal::Dimension i = 0; i < dim; i++ )
301  q[ i ] = cast( p[ i ] );
302  return q;
303  }
DGtal::uint32_t Dimension
Definition: Common.h:136
static DGtal::int64_t cast(DGtal::int32_t i)
unsigned int dim(const Vector &z)

References DGtal::IntegerConverter< dim, TInteger >::cast(), and dim().

◆ cast() [5/6]

template<DGtal::Dimension dim>
static PointVector< dim, DGtal::int64_t > DGtal::IntegerConverter< dim, DGtal::int64_t >::cast ( PointVector< dim, DGtal::int32_t p)
inlinestatic

Conversion of a lattice point.

Parameters
pany point
Returns
the same point

Definition at line 251 of file IntegerConverter.h.

252  {
253  PointVector< dim, DGtal::int64_t > q;
254  for ( DGtal::Dimension i = 0; i < dim; i++ )
255  q[ i ] = cast( p[ i ] );
256  return q;
257  }

References DGtal::IntegerConverter< dim, TInteger >::cast(), and dim().

◆ cast() [6/6]

template<DGtal::Dimension dim>
static PointVector< dim, DGtal::int64_t > DGtal::IntegerConverter< dim, DGtal::int64_t >::cast ( PointVector< dim, DGtal::int64_t p)
inlinestatic

Conversion of a lattice point.

Parameters
pany point
Returns
the same point

Definition at line 272 of file IntegerConverter.h.

273  {
274  return p;
275  }

The documentation for this struct was generated from the following file: