Orfeo Toolbox  3.16
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;
126 }
127 
128 } // namespace Detail
129 
130 
132 template <typename T>
134 {
135  struct Constraints
136  {
137  void constraints()
138  {
139  T a;
141  }
142  };
143 
145 };
146 
148 template <typename T>
150 {
151  struct Constraints
152  {
153  void constraints()
154  {
155  T a(b);
156  T* p = &a;
159  }
160  void const_constraints(const T& a)
161  {
162  T c(a);
163  const T* p = &a;
166  }
167  T b;
168  };
169 
171 };
172 
174 template <typename T1, typename T2>
176 {
177  struct Constraints
178  {
179  void constraints()
180  {
181  T2 b = static_cast<T2>(a);
183  }
184  T1 a;
185  };
187 };
188 
190 template <typename T>
192 {
193  struct Constraints
194  {
195  void constraints()
196  {
197  a = a;
199  }
200  void const_constraints(const T& b)
201  {
202  a = b;
203  }
204  T a;
205  };
206 
208 };
209 
212 template <typename T1, typename T2=T1>
214 {
215  struct Constraints
216  {
217  void constraints()
218  {
221  }
222  T1 a;
223  T2 b;
224  };
225 
227 };
228 
231 template <typename T1, typename T2=T1>
233 {
234  struct Constraints
235  {
236  void constraints()
237  {
240  }
241  T1 a;
242  T2 b;
243  };
244 
246 };
247 
250 template <typename T1, typename T2=T1>
252 {
253  struct Constraints
254  {
255  void constraints()
256  {
259  }
260  T1 a;
261  T2 b;
262  };
263 
265 };
266 
269 template <typename T1, typename T2=T1>
271 {
272  struct Constraints
273  {
274  void constraints()
275  {
282  }
283  T1 a;
284  T2 b;
285  };
286 
288 };
289 
292 template <typename T1, typename T2=T1, typename T3=T1>
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);
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 
318 };
319 
321 template <typename T1, typename T2=T1, typename T3=T1>
323 {
324  struct Constraints
325  {
326  void constraints()
327  {
328  a = static_cast<T3>(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  };
340 };
341 
343 template <typename T1, typename T2=T1>
345 {
346  struct Constraints
347  {
348  void constraints()
349  {
350  a *= static_cast<T2>(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 
362 };
363 
365 template <typename T1, typename T2=T1, typename T3=T1>
367 {
368  struct Constraints
369  {
370  void constraints()
371  {
372  a = static_cast<T3>(b / c);
373  a /= 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 
387 };
388 
391 template <typename T1, typename T2=T1, typename T3=T1>
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);
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 
421 };
422 
424 template <typename T1, typename T2=T1, typename T3=T1>
426 {
427  struct Constraints
428  {
429  void constraints()
430  {
431  a = static_cast<T3>(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 
444 };
445 
446 
448 template <typename T>
450 {
451  struct Constraints
452  {
453  void constraints()
454  {
455  a = !a;
456  }
457  T a;
458  };
459 
461 };
462 
464 template <typename T>
466 {
467  struct Constraints
468  {
469  void constraints()
470  {
471  a++;
472  a--;
473  ++a;
474  --a;
475  }
476  T a;
477  };
478 
480 };
481 
483 template <typename T>
485 {
486  struct Constraints
487  {
488  void constraints()
489  {
490  std::cout << a;
491  }
492  T a;
493  };
494 
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  {
508  void constraints()
509  {
510  SignedT a = TrueT();
512  }
513  };
514 
516 };
517 
519 template <typename T1, typename T2>
520 struct SameType
521 {
522  struct Constraints
523  {
524  void constraints()
525  {
528  }
529  };
531 };
532 
534 template <unsigned int D1, unsigned int D2>
536 {
537  struct Constraints
538  {
541  void constraints()
542  {
543  DT1 a = DT2();
545  }
546  };
548 };
549 
551 template <typename T>
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);
577  }
578  };
579 
581 };
582 
584 template <typename T>
586 {
587  struct Constraints
588  {
589  void constraints()
590  {
591  typedef typename PixelTraits<T>::ValueType ValueType;
592  unsigned int a = PixelTraits<T>::Dimension;
594  }
595  };
596 
598 };
599 
601 template <typename T>
603 {
604  struct Constraints
605  {
606  void constraints()
607  {
608  typedef typename T::ValueType ValueType;
609  }
610  };
611 
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;
627  }
628  };
629 
631 };
632 
634 template <typename T1, typename T2>
636 {
637  struct Constraints
638  {
639  void constraints()
640  {
641  typedef typename JoinTraits<T1, T2>::ValueType ValueType;
642  }
643  };
644 
646 };
647 
649 template <unsigned int D1, unsigned int D2>
651 {
652  struct Constraints
653  {
656 
657  void f( Type1 ) {}
658  void f( Type2, int = 0 ) {}
659 
660  void constraints()
661  {
663  this->f( tt );
664  }
665  };
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  {
679  void constraints()
680  {
681  IntegralT a = TrueT();
683  }
684  };
685 
687 };
688 
690 template <typename T>
692 {
694  itkStaticConstMacro(NonIntegral, bool, NumericTraits<T>::is_integer);
695  struct Constraints
696  {
699  void constraints()
700  {
701  NonIntegralT a = FalseT();
703  }
704  };
705 
707 };
708 
710 template <typename T>
712 {
714  itkStaticConstMacro(Integral, bool, NumericTraits<T>::is_integer);
715  itkStaticConstMacro(IsExact, bool, NumericTraits<T>::is_exact);
716  struct Constraints
717  {
721  void constraints()
722  {
723  IntegralT a = FalseT();
724  ExactT b = FalseT();
727  }
728  };
729 
731 };
732 
734 template <typename T>
736 {
738  itkStaticConstMacro(Integral, bool, NumericTraits<T>::is_integer);
739  itkStaticConstMacro(IsExact, bool, NumericTraits<T>::is_exact);
740  struct Constraints
741  {
746  void constraints()
747  {
748  IntegralT a = FalseT();
749  ExactT b = TrueT();
752  }
753  };
754 
756 };
757 
758 } // end namespace Concept
759 
760 } // end namespace itk
761 
762 #endif

Generated at Sat Feb 2 2013 23:32:50 for Orfeo Toolbox with doxygen 1.8.1.1