summaryrefslogtreecommitdiff
path: root/gtk2_ardour/extra_bind.h
blob: 70e1c3e5383220bd2040925e07198a86127dffd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
    Copyright (C) 2002 Paul Davis 

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id$
*/

#ifndef __ardour_extra_bind_h__
#define __ardour_extra_bind_h__

#include <sigc++/adaptor.h>
#include <sigc++/scope.h>

namespace SigC
{

/****************************************************************
 ***** Adaptor Bind Slot 0 arguments, 3 hidden arguments
 ****************************************************************/
template <class R,
   class C1, class C2, class C3>
struct AdaptorBindSlot0_3: public AdaptorSlot_
  {
#ifdef SIGC_CXX_PARTIAL_SPEC
   typedef R RType;
#else
   typedef typename Trait<R>::type RType;
#endif
   typedef Slot0<R> SlotType;
   typedef Slot3<R,C1,C2,C3> InSlotType;

   struct Node:public AdaptorNode
     {
      C1 c1_;
      C2 c2_;
      C3 c3_;	 
     };

   typedef CallDataObj2<typename SlotType::Func,Node> CallData;

   static RType callback(void* d)
     {
      CallData* data=(CallData*)d;
      Node* node=data->obj;
      return ((typename InSlotType::Callback&)(node->data_))(
                                     node->c1_,
				     node->c2_,
				     node->c3_);
     }
   static SlotData* create(SlotData *s,C1 c1, C2 c2, C3 c3)
     {
      SlotData* tmp=(SlotData*)s;
      Node *node=new Node();
      copy_callback(tmp,node);
      node->c1_=c1; 
      node->c2_=c2; 
      node->c3_=c3; 
      CallData &data=reinterpret_cast<CallData&>(tmp->data_);
      data.callback=&callback;
      data.obj=node;
      return tmp;
     }
  };


#ifndef SIGC_CXX_VOID_RETURN
#ifdef SIGC_CXX_PARTIAL_SPEC
template <
   class C1,C2,C3>
struct AdaptorBindSlot0_3
   <void,
    C1,C2,C3> : public AdaptorSlot_
  {
   typedef void RType;
   typedef Slot0<void> SlotType;
   typedef Slot3<void,C1,C2,C3> InSlotType;

   struct Node:public AdaptorNode
     {
      C1 c1_;
      C2 c2_;
      C3 c3_;
     };

   typedef CallDataObj2<typename SlotType::Func,Node> CallData;

   static RType callback(void* d)
     {
      CallData* data=(CallData*)d;
      Node* node=data->obj;
       ((typename InSlotType::Callback&)(node->data_))(
                                     node->c1_,
                                     node->c2_,
                                     node->c3);
     }
   static SlotData* create(SlotData *s,C1 c1, C2 c2, C3 c3)
     {
      SlotData* tmp=(SlotData*)s;
      Node *node=new Node();
      copy_callback(tmp,node);
      node->c1_=c1; 
      node->c2_=c2; 
      node->c3_=c3; 
      CallData &data=reinterpret_cast<CallData&>(tmp->data_);
      data.callback=&callback;
      data.obj=node;
      return tmp;
     }
  };

#endif
#endif

template <class C1, class C2, class C3,
    class R>
Slot0<R>
  bind(const Slot3<R,C1,C2,C3> &s,
       C1 c1, C2 c2, C3 c3)
  {return AdaptorBindSlot0_3<R,
           C1,C2,C3>::create(s.data(),c1,c2,c3);
  }

} /* namespace */

#endif /* __ardour_extra_bind_h__ */