Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Constraints.hh
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 #ifndef __Contraints_hh__
24 #define __Contraints_hh__
25 
26 namespace BIAS {
27 
28  /** @class DerivedFrom
29  @brief compile time check if B is (grand)father of T
30  Found it in Bjarne Stroustrup's FAQ:
31  http://public.research.att.com/~bs/bs_faq2.html
32  "Actually, Derived_from doesn't check derivation, but conversion, but
33  that's often a better constraint. Finding good names for constraints
34  can be hard."
35  @author woelk 02/2006 */
36 
37  template<class T, class B>
39  {
40  public:
42  T* p = 0;
43  B* pb = p;
44  pb++; // avoid warn
45  }
46  };
47 
48 
49  /** @class CanCopy
50  @brief compile time check for copy compatibilty between T1 and T2
51  Found it in Bjarne Stroustrup's FAQ:
52  http://public.research.att.com/~bs/bs_faq2.html
53  @author woelk 02/2006 */
54  template<class T1, class T2>
55  class CanCopy
56  {
57  public:
58  static void Constraints(T1 a, T2 b) { T2 c = a; b = a; }
59  CanCopy() {
60  void(*p)(T1,T2) = Constraints;
61  p=0 /*NULL*/;
62  }
63  };
64 
65 
66  /** @class CanCompare
67  @brief compile time check for comparabilty of T1 and T2
68  Found it in Bjarne Stroustrup's FAQ:
69  http://public.research.att.com/~bs/bs_faq2.html
70  @author woelk 02/2006 */
71  template<class T1, class T2 = T1>
72  class CanCompare
73  {
74  public:
75  static void Constraints(T1 a, T2 b) { a==b; a!=b; a<b; }
77  void(*p)(T1,T2) = Constraints;
78  p=0 /*NULL*/;
79  }
80  };
81 
82 
83  /** @class CanMultiply
84  @brief compile time check if T1 can be multiplied by T2
85  Found it in Bjarne Stroustrup's FAQ:
86  http://public.research.att.com/~bs/bs_faq2.html
87  @author woelk 02/2006 */
88  template<class T1, class T2, class T3 = T1>
89  class CanMultiply
90  {
91  public:
92  static void Constraints(T1 a, T2 b, T3 c) { c = a*b; }
94  void(*p)(T1,T2,T3) = Constraints;
95  p=0 /*NULL*/;
96  }
97  };
98 
99 
100  /** @class SameButConst
101  @brief compile time check if the ConstType differs from
102  EditableType merely by a const qualifier, i.e.
103  const EditableType == ConstType
104  @author woelk 02/2008 (c) www.vision-n.de*/
105  template<class EditableType, class ConstType>
107  {
108  public:
109  static void Constraints(EditableType *a, ConstType *b,
110  const EditableType *c) {
111  c = const_cast<ConstType *>(a);
112  *a = *c;
113  }
115  void(*p)(EditableType *, ConstType *, const EditableType *) =
116  Constraints;
117  p = p; //avoid warning
118  p=0 /*NULL*/;
119  }
120  };
121 
122 
123 
124 
125 }
126 
127 #endif // __Contraints_hh__
static void Constraints(T1 a, T2 b, T3 c)
Definition: Constraints.hh:92
compile time check if T1 can be multiplied by T2 Found it in Bjarne Stroustrup&#39;s FAQ: http://public...
Definition: Constraints.hh:89
compile time check if B is (grand)father of T Found it in Bjarne Stroustrup&#39;s FAQ: http://public...
Definition: Constraints.hh:38
compile time check for copy compatibilty between T1 and T2 Found it in Bjarne Stroustrup&#39;s FAQ: http:...
Definition: Constraints.hh:55
static void Constraints(T1 a, T2 b)
Definition: Constraints.hh:58
compile time check for comparabilty of T1 and T2 Found it in Bjarne Stroustrup&#39;s FAQ: http://public...
Definition: Constraints.hh:72
static void Constraints(T1 a, T2 b)
Definition: Constraints.hh:75
compile time check if the ConstType differs from EditableType merely by a const qualifier, i.e.
Definition: Constraints.hh:106
static void Constraints(EditableType *a, ConstType *b, const EditableType *c)
Definition: Constraints.hh:109