xsens_janitors.h
Go to the documentation of this file.00001 #ifndef _CMT_MONOLITHIC
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #endif
00025
00026 #ifndef _JANITORS_H_2006_05_01
00027 #define _JANITORS_H_2006_05_01
00028
00029
00030 #if defined(__GNUC__) && !defined(HAVE_CDECL)
00031 # define __cdecl __attribute__((cdecl))
00032 # define __stdcall __attribute__((stdcall))
00033 #endif
00034
00035 namespace xsens {
00036
00037
00038
00039
00040
00041
00042
00043
00044 template <class T, typename R = void>
00045 class JanitorClassFunc {
00046 public:
00047 typedef R (T::*t_func_JanitorClasssFunc)(void);
00048 private:
00049 T& m_control;
00050 t_func_JanitorClasssFunc m_funcJCF;
00051 bool m_enabled;
00052 public:
00053
00054 JanitorClassFunc<T,R>(T& control, t_func_JanitorClasssFunc func, bool enabl = true) :
00055 m_control(control), m_funcJCF(func), m_enabled(enabl)
00056 {
00057 }
00058 ~JanitorClassFunc<T,R>()
00059 {
00060 if (m_enabled)
00061 (m_control.*m_funcJCF)();
00062 }
00063
00064 void disable(void)
00065 { m_enabled = false; }
00066
00067 void enable(void)
00068 { m_enabled = true; }
00069 };
00070
00071
00072 }
00073
00074 #endif // _JANITORS_H_2006_05_01