ITK  4.2.0
Insight Segmentation and Registration Toolkit
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 >
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 
135 }
136 } // namespace Detail
137 
139 template< typename T >
141  struct Constraints {
142  void constraints()
143  {
144  T a;
145 
147  }
148  };
149 
151 };
152 
154 template< typename T >
156  struct Constraints {
157  void constraints()
158  {
159  T a(b);
160  T *p = &a;
162 
165  }
166 
167  void const_constraints(const T & a)
168  {
169  T c(a);
170  const T *p = &a;
171 
174  }
175 
176  T b;
177  };
178 
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 
191  }
192 
193  T1 a;
194  };
196 };
197 
199 template< typename T >
200 struct Assignable {
201  struct Constraints {
202  void constraints()
203  {
204  a = a;
206  }
208 
209  void const_constraints(const T & b)
210  {
211  a = b;
212  }
213 
214  T a;
215  };
216 
218 };
219 
222 template< typename T1, typename T2 = T1 >
224  struct Constraints {
225  void constraints()
226  {
229  }
231 
232  T1 a;
233  T2 b;
234  };
235 
237 };
238 
241 template< typename T1, typename T2 = T1 >
243  struct Constraints {
244  void constraints()
245  {
248  }
250 
251  T1 a;
252  T2 b;
253  };
254 
256 };
257 
260 template< typename T1, typename T2 = T1 >
262  struct Constraints {
263  void constraints()
264  {
267  }
269 
270  T1 a;
271  T2 b;
272  };
273 
275 };
276 
279 template< typename T1, typename T2 = T1 >
280 struct Comparable {
281  struct Constraints {
282  void constraints()
283  {
290  }
292 
293  T1 a;
294  T2 b;
295  };
296 
298 };
299 
302 template< typename T1, typename T2 = T1, typename T3 = T1 >
304  struct Constraints {
305  void constraints()
306  {
307  a = static_cast< T3 >( b + c );
308  a = static_cast< T3 >( 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 
325 };
326 
327 
330 template< typename T1, typename T2 = T1>
332  struct Constraints {
333  void constraints()
334  {
335  a += c;
336  a -= 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 
352 };
353 
355 template< typename T1, typename T2 = T1, typename T3 = T1 >
357  struct Constraints {
358  void constraints()
359  {
360  a = static_cast< T3 >( 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  };
375 };
376 
378 template< typename T1, typename T2 = T1 >
380  struct Constraints {
381  void constraints()
382  {
383  a *= b;
385  }
387 
388  void const_constraints(const T1 & d)
389  {
390  a *= d;
391  }
392 
393  T2 a;
394  T1 b;
395  };
396 
398 };
399 
401 template< typename T1, typename T2 = T1, typename T3 = T1 >
403  struct Constraints {
404  void constraints()
405  {
406  a = static_cast< T3 >( 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 
422 };
423 
424 
426 template< typename T1, typename T2 = T1 >
428  struct Constraints {
429  void constraints()
430  {
431  a /= c;
433  }
435 
436  void const_constraints(const T1 & d)
437  {
438  a /= d;
439  }
440 
441  T1 c;
442  T2 a;
443  };
444 
446 };
447 
448 
451 template< typename T1, typename T2 = T1, typename T3 = T1 >
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 );
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 
482 };
483 
485 template< typename T1, typename T2 = T1, typename T3 = T1 >
487  struct Constraints {
488  void constraints()
489  {
490  a = static_cast< T3 >( 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 
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 
521 };
522 
524 template< typename T >
526  struct Constraints {
527  void constraints()
528  {
529  a++;
530  a--;
531  ++a;
532  --a;
533  }
534 
535  T a;
536  };
537 
539 };
540 
542 template< typename T >
544  struct Constraints {
545  void constraints()
546  {
547  std::cout << a;
548  }
549 
550  T a;
551  };
552 
554 };
555 
557 template< typename T >
558 struct Signed {
559  typedef Signed Self;
560  itkStaticConstMacro(IsSigned, bool, NumericTraits< T >::is_signed);
561  struct Constraints {
564  void constraints()
565  {
566  SignedT a = TrueT();
568 
570  }
571  };
572 
574 };
575 
577 template< typename T1, typename T2 >
578 struct SameType {
579  struct Constraints {
580  void constraints()
581  {
584  }
585  };
587 };
589 
591 template< unsigned int D1, unsigned int D2 >
593  struct Constraints {
596  void constraints()
597  {
598  DT1 a = DT2();
600 
602  }
603  };
605 };
606 
608 template< typename T >
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;
632  }
633  };
635 
637 };
638 
640 template< typename T >
642  struct Constraints {
643  void constraints()
644  {
645  typedef typename PixelTraits< T >::ValueType ValueType;
646  unsigned int a = PixelTraits< T >::Dimension;
648  }
649  };
651 
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 
666 };
667 
669 template< typename T >
670 struct HasZero {
671  struct Constraints {
672  void constraints()
673  {
674  T a;
675 
678  }
679  };
680 
682 };
683 
685 template< typename T1, typename T2 >
687  struct Constraints {
688  void constraints()
689  {
690  typedef typename JoinTraits< T1, T2 >::ValueType ValueType;
691  }
692  };
693 
695 };
696 
698 template< unsigned int D1, unsigned int D2 >
700  struct Constraints {
703 
704  void f(Type1) {}
705  void f(Type2, int = 0) {}
706 
707  void constraints()
708  {
710  this->f(tt);
711  }
712  };
714 };
715 
717 template< unsigned int D1, unsigned int D2 >
719  struct Constraints {
723 
724  void f(Type1) {}
725  void f(Type2, int = 0) {}
726  void f(Type3, int = 0, int = 0) {}
727 
728  void constraints()
729  {
731  this->f(tt);
732  }
733  };
735 };
736 
738 template< typename T >
739 struct IsInteger {
740  typedef IsInteger Self;
741  itkStaticConstMacro(Integral, bool, NumericTraits< T >::is_integer);
742  struct Constraints {
745  void constraints()
746  {
747  IntegralT a = TrueT();
749 
751  }
752  };
753 
755 };
756 
758 template< typename T >
759 struct IsNonInteger {
761  itkStaticConstMacro(NonIntegral, bool, NumericTraits< T >::is_integer);
762  struct Constraints {
765  void constraints()
766  {
767  NonIntegralT a = FalseT();
769 
771  }
772  };
773 
775 };
776 
778 template< typename T >
781  itkStaticConstMacro(Integral, bool, NumericTraits< T >::is_integer);
782  itkStaticConstMacro(IsExact, bool, NumericTraits< T >::is_exact);
783  struct Constraints {
787  void constraints()
788  {
789  IntegralT a = FalseT();
790  ExactT b = FalseT();
792 
795  }
796  };
797 
799 };
800 
802 template< typename T >
803 struct IsFixedPoint {
805  itkStaticConstMacro(Integral, bool, NumericTraits< T >::is_integer);
806  itkStaticConstMacro(IsExact, bool, NumericTraits< T >::is_exact);
807  struct Constraints {
812  void constraints()
813  {
814  IntegralT a = FalseT();
815  ExactT b = TrueT();
817 
820  }
821  };
822 
824 };
825 } // end namespace Concept
826 } // end namespace itk
827 
828 #endif
829