fix linux side of semaphore abstraction
[ardour.git] / libs / pbd / pbd / touchable.h
1 /*
2     Copyright (C) 1999 Paul Barton-Davis 
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation; either version 2 of the License, or
6     (at your option) any later version.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 */
18
19 #ifndef __pbd_touchable_h__
20 #define __pbd_touchable_h__
21
22 class Touchable
23 {
24   public:
25         Touchable() : _delete_after_touch (false) {}
26         virtual ~Touchable() {}
27
28         void set_delete_after_touch (bool yn) { _delete_after_touch = yn; }
29         bool delete_after_touch() const { return _delete_after_touch; }
30
31         virtual void touch () = 0;
32
33   protected:
34         bool _delete_after_touch;
35 };
36
37 template<class T>
38 class DynamicTouchable : public Touchable
39 {
40   public:
41         DynamicTouchable (T& t, void (T::*m)(void)) 
42                 : object (t), method (m) { set_delete_after_touch (true); }
43
44         void touch () {
45                 (object.*method)();
46         }
47         
48   protected:
49         T& object;
50         void (T::*method)(void);
51 };
52
53 template<class T1, class T2>
54 class DynamicTouchable1 : public Touchable
55 {
56   public:
57         DynamicTouchable1 (T1& t, void (T1::*m)(T2), T2 a) 
58                 : object (t), method (m), arg (a) { set_delete_after_touch (true); }
59
60         void touch () {
61                 (object.*method)(arg);
62         }
63         
64   protected:
65         T1& object;
66         void (T1::*method)(T2);
67         T2 arg;
68 };
69
70 template<class T1, class T2, class T3>
71 class DynamicTouchable2 : public Touchable
72 {
73   public:
74         DynamicTouchable2 (T1& t, void (T1::*m)(T2, T3), T2 a1, T3 a2) 
75                 : object (t), method (m), arg1 (a1), arg2 (a2) { set_delete_after_touch (true); }
76
77         void touch () {
78                 (object.*method)(arg1, arg2);
79         }
80         
81   protected:
82         T1& object;
83         void (T1::*method)(T2,T3);
84         T2 arg1;
85         T3 arg2;
86 };
87         
88 #endif // __pbd_touchable_h__