Orfeo Toolbox
3.16
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
OTB
Utilities
ITK
Code
Common
itkConceptChecking.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: itkConceptChecking.h,v $
5
Language: C++
6
Date: $Date: 2008-12-10 23:24:43 $
7
Version: $Revision: 1.34 $
8
9
Copyright (c) Insight Software Consortium. All rights reserved.
10
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12
Portions of this code are covered under the VTK copyright.
13
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15
This software is distributed WITHOUT ANY WARRANTY; without even
16
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17
PURPOSE. See the above copyright notices for more information.
18
19
=========================================================================*/
20
#ifndef __itkConceptChecking_h
21
#define __itkConceptChecking_h
22
23
#include "itkPixelTraits.h"
24
#include "itkNumericTraits.h"
25
#include <iostream>
26
28
#ifndef ITK_CONCEPT_NO_CHECKING
29
# if defined(_MSC_VER) && !defined(__ICL)
30
# define ITK_CONCEPT_IMPLEMENTATION_VTABLE
31
# elif defined(__BORLANDC__) && (__BORLANDC__ <= 0x551)
32
# define ITK_CONCEPT_IMPLEMENTATION_VTABLE
33
# elif defined(__MWERKS__) && (__MWERKS__ <= 0x3002)
34
# define ITK_CONCEPT_IMPLEMENTATION_VTABLE
35
# elif defined(__SUNPRO_CC)
36
# define ITK_CONCEPT_IMPLEMENTATION_VTABLE
37
# else
38
# define ITK_CONCEPT_IMPLEMENTATION_STANDARD
39
# endif
40
#endif
41
43
#if defined(ITK_CONCEPT_IMPLEMENTATION_STANDARD)
44
52
// Leave ()'s off the sizeof to force the caller to pass them in the
53
// concept argument of the itkConceptMacro. This is necessary because
54
// the argument may contain commas.
55
# define itkConceptConstraintsMacro() \
56
template <void (Constraints::*)()> struct Enforcer {}; \
57
typedef Enforcer<&Constraints::constraints> EnforcerInstantiation
58
# define itkConceptMacro(name, concept) enum { name = sizeof concept }
59
60
#elif defined(ITK_CONCEPT_IMPLEMENTATION_VTABLE)
61
67
# define itkConceptConstraintsMacro() \
68
virtual void Enforcer() { &Constraints::constraints; }
69
# define itkConceptMacro(name, concept) enum { name = sizeof concept }
70
71
#elif defined(ITK_CONCEPT_IMPLEMENTATION_CALL)
72
74
# define itkConceptConstraintsMacro()
75
# define itkConceptMacro(name, concept) enum { name = 0 }
76
77
#else
78
80
# define itkConceptConstraintsMacro()
81
# define itkConceptMacro(name, concept) enum { name = 0 }
82
83
#endif
84
85
namespace
itk
86
{
87
90
namespace
Concept
91
{
92
100
namespace
Detail
101
{
102
103
template
<
typename
T>
struct
UniqueType
{};
104
template
<
int
>
struct
UniqueType_int
{};
105
template
<
unsigned
int
>
struct
UniqueType_unsigned_int
{};
106
template
<
bool
>
struct
UniqueType_bool
{};
107
108
114
template
<
typename
T>
inline
void
IgnoreUnusedVariable
(T) {}
115
121
template
<
class
T>
122
void
RequireBooleanExpression
(
const
T& t)
123
{
124
bool
x = t;
125
IgnoreUnusedVariable
(x);
126
}
127
128
}
// namespace Detail
129
130
132
template
<
typename
T>
133
struct
DefaultConstructible
134
{
135
struct
Constraints
136
{
137
void
constraints
()
138
{
139
T a;
140
Detail::IgnoreUnusedVariable
(a);
141
}
142
};
143
144
itkConceptConstraintsMacro
();
145
};
146
148
template
<
typename
T>
149
struct
CopyConstructible
150
{
151
struct
Constraints
152
{
153
void
constraints
()
154
{
155
T a(
b
);
156
T* p = &a;
157
const_constraints
(a);
158
Detail::IgnoreUnusedVariable
(p);
159
}
160
void
const_constraints
(
const
T& a)
161
{
162
T c(a);
163
const
T* p = &a;
164
Detail::IgnoreUnusedVariable
(c);
165
Detail::IgnoreUnusedVariable
(p);
166
}
167
T
b
;
168
};
169
170
itkConceptConstraintsMacro
();
171
};
172
174
template
<
typename
T1,
typename
T2>
175
struct
Convertible
176
{
177
struct
Constraints
178
{
179
void
constraints
()
180
{
181
T2 b =
static_cast<
T2
>
(
a
);
182
Detail::IgnoreUnusedVariable
(b);
183
}
184
T1
a
;
185
};
186
itkConceptConstraintsMacro
();
187
};
188
190
template
<
typename
T>
191
struct
Assignable
192
{
193
struct
Constraints
194
{
195
void
constraints
()
196
{
197
a
=
a
;
198
const_constraints
(
a
);
199
}
200
void
const_constraints
(
const
T& b)
201
{
202
a
= b;
203
}
204
T
a
;
205
};
206
207
itkConceptConstraintsMacro
();
208
};
209
212
template
<
typename
T1,
typename
T2=T1>
213
struct
LessThanComparable
214
{
215
struct
Constraints
216
{
217
void
constraints
()
218
{
219
Detail::RequireBooleanExpression
(
a
<
b
);
220
Detail::RequireBooleanExpression
(
a
<=
b
);
221
}
222
T1
a
;
223
T2
b
;
224
};
225
226
itkConceptConstraintsMacro
();
227
};
228
231
template
<
typename
T1,
typename
T2=T1>
232
struct
GreaterThanComparable
233
{
234
struct
Constraints
235
{
236
void
constraints
()
237
{
238
Detail::RequireBooleanExpression
(
a
>
b
);
239
Detail::RequireBooleanExpression
(
a
>=
b
);
240
}
241
T1
a
;
242
T2
b
;
243
};
244
245
itkConceptConstraintsMacro
();
246
};
247
250
template
<
typename
T1,
typename
T2=T1>
251
struct
EqualityComparable
252
{
253
struct
Constraints
254
{
255
void
constraints
()
256
{
257
Detail::RequireBooleanExpression
(
a
==
b
);
258
Detail::RequireBooleanExpression
(
a
!=
b
);
259
}
260
T1
a
;
261
T2
b
;
262
};
263
264
itkConceptConstraintsMacro
();
265
};
266
269
template
<
typename
T1,
typename
T2=T1>
270
struct
Comparable
271
{
272
struct
Constraints
273
{
274
void
constraints
()
275
{
276
Detail::RequireBooleanExpression
(
a
<
b
);
277
Detail::RequireBooleanExpression
(
a
>
b
);
278
Detail::RequireBooleanExpression
(
a
<=
b
);
279
Detail::RequireBooleanExpression
(
a
>=
b
);
280
Detail::RequireBooleanExpression
(
a
==
b
);
281
Detail::RequireBooleanExpression
(
a
!=
b
);
282
}
283
T1
a
;
284
T2
b
;
285
};
286
287
itkConceptConstraintsMacro
();
288
};
289
292
template
<
typename
T1,
typename
T2=T1,
typename
T3=T1>
293
struct
AdditiveOperators
294
{
295
struct
Constraints
296
{
297
void
constraints
()
298
{
299
a
=
static_cast<
T3
>
(
b
+
c
);
300
a
=
static_cast<
T3
>
(
b
-
c
);
301
a
+=
static_cast<
T3
>
(
c
);
302
a
-=
static_cast<
T3
>
(
c
);
303
const_constraints
(
b
,
c
);
304
}
305
void
const_constraints
(
const
T1& d,
const
T2& e)
306
{
307
a
=
static_cast<
T3
>
(d + e);
308
a
=
static_cast<
T3
>
(d - e);
309
a
+=
static_cast<
T3
>
(e);
310
a
-=
static_cast<
T3
>
(e);
311
}
312
T3
a
;
313
T1
b
;
314
T2
c
;
315
};
316
317
itkConceptConstraintsMacro
();
318
};
319
321
template
<
typename
T1,
typename
T2=T1,
typename
T3=T1>
322
struct
MultiplyOperator
323
{
324
struct
Constraints
325
{
326
void
constraints
()
327
{
328
a
=
static_cast<
T3
>
(
b
*
c
);
329
const_constraints
(
b
,
c
);
330
}
331
void
const_constraints
(
const
T1& d,
const
T2& e)
332
{
333
a
=
static_cast<
T3
>
(d * e);
334
}
335
T3
a
;
336
T1
b
;
337
T2
c
;
338
};
339
itkConceptConstraintsMacro
();
340
};
341
343
template
<
typename
T1,
typename
T2=T1>
344
struct
MultiplyAndAssignOperator
345
{
346
struct
Constraints
347
{
348
void
constraints
()
349
{
350
a
*=
static_cast<
T2
>
(
b
);
351
const_constraints
(
b
);
352
}
353
void
const_constraints
(
const
T1& d)
354
{
355
a
*=
static_cast<
T2
>
(d);
356
}
357
T2
a
;
358
T1
b
;
359
};
360
361
itkConceptConstraintsMacro
();
362
};
363
365
template
<
typename
T1,
typename
T2=T1,
typename
T3=T1>
366
struct
DivisionOperators
367
{
368
struct
Constraints
369
{
370
void
constraints
()
371
{
372
a
=
static_cast<
T3
>
(
b
/
c
);
373
a
/=
c
;
374
const_constraints
(
b
,
c
);
375
}
376
void
const_constraints
(
const
T1& d,
const
T2& e)
377
{
378
a
=
static_cast<
T3
>
(d / e);
379
a
/= e;
380
}
381
T3
a
;
382
T1
b
;
383
T2
c
;
384
};
385
386
itkConceptConstraintsMacro
();
387
};
388
391
template
<
typename
T1,
typename
T2=T1,
typename
T3=T1>
392
struct
LogicalOperators
393
{
394
struct
Constraints
395
{
396
void
constraints
()
397
{
398
a
=
static_cast<
T3
>
(
b
&
c
);
399
a
=
static_cast<
T3
>
(
b
|
c
);
400
a
=
static_cast<
T3
>
(
b
^
c
);
401
a
&=
static_cast<
T3
>
(
c
);
402
a
|=
static_cast<
T3
>
(
c
);
403
a
^=
static_cast<
T3
>
(
c
);
404
const_constraints
(
b
,
c
);
405
}
406
void
const_constraints
(
const
T1& d,
const
T2& e)
407
{
408
a
=
static_cast<
T3
>
(d & e);
409
a
=
static_cast<
T3
>
(d | e);
410
a
=
static_cast<
T3
>
(d ^ e);
411
a
&=
static_cast<
T3
>
(e);
412
a
|=
static_cast<
T3
>
(e);
413
a
^=
static_cast<
T3
>
(e);
414
}
415
T3
a
;
416
T1
b
;
417
T2
c
;
418
};
419
420
itkConceptConstraintsMacro
();
421
};
422
424
template
<
typename
T1,
typename
T2=T1,
typename
T3=T1>
425
struct
BracketOperator
426
{
427
struct
Constraints
428
{
429
void
constraints
()
430
{
431
a
=
static_cast<
T3
>
(
b
[
c
]);
432
const_constraints
(
b
,
c
);
433
}
434
void
const_constraints
(
const
T1& d,
const
T2& e)
435
{
436
a
=
static_cast<
T3
>
(d [ e ]);
437
}
438
T3
a
;
439
T1
b
;
440
T2
c
;
441
};
442
443
itkConceptConstraintsMacro
();
444
};
445
446
448
template
<
typename
T>
449
struct
NotOperator
450
{
451
struct
Constraints
452
{
453
void
constraints
()
454
{
455
a
= !
a
;
456
}
457
T
a
;
458
};
459
460
itkConceptConstraintsMacro
();
461
};
462
464
template
<
typename
T>
465
struct
IncrementDecrementOperators
466
{
467
struct
Constraints
468
{
469
void
constraints
()
470
{
471
a
++;
472
a
--;
473
++
a
;
474
--
a
;
475
}
476
T
a
;
477
};
478
479
itkConceptConstraintsMacro
();
480
};
481
483
template
<
typename
T>
484
struct
OStreamWritable
485
{
486
struct
Constraints
487
{
488
void
constraints
()
489
{
490
std::cout <<
a
;
491
}
492
T
a
;
493
};
494
495
itkConceptConstraintsMacro
();
496
};
497
499
template
<
typename
T>
500
struct
Signed
501
{
502
typedef
Signed
Self
;
503
itkStaticConstMacro(
IsSigned
,
bool
,
NumericTraits<T>::is_signed
);
504
struct
Constraints
505
{
506
typedef
Detail::UniqueType_bool<true>
TrueT
;
507
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(IsSigned)>
SignedT
;
508
void
constraints
()
509
{
510
SignedT
a =
TrueT
();
511
Detail::IgnoreUnusedVariable
(a);
512
}
513
};
514
515
itkConceptConstraintsMacro
();
516
};
517
519
template
<
typename
T1,
typename
T2>
520
struct
SameType
521
{
522
struct
Constraints
523
{
524
void
constraints
()
525
{
526
Detail::UniqueType<T1>
a =
Detail::UniqueType<T2>
();
527
Detail::IgnoreUnusedVariable
(a);
528
}
529
};
530
itkConceptConstraintsMacro
();
531
};
532
534
template
<
unsigned
int
D1,
unsigned
int
D2>
535
struct
SameDimension
536
{
537
struct
Constraints
538
{
539
typedef
Detail::UniqueType_unsigned_int<D1>
DT1
;
540
typedef
Detail::UniqueType_unsigned_int<D2>
DT2
;
541
void
constraints
()
542
{
543
DT1
a =
DT2
();
544
Detail::IgnoreUnusedVariable
(a);
545
}
546
};
547
itkConceptConstraintsMacro
();
548
};
549
551
template
<
typename
T>
552
struct
HasNumericTraits
553
{
554
struct
Constraints
555
{
556
void
constraints
()
557
{
558
typedef
typename
NumericTraits<T>::ValueType
ValueType;
559
typedef
typename
NumericTraits<T>::PrintType
PrintType;
560
typedef
typename
NumericTraits<T>::AbsType
AbsType;
561
typedef
typename
NumericTraits<T>::AccumulateType
AccumulateType;
562
typedef
typename
NumericTraits<T>::RealType
RealType;
563
typedef
typename
NumericTraits<T>::ScalarRealType
ScalarRealType;
564
typedef
typename
NumericTraits<T>::FloatType
FloatType;
565
T a;
566
bool
b;
567
a =
NumericTraits<T>::Zero
;
568
a =
NumericTraits<T>::One
;
569
a =
NumericTraits<T>::NonpositiveMin
();
570
a =
NumericTraits<T>::ZeroValue
();
571
b =
NumericTraits<T>::IsPositive
(a);
572
b =
NumericTraits<T>::IsNonpositive
(a);
573
b =
NumericTraits<T>::IsNegative
(a);
574
b =
NumericTraits<T>::IsNonnegative
(a);
575
Detail::IgnoreUnusedVariable
(a);
576
Detail::IgnoreUnusedVariable
(b);
577
}
578
};
579
580
itkConceptConstraintsMacro
();
581
};
582
584
template
<
typename
T>
585
struct
HasPixelTraits
586
{
587
struct
Constraints
588
{
589
void
constraints
()
590
{
591
typedef
typename
PixelTraits<T>::ValueType ValueType;
592
unsigned
int
a = PixelTraits<T>::Dimension;
593
Detail::IgnoreUnusedVariable
(a);
594
}
595
};
596
597
itkConceptConstraintsMacro
();
598
};
599
601
template
<
typename
T>
602
struct
HasValueType
603
{
604
struct
Constraints
605
{
606
void
constraints
()
607
{
608
typedef
typename
T::ValueType ValueType;
609
}
610
};
611
612
itkConceptConstraintsMacro
();
613
};
614
615
617
template
<
typename
T>
618
struct
HasZero
619
{
620
struct
Constraints
621
{
622
void
constraints
()
623
{
624
T a;
625
a =
NumericTraits<T>::Zero
;
626
Detail::IgnoreUnusedVariable
(a);
627
}
628
};
629
630
itkConceptConstraintsMacro
();
631
};
632
634
template
<
typename
T1,
typename
T2>
635
struct
HasJoinTraits
636
{
637
struct
Constraints
638
{
639
void
constraints
()
640
{
641
typedef
typename
JoinTraits<T1, T2>::ValueType ValueType;
642
}
643
};
644
645
itkConceptConstraintsMacro
();
646
};
647
649
template
<
unsigned
int
D1,
unsigned
int
D2>
650
struct
SameDimensionOrMinusOne
651
{
652
struct
Constraints
653
{
654
typedef
Detail::UniqueType_unsigned_int< D1 >
Type1
;
655
typedef
Detail::UniqueType_unsigned_int
< D1-1 >
Type2
;
656
657
void
f
(
Type1
) {}
658
void
f
(
Type2
,
int
= 0 ) {}
659
660
void
constraints
()
661
{
662
Detail::UniqueType_unsigned_int< D2 >
tt;
663
this->
f
( tt );
664
}
665
};
666
itkConceptConstraintsMacro
();
667
};
668
670
template
<
typename
T>
671
struct
IsInteger
672
{
673
typedef
IsInteger
Self
;
674
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits<T>::is_integer
);
675
struct
Constraints
676
{
677
typedef
Detail::UniqueType_bool<true>
TrueT
;
678
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(Integral)>
IntegralT
;
679
void
constraints
()
680
{
681
IntegralT
a =
TrueT
();
682
Detail::IgnoreUnusedVariable
(a);
683
}
684
};
685
686
itkConceptConstraintsMacro
();
687
};
688
690
template
<
typename
T>
691
struct
IsNonInteger
692
{
693
typedef
IsNonInteger
Self
;
694
itkStaticConstMacro(
NonIntegral
,
bool
,
NumericTraits<T>::is_integer
);
695
struct
Constraints
696
{
697
typedef
Detail::UniqueType_bool<false>
FalseT
;
698
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(NonIntegral)>
NonIntegralT
;
699
void
constraints
()
700
{
701
NonIntegralT
a =
FalseT
();
702
Detail::IgnoreUnusedVariable
(a);
703
}
704
};
705
706
itkConceptConstraintsMacro
();
707
};
708
710
template
<
typename
T>
711
struct
IsFloatingPoint
712
{
713
typedef
IsFloatingPoint
Self
;
714
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits<T>::is_integer
);
715
itkStaticConstMacro(
IsExact
,
bool
,
NumericTraits<T>::is_exact
);
716
struct
Constraints
717
{
718
typedef
Detail::UniqueType_bool<false>
FalseT
;
719
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(Integral)>
IntegralT
;
720
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(IsExact)>
ExactT
;
721
void
constraints
()
722
{
723
IntegralT
a =
FalseT
();
724
ExactT
b =
FalseT
();
725
Detail::IgnoreUnusedVariable
(a);
726
Detail::IgnoreUnusedVariable
(b);
727
}
728
};
729
730
itkConceptConstraintsMacro
();
731
};
732
734
template
<
typename
T>
735
struct
IsFixedPoint
736
{
737
typedef
IsFixedPoint
Self
;
738
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits<T>::is_integer
);
739
itkStaticConstMacro(
IsExact
,
bool
,
NumericTraits<T>::is_exact
);
740
struct
Constraints
741
{
742
typedef
Detail::UniqueType_bool<true>
TrueT
;
743
typedef
Detail::UniqueType_bool<false>
FalseT
;
744
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(Integral)>
IntegralT
;
745
typedef
Detail::UniqueType_bool<itkGetStaticConstMacro(IsExact)>
ExactT
;
746
void
constraints
()
747
{
748
IntegralT
a =
FalseT
();
749
ExactT
b =
TrueT
();
750
Detail::IgnoreUnusedVariable
(a);
751
Detail::IgnoreUnusedVariable
(b);
752
}
753
};
754
755
itkConceptConstraintsMacro
();
756
};
757
758
}
// end namespace Concept
759
760
}
// end namespace itk
761
762
#endif
Generated at Sat May 18 2013 23:34:08 for
Orfeo Toolbox
with
doxygen 1.8.3.1