MEL
Microthread & Execution library
MemberEncapsulateImpl.h
1 
2 namespace mel
3 {
4  namespace mpl
5  {
6  #if VARIABLE_NUM_ARGS == VARIABLE_MAX_ARGS
8  struct const_function_t
9  {
10  };
11  struct no_const_function_t
12  {
13  };
14  const static const_function_t const_function = const_function_t();
15  const static no_const_function_t no_const_function = no_const_function_t();
16 
17  template <bool isConst,class T, class PointerType, class TRet, VARIABLE_ARGS>
18  class MEncapsulate_Base
19  {
20 
21  protected:
22  typedef TRet (T::*FNoConst)(VARIABLE_ARGS_DECL);
23  typedef TRet (T::*FConst)(VARIABLE_ARGS_DECL) const;
24  typedef typename _if<isConst,FConst,FNoConst>::Result F;
25 
26  public:
27  MEncapsulate_Base():mOwner(0){};
28  MEncapsulate_Base( const F& function, PointerType& obj ):mOwner(obj),mFunction(function)
29  {
30  }
31  template <class F2>
32  bool operator == ( const F2& ob2 ) const
33  {
34  return equality( Int2Type< Conversion<F2, MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL> >::exists >(),ob2 );
35  }
36  /*bool operator == ( const MEncapsulate_Base& ob2 ) const
37  {
38  return equality( Int2Type< true >(),ob2 );;
39  }*/
40 
41  private:
42  template <class F>
43  bool equality( Int2Type<false>,const F&) const
44  {
45  return false;
46  }
47  bool equality( Int2Type<true >,const MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>& me2) const
48  {
49  //return (mFunction == me2.mFunction && mOwner == me2.mOwner );
50  //return mOwner == me2.mOwner &&::mel::mpl::Compare<::mel::mpl::ComparableTraits<F>::Result>::compare( mFunction,me2.mFunction);
51  return mOwner == me2.mOwner && mel::mpl::equal<true>( mFunction,me2.mFunction);
52  }
53 
54  protected:
55 
56  F mFunction;
57  PointerType mOwner;
58  };
59 
61 
76  template <bool isConst, class T, class PointerType, class TRet, VARIABLE_ARGS>
77  class MEncapsulate : public MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>
78  {
79  typedef typename MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::F F;
80  public:
81  MEncapsulate():MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>(){};
82  MEncapsulate( const F& function, PointerType& obj ):MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>(function,obj)
83  {
84  }
85  TRet operator()( VARIABLE_ARGS_IMPL )
86  {
87  return (MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::mOwner->*MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::mFunction)( VARIABLE_ARGS_USE);
88  }
89  };
91  //specialization for void arguments
92  template <bool isConst,class T, class PointerType, class TRet>
93  class MEncapsulate_Base<isConst,T,PointerType,TRet>
94  {
95 
96  protected:
97  typedef TRet (T::*FNoConst)();
98  typedef TRet (T::*FConst)() const;
99  typedef typename _if<isConst,FConst,FNoConst>::Result F;
100 
101  public:
102  MEncapsulate_Base():mOwner(0){};
103  MEncapsulate_Base( const F& function, PointerType& obj ):mFunction(function), mOwner(obj)
104  {
105  }
106  template <class F2>
107  bool operator == ( const F2& ob2 ) const
108  {
109  return equality( Int2Type< Conversion<F2, MEncapsulate_Base<isConst,T,PointerType,TRet> >::exists >(),ob2 );
110  }
111  /*bool operator == ( const MEncapsulate_Base<isConst,T,PointerType,TRet>& ob2 ) const
112  {
113  return equality( Int2Type< true >(),ob2 );
114  }*/
115  private:
116  template <class F>
117  bool equality( Int2Type<false>,const F&) const
118  {
119  return false;
120  }
121  bool equality( Int2Type<true >,const MEncapsulate_Base<isConst,T,PointerType,TRet>& me2) const
122  {
123  //return (mFunction == me2.mFunction && mOwner == me2.mOwner );
124  //return mOwner == me2.mOwner &&::mel::mpl::Compare<::mel::mpl::ComparableTraits<F>::Result>::compare( mFunction,me2.mFunction);
125  return mOwner == me2.mOwner &&::mel::mpl::equal<true>( mFunction,me2.mFunction);
126  }
127 
128  protected:
129 
130  F mFunction;
131  //T* mOwner;
132  PointerType mOwner;
133  };
134 
136  template <bool isConst,class T, class PointerType, class TRet >
137  class MEncapsulate<isConst,T,PointerType,TRet> : public MEncapsulate_Base<isConst,T,PointerType,TRet,void>
138  {
139  typedef typename MEncapsulate_Base<isConst,T,PointerType,TRet,void>::F F;
140 
141  public:
142  MEncapsulate():MEncapsulate_Base<isConst,T,PointerType, TRet>(){};
143  MEncapsulate( const F& function, PointerType& obj ):MEncapsulate_Base<isConst,T,PointerType,TRet>(function,obj)
144  {
145  }
146  TRet operator()( )
147  {
148  return (MEncapsulate_Base<isConst,T,PointerType,TRet,void>::mOwner->*MEncapsulate_Base<isConst,T,PointerType,TRet,void>::mFunction)( );
149  }
150  };
151 
152 
153  template <class TRet, class T,VARIABLE_ARGS_NODEFAULT,class PointerType > inline
154  MEncapsulate<false,T,PointerType,TRet,VARIABLE_ARGS_DECL> makeMemberEncapsulate( TRet (T::*F)(VARIABLE_ARGS_DECL),PointerType owner)
155  {
157  }
158 
159  template <class TRet, class T,VARIABLE_ARGS_NODEFAULT,class PointerType > inline
160  MEncapsulate<false,T,PointerType,TRet,VARIABLE_ARGS_DECL> makeMemberEncapsulate( TRet (T::*F)(VARIABLE_ARGS_DECL),PointerType owner, no_const_function_t)
161  {
162  return MEncapsulate<false,T,PointerType,TRet,VARIABLE_ARGS_DECL>(F,owner);
163  }
167  template <class TRet, class T,VARIABLE_ARGS_NODEFAULT,class PointerType > inline
168  MEncapsulate<true,T,PointerType,TRet,VARIABLE_ARGS_DECL> makeMemberEncapsulate( TRet (T::*F)(VARIABLE_ARGS_DECL) const,PointerType owner,const_function_t)
169  {
171  }
172 
173 
174  //specialization for void parameters
175  template <class TRet, class T,class PointerType> inline
176  MEncapsulate<false,T,PointerType,TRet> makeMemberEncapsulate( TRet (T::*F)(),PointerType owner)
177  {
178  return MEncapsulate<false,T,PointerType,TRet>(F,owner);
179  }
180  template <class TRet, class T,class PointerType> inline
181  MEncapsulate<false,T,PointerType,TRet> makeMemberEncapsulate( TRet (T::*F)(),PointerType owner,no_const_function_t)
182  {
183  return MEncapsulate<false,T,PointerType,TRet>(F,owner);
184  }
185 
186  template <class TRet, class T,class PointerType> inline
187  MEncapsulate<true,T,PointerType,TRet> makeMemberEncapsulate( TRet (T::*F)() const,PointerType owner, const_function_t)
188  {
189  return MEncapsulate<true,T,PointerType,TRet>(F,owner);
190  }
191 
192 
193  #else
194 
196  template <bool isConst, class T, class PointerType, class TRet, VARIABLE_ARGS>
197  class MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL,void>
198  {
199  protected:
200  typedef TRet (T::*FNoConst)(VARIABLE_ARGS_DECL);
201  typedef TRet (T::*FConst)(VARIABLE_ARGS_DECL) const;
202  typedef typename _if<isConst,FConst,FNoConst>::Result F;
203 
204 
205  public:
206  MEncapsulate_Base():mOwner(0){};
207  MEncapsulate_Base( const F& function, PointerType& obj ):mFunction(function), mOwner(obj)
208  {
209  }
210  template <class F2>
211  bool operator == ( const F2& ob2 ) const
212  {
213  return equality( Int2Type< Conversion<F2, MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL> >::exists >(),ob2 );
214  }
215  /*bool operator == ( const MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL,void>& ob2 ) const
216  {
217  return equality( Int2Type< true >(),ob2 );
218  }*/
219 
220  private:
221  template <class F>
222  bool equality( Int2Type<false>,const F&) const
223  {
224  return false;
225  }
226  bool equality( Int2Type<true >,const MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>& me2) const
227  {
228  //return (mFunction == me2.mFunction && mOwner == me2.mOwner );
229  //return mOwner == me2.mOwner &&::mel::mpl::Compare<::mel::mpl::ComparableTraits<F>::Result>::compare( mFunction,me2.mFunction);
230  return mOwner == me2.mOwner &&::mel::mpl::equal<true>( mFunction,me2.mFunction);
231  }
232  protected:
233 
234  F mFunction;
235  PointerType mOwner;
236  };
238  template <bool isConst, class T, class PointerType, class TRet, VARIABLE_ARGS>
239  class MEncapsulate<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL,void> : public MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>
240  {
241  typedef typename MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::F F;
242  public:
243  MEncapsulate():MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>(){};
244  MEncapsulate( F function, PointerType& obj ):MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>(function,obj){}
245  TRet operator()( VARIABLE_ARGS_IMPL )
246  {
247  return (MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::mOwner->*MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::mFunction)( VARIABLE_ARGS_USE);
248  }
249  /*bool operator == ( const MEncapsulate<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL,void>& ob2 ) const
250  {
251  return MEncapsulate_Base<isConst,T,PointerType,TRet,VARIABLE_ARGS_DECL>::operator ==( ob2 );
252  }*/
253 
254  };
255  //helper function for argument deduction
256 
257  template <class TRet,class T, VARIABLE_ARGS,class PointerType> inline
258  MEncapsulate<false,T,PointerType,TRet,VARIABLE_ARGS_DECL> makeMemberEncapsulate( TRet (T::*F)(VARIABLE_ARGS_DECL),PointerType owner)
259  {
260  return MEncapsulate<false,T,PointerType,TRet,VARIABLE_ARGS_DECL>(F,owner);
261  }
266  template <class TRet,class T, VARIABLE_ARGS,class PointerType > inline
267  MEncapsulate<false,T,PointerType, TRet,VARIABLE_ARGS_DECL> makeMemberEncapsulate( TRet (T::*F)(VARIABLE_ARGS_DECL) ,PointerType owner,no_const_function_t)
268  {
269  return MEncapsulate<false,T,PointerType,TRet,VARIABLE_ARGS_DECL>(F,owner);
270  }
271 
272  template <class TRet,class T,VARIABLE_ARGS,class PointerType > inline
273  MEncapsulate<true,T,PointerType,TRet,VARIABLE_ARGS_DECL> makeMemberEncapsulate( TRet (T::*F)(VARIABLE_ARGS_DECL) const,PointerType owner,const_function_t)
274  {
275  return MEncapsulate<true,T,PointerType,TRet,VARIABLE_ARGS_DECL>(F,owner);
276  }
277 
278  #endif
279  }
280 }
Definition: MemberEncapsulateImpl.h:78
Definition: BasicTypes.h:7
Small operator==(const AnyType &, const AnyType &)
Definition: Callback_Impl.h:11