ITK
4.4.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Core
Common
include
itkConceptChecking.h
Go to the documentation of this file.
1
/*=========================================================================
2
*
3
* Copyright Insight Software Consortium
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*=========================================================================*/
18
/*=========================================================================
19
*
20
* Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21
*
22
* Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23
*
24
* For complete copyright, license and disclaimer of warranty information
25
* please refer to the NOTICE file at the top of the ITK source tree.
26
*
27
*=========================================================================*/
28
#ifndef __itkConceptChecking_h
29
#define __itkConceptChecking_h
30
31
#include "
itkPixelTraits.h
"
32
#include "
itkNumericTraits.h
"
33
#include <iostream>
34
36
#ifndef ITK_CONCEPT_NO_CHECKING
37
#if defined( _MSC_VER ) && !defined( __ICL )
38
#define ITK_CONCEPT_IMPLEMENTATION_VTABLE
39
//TST_RMV_20100730 #elif defined(__SUNPRO_CC)
40
//TST_RMV_20100730 #define ITK_CONCEPT_IMPLEMENTATION_VTABLE
41
#else
42
#define ITK_CONCEPT_IMPLEMENTATION_STANDARD
43
#endif
44
#endif
45
47
#if defined( ITK_CONCEPT_IMPLEMENTATION_STANDARD )
48
56
// Leave ()'s off the sizeof to force the caller to pass them in the
57
// concept argument of the itkConceptMacro. This is necessary because
58
// the argument may contain commas.
59
#define itkConceptConstraintsMacro() \
60
template< void (Constraints::*) ( ) > \
61
struct Enforcer {}; \
62
typedef Enforcer< & Constraints::constraints > EnforcerInstantiation
63
#define itkConceptMacro(name, concept) enum { name = sizeof concept }
64
65
#elif defined( ITK_CONCEPT_IMPLEMENTATION_VTABLE )
66
72
#define itkConceptConstraintsMacro() \
73
virtual void Enforcer() { &Constraints::constraints; }
74
#define itkConceptMacro(name, concept) enum { name = sizeof concept }
75
76
77
#elif defined( ITK_CONCEPT_IMPLEMENTATION_CALL )
78
80
#define itkConceptConstraintsMacro()
81
#define itkConceptMacro(name, concept) enum { name = 0 }
82
83
#else
84
86
#define itkConceptConstraintsMacro()
87
#define itkConceptMacro(name, concept) enum { name = 0 }
88
89
#endif
90
91
namespace
itk
92
{
95
namespace
Concept
96
{
97
105
namespace
Detail
106
{
107
template
<
typename
T >
108
struct
UniqueType
{};
109
template
<
int
>
110
struct
UniqueType_int
{};
111
template
<
unsigned
int
>
112
struct
UniqueType_unsigned_int
{};
113
template
<
bool
>
114
struct
UniqueType_bool
{};
115
121
template
<
typename
T >
122
inline
void
IgnoreUnusedVariable
(T) {}
123
129
template
<
class
T >
130
void
RequireBooleanExpression
(
const
T & t)
131
{
132
bool
x = t;
133
134
IgnoreUnusedVariable
(x);
135
}
136
}
// namespace Detail
137
139
template
<
typename
T >
140
struct
DefaultConstructible
{
141
struct
Constraints
{
142
void
constraints
()
143
{
144
T a;
145
146
Detail::IgnoreUnusedVariable
(a);
147
}
148
};
149
150
itkConceptConstraintsMacro
();
151
};
152
154
template
<
typename
T >
155
struct
CopyConstructible
{
156
struct
Constraints
{
157
void
constraints
()
158
{
159
T a(
b
);
160
T *p = &a;
162
163
const_constraints
(a);
164
Detail::IgnoreUnusedVariable
(p);
165
}
166
167
void
const_constraints
(
const
T & a)
168
{
169
T c(a);
170
const
T *p = &a;
171
172
Detail::IgnoreUnusedVariable
(c);
173
Detail::IgnoreUnusedVariable
(p);
174
}
175
176
T
b
;
177
};
178
179
itkConceptConstraintsMacro
();
180
};
181
183
template
<
typename
T1,
typename
T2 >
184
struct
Convertible
{
185
struct
Constraints
{
186
void
constraints
()
187
{
188
T2 b =
static_cast<
T2
>
(
a
);
189
190
Detail::IgnoreUnusedVariable
(b);
191
}
192
193
T1
a
;
194
};
195
itkConceptConstraintsMacro
();
196
};
197
199
template
<
typename
T >
200
struct
Assignable
{
201
struct
Constraints
{
202
void
constraints
()
203
{
204
a
=
a
;
205
const_constraints
(
a
);
206
}
208
209
void
const_constraints
(
const
T & b)
210
{
211
a
= b;
212
}
213
214
T
a
;
215
};
216
217
itkConceptConstraintsMacro
();
218
};
219
222
template
<
typename
T1,
typename
T2 = T1 >
223
struct
LessThanComparable
{
224
struct
Constraints
{
225
void
constraints
()
226
{
227
Detail::RequireBooleanExpression
(
a
<
b
);
228
Detail::RequireBooleanExpression
(
a
<=
b
);
229
}
231
232
T1
a
;
233
T2
b
;
234
};
235
236
itkConceptConstraintsMacro
();
237
};
238
241
template
<
typename
T1,
typename
T2 = T1 >
242
struct
GreaterThanComparable
{
243
struct
Constraints
{
244
void
constraints
()
245
{
246
Detail::RequireBooleanExpression
(
a
>
b
);
247
Detail::RequireBooleanExpression
(
a
>=
b
);
248
}
250
251
T1
a
;
252
T2
b
;
253
};
254
255
itkConceptConstraintsMacro
();
256
};
257
260
template
<
typename
T1,
typename
T2 = T1 >
261
struct
EqualityComparable
{
262
struct
Constraints
{
263
void
constraints
()
264
{
265
Detail::RequireBooleanExpression
(
a
==
b
);
266
Detail::RequireBooleanExpression
(
a
!=
b
);
267
}
269
270
T1
a
;
271
T2
b
;
272
};
273
274
itkConceptConstraintsMacro
();
275
};
276
279
template
<
typename
T1,
typename
T2 = T1 >
280
struct
Comparable
{
281
struct
Constraints
{
282
void
constraints
()
283
{
284
Detail::RequireBooleanExpression
(
a
<
b
);
285
Detail::RequireBooleanExpression
(
a
>
b
);
286
Detail::RequireBooleanExpression
(
a
<=
b
);
287
Detail::RequireBooleanExpression
(
a
>=
b
);
288
Detail::RequireBooleanExpression
(
a
==
b
);
289
Detail::RequireBooleanExpression
(
a
!=
b
);
290
}
292
293
T1
a
;
294
T2
b
;
295
};
296
297
itkConceptConstraintsMacro
();
298
};
299
302
template
<
typename
T1,
typename
T2 = T1,
typename
T3 = T1 >
303
struct
AdditiveOperators
{
304
struct
Constraints
{
305
void
constraints
()
306
{
307
a
=
static_cast<
T3
>
(
b
+
c
);
308
a
=
static_cast<
T3
>
(
b
-
c
);
309
const_constraints
(
b
,
c
);
310
}
312
313
void
const_constraints
(
const
T1 & d,
const
T2 &
e
)
314
{
315
a
=
static_cast<
T3
>
( d +
e
);
316
a
=
static_cast<
T3
>
( d -
e
);
317
}
318
319
T3
a
;
320
T1
b
;
321
T2
c
;
322
};
323
324
itkConceptConstraintsMacro
();
325
};
326
327
330
template
<
typename
T1,
typename
T2 = T1>
331
struct
AdditiveAndAssignOperators
{
332
struct
Constraints
{
333
void
constraints
()
334
{
335
a
+=
c
;
336
a
-=
c
;
337
const_constraints
(
c
);
338
}
340
341
void
const_constraints
(
const
T1 & d)
342
{
343
a
+= d;
344
a
-= d;
345
}
346
347
T2
a
;
348
T1
c
;
349
};
350
351
itkConceptConstraintsMacro
();
352
};
353
355
template
<
typename
T1,
typename
T2 = T1,
typename
T3 = T1 >
356
struct
MultiplyOperator
{
357
struct
Constraints
{
358
void
constraints
()
359
{
360
a
=
static_cast<
T3
>
(
b
*
c
);
361
const_constraints
(
b
,
c
);
362
}
364
365
void
const_constraints
(
const
T1 & d,
const
T2 &
e
)
366
{
367
a
=
static_cast<
T3
>
( d *
e
);
368
}
369
370
T3
a
;
371
T1
b
;
372
T2
c
;
373
};
374
itkConceptConstraintsMacro
();
375
};
376
378
template
<
typename
T1,
typename
T2 = T1 >
379
struct
MultiplyAndAssignOperator
{
380
struct
Constraints
{
381
void
constraints
()
382
{
383
a
*=
b
;
384
const_constraints
(
b
);
385
}
387
388
void
const_constraints
(
const
T1 & d)
389
{
390
a
*= d;
391
}
392
393
T2
a
;
394
T1
b
;
395
};
396
397
itkConceptConstraintsMacro
();
398
};
399
401
template
<
typename
T1,
typename
T2 = T1,
typename
T3 = T1 >
402
struct
DivisionOperators
{
403
struct
Constraints
{
404
void
constraints
()
405
{
406
a
=
static_cast<
T3
>
(
b
/
c
);
407
const_constraints
(
b
,
c
);
408
}
410
411
void
const_constraints
(
const
T1 & d,
const
T2 &
e
)
412
{
413
a
=
static_cast<
T3
>
( d /
e
);
414
}
415
416
T3
a
;
417
T1
b
;
418
T2
c
;
419
};
420
421
itkConceptConstraintsMacro
();
422
};
423
424
426
template
<
typename
T1,
typename
T2 = T1 >
427
struct
DivisionAndAssignOperators
{
428
struct
Constraints
{
429
void
constraints
()
430
{
431
a
/=
c
;
432
const_constraints
(
c
);
433
}
435
436
void
const_constraints
(
const
T1 & d)
437
{
438
a
/= d;
439
}
440
441
T1
c
;
442
T2
a
;
443
};
444
445
itkConceptConstraintsMacro
();
446
};
447
448
451
template
<
typename
T1,
typename
T2 = T1,
typename
T3 = T1 >
452
struct
BitwiseOperators
{
453
struct
Constraints
{
454
void
constraints
()
455
{
456
a
=
static_cast<
T3
>
(
b
&
c
);
457
a
=
static_cast<
T3
>
(
b
|
c
);
458
a
=
static_cast<
T3
>
(
b
^
c
);
459
a
&=
static_cast<
T3
>
(
c
);
460
a
|=
static_cast<
T3
>
(
c
);
461
a
^=
static_cast<
T3
>
(
c
);
462
const_constraints
(
b
,
c
);
463
}
465
466
void
const_constraints
(
const
T1 & d,
const
T2 &
e
)
467
{
468
a
=
static_cast<
T3
>
( d &
e
);
469
a
=
static_cast<
T3
>
( d |
e
);
470
a
=
static_cast<
T3
>
( d ^
e
);
471
a
&=
static_cast<
T3
>
(
e
);
472
a
|=
static_cast<
T3
>
(
e
);
473
a
^=
static_cast<
T3
>
(
e
);
474
}
475
476
T3
a
;
477
T1
b
;
478
T2
c
;
479
};
480
481
itkConceptConstraintsMacro
();
482
};
483
485
template
<
typename
T1,
typename
T2 = T1,
typename
T3 = T1 >
486
struct
BracketOperator
{
487
struct
Constraints
{
488
void
constraints
()
489
{
490
a
=
static_cast<
T3
>
(
b
[
c
] );
491
const_constraints
(
b
,
c
);
492
}
494
495
void
const_constraints
(
const
T1 & d,
const
T2 &
e
)
496
{
497
a
=
static_cast<
T3
>
( d[
e
] );
498
}
499
500
T3
a
;
501
T1
b
;
502
T2
c
;
503
};
504
505
itkConceptConstraintsMacro
();
506
};
507
509
template
<
typename
T >
510
struct
NotOperator
{
511
struct
Constraints
{
512
void
constraints
()
513
{
514
a
= !
a
;
515
}
516
517
T
a
;
518
};
519
520
itkConceptConstraintsMacro
();
521
};
522
524
template
<
typename
T >
525
struct
IncrementDecrementOperators
{
526
struct
Constraints
{
527
void
constraints
()
528
{
529
a
++;
530
a
--;
531
++
a
;
532
--
a
;
533
}
534
535
T
a
;
536
};
537
538
itkConceptConstraintsMacro
();
539
};
540
542
template
<
typename
T >
543
struct
OStreamWritable
{
544
struct
Constraints
{
545
void
constraints
()
546
{
547
std::cout <<
a
;
548
}
549
550
T
a
;
551
};
552
553
itkConceptConstraintsMacro
();
554
};
555
557
template
<
typename
T >
558
struct
Signed
{
559
typedef
Signed
Self
;
560
itkStaticConstMacro(
IsSigned
,
bool
,
NumericTraits< T >::is_signed
);
561
struct
Constraints
{
562
typedef
Detail::UniqueType_bool< true >
TrueT
;
563
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(IsSigned) >
SignedT
;
564
void
constraints
()
565
{
566
SignedT
a =
TrueT
();
568
569
Detail::IgnoreUnusedVariable
(a);
570
}
571
};
572
573
itkConceptConstraintsMacro
();
574
};
575
577
template
<
typename
T1,
typename
T2 >
578
struct
SameType
{
579
struct
Constraints
{
580
void
constraints
()
581
{
582
Detail::UniqueType< T1 >
a =
Detail::UniqueType< T2 >
();
583
Detail::IgnoreUnusedVariable
(a);
584
}
585
};
586
itkConceptConstraintsMacro
();
587
};
589
591
template
<
unsigned
int
D1,
unsigned
int
D2 >
592
struct
SameDimension
{
593
struct
Constraints
{
594
typedef
Detail::UniqueType_unsigned_int< D1 >
DT1
;
595
typedef
Detail::UniqueType_unsigned_int< D2 >
DT2
;
596
void
constraints
()
597
{
598
DT1
a =
DT2
();
600
601
Detail::IgnoreUnusedVariable
(a);
602
}
603
};
604
itkConceptConstraintsMacro
();
605
};
606
608
template
<
typename
T >
609
struct
HasNumericTraits
{
610
struct
Constraints
{
611
void
constraints
()
612
{
613
typedef
typename
NumericTraits< T >::ValueType
ValueType;
614
typedef
typename
NumericTraits< T >::PrintType
PrintType;
615
typedef
typename
NumericTraits< T >::AbsType
AbsType;
616
typedef
typename
NumericTraits< T >::AccumulateType
AccumulateType;
617
typedef
typename
NumericTraits< T >::RealType
RealType;
618
typedef
typename
NumericTraits< T >::ScalarRealType
ScalarRealType;
619
typedef
typename
NumericTraits< T >::FloatType
FloatType;
620
T a;
621
bool
b;
622
623
// Test these methods that take an instance of T to
624
// allow for types with variable length.
625
a =
NumericTraits< T >::NonpositiveMin
( a );
626
a =
NumericTraits< T >::ZeroValue
( a );
627
a =
NumericTraits< T >::OneValue
( a );
628
629
b =
NumericTraits< T >::IsPositive
(a);
630
b =
NumericTraits< T >::IsNonpositive
(a);
631
b =
NumericTraits< T >::IsNegative
(a);
632
b =
NumericTraits< T >::IsNonnegative
(a);
633
Detail::IgnoreUnusedVariable
(a);
634
Detail::IgnoreUnusedVariable
(b);
635
}
636
};
637
638
itkConceptConstraintsMacro
();
639
};
640
642
template
<
typename
T >
643
struct
HasPixelTraits
{
644
struct
Constraints
{
645
void
constraints
()
646
{
647
typedef
typename
PixelTraits< T >::ValueType
ValueType;
648
unsigned
int
a =
PixelTraits< T >::Dimension
;
649
Detail::IgnoreUnusedVariable
(a);
650
}
651
};
653
654
itkConceptConstraintsMacro
();
655
};
656
658
template
<
typename
T >
659
struct
HasValueType
{
660
struct
Constraints
{
661
void
constraints
()
662
{
663
typedef
typename
T::ValueType ValueType;
664
}
665
};
666
667
itkConceptConstraintsMacro
();
668
};
669
671
template
<
typename
T >
672
struct
HasZero
{
673
struct
Constraints
{
674
void
constraints
()
675
{
676
T a;
677
678
a =
NumericTraits< T >::Zero
;
679
Detail::IgnoreUnusedVariable
(a);
680
}
681
};
682
683
itkConceptConstraintsMacro
();
684
};
685
687
template
<
typename
T1,
typename
T2 >
688
struct
HasJoinTraits
{
689
struct
Constraints
{
690
void
constraints
()
691
{
692
typedef
typename
JoinTraits< T1, T2 >::ValueType
ValueType;
693
}
694
};
695
696
itkConceptConstraintsMacro
();
697
};
698
700
template
<
unsigned
int
D1,
unsigned
int
D2 >
701
struct
SameDimensionOrMinusOne
{
702
struct
Constraints
{
703
typedef
Detail::UniqueType_unsigned_int< D1 >
Type1
;
704
typedef
Detail::UniqueType_unsigned_int
< D1 - 1 >
Type2
;
705
706
void
f
(
Type1
) {}
707
void
f
(
Type2
,
int
= 0) {}
708
709
void
constraints
()
710
{
711
Detail::UniqueType_unsigned_int< D2 >
tt;
712
this->
f
(tt);
713
}
714
};
715
itkConceptConstraintsMacro
();
716
};
717
719
template
<
unsigned
int
D1,
unsigned
int
D2 >
720
struct
SameDimensionOrMinusOneOrTwo
{
721
struct
Constraints
{
722
typedef
Detail::UniqueType_unsigned_int< D1 >
Type1
;
723
typedef
Detail::UniqueType_unsigned_int
< D1 - 1 >
Type2
;
724
typedef
Detail::UniqueType_unsigned_int
< D1 - 2 >
Type3
;
725
726
void
f
(
Type1
) {}
727
void
f
(
Type2
,
int
= 0) {}
728
void
f
(
Type3
,
int
= 0,
int
= 0) {}
729
730
void
constraints
()
731
{
732
Detail::UniqueType_unsigned_int< D2 >
tt;
733
this->
f
(tt);
734
}
735
};
736
itkConceptConstraintsMacro
();
737
};
738
740
template
<
typename
T >
741
struct
IsInteger
{
742
typedef
IsInteger
Self
;
743
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits< T >::is_integer
);
744
struct
Constraints
{
745
typedef
Detail::UniqueType_bool< true >
TrueT
;
746
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(Integral) >
IntegralT
;
747
void
constraints
()
748
{
749
IntegralT
a =
TrueT
();
751
752
Detail::IgnoreUnusedVariable
(a);
753
}
754
};
755
756
itkConceptConstraintsMacro
();
757
};
758
760
template
<
typename
T >
761
struct
IsNonInteger
{
762
typedef
IsNonInteger
Self
;
763
itkStaticConstMacro(
NonIntegral
,
bool
,
NumericTraits< T >::is_integer
);
764
struct
Constraints
{
765
typedef
Detail::UniqueType_bool< false >
FalseT
;
766
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(NonIntegral) >
NonIntegralT
;
767
void
constraints
()
768
{
769
NonIntegralT
a =
FalseT
();
771
772
Detail::IgnoreUnusedVariable
(a);
773
}
774
};
775
776
itkConceptConstraintsMacro
();
777
};
778
780
template
<
typename
T >
781
struct
IsFloatingPoint
{
782
typedef
IsFloatingPoint
Self
;
783
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits< T >::is_integer
);
784
itkStaticConstMacro(
IsExact
,
bool
,
NumericTraits< T >::is_exact
);
785
struct
Constraints
{
786
typedef
Detail::UniqueType_bool< false >
FalseT
;
787
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(Integral) >
IntegralT
;
788
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(IsExact) >
ExactT
;
789
void
constraints
()
790
{
791
IntegralT
a =
FalseT
();
792
ExactT
b =
FalseT
();
794
795
Detail::IgnoreUnusedVariable
(a);
796
Detail::IgnoreUnusedVariable
(b);
797
}
798
};
799
800
itkConceptConstraintsMacro
();
801
};
802
804
template
<
typename
T >
805
struct
IsFixedPoint
{
806
typedef
IsFixedPoint
Self
;
807
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits< T >::is_integer
);
808
itkStaticConstMacro(
IsExact
,
bool
,
NumericTraits< T >::is_exact
);
809
struct
Constraints
{
810
typedef
Detail::UniqueType_bool< true >
TrueT
;
811
typedef
Detail::UniqueType_bool< false >
FalseT
;
812
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(Integral) >
IntegralT
;
813
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(IsExact) >
ExactT
;
814
void
constraints
()
815
{
816
IntegralT
a =
FalseT
();
817
ExactT
b =
TrueT
();
819
820
Detail::IgnoreUnusedVariable
(a);
821
Detail::IgnoreUnusedVariable
(b);
822
}
823
};
824
825
itkConceptConstraintsMacro
();
826
};
827
}
// end namespace Concept
828
}
// end namespace itk
829
830
#endif
831
Generated on Mon May 13 2013 00:46:34 for ITK by
1.8.3.1