70e1c3e5383220bd2040925e07198a86127dffd5
[ardour.git] / gtk2_ardour / extra_bind.h
1 /*
2     Copyright (C) 2002 Paul Davis 
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __ardour_extra_bind_h__
22 #define __ardour_extra_bind_h__
23
24 #include <sigc++/adaptor.h>
25 #include <sigc++/scope.h>
26
27 namespace SigC
28 {
29
30 /****************************************************************
31  ***** Adaptor Bind Slot 0 arguments, 3 hidden arguments
32  ****************************************************************/
33 template <class R,
34    class C1, class C2, class C3>
35 struct AdaptorBindSlot0_3: public AdaptorSlot_
36   {
37 #ifdef SIGC_CXX_PARTIAL_SPEC
38    typedef R RType;
39 #else
40    typedef typename Trait<R>::type RType;
41 #endif
42    typedef Slot0<R> SlotType;
43    typedef Slot3<R,C1,C2,C3> InSlotType;
44
45    struct Node:public AdaptorNode
46      {
47       C1 c1_;
48       C2 c2_;
49       C3 c3_;    
50      };
51
52    typedef CallDataObj2<typename SlotType::Func,Node> CallData;
53
54    static RType callback(void* d)
55      {
56       CallData* data=(CallData*)d;
57       Node* node=data->obj;
58       return ((typename InSlotType::Callback&)(node->data_))(
59                                      node->c1_,
60                                      node->c2_,
61                                      node->c3_);
62      }
63    static SlotData* create(SlotData *s,C1 c1, C2 c2, C3 c3)
64      {
65       SlotData* tmp=(SlotData*)s;
66       Node *node=new Node();
67       copy_callback(tmp,node);
68       node->c1_=c1; 
69       node->c2_=c2; 
70       node->c3_=c3; 
71       CallData &data=reinterpret_cast<CallData&>(tmp->data_);
72       data.callback=&callback;
73       data.obj=node;
74       return tmp;
75      }
76   };
77
78
79 #ifndef SIGC_CXX_VOID_RETURN
80 #ifdef SIGC_CXX_PARTIAL_SPEC
81 template <
82    class C1,C2,C3>
83 struct AdaptorBindSlot0_3
84    <void,
85     C1,C2,C3> : public AdaptorSlot_
86   {
87    typedef void RType;
88    typedef Slot0<void> SlotType;
89    typedef Slot3<void,C1,C2,C3> InSlotType;
90
91    struct Node:public AdaptorNode
92      {
93       C1 c1_;
94       C2 c2_;
95       C3 c3_;
96      };
97
98    typedef CallDataObj2<typename SlotType::Func,Node> CallData;
99
100    static RType callback(void* d)
101      {
102       CallData* data=(CallData*)d;
103       Node* node=data->obj;
104        ((typename InSlotType::Callback&)(node->data_))(
105                                      node->c1_,
106                                      node->c2_,
107                                      node->c3);
108      }
109    static SlotData* create(SlotData *s,C1 c1, C2 c2, C3 c3)
110      {
111       SlotData* tmp=(SlotData*)s;
112       Node *node=new Node();
113       copy_callback(tmp,node);
114       node->c1_=c1; 
115       node->c2_=c2; 
116       node->c3_=c3; 
117       CallData &data=reinterpret_cast<CallData&>(tmp->data_);
118       data.callback=&callback;
119       data.obj=node;
120       return tmp;
121      }
122   };
123
124 #endif
125 #endif
126
127 template <class C1, class C2, class C3,
128     class R>
129 Slot0<R>
130   bind(const Slot3<R,C1,C2,C3> &s,
131        C1 c1, C2 c2, C3 c3)
132   {return AdaptorBindSlot0_3<R,
133            C1,C2,C3>::create(s.data(),c1,c2,c3);
134   }
135
136 } /* namespace */
137
138 #endif /* __ardour_extra_bind_h__ */