Ardour  9.0-pre0-350-gf17a656217
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 #pragma once
20 
21 #include "pbd/libpbd_visibility.h"
22 
23 class /*LIBPBD_API*/ Touchable
24 {
25  public:
27  virtual ~Touchable() {}
28 
30  bool delete_after_touch() const { return _delete_after_touch; }
31 
32  virtual void touch () = 0;
33 
34  protected:
36 };
37 
38 template<class T>
39 class /*LIBPBD_API*/ DynamicTouchable : public Touchable
40 {
41  public:
42  DynamicTouchable (T& t, void (T::*m)(void))
43  : object (t), method (m) { set_delete_after_touch (true); }
44 
45  void touch () {
46  (object.*method)();
47  }
48 
49  protected:
50  T& object;
51  void (T::*method)(void);
52 };
53 
54 template<class T1, class T2>
55 class /*LIBPBD_API*/ DynamicTouchable1 : public Touchable
56 {
57  public:
58  DynamicTouchable1 (T1& t, void (T1::*m)(T2), T2 a)
59  : object (t), method (m), arg (a) { set_delete_after_touch (true); }
60 
61  void touch () {
62  (object.*method)(arg);
63  }
64 
65  protected:
66  T1& object;
67  void (T1::*method)(T2);
68  T2 arg;
69 };
70 
71 template<class T1, class T2, class T3>
72 class /*LIBPBD_API*/ DynamicTouchable2 : public Touchable
73 {
74  public:
75  DynamicTouchable2 (T1& t, void (T1::*m)(T2, T3), T2 a1, T3 a2)
76  : object (t), method (m), arg1 (a1), arg2 (a2) { set_delete_after_touch (true); }
77 
78  void touch () {
79  (object.*method)(arg1, arg2);
80  }
81 
82  protected:
83  T1& object;
84  void (T1::*method)(T2,T3);
85  T2 arg1;
86  T3 arg2;
87 };
88 
void(T1::* method)(T2)
Definition: touchable.h:67
DynamicTouchable1(T1 &t, void(T1::*m)(T2), T2 a)
Definition: touchable.h:58
void(T1::* method)(T2, T3)
Definition: touchable.h:84
DynamicTouchable2(T1 &t, void(T1::*m)(T2, T3), T2 a1, T3 a2)
Definition: touchable.h:75
DynamicTouchable(T &t, void(T::*m)(void))
Definition: touchable.h:42
void(T::* method)(void)
Definition: touchable.h:51
bool _delete_after_touch
Definition: touchable.h:35
virtual void touch()=0
void set_delete_after_touch(bool yn)
Definition: touchable.h:29
virtual ~Touchable()
Definition: touchable.h:27
Touchable()
Definition: touchable.h:26
bool delete_after_touch() const
Definition: touchable.h:30