Removed libglademm.
[ardour.git] / libs / sigc++2 / sigc++ / type_traits.h
1 /*
2  * Copyright 2002, The libsigc++ Development Team
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 #ifndef _SIGC_TYPE_TRAIT_H_
20 #define _SIGC_TYPE_TRAIT_H_
21
22 #include <sigc++config.h> //To get SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
23
24
25 namespace sigc {
26
27 template <class T_type>
28 struct type_trait
29 {
30   typedef T_type  type;
31   typedef T_type& pass;
32   typedef const T_type& take;
33   typedef T_type* pointer;
34 };
35
36 template <class T_type, int N>
37 struct type_trait<T_type[N]>
38 {
39   typedef T_type*  type;
40   typedef T_type*& pass;
41   typedef const T_type*& take;
42   typedef T_type** pointer;
43 };
44
45 template <class T_type>
46 struct type_trait<T_type&>
47 {
48   typedef T_type  type;
49   typedef T_type& pass;
50   typedef T_type& take;
51   typedef T_type* pointer;
52 };
53
54 template <class T_type>
55 struct type_trait<const T_type&>
56 {
57   typedef const T_type  type;
58   typedef const T_type& pass;
59   typedef const T_type& take;
60   typedef const T_type* pointer;
61 };
62
63 template<>
64 struct type_trait<void>
65 {
66   typedef void  type;
67   typedef void  pass;
68   typedef void  take;
69   typedef void* pointer;
70 };
71
72
73 // From Esa Pulkkin:
74 /**
75  * Compile-time determination of base-class relationship in C++
76  * (adapted to match the syntax of boost's type_traits library).
77  *
78  * Use this to provide a template specialization for a set of types.
79  * For instance,
80  *
81  * template < class T_thing, bool Tval_derives_from_something = sigc::is_base_and_derived<Something, T_thing>::value >
82  * class TheTemplate
83  * {
84  *   //Standard implementation.
85  * }
86  *
87  * //Specialization for T_things that derive from Something (Tval_derives_from_something is true)
88  * template <class T_thing>
89  * class TheTemplate<T_thing, true>
90  * {
91  *   T_thing thing;
92      thing.method_that_is_in_something();
93  * }
94  */
95 template <class T_base, class T_derived>
96 struct is_base_and_derived
97 {
98 private:
99   struct big {
100     char memory[64];
101   };
102
103 #ifndef SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
104
105   //Allow the internal inner class to access the other (big) inner
106   //class.  The Tru64 compiler needs this. murrayc.
107   friend struct internal_class;
108
109   //Certain compilers, notably GCC 3.2, require these functions to be inside an inner class.
110   struct internal_class
111   {
112     static big  is_base_class_(...);
113     static char is_base_class_(typename type_trait<T_base>::pointer);
114   };
115
116 public:
117   static const bool value =
118     sizeof(internal_class::is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) ==
119     sizeof(char);
120
121 #else //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
122
123   //The AIX xlC compiler does not like these 2 functions being in the inner class.
124   //It says "The incomplete type "test" must not be used as a qualifier.
125   //It does not seem necessary anyway. murrayc.
126   static big  is_base_class_(...);
127   static char is_base_class_(typename type_trait<T_base>::pointer);
128
129 public:
130   static const bool value =
131     sizeof(is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) ==
132     sizeof(char);
133
134 #endif //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
135
136   void avoid_gcc3_warning_(); //Not implemented. g++ 3.3.5 (but not 3.3.4, and not 3.4) warn that there are no public methods, even though there is a public variable.
137 };
138
139 template <class T_base>
140 struct is_base_and_derived<T_base, T_base>
141 {
142   static const bool value = true;
143 };
144
145 } /* namespace sigc */
146
147 #endif /* _SIGC_TYPE_TRAIT_H_ */