DGtal  1.5.beta
DGtal::IntegerConverter< dim, DGtal::int32_t > Struct Template Reference

#include <DGtal/kernel/IntegerConverter.h>

Public Types

typedef DGtal::int32_t Integer
 

Static Public Member Functions

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

Detailed Description

template<DGtal::Dimension dim>
struct DGtal::IntegerConverter< dim, DGtal::int32_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 int32_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 149 of file IntegerConverter.h.

Member Typedef Documentation

◆ Integer

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

Definition at line 150 of file IntegerConverter.h.

Member Function Documentation

◆ cast() [1/6]

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

Definition at line 198 of file IntegerConverter.h.

199  {
200  auto r = i.get_si();
201  if ( DGtal::BigInteger( r ) != i )
202  trace.warning() << "Bad integer conversion: " << i << " -> " << r
203  << std::endl;
204  return (DGtal::int32_t)r;
205  }
std::ostream & warning()
Trace trace
Definition: Common.h:153
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition: BasicTypes.h:79

References DGtal::trace, and DGtal::Trace::warning().

◆ cast() [2/6]

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

Definition at line 154 of file IntegerConverter.h.

155  {
156  return i;
157  }

◆ cast() [3/6]

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

Definition at line 172 of file IntegerConverter.h.

173  {
175  if ( DGtal::int64_t( r ) != i )
176  trace.warning() << "Bad integer conversion: " << i << " -> " << r
177  << std::endl;
178  return r;
179  }
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74

References DGtal::trace, and DGtal::Trace::warning().

◆ cast() [4/6]

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

Conversion of a lattice point.

Parameters
pany point
Returns
the same point

Definition at line 213 of file IntegerConverter.h.

214  {
215  PointVector< dim, DGtal::int32_t > q;
216  for ( DGtal::Dimension i = 0; i < dim; i++ )
217  q[ i ] = cast( p[ i ] );
218  return q;
219  }
DGtal::uint32_t Dimension
Definition: Common.h:136
static DGtal::int32_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::int32_t > DGtal::IntegerConverter< dim, DGtal::int32_t >::cast ( PointVector< dim, DGtal::int32_t p)
inlinestatic

Conversion of a lattice point.

Parameters
pany point
Returns
the same point

Definition at line 165 of file IntegerConverter.h.

166  {
167  return p;
168  }

◆ cast() [6/6]

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

Conversion of a lattice point.

Parameters
pany point
Returns
the same point

Definition at line 187 of file IntegerConverter.h.

188  {
189  PointVector< dim, DGtal::int32_t > q;
190  for ( DGtal::Dimension i = 0; i < dim; i++ )
191  q[ i ] = cast( p[ i ] );
192  return q;
193  }

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


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