Orfeo Toolbox  4.0
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 #elif defined( ITK_CONCEPT_IMPLEMENTATION_CALL )
77 
79 #define itkConceptConstraintsMacro()
80 #define itkConceptMacro(name, concept) enum { name = 0 }
81 
82 #else
83 
85 #define itkConceptConstraintsMacro()
86 #define itkConceptMacro(name, concept) enum { name = 0 }
87 
88 #endif
89 
90 namespace itk
91 {
94 namespace Concept
95 {
103 namespace Detail
104 {
105 template< typename T >
106 struct UniqueType {};
107 template< int >
108 struct UniqueType_int {};
109 template< unsigned int >
111 template< bool >
112 struct UniqueType_bool {};
113 
119 template< typename T >
120 inline void IgnoreUnusedVariable(T) {}
121 
127 template< typename T >
128 void RequireBooleanExpression(const T & t)
129 {
130  bool x = t;
131 
133 }
134 } // namespace Detail
135 
137 template< typename T >
139  struct Constraints {
140  void constraints()
141  {
142  T a;
143 
145  }
146  };
147 
149 };
150 
152 template< typename T >
154  struct Constraints {
155  void constraints()
156  {
157  T a(b);
158  T *p = &a;
159 
162  }
163 
164  void const_constraints(const T & a)
165  {
166  T c(a);
167  const T *p = &a;
168 
171  }
172 
173  T b;
174  };
175 
177 };
178 
180 template< typename T1, typename T2 >
181 struct Convertible {
182  struct Constraints {
183  void constraints()
184  {
185  T2 b = static_cast< T2 >( a );
186 
188  }
189 
190  T1 a;
191  };
193 };
194 
196 template< typename T >
197 struct Assignable {
198  struct Constraints {
199  void constraints()
200  {
201  a = a;
203  }
204 
205  void const_constraints(const T & b)
206  {
207  a = b;
208  }
209 
210  T a;
211  };
212 
214 };
215 
218 template< typename T1, typename T2 = T1 >
220  struct Constraints {
221  void constraints()
222  {
225  }
226 
227  T1 a;
228  T2 b;
229  };
230 
232 };
233 
236 template< typename T1, typename T2 = T1 >
238  struct Constraints {
239  void constraints()
240  {
243  }
244 
245  T1 a;
246  T2 b;
247  };
248 
250 };
251 
254 template< typename T1, typename T2 = T1 >
256  struct Constraints {
257  void constraints()
258  {
261  }
262 
263  T1 a;
264  T2 b;
265  };
266 
268 };
269 
272 template< typename T1, typename T2 = T1 >
273 struct Comparable {
274  struct Constraints {
275  void constraints()
276  {
283  }
284 
285  T1 a;
286  T2 b;
287  };
288 
290 };
291 
294 template< typename T1, typename T2 = T1, typename T3 = T1 >
296  struct Constraints {
297  void constraints()
298  {
299  a = static_cast< T3 >( b + c );
300  a = static_cast< T3 >( b - c );
302  }
303 
304  void const_constraints(const T1 & d, const T2 & e)
305  {
306  a = static_cast< T3 >( d + e );
307  a = static_cast< T3 >( d - e );
308  }
309 
310  T3 a;
311  T1 b;
312  T2 c;
313  };
314 
316 };
317 
318 
321 template< typename T1, typename T2 = T1>
323  struct Constraints {
324  void constraints()
325  {
326  a += c;
327  a -= c;
329  }
330 
331  void const_constraints(const T1 & d)
332  {
333  a += d;
334  a -= d;
335  }
336 
337  T2 a;
338  T1 c;
339  };
340 
342 };
343 
345 template< typename T1, typename T2 = T1, typename T3 = T1 >
347  struct Constraints {
348  void constraints()
349  {
350  a = static_cast< T3 >( b * c );
352  }
353 
354  void const_constraints(const T1 & d, const T2 & e)
355  {
356  a = static_cast< T3 >( d * e );
357  }
358 
359  T3 a;
360  T1 b;
361  T2 c;
362  };
364 };
365 
367 template< typename T1, typename T2 = T1 >
369  struct Constraints {
370  void constraints()
371  {
372  a *= b;
374  }
375 
376  void const_constraints(const T1 & d)
377  {
378  a *= d;
379  }
380 
381  T2 a;
382  T1 b;
383  };
384 
386 };
387 
389 template< typename T1, typename T2 = T1, typename T3 = T1 >
391  struct Constraints {
392  void constraints()
393  {
394  a = static_cast< T3 >( b / c );
396  }
397 
398  void const_constraints(const T1 & d, const T2 & e)
399  {
400  a = static_cast< T3 >( d / e );
401  }
402 
403  T3 a;
404  T1 b;
405  T2 c;
406  };
407 
409 };
410 
411 
413 template< typename T1, typename T2 = T1 >
415  struct Constraints {
416  void constraints()
417  {
418  a /= c;
420  }
421 
422  void const_constraints(const T1 & d)
423  {
424  a /= d;
425  }
426 
427  T1 c;
428  T2 a;
429  };
430 
432 };
433 
434 
437 template< typename T1, typename T2 = T1, typename T3 = T1 >
439  struct Constraints {
440  void constraints()
441  {
442  a = static_cast< T3 >( b & c );
443  a = static_cast< T3 >( b | c );
444  a = static_cast< T3 >( b ^ c );
445  a &= static_cast< T3 >( c );
446  a |= static_cast< T3 >( c );
447  a ^= static_cast< T3 >( c );
449  }
450 
451  void const_constraints(const T1 & d, const T2 & e)
452  {
453  a = static_cast< T3 >( d & e );
454  a = static_cast< T3 >( d | e );
455  a = static_cast< T3 >( d ^ e );
456  a &= static_cast< T3 >( e );
457  a |= static_cast< T3 >( e );
458  a ^= static_cast< T3 >( e );
459  }
460 
461  T3 a;
462  T1 b;
463  T2 c;
464  };
465 
467 };
468 
470 template< typename T1, typename T2 = T1, typename T3 = T1 >
472  struct Constraints {
473  void constraints()
474  {
475  a = static_cast< T3 >( b[c] );
477  }
478 
479  void const_constraints(const T1 & d, const T2 & e)
480  {
481  a = static_cast< T3 >( d[e] );
482  }
483 
484  T3 a;
485  T1 b;
486  T2 c;
487  };
488 
490 };
491 
493 template< typename T >
494 struct NotOperator {
495  struct Constraints {
496  void constraints()
497  {
498  a = !a;
499  }
500 
501  T a;
502  };
503 
505 };
506 
508 template< typename T >
510  struct Constraints {
511  void constraints()
512  {
513  a++;
514  a--;
515  ++a;
516  --a;
517  }
518 
519  T a;
520  };
521 
523 };
524 
526 template< typename T >
528  struct Constraints {
529  void constraints()
530  {
531  std::cout << a;
532  }
533 
534  T a;
535  };
536 
538 };
539 
541 template< typename T >
542 struct Signed {
543  typedef Signed Self;
544  itkStaticConstMacro(IsSigned, bool, NumericTraits< T >::is_signed);
545  struct Constraints {
548  void constraints()
549  {
550  SignedT a = TrueT();
551 
553  }
554  };
555 
557 };
558 
560 template< typename T1, typename T2 >
561 struct SameType {
562  struct Constraints {
563  void constraints()
564  {
567  }
568  };
570 };
571 
573 template< unsigned int D1, unsigned int D2 >
575  struct Constraints {
578  void constraints()
579  {
580  DT1 a = DT2();
581 
583  }
584  };
586 };
587 
589 template< typename T >
591  struct Constraints {
592  void constraints()
593  {
594  typedef typename NumericTraits< T >::ValueType ValueType;
595  typedef typename NumericTraits< T >::PrintType PrintType;
596  typedef typename NumericTraits< T >::AbsType AbsType;
597  typedef typename NumericTraits< T >::AccumulateType AccumulateType;
598  typedef typename NumericTraits< T >::RealType RealType;
599  typedef typename NumericTraits< T >::ScalarRealType ScalarRealType;
600  typedef typename NumericTraits< T >::FloatType FloatType;
601  T a;
602  bool b;
603 
604  // Test these methods that take an instance of T to
605  // allow for types with variable length.
609 
616  }
617  };
618 
620 };
621 
623 template< typename T >
625  struct Constraints {
626  void constraints()
627  {
628  typedef typename PixelTraits< T >::ValueType ValueType;
629  unsigned int a = PixelTraits< T >::Dimension;
631  }
632  };
633 
635 };
636 
638 template< typename T >
639 struct HasValueType {
640  struct Constraints {
641  void constraints()
642  {
643  typedef typename T::ValueType ValueType;
644  }
645  };
646 
648 };
649 
651 template< typename T >
652 struct HasZero {
653  struct Constraints {
654  void constraints()
655  {
656  T a;
657 
660  }
661  };
662 
664 };
665 
667 template< typename T1, typename T2 >
669  struct Constraints {
670  void constraints()
671  {
672  typedef typename JoinTraits< T1, T2 >::ValueType ValueType;
673  }
674  };
675 
677 };
678 
680 template< unsigned int D1, unsigned int D2 >
682  struct Constraints {
685 
686  void f(Type1) {}
687  void f(Type2, int = 0) {}
688 
689  void constraints()
690  {
692  this->f(tt);
693  }
694  };
696 };
697 
699 template< unsigned int D1, unsigned int D2 >
701  struct Constraints {
705 
706  void f(Type1) {}
707  void f(Type2, int = 0) {}
708  void f(Type3, int = 0, int = 0) {}
709 
710  void constraints()
711  {
713  this->f(tt);
714  }
715  };
717 };
718 
720 template< typename T >
721 struct IsInteger {
722  typedef IsInteger Self;
723  itkStaticConstMacro(Integral, bool, NumericTraits< T >::is_integer);
724  struct Constraints {
727  void constraints()
728  {
729  IntegralT a = TrueT();
730 
732  }
733  };
734 
736 };
737 
738 
740 template< typename T >
743  itkStaticConstMacro(Unsigned, bool, !NumericTraits< T >::is_signed);
744  struct Constraints {
747  void constraints()
748  {
749  UnsignedT a = TrueT();
750 
752  }
753  };
754 
756 };
757 
758 
760 template< typename T >
761 struct IsNonInteger {
763  itkStaticConstMacro(NonIntegral, bool, NumericTraits< T >::is_integer);
764  struct Constraints {
767  void constraints()
768  {
769  NonIntegralT a = FalseT();
770 
772  }
773  };
774 
776 };
777 
779 template< typename T >
782  itkStaticConstMacro(Integral, bool, NumericTraits< T >::is_integer);
783  itkStaticConstMacro(IsExact, bool, NumericTraits< T >::is_exact);
784  struct Constraints {
788  void constraints()
789  {
790  IntegralT a = FalseT();
791  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();
816 
819  }
820  };
821 
823 };
824 } // end namespace Concept
825 } // end namespace itk
826 
827 #endif

Generated at Sat Mar 8 2014 14:28:05 for Orfeo Toolbox with doxygen 1.8.3.1