MIRA
HasMember.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
46 #ifndef MIRA_HASMEMBER_H_
47 #define MIRA_HASMEMBER_H_
48 
49 #ifndef Q_MOC_RUN
50 #include <boost/type_traits/integral_constant.hpp>
51 #include <boost/type_traits/is_class.hpp>
52 #endif
53 
54 namespace mira {
55 
57 
59 struct HasMemberCheckNonClassTypeDummy {};
61 
63 
64 }
65 
67 /*
68  * The following macro makes usage of SFINAE (Substitution failure is not an error).
69  *
70  * For more details on member function detection see:
71  * http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
72  *
73  * And for an explanation see:
74  * http://cplusplus.co.il/2009/09/11/substitution-failure-is-not-an-error-1/
75  */
76 
77 #define MIRA_MEMBER_DETECTOR_EX(Identifier, Member) \
78 template <typename Type> \
79 class MIRAHasMemberCheck##Identifier \
80 { \
81  struct NotFound { char x[1]; }; \
82  struct Found { char x[2]; }; \
83  struct BaseMixin { \
84  void Member(){} \
85  }; \
86  \
87  struct Base : public Type, public BaseMixin {}; \
88  template <typename T, T t> class Helper{}; \
89  \
90  template <typename U> \
91  static NotFound deduce(U*, Helper<void (BaseMixin::*)(), &U::Member>* = 0);\
92  static Found deduce(...); \
93  \
94 public: \
95  enum { value = (sizeof(Found) == sizeof(deduce((Base*)(0))))}; \
96  typedef boost::integral_constant<bool, \
97  (sizeof(Found) == sizeof(deduce((Base*)(0)))) > type; \
98  \
99 };
100 
101 
102 #define MIRA_MEMBER_DETECTOR(Member) MIRA_MEMBER_DETECTOR_EX(Member,Member)
103 
105 template <typename T, typename IsClassType>
106 struct MIRAHasMemberCheckTraitHelper { typedef T type; };
107 
108 // use HasMemberCheckNonClassTypeDummy for non class-types to prevent
109 // compiler error
110 template <typename T>
111 struct MIRAHasMemberCheckTraitHelper<T, boost::false_type> {
112  typedef mira::HasMemberCheckNonClassTypeDummy type;
113 };
114 
115 template <typename T>
116 struct MIRAHasMemberCheckTrait {
117  typedef typename MIRAHasMemberCheckTraitHelper<T,
119 };
121 
123 
137 #define MIRA_HAS_MEMBER(Class, Identifier) \
138  MIRAHasMemberCheck##Identifier<MIRAHasMemberCheckTrait<Class>::type>
139 
140 #define MIRA_HAS_MEMBER_TEMPLATE(Class, Identifier) \
141  MIRAHasMemberCheck##Identifier<typename MIRAHasMemberCheckTrait<Class>::type>
142 
144 
145 #endif
Definition: SyncTimedRead.h:62
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295