DGtal  1.2.0
Public Types | Static Public Member Functions
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 150 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 151 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 199 of file IntegerConverter.h.

200  {
201  DGtal::int32_t r = i.get_si();
202  if ( DGtal::BigInteger( r ) != i )
203  trace.warning() << "Bad integer conversion: " << i << " -> " << r
204  << std::endl;
205  return r;
206  }
std::ostream & warning()
Trace trace
Definition: Common.h:154
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 155 of file IntegerConverter.h.

156  {
157  return i;
158  }

◆ 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 173 of file IntegerConverter.h.

174  {
176  if ( DGtal::int64_t( r ) != i )
177  trace.warning() << "Bad integer conversion: " << i << " -> " << r
178  << std::endl;
179  return r;
180  }
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 214 of file IntegerConverter.h.

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

167  {
168  return p;
169  }

◆ 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 188 of file IntegerConverter.h.

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

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


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