DGtal
0.6.devel
Main Page
Related Pages
Modules
Namespaces
Data Structures
Examples
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
src
DGtal
kernel
CInteger.h
1
17
#pragma once
18
31
#if defined(CInteger_RECURSES)
32
#error Recursive header files inclusion detected in CInteger.h
33
#else // defined(CInteger_RECURSES)
34
35
#define CInteger_RECURSES
36
37
#if !defined CInteger_h
38
39
#define CInteger_h
40
42
// Inclusions
43
#include <iostream>
44
#include "boost/concept_check.hpp"
45
#include "DGtal/base/ConceptUtils.h"
46
#include "DGtal/base/Common.h"
47
#include "DGtal/kernel/NumberTraits.h"
49
50
namespace
DGtal
51
{
52
54
// class CInteger
268
template
<
typename
T>
269
struct
CInteger
: boost::Assignable<T>, boost::EqualityComparable<T>, boost::LessThanComparable<T>
270
{
271
// ----------------------- Concept checks ------------------------------
272
public
:
273
BOOST_CONCEPT_USAGE
(
CInteger
)
274
{
275
T x( 0 );
// require constructor from built-in integer.
276
T y( 1 );
// require constructor from built-in integer.
277
ConceptUtils::sameType
(
myX
, ++x );
278
ConceptUtils::sameType
(
myX
, --x );
279
ConceptUtils::sameType
(
myX
,
NumberTraits<T>::ZERO
);
280
ConceptUtils::sameType
(
myX
,
NumberTraits<T>::ONE
);
281
282
// @note x-y with short is promoted to int. We should use some
283
// verification with possible promoting.
284
//
285
// @note T(x-y) is required (instead of 'x-y') because of
286
// gmpxx. Indeed, x+y returns an expression template in GMP and
287
// thus cannot be of type T.
288
ConceptUtils::sameType
(
myX
, T(x-y) );
289
// @note x+y with short is promoted to int. We should use some
290
// verification with possible promoting.
291
//
292
// @note T(x+y) is required (instead of 'x+y') because of
293
// gmpxx. Indeed, x+y returns an expression template in GMP and
294
// thus cannot be of type T.
295
ConceptUtils::sameType
(
myX
, T(x+y) );
296
ConceptUtils::sameType
(
myX
, T(x*y) );
297
ConceptUtils::sameType
(
myX
, T(x/y) );
298
ConceptUtils::sameType
(
myX
, T(x%y) );
299
}
300
301
// ------------------------- Private Datas --------------------------------
302
private
:
303
T
myX
;
304
typename
NumberTraits<T>::IsUnsigned
myIsUnsigned
;
305
typename
NumberTraits<T>::IsSigned
myIsSigned
;
306
typename
NumberTraits<T>::IsBounded
myIsBounded
;
307
typename
NumberTraits<T>::SignedVersion
mySignedVersion
;
308
typename
NumberTraits<T>::UnsignedVersion
myUnsignedVersion
;
309
typename
NumberTraits<T>::ReturnType
myReturnType
;
310
311
BOOST_STATIC_ASSERT
((
ConceptUtils::CheckTrueOrFalse
<
typename
NumberTraits<T>::IsUnsigned
>::value ));
312
BOOST_STATIC_ASSERT
((
ConceptUtils::CheckTrueOrFalse
<
typename
NumberTraits<T>::IsSigned
>::value ));
313
BOOST_STATIC_ASSERT
((
ConceptUtils::CheckTrueOrFalse
<
typename
NumberTraits<T>::IsBounded
>::value ));
314
315
// ------------------------- Internals ------------------------------------
316
private
:
317
318
};
// end of concept CInteger
319
320
}
// namespace DGtal
321
322
// //
324
325
#endif // !defined CInteger_h
326
327
#undef CInteger_RECURSES
328
#endif // else defined(CInteger_RECURSES)
Generated on Wed Dec 19 2012 19:10:20 for DGtal by
1.8.1.1