Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Constraints.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 namespace BIAS {
26 
27  /** @brief compile time check if B is (grand)father of T
28  Found it in Bjarne Stroustrup's FAQ:
29  http://public.research.att.com/~bs/bs_faq2.html
30  "Actually, Derived_from doesn't check derivation, but conversion, but
31  that's often a better constaint. Finding good names for constraints
32  can be hard."
33  @author woelk 02/2006 */
34  template<class T, class B>
35  class DerivedFrom
36  {
37  public:
38  static void Constraints(T* p)
39  {
40  B* pb = p;
41  pb=0 /*NULL*/;
42  }
43 
45  void(*p)(T*) = Constraints;
46  p=0 /*NULL*/;
47  }
48  };
49 
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  /** @brief compile time check for comparabilty of T1 and T2
66  Found it in Bjarne Stroustrup's FAQ:
67  http://public.research.att.com/~bs/bs_faq2.html
68  @author woelk 02/2006 */
69  template<class T1, class T2 = T1>
70  class CanCompare
71  {
72  public:
73  static void Constraints(T1 a, T2 b) { a==b; a!=b; a<b; }
75  void(*p)(T1,T2) = Constraints;
76  p=0 /*NULL*/;
77  }
78  };
79 
80  /** @brief compile time check if T1 can be multiplied by T2
81  Found it in Bjarne Stroustrup's FAQ:
82  http://public.research.att.com/~bs/bs_faq2.html
83  @author woelk 02/2006 */
84  template<class T1, class T2, class T3 = T1>
85  class CanMultiply
86  {
87  public:
88  static void Constraints(T1 a, T2 b, T3 c) { c = a*b; }
90  void(*p)(T1,T2,T3) = Constraints;
91  p=0 /*NULL*/;
92  }
93  };
94 }
95 
static void Constraints(T *p)
Definition: Constraints.hh:38
static void Constraints(T1 a, T2 b, T3 c)
Definition: Constraints.hh:88
static void Constraints(T1 a, T2 b)
Definition: Constraints.hh:58
static void Constraints(T1 a, T2 b)
Definition: Constraints.hh:73