Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
IntegerConverter.h
1
16
17#pragma once
18
30
31#if defined(IntegerConverter_RECURSES)
32#error Recursive header files inclusion detected in IntegerConverter.h
33#else // defined(IntegerConverter_RECURSES)
35#define IntegerConverter_RECURSES
36
37#if !defined IntegerConverter_h
39#define IntegerConverter_h
40
42// Inclusions
43#include <iostream>
44#include <string>
45#include <vector>
46#include <array>
47#include "DGtal/base/Common.h"
48#include "DGtal/kernel/CInteger.h"
49#include "DGtal/kernel/NumberTraits.h"
50#include "DGtal/kernel/PointVector.h"
51
52namespace DGtal
53{
55
67 template < DGtal::Dimension dim,
68 typename TInteger >
71 typedef TInteger Integer;
72
75 static Integer cast( Integer i )
76 {
77 return i;
78 }
79
84 static
87 {
88 return p;
89 }
90 };
91
101 template < DGtal::Dimension dim >
104
108 {
109 return i;
110 }
111
116 static
119 {
120 return p;
121 }
122
126 {
128 if ( DGtal::int64_t( r ) != i )
129 trace.warning() << "Bad integer conversion: " << i << " -> " << r
130 << std::endl;
131 return r;
132 }
133
138 static
141 {
143 for ( DGtal::Dimension i = 0; i < dim; i++ )
144 q[ i ] = cast( p[ i ] );
145 return q;
146 }
147
151 {
153 if ( DGtal::BigInteger( r ) != i )
154 trace.warning() << "Bad integer conversion: " << i << " -> " << r
155 << std::endl;
156 return (DGtal::int32_t)r;
157 }
158
163 static
166 {
168 for ( DGtal::Dimension i = 0; i < dim; i++ )
169 q[ i ] = cast( p[ i ] );
170 return q;
171 }
172 };
173
174
184 template < DGtal::Dimension dim >
187
191 {
192 return i;
193 }
194
199 static
202 {
204 for ( DGtal::Dimension i = 0; i < dim; i++ )
205 q[ i ] = cast( p[ i ] );
206 return q;
207 }
208
212 {
213 return i;
214 }
215
220 static
223 {
224 return p;
225 }
226
230 {
232 DGtal::BigInteger tmp(r);
233 if ( tmp != i )
234 trace.warning() << "Bad integer conversion: " << i << " -> " << r
235 << std::endl;
236 return r;
237 }
238
243 static
246 {
248 for ( DGtal::Dimension i = 0; i < dim; i++ )
249 q[ i ] = cast( p[ i ] );
250 return q;
251 }
252 };
253
263 template < DGtal::Dimension dim >
266
270 {
271 return DGtal::BigInteger( i );
272 }
273
278 static
281 {
283 for ( DGtal::Dimension i = 0; i < dim; i++ )
284 q[ i ] = cast( p[ i ] );
285 return q;
286 }
287
291 {
292 DGtal::BigInteger tmp = i;
293 return tmp;
294 }
295
300 static
303 {
305 for ( DGtal::Dimension i = 0; i < dim; i++ )
306 q[ i ] = cast( p[ i ] );
307 return q;
308 }
309
313 {
314 return i;
315 }
316
321 static
324 {
325 return p;
326 }
327
328 };
329
330} // namespace DGtal {
331
332#endif // !defined IntegerConverter_h
333
334#undef IntegerConverter_RECURSES
335#endif // else defined(IntegerConverter_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::int32_t int32_t
signed 32-bit integer.
Definition BasicTypes.h:71
std::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:73
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
static PointVector< dim, DGtal::BigInteger > cast(PointVector< dim, DGtal::BigInteger > p)
static DGtal::BigInteger cast(DGtal::int32_t i)
static PointVector< dim, DGtal::BigInteger > cast(PointVector< dim, DGtal::int32_t > p)
static PointVector< dim, DGtal::BigInteger > cast(PointVector< dim, DGtal::int64_t > p)
static DGtal::BigInteger cast(DGtal::BigInteger i)
static DGtal::BigInteger cast(DGtal::int64_t i)
static DGtal::int32_t cast(DGtal::int32_t i)
static PointVector< dim, DGtal::int32_t > cast(PointVector< dim, DGtal::int64_t > p)
static PointVector< dim, DGtal::int32_t > cast(PointVector< dim, DGtal::BigInteger > p)
static DGtal::int32_t cast(DGtal::BigInteger i)
static PointVector< dim, DGtal::int32_t > cast(PointVector< dim, DGtal::int32_t > p)
static DGtal::int32_t cast(DGtal::int64_t i)
static DGtal::int64_t cast(DGtal::int32_t i)
static PointVector< dim, DGtal::int64_t > cast(PointVector< dim, DGtal::int64_t > p)
static DGtal::int64_t cast(DGtal::int64_t i)
static PointVector< dim, DGtal::int64_t > cast(PointVector< dim, DGtal::BigInteger > p)
static PointVector< dim, DGtal::int64_t > cast(PointVector< dim, DGtal::int32_t > p)
static DGtal::int64_t cast(DGtal::BigInteger i)
----------— INTEGER/POINT CONVERSION SERVICES -----------------—
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
static PointVector< dim, Integer > cast(PointVector< dim, Integer > p)
static Integer cast(Integer i)
static DGtal::int64_t castToInt64_t(const T &aT)
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition CInteger.h:88