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