uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Function.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 #ifndef U_CORE_FUNCTION_H
29 #define U_CORE_FUNCTION_H
30 
31 #include <typeinfo>
32 
33 #include <boost/type_traits.hpp>
34 #include <boost/type_traits/remove_pointer.hpp>
35 
36 #include <boost/function_types/function_type.hpp>
37 #include <boost/function_types/parameter_types.hpp>
38 #include <boost/function_types/function_arity.hpp>
39 //#include <boost/typeof/std/utility.hpp>
40 
41 
42 namespace uLib {
43 
44 
45 
46 
47 
48 
49 
50 
51 
53 // type synthesize ( please read: boost implementation synthesize.hpp ) //
55 // TODO: change this to boost implementation //
56 // return a reference to function ... as the boost signal signature wants
57 
58 template <typename FuncT>
59 struct FunctionTypes {};
60 
61 template <typename R, class O>
62 struct FunctionTypes< R(O::*)() > {
63  typedef R ref();
64  typedef R (ptr)();
65  typedef O obj;
66 };
67 
68 template <typename R, class O, typename T0>
69 struct FunctionTypes< R(O::*)(T0) > {
70  typedef R ref(T0);
71  typedef R (ptr)(T0);
72  typedef O obj;
73 };
74 
75 template <typename R, class O, typename T0, typename T1>
76 struct FunctionTypes< R(O::*)(T0,T1) > {
77  typedef R ref(T0,T1);
78  typedef R (ptr)(T0,T1);
79  typedef O obj;
80 };
81 
82 template <typename R, class O, typename T0, typename T1, typename T2>
83 struct FunctionTypes< R(O::*)(T0,T1,T2) > {
84  typedef R ref(T0,T1,T2);
85  typedef R (ptr)(T0,T1,T2);
86  typedef O obj;
87 };
88 
89 
90 
91 
92 
93 
97 // Function pointers //
98 
99 template<typename Func>
100 struct FunctionPointer {
101  typedef typename boost::function_types::function_type<Func>::type Signature;
102  typedef typename FunctionTypes<Func>::ref SignalSignature;
103  enum {
104  arity = boost::function_types::function_arity<Func>::value,
105  ismfp = boost::is_member_function_pointer<Func>::value
106  };
107 
108  typedef boost::mpl::bool_< ismfp > HasObjectType;
109  typedef typename FunctionTypes<Func>::obj Object;
110  typedef boost::function_traits< Signature > Traits;
111 
112  virtual void PrintSelf( std::ostream &o ) {
113  o << "[fp: " << typeid(Signature).name()
114  << " arity: " << arity << "]\n"; }
115 };
116 
117 
118 
119 
121 
122 class GenericMFPtr {
123  typedef void (GenericMFPtr::*_MFPtrStub_t)();
124 public:
125 
126  typedef _MFPtrStub_t Type;
127 
128  GenericMFPtr() {}
129 
130  template <typename T>
131  GenericMFPtr(T in) {
132  m_ptr = reinterpret_cast<_MFPtrStub_t>(in);
133  }
134 
135  template <typename T>
136  inline bool operator == (T in) {
137  return m_ptr == reinterpret_cast<_MFPtrStub_t>(in);
138  }
139 
140  inline bool operator == (const GenericMFPtr &in) {
141  return m_ptr == in.m_ptr;
142  }
143 
144  Type operator()() { return m_ptr; }
145 
146  _MFPtrStub_t m_ptr;
147 private:
148 };
149 
150 } // uLib
151 
152 
153 
154 
155 #endif // FUNCTION_H