Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: ui/base/glib/glib_signal.h

Issue 8523019: Devirtualize CHROMEG_CALLBACK (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/gtk/gtk_signal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_BASE_GLIB_GLIB_SIGNAL_H_ 5 #ifndef UI_BASE_GLIB_GLIB_SIGNAL_H_
6 #define UI_BASE_GLIB_GLIB_SIGNAL_H_ 6 #define UI_BASE_GLIB_GLIB_SIGNAL_H_
7 #pragma once 7 #pragma once
8 8
9 typedef void* gpointer; 9 typedef void* gpointer;
10 10
11 // At the time of writing this, there were two common ways of binding our C++ 11 // At the time of writing this, there were two common ways of binding our C++
12 // code to the gobject C system. We either defined a whole bunch of "static 12 // code to the gobject C system. We either defined a whole bunch of "static
13 // MethodThunk()" which just called nonstatic Method()s on a class (which hurt 13 // MethodThunk()" which just called nonstatic Method()s on a class (which hurt
14 // readability of the headers and signal connection code) OR we declared 14 // readability of the headers and signal connection code) OR we declared
15 // "static Method()" and passed in the current object as the gpointer (and hurt 15 // "static Method()" and passed in the current object as the gpointer (and hurt
16 // readability in the implementation by having "context->" before every 16 // readability in the implementation by having "context->" before every
17 // variable). 17 // variable).
18 18
19 // The hopeful result of using these macros is that the code will be more 19 // The hopeful result of using these macros is that the code will be more
20 // readable and regular. There shouldn't be a bunch of static Thunks visible in 20 // readable and regular. There shouldn't be a bunch of static Thunks visible in
21 // the headers and the implementations shouldn't be filled with "context->" 21 // the headers and the implementations shouldn't be filled with "context->"
22 // de-references. 22 // de-references.
23 23
24 #define CHROMEG_CALLBACK_0(CLASS, RETURN, METHOD, SENDER) \ 24 #define CHROMEG_CALLBACK_0(CLASS, RETURN, METHOD, SENDER) \
tfarina 2011/11/11 19:28:16 since this in ui/base/ directory, would we rename
25 static RETURN METHOD ## Thunk(SENDER sender, gpointer userdata) { \ 25 static RETURN METHOD ## Thunk(SENDER sender, gpointer userdata) { \
26 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender); \ 26 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender); \
27 } \ 27 } \
28 \ 28 \
29 virtual RETURN METHOD(SENDER); 29 RETURN METHOD(SENDER);
30 30
31 #define CHROMEG_CALLBACK_1(CLASS, RETURN, METHOD, SENDER, ARG1) \ 31 #define CHROMEG_CALLBACK_1(CLASS, RETURN, METHOD, SENDER, ARG1) \
32 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, \ 32 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, \
33 gpointer userdata) { \ 33 gpointer userdata) { \
34 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one); \ 34 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one); \
35 } \ 35 } \
36 \ 36 \
37 virtual RETURN METHOD(SENDER, ARG1); 37 RETURN METHOD(SENDER, ARG1);
38 38
39 #define CHROMEG_CALLBACK_2(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2) \ 39 #define CHROMEG_CALLBACK_2(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2) \
40 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \ 40 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
41 gpointer userdata) { \ 41 gpointer userdata) { \
42 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one, two); \ 42 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one, two); \
43 } \ 43 } \
44 \ 44 \
45 virtual RETURN METHOD(SENDER, ARG1, ARG2); 45 RETURN METHOD(SENDER, ARG1, ARG2);
46 46
47 #define CHROMEG_CALLBACK_3(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3) \ 47 #define CHROMEG_CALLBACK_3(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3) \
48 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \ 48 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
49 ARG3 three, gpointer userdata) { \ 49 ARG3 three, gpointer userdata) { \
50 return reinterpret_cast<CLASS*>(userdata)-> \ 50 return reinterpret_cast<CLASS*>(userdata)-> \
51 METHOD(sender, one, two, three); \ 51 METHOD(sender, one, two, three); \
52 } \ 52 } \
53 \ 53 \
54 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3); 54 RETURN METHOD(SENDER, ARG1, ARG2, ARG3);
55 55
56 #define CHROMEG_CALLBACK_4(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \ 56 #define CHROMEG_CALLBACK_4(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \
57 ARG4) \ 57 ARG4) \
58 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \ 58 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
59 ARG3 three, ARG4 four, \ 59 ARG3 three, ARG4 four, \
60 gpointer userdata) { \ 60 gpointer userdata) { \
61 return reinterpret_cast<CLASS*>(userdata)-> \ 61 return reinterpret_cast<CLASS*>(userdata)-> \
62 METHOD(sender, one, two, three, four); \ 62 METHOD(sender, one, two, three, four); \
63 } \ 63 } \
64 \ 64 \
65 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4); 65 RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4);
66 66
67 #define CHROMEG_CALLBACK_5(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \ 67 #define CHROMEG_CALLBACK_5(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \
68 ARG4, ARG5) \ 68 ARG4, ARG5) \
69 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \ 69 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
70 ARG3 three, ARG4 four, ARG5 five, \ 70 ARG3 three, ARG4 four, ARG5 five, \
71 gpointer userdata) { \ 71 gpointer userdata) { \
72 return reinterpret_cast<CLASS*>(userdata)-> \ 72 return reinterpret_cast<CLASS*>(userdata)-> \
73 METHOD(sender, one, two, three, four, five); \ 73 METHOD(sender, one, two, three, four, five); \
74 } \ 74 } \
75 \ 75 \
76 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5); 76 RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5);
77 77
78 #define CHROMEG_CALLBACK_6(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \ 78 #define CHROMEG_CALLBACK_6(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, ARG3, \
79 ARG4, ARG5, ARG6) \ 79 ARG4, ARG5, ARG6) \
80 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \ 80 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
81 ARG3 three, ARG4 four, ARG5 five, \ 81 ARG3 three, ARG4 four, ARG5 five, \
82 ARG6 six, gpointer userdata) { \ 82 ARG6 six, gpointer userdata) { \
83 return reinterpret_cast<CLASS*>(userdata)-> \ 83 return reinterpret_cast<CLASS*>(userdata)-> \
84 METHOD(sender, one, two, three, four, five, six); \ 84 METHOD(sender, one, two, three, four, five, six); \
85 } \ 85 } \
86 \ 86 \
87 RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
88
89 #define CHROMEG_VIRTUAL_CALLBACK_0(CLASS, RETURN, METHOD, SENDER) \
90 static RETURN METHOD ## Thunk(SENDER sender, gpointer userdata) { \
91 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender); \
92 } \
93 \
94 virtual RETURN METHOD(SENDER);
95
96 #define CHROMEG_VIRTUAL_CALLBACK_1(CLASS, RETURN, METHOD, SENDER, ARG1) \
97 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, \
98 gpointer userdata) { \
99 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one); \
100 } \
101 \
102 virtual RETURN METHOD(SENDER, ARG1);
103
104 #define CHROMEG_VIRTUAL_CALLBACK_2(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2) \
105 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
106 gpointer userdata) { \
107 return reinterpret_cast<CLASS*>(userdata)->METHOD(sender, one, two); \
108 } \
109 \
110 virtual RETURN METHOD(SENDER, ARG1, ARG2);
111
112 #define CHROMEG_VIRTUAL_CALLBACK_3(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, \
113 ARG3) \
114 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
115 ARG3 three, gpointer userdata) { \
116 return reinterpret_cast<CLASS*>(userdata)-> \
117 METHOD(sender, one, two, three); \
118 } \
119 \
120 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3);
121
122 #define CHROMEG_VIRTUAL_CALLBACK_4(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, \
123 ARG3, ARG4) \
124 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
125 ARG3 three, ARG4 four, \
126 gpointer userdata) { \
127 return reinterpret_cast<CLASS*>(userdata)-> \
128 METHOD(sender, one, two, three, four); \
129 } \
130 \
131 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4);
132
133 #define CHROMEG_VIRTUAL_CALLBACK_5(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, \
134 ARG3, ARG4, ARG5) \
135 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
136 ARG3 three, ARG4 four, ARG5 five, \
137 gpointer userdata) { \
138 return reinterpret_cast<CLASS*>(userdata)-> \
139 METHOD(sender, one, two, three, four, five); \
140 } \
141 \
142 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5);
143
144 #define CHROMEG_VIRTUAL_CALLBACK_6(CLASS, RETURN, METHOD, SENDER, ARG1, ARG2, \
145 ARG3, ARG4, ARG5, ARG6) \
146 static RETURN METHOD ## Thunk(SENDER sender, ARG1 one, ARG2 two, \
147 ARG3 three, ARG4 four, ARG5 five, \
148 ARG6 six, gpointer userdata) { \
149 return reinterpret_cast<CLASS*>(userdata)-> \
150 METHOD(sender, one, two, three, four, five, six); \
151 } \
152 \
87 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6); 153 virtual RETURN METHOD(SENDER, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
88 154
89 #endif 155 #endif
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/gtk/gtk_signal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698