ITK
4.2.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
LogicalOperators
{
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
a =
NumericTraits< T >::Zero
;
623
a =
NumericTraits< T >::One
;
624
a =
NumericTraits< T >::NonpositiveMin
();
625
a =
NumericTraits< T >::ZeroValue
();
626
b =
NumericTraits< T >::IsPositive
(a);
627
b =
NumericTraits< T >::IsNonpositive
(a);
628
b =
NumericTraits< T >::IsNegative
(a);
629
b =
NumericTraits< T >::IsNonnegative
(a);
630
Detail::IgnoreUnusedVariable
(a);
631
Detail::IgnoreUnusedVariable
(b);
632
}
633
};
635
636
itkConceptConstraintsMacro
();
637
};
638
640
template
<
typename
T >
641
struct
HasPixelTraits
{
642
struct
Constraints
{
643
void
constraints
()
644
{
645
typedef
typename
PixelTraits< T >::ValueType
ValueType;
646
unsigned
int
a =
PixelTraits< T >::Dimension
;
647
Detail::IgnoreUnusedVariable
(a);
648
}
649
};
651
652
itkConceptConstraintsMacro
();
653
};
654
656
template
<
typename
T >
657
struct
HasValueType
{
658
struct
Constraints
{
659
void
constraints
()
660
{
661
typedef
typename
T::ValueType ValueType;
662
}
663
};
664
665
itkConceptConstraintsMacro
();
666
};
667
669
template
<
typename
T >
670
struct
HasZero
{
671
struct
Constraints
{
672
void
constraints
()
673
{
674
T a;
675
676
a =
NumericTraits< T >::Zero
;
677
Detail::IgnoreUnusedVariable
(a);
678
}
679
};
680
681
itkConceptConstraintsMacro
();
682
};
683
685
template
<
typename
T1,
typename
T2 >
686
struct
HasJoinTraits
{
687
struct
Constraints
{
688
void
constraints
()
689
{
690
typedef
typename
JoinTraits< T1, T2 >::ValueType
ValueType;
691
}
692
};
693
694
itkConceptConstraintsMacro
();
695
};
696
698
template
<
unsigned
int
D1,
unsigned
int
D2 >
699
struct
SameDimensionOrMinusOne
{
700
struct
Constraints
{
701
typedef
Detail::UniqueType_unsigned_int< D1 >
Type1
;
702
typedef
Detail::UniqueType_unsigned_int
< D1 - 1 >
Type2
;
703
704
void
f
(
Type1
) {}
705
void
f
(
Type2
,
int
= 0) {}
706
707
void
constraints
()
708
{
709
Detail::UniqueType_unsigned_int< D2 >
tt;
710
this->
f
(tt);
711
}
712
};
713
itkConceptConstraintsMacro
();
714
};
715
717
template
<
unsigned
int
D1,
unsigned
int
D2 >
718
struct
SameDimensionOrMinusOneOrTwo
{
719
struct
Constraints
{
720
typedef
Detail::UniqueType_unsigned_int< D1 >
Type1
;
721
typedef
Detail::UniqueType_unsigned_int
< D1 - 1 >
Type2
;
722
typedef
Detail::UniqueType_unsigned_int
< D1 - 2 >
Type3
;
723
724
void
f
(
Type1
) {}
725
void
f
(
Type2
,
int
= 0) {}
726
void
f
(
Type3
,
int
= 0,
int
= 0) {}
727
728
void
constraints
()
729
{
730
Detail::UniqueType_unsigned_int< D2 >
tt;
731
this->
f
(tt);
732
}
733
};
734
itkConceptConstraintsMacro
();
735
};
736
738
template
<
typename
T >
739
struct
IsInteger
{
740
typedef
IsInteger
Self
;
741
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits< T >::is_integer
);
742
struct
Constraints
{
743
typedef
Detail::UniqueType_bool< true >
TrueT
;
744
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(Integral) >
IntegralT
;
745
void
constraints
()
746
{
747
IntegralT
a =
TrueT
();
749
750
Detail::IgnoreUnusedVariable
(a);
751
}
752
};
753
754
itkConceptConstraintsMacro
();
755
};
756
758
template
<
typename
T >
759
struct
IsNonInteger
{
760
typedef
IsNonInteger
Self
;
761
itkStaticConstMacro(
NonIntegral
,
bool
,
NumericTraits< T >::is_integer
);
762
struct
Constraints
{
763
typedef
Detail::UniqueType_bool< false >
FalseT
;
764
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(NonIntegral) >
NonIntegralT
;
765
void
constraints
()
766
{
767
NonIntegralT
a =
FalseT
();
769
770
Detail::IgnoreUnusedVariable
(a);
771
}
772
};
773
774
itkConceptConstraintsMacro
();
775
};
776
778
template
<
typename
T >
779
struct
IsFloatingPoint
{
780
typedef
IsFloatingPoint
Self
;
781
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits< T >::is_integer
);
782
itkStaticConstMacro(
IsExact
,
bool
,
NumericTraits< T >::is_exact
);
783
struct
Constraints
{
784
typedef
Detail::UniqueType_bool< false >
FalseT
;
785
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(Integral) >
IntegralT
;
786
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(IsExact) >
ExactT
;
787
void
constraints
()
788
{
789
IntegralT
a =
FalseT
();
790
ExactT
b =
FalseT
();
792
793
Detail::IgnoreUnusedVariable
(a);
794
Detail::IgnoreUnusedVariable
(b);
795
}
796
};
797
798
itkConceptConstraintsMacro
();
799
};
800
802
template
<
typename
T >
803
struct
IsFixedPoint
{
804
typedef
IsFixedPoint
Self
;
805
itkStaticConstMacro(
Integral
,
bool
,
NumericTraits< T >::is_integer
);
806
itkStaticConstMacro(
IsExact
,
bool
,
NumericTraits< T >::is_exact
);
807
struct
Constraints
{
808
typedef
Detail::UniqueType_bool< true >
TrueT
;
809
typedef
Detail::UniqueType_bool< false >
FalseT
;
810
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(Integral) >
IntegralT
;
811
typedef
Detail::UniqueType_bool< itkGetStaticConstMacro(IsExact) >
ExactT
;
812
void
constraints
()
813
{
814
IntegralT
a =
FalseT
();
815
ExactT
b =
TrueT
();
817
818
Detail::IgnoreUnusedVariable
(a);
819
Detail::IgnoreUnusedVariable
(b);
820
}
821
};
822
823
itkConceptConstraintsMacro
();
824
};
825
}
// end namespace Concept
826
}
// end namespace itk
827
828
#endif
829
Generated on Tue Jul 10 2012 23:21:54 for ITK by
1.8.1