Compare commits
1208 Commits
svn-branch
...
boost-0.9.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d9527fca6 | ||
|
|
256e3a467c | ||
|
|
4477fe4dd6 | ||
|
|
5d1e245858 | ||
|
|
ec750a44c9 | ||
|
|
006f1d9802 | ||
|
|
638b3d4ee1 | ||
|
|
a1cc1651fa | ||
|
|
9fe141f5ad | ||
|
|
d52f0c7d40 | ||
|
|
bb55c4a855 | ||
|
|
f1a06b14de | ||
|
|
286f3dc093 | ||
|
|
a731322782 | ||
|
|
0db07ec25e | ||
|
|
bc112ba65f | ||
|
|
62ba322658 | ||
|
|
02135b550d | ||
|
|
ee4b06bb50 | ||
|
|
16c5435ca8 | ||
|
|
2595049748 | ||
|
|
5911691c0d | ||
|
|
e369bddc84 | ||
|
|
dccf2bbb4a | ||
|
|
eaab3fc038 | ||
|
|
858e1aba67 | ||
|
|
19eff7791d | ||
|
|
c81af4ffe0 | ||
|
|
9675e4233b | ||
|
|
e6a176bb1e | ||
|
|
ff0980914b | ||
|
|
43e5ccd0a7 | ||
|
|
66d6272942 | ||
|
|
2f1b828967 | ||
|
|
622636dcf1 | ||
|
|
0c22c276bf | ||
|
|
7a4a79c74e | ||
|
|
06f454e1d3 | ||
|
|
c1dbd52de1 | ||
|
|
c3f5679188 | ||
|
|
97e2628f95 | ||
|
|
6cecfcb704 | ||
|
|
022a5a16f5 | ||
|
|
a39a834e75 | ||
|
|
2a1210384a | ||
|
|
d497611069 | ||
|
|
46d8786f5a | ||
|
|
b8028729eb | ||
|
|
30e7768a87 | ||
|
|
10dc663e07 | ||
|
|
42fc57d761 | ||
|
|
74cd2f4844 | ||
|
|
a15135f1c1 | ||
|
|
ccd84c0be6 | ||
|
|
510215f284 | ||
|
|
c7ea0aacd6 | ||
|
|
f7f089d2d4 | ||
|
|
82721c77a1 | ||
|
|
1c9bf7d91c | ||
|
|
9bf78396cb | ||
|
|
d994e4719c | ||
|
|
44b886bb76 | ||
|
|
8d2f012bcf | ||
|
|
a86deed5f6 | ||
|
|
3fd9ad7a60 | ||
|
|
319a5cf97c | ||
|
|
0fd503d6af | ||
|
|
bf696026bd | ||
|
|
734657244b | ||
|
|
d2470e4f9c | ||
|
|
28a2792280 | ||
|
|
cd985a33d8 | ||
|
|
726d2beffd | ||
|
|
f04be3fc1b | ||
|
|
b6927410d9 | ||
|
|
44b2e1ef8b | ||
|
|
3d01e6af89 | ||
|
|
00387b2076 | ||
|
|
f9bf514801 | ||
|
|
fa27bddfab | ||
|
|
f27e8f8ddc | ||
|
|
5b2623ff2e | ||
|
|
a83a726b6e | ||
|
|
93df7e00a7 | ||
|
|
6b7748a88d | ||
|
|
f102c77fa2 | ||
|
|
a4fa261b77 | ||
|
|
8a15fefc6c | ||
|
|
12a4cc16be | ||
|
|
6335716342 | ||
|
|
db0602ac2a | ||
|
|
390ad530f1 | ||
|
|
6eb2e8d68a | ||
|
|
b804b3b221 | ||
|
|
936c1118bd | ||
|
|
4ba7b8a8ff | ||
|
|
70601e9da0 | ||
|
|
c32d1f9614 | ||
|
|
e031f78ad4 | ||
|
|
7d0273051a | ||
|
|
29d537571b | ||
|
|
39f243f76b | ||
|
|
0712360cc9 | ||
|
|
02c125cbb4 | ||
|
|
13256fb7e9 | ||
|
|
f11d757807 | ||
|
|
2e123849fb | ||
|
|
2f6cfaf0e9 | ||
|
|
f9b216d6f9 | ||
|
|
5fdd10d77e | ||
|
|
41de02d528 | ||
|
|
1c3d08f23a | ||
|
|
0f1dc1fd50 | ||
|
|
cd06018820 | ||
|
|
7816eb6344 | ||
|
|
9813f4b55f | ||
|
|
f81ca21b22 | ||
|
|
f1b7620c9e | ||
|
|
7d5c453f59 | ||
|
|
bc4feb42b5 | ||
|
|
ca9920874f | ||
|
|
415991f6fc | ||
|
|
20c52def19 | ||
|
|
7dcacbcfc4 | ||
|
|
34bf1560a9 | ||
|
|
39195ac97a | ||
|
|
6aa71e1f72 | ||
|
|
257a6c45f8 | ||
|
|
d34a11b584 | ||
|
|
ca64c96133 | ||
|
|
ff734e3269 | ||
|
|
d028a60cc2 | ||
|
|
577f58149c | ||
|
|
4b97e191b8 | ||
|
|
15a148ab10 | ||
|
|
5ac7741ca9 | ||
|
|
4c7cff6e8e | ||
|
|
c6ca85b525 | ||
|
|
99f45b474e | ||
|
|
ee44c90e85 | ||
|
|
2c4fa48f46 | ||
|
|
90fcd9369d | ||
|
|
923feda9f7 | ||
|
|
6d7d2ea5fe | ||
|
|
4874a1801b | ||
|
|
479d8fc0f6 | ||
|
|
1c346b2531 | ||
|
|
5cdebaf896 | ||
|
|
600602f9dc | ||
|
|
2a530bb9d2 | ||
|
|
acdad5caf3 | ||
|
|
b42b243287 | ||
|
|
a76f5f3db7 | ||
|
|
4e9f745d4a | ||
|
|
101961a7c6 | ||
|
|
29d1f860c1 | ||
|
|
2663e73f1c | ||
|
|
1f9d0bb196 | ||
|
|
ff9f262fac | ||
|
|
472dc3bd41 | ||
|
|
6f91b93519 | ||
|
|
47291f68b2 | ||
|
|
2b5ef3c572 | ||
|
|
9c50496d93 | ||
|
|
80488e2f23 | ||
|
|
ad8da7166b | ||
|
|
55cb918c51 | ||
|
|
ac55c5ccf7 | ||
|
|
5bcf90766f | ||
|
|
8f12fdea4a | ||
|
|
6f687ee402 | ||
|
|
9dfe98abb0 | ||
|
|
399cf70b92 | ||
|
|
571790097a | ||
|
|
21f3c7c8c2 | ||
|
|
9d26167ec1 | ||
|
|
ba4906d05c | ||
|
|
e13a11eb7f | ||
|
|
72b214b8db | ||
|
|
84a8fb71b8 | ||
|
|
4f5272cab9 | ||
|
|
5895047e23 | ||
|
|
50bcf8db34 | ||
|
|
7defd3bbed | ||
|
|
b9ecc931b0 | ||
|
|
b84a8fd737 | ||
|
|
2b1a2ce09c | ||
|
|
bcf36610e1 | ||
|
|
1bb3254d4d | ||
|
|
0f95d507c4 | ||
|
|
aa58e21bda | ||
|
|
eac0412d18 | ||
|
|
0c8aa84f2f | ||
|
|
3d874d1618 | ||
|
|
b8edd99dbd | ||
|
|
0df5ebf0fa | ||
|
|
809535b934 | ||
|
|
854e957b78 | ||
|
|
df24f29232 | ||
|
|
14c7d9ab14 | ||
|
|
0e36ac6b72 | ||
|
|
0d2cdbbdfe | ||
|
|
48f9bee21e | ||
|
|
dd8fc049ff | ||
|
|
abd22f1273 | ||
|
|
4a5817d8ba | ||
|
|
eab084c9a2 | ||
|
|
80ea2383a7 | ||
|
|
ec76fbe027 | ||
|
|
c772038e77 | ||
|
|
59b1a8e71c | ||
|
|
83c38876fe | ||
|
|
9163c40a1a | ||
|
|
8b79380977 | ||
|
|
34c9d895c8 | ||
|
|
bf8bb83ec5 | ||
|
|
328697952f | ||
|
|
3c19b89d9a | ||
|
|
ae9f394906 | ||
|
|
8467f36b80 | ||
|
|
43a9571b2c | ||
|
|
bbef71dc7d | ||
|
|
c4df3c6562 | ||
|
|
0ad3bfd0ab | ||
|
|
fb7c450b76 | ||
|
|
3fc70519cf | ||
|
|
98c2bf8ff2 | ||
|
|
f9c8bf15bb | ||
|
|
a7e19ffb0b | ||
|
|
7609a1c7c6 | ||
|
|
087e2d6e35 | ||
|
|
bb7710a5a2 | ||
|
|
0d582e0e79 | ||
|
|
3d0579cc08 | ||
|
|
352e390c7b | ||
|
|
394037a127 | ||
|
|
9d4e235cf6 | ||
|
|
cfbc1a6b48 | ||
|
|
31b8b58de9 | ||
|
|
a77a835694 | ||
|
|
dca5c5108b | ||
|
|
e14e4e156c | ||
|
|
05ce65d9d2 | ||
|
|
b952e45036 | ||
|
|
4c630512fe | ||
|
|
0461d25de6 | ||
|
|
2df120af72 | ||
|
|
791b7e1a1b | ||
|
|
f6f4e59473 | ||
|
|
60924e82e2 | ||
|
|
75bd427b8e | ||
|
|
715118ce39 | ||
|
|
e3deb8275d | ||
|
|
c30e12f956 | ||
|
|
983b23db92 | ||
|
|
ed2da9bedb | ||
|
|
409ff3c179 | ||
|
|
39eab72293 | ||
|
|
71ea2bec86 | ||
|
|
c9af6ca94b | ||
|
|
72d5bac69f | ||
|
|
6e0733afa2 | ||
|
|
e660cc50c6 | ||
|
|
e6b40f54cd | ||
|
|
c2af21169d | ||
|
|
4f7af97f8c | ||
|
|
57f54952c3 | ||
|
|
b321b6d9db | ||
|
|
56c5227cf7 | ||
|
|
ae2931ba1b | ||
|
|
9e3589ec4d | ||
|
|
61b7094dbd | ||
|
|
50ecc751d1 | ||
|
|
bb536a0eaa | ||
|
|
8b7527318d | ||
|
|
f2ac0145da | ||
|
|
06fe0f1bcc | ||
|
|
7ea2447246 | ||
|
|
0adf4477a3 | ||
|
|
b3311fd59d | ||
|
|
ae109f13a2 | ||
|
|
cb1901e111 | ||
|
|
bbc052bedc | ||
|
|
f2797ec262 | ||
|
|
a21727741f | ||
|
|
5f022269b1 | ||
|
|
0e76fcf706 | ||
|
|
6b4dc2901d | ||
|
|
bcf864fce3 | ||
|
|
0168d8fbc8 | ||
|
|
88b1c1b926 | ||
|
|
1f93827b63 | ||
|
|
8e3ba0bba3 | ||
|
|
42a0441cb8 | ||
|
|
7b091b86d2 | ||
|
|
f346eaf693 | ||
|
|
038be89766 | ||
|
|
a682dd9362 | ||
|
|
387e8aadc6 | ||
|
|
da273519fd | ||
|
|
8c2d6bb31b | ||
|
|
3cb4a029e0 | ||
|
|
037f952136 | ||
|
|
7fc441801d | ||
|
|
c389e057b4 | ||
|
|
2c7829f50e | ||
|
|
0593074196 | ||
|
|
c7626150fc | ||
|
|
f6990fedc7 | ||
|
|
adb02376eb | ||
|
|
65b6eb0c27 | ||
|
|
654354e681 | ||
|
|
f1a709e074 | ||
|
|
87b011e7e8 | ||
|
|
6bb7c2d7b3 | ||
|
|
7d9770762c | ||
|
|
df8c8f025c | ||
|
|
51264c30cc | ||
|
|
1d5fb97981 | ||
|
|
a06540e471 | ||
|
|
f79dc1c2e7 | ||
|
|
8a94c597a0 | ||
|
|
8a9a3a00bd | ||
|
|
8c8b4ee332 | ||
|
|
a295ac6590 | ||
|
|
e49e0d2705 | ||
|
|
4fd20185e9 | ||
|
|
920125794a | ||
|
|
ca6c28ed93 | ||
|
|
e9757c46e3 | ||
|
|
7e840acd19 | ||
|
|
6f76db9c6c | ||
|
|
86489dd5a7 | ||
|
|
33f139e516 | ||
|
|
30d9331079 | ||
|
|
8207dc756a | ||
|
|
1887594d8a | ||
|
|
ee17b41e62 | ||
|
|
5e8d775b87 | ||
|
|
f4d457998f | ||
|
|
bd0175c167 | ||
|
|
81ffe96c76 | ||
|
|
e5fbe651d8 | ||
|
|
a91112e5d9 | ||
|
|
2b5f421501 | ||
|
|
ecd7905e8f | ||
|
|
8f989f318b | ||
|
|
7b9dad44d1 | ||
|
|
f5eab48017 | ||
|
|
66ff762fbb | ||
|
|
2bdd01d084 | ||
|
|
2bdc4cdffa | ||
|
|
90a6d484b7 | ||
|
|
021aa51707 | ||
|
|
48fffd7a7b | ||
|
|
17033037eb | ||
|
|
f43b913302 | ||
|
|
f7b087ed8f | ||
|
|
8cecbe31a7 | ||
|
|
f2055b0d80 | ||
|
|
28e5bedf49 | ||
|
|
f8a9b922be | ||
|
|
2a199af8f7 | ||
|
|
2373020225 | ||
|
|
e13d09242c | ||
|
|
09eba4c38f | ||
|
|
2aa23a317d | ||
|
|
5cd513859d | ||
|
|
c6cba55667 | ||
|
|
65ce6ddf1d | ||
|
|
fa7b1404c1 | ||
|
|
61b528c85d | ||
|
|
77b1b247c4 | ||
|
|
a06430c5fa | ||
|
|
0e38aa7f37 | ||
|
|
707ce53c16 | ||
|
|
19982e5551 | ||
|
|
170bbea166 | ||
|
|
6b5ea675c3 | ||
|
|
d873aec9e6 | ||
|
|
0d1efb61e2 | ||
|
|
a27c2f7a80 | ||
|
|
36d85eb02e | ||
|
|
9ae0940e99 | ||
|
|
2f4e12916d | ||
|
|
c860d74cba | ||
|
|
8cd3e16e26 | ||
|
|
94063f7862 | ||
|
|
a0ff708d29 | ||
|
|
6bfbeb3dfa | ||
|
|
3158d28264 | ||
|
|
997e84f117 | ||
|
|
bc91db64d7 | ||
|
|
82ef6ec659 | ||
|
|
374b55be8a | ||
|
|
72e1c1a7f6 | ||
|
|
173021377e | ||
|
|
17879958ca | ||
|
|
31a8be0434 | ||
|
|
87d619e02a | ||
|
|
f4aa72373b | ||
|
|
3cb9ecae78 | ||
|
|
88caf4f5b6 | ||
|
|
a75ee50533 | ||
|
|
8e941417a5 | ||
|
|
e8d2bbd2c9 | ||
|
|
065a53b997 | ||
|
|
ca5a222aec | ||
|
|
4320c73336 | ||
|
|
7f98265272 | ||
|
|
0b75a8e94e | ||
|
|
eb3e237e47 | ||
|
|
b1796c0acb | ||
|
|
bff10e5711 | ||
|
|
0f559f3f97 | ||
|
|
34aead4d49 | ||
|
|
7cc01e155c | ||
|
|
7fe5fb92b4 | ||
|
|
b084f8a616 | ||
|
|
802a2f3fdb | ||
|
|
06f6f2ff21 | ||
|
|
b37198106d | ||
|
|
604928adc4 | ||
|
|
4a6762540d | ||
|
|
af5176be70 | ||
|
|
482006ed1a | ||
|
|
5923e20b7e | ||
|
|
14cca4610b | ||
|
|
2dbb0093c1 | ||
|
|
d91b6e9a1b | ||
|
|
ada55bd9e2 | ||
|
|
5113de875e | ||
|
|
e079006a4b | ||
|
|
07561794e9 | ||
|
|
75a0da31fb | ||
|
|
33ee2a43c5 | ||
|
|
dcb6a88c63 | ||
|
|
eeda822196 | ||
|
|
060f59daa8 | ||
|
|
4117614861 | ||
|
|
e76440e940 | ||
|
|
f8490a8850 | ||
|
|
ee1cc99c65 | ||
|
|
dcf7e7cf0c | ||
|
|
4c8bcd918b | ||
|
|
a26bb0390d | ||
|
|
26a0df8253 | ||
|
|
526d99f832 | ||
|
|
acbb5be6ab | ||
|
|
522a29241b | ||
|
|
b8d3c84d3c | ||
|
|
9d520877d1 | ||
|
|
5cda0581cd | ||
|
|
ce2e9de6fb | ||
|
|
4d53fb97b6 | ||
|
|
d274a8395b | ||
|
|
ba86f516d8 | ||
|
|
ac02c763c7 | ||
|
|
7407a6b144 | ||
|
|
0453e05bb2 | ||
|
|
946a93164a | ||
|
|
fe02cae4f7 | ||
|
|
5762eb9b33 | ||
|
|
73ffc4a13f | ||
|
|
865ef2ab7f | ||
|
|
7d35ed4eda | ||
|
|
ec3cc6abe8 | ||
|
|
6f7957fd40 | ||
|
|
ec4de3326e | ||
|
|
f030618d19 | ||
|
|
5bcb9010f6 | ||
|
|
780fff70c4 | ||
|
|
1d94d7e604 | ||
|
|
a6cac2886b | ||
|
|
2566b8732e | ||
|
|
d4c50383af | ||
|
|
1ee7bd2a60 | ||
|
|
0bbfa9b483 | ||
|
|
2cad1b3d93 | ||
|
|
bcaa1043ea | ||
|
|
0b33d1800d | ||
|
|
946942214f | ||
|
|
cd6476e487 | ||
|
|
0b02fd4e99 | ||
|
|
d779a94cfb | ||
|
|
2f89a8eb58 | ||
|
|
26d3375900 | ||
|
|
b06e8c3022 | ||
|
|
8a20f8b2da | ||
|
|
e1099e9370 | ||
|
|
68c8901c2a | ||
|
|
cfb1aebf66 | ||
|
|
e4f54bd53a | ||
|
|
30ea4dd46e | ||
|
|
d5c33a203d | ||
|
|
087c09cc65 | ||
|
|
a9bb2a017e | ||
|
|
8a049b8ee7 | ||
|
|
37efd93725 | ||
|
|
3e61803e89 | ||
|
|
3173d88f3f | ||
|
|
f96a898c51 | ||
|
|
d66b79f468 | ||
|
|
b7e300d155 | ||
|
|
4bd680cec8 | ||
|
|
78ae892db6 | ||
|
|
d748e371e5 | ||
|
|
6bdc89252e | ||
|
|
c104f0167f | ||
|
|
6e3c6d1ba8 | ||
|
|
b77262ba13 | ||
|
|
960ebb13db | ||
|
|
1a7b331a4b | ||
|
|
3092e07281 | ||
|
|
a5d53d1ac8 | ||
|
|
3c5df28101 | ||
|
|
49e071d363 | ||
|
|
6e06ff048d | ||
|
|
c5ee39f54b | ||
|
|
f7b1e4ec09 | ||
|
|
e6830b2c19 | ||
|
|
fe3cf386c3 | ||
|
|
0a6a213891 | ||
|
|
2103e691db | ||
|
|
cf15a99730 | ||
|
|
a3102b552c | ||
|
|
bd0257cbe5 | ||
|
|
56e7b2a592 | ||
|
|
61d030748c | ||
|
|
f59ed991fe | ||
|
|
2bdf958663 | ||
|
|
bd8b6a2a64 | ||
|
|
88528e338b | ||
|
|
88b3bf1887 | ||
|
|
6907df1457 | ||
|
|
19036c14f5 | ||
|
|
ddb1236f2f | ||
|
|
30ef9c6418 | ||
|
|
8763fd1c53 | ||
|
|
5976005c4a | ||
|
|
63eed8994a | ||
|
|
f458dbdbcb | ||
|
|
b7421fd5cd | ||
|
|
a2feb04509 | ||
|
|
e25fee71a2 | ||
|
|
bfe2a6656c | ||
|
|
e15ca5c642 | ||
|
|
3232c5be86 | ||
|
|
1c5a50d4cb | ||
|
|
4ef5f77161 | ||
|
|
d27e5a5e1d | ||
|
|
7ecf76490c | ||
|
|
12120413f9 | ||
|
|
c0eea6e667 | ||
|
|
5c54aecdda | ||
|
|
5cfc0cce14 | ||
|
|
d9a58ef830 | ||
|
|
dfd85da9d7 | ||
|
|
94edc13393 | ||
|
|
a9baa519f3 | ||
|
|
a6c859c9cc | ||
|
|
f9a67b34b2 | ||
|
|
6ac5735d14 | ||
|
|
9d5e8b9ad8 | ||
|
|
bd72ee9cd1 | ||
|
|
c2e115b6a5 | ||
|
|
61ba4cd1ce | ||
|
|
244e0fa5e6 | ||
|
|
134bc44c45 | ||
|
|
1d2dc98f50 | ||
|
|
7a05b89a93 | ||
|
|
2bfeb20550 | ||
|
|
fa779034b5 | ||
|
|
ea5cfdcdce | ||
|
|
ba1eab1bf0 | ||
|
|
149c60bd2e | ||
|
|
9795a27482 | ||
|
|
baccdba75c | ||
|
|
93b4c6291a | ||
|
|
815edf1ba5 | ||
|
|
df7b4d81c7 | ||
|
|
3e07ba1012 | ||
|
|
32c6906750 | ||
|
|
3ebe4c47ba | ||
|
|
5b803f00e1 | ||
|
|
9a0118d991 | ||
|
|
093aae1f46 | ||
|
|
e431318dc0 | ||
|
|
c15812add2 | ||
|
|
3375cdbb49 | ||
|
|
559b564714 | ||
|
|
3ac4cfb9a7 | ||
|
|
a4d651ce9a | ||
|
|
d3bbc0eaa5 | ||
|
|
9ff90c98cd | ||
|
|
b8aaf7d7b1 | ||
|
|
c0ecde90bc | ||
|
|
83719a6f48 | ||
|
|
28011bbf55 | ||
|
|
88170f6dc4 | ||
|
|
931aab22bb | ||
|
|
6cb4fbb1c4 | ||
|
|
54a551e488 | ||
|
|
5a0d84f185 | ||
|
|
222396759b | ||
|
|
128c0ed5a1 | ||
|
|
ea74e34446 | ||
|
|
c7225a059f | ||
|
|
c1f8ae662f | ||
|
|
7d3227128c | ||
|
|
182b6755f5 | ||
|
|
0945f79ced | ||
|
|
8b611322e5 | ||
|
|
b255796b33 | ||
|
|
2ae7c60780 | ||
|
|
279ad90a3c | ||
|
|
bed7a7d29c | ||
|
|
f02a3c5b47 | ||
|
|
d7df5126ce | ||
|
|
97ecfe7e03 | ||
|
|
f30fde3a52 | ||
|
|
d7273dee1c | ||
|
|
55dff4d512 | ||
|
|
693b21188c | ||
|
|
220734ccac | ||
|
|
bf84024d6b | ||
|
|
7bb39ae541 | ||
|
|
d250057a7c | ||
|
|
d07454659a | ||
|
|
913d2984ce | ||
|
|
e2d75c0b76 | ||
|
|
8aba486295 | ||
|
|
66f2cd81a8 | ||
|
|
87bda9e124 | ||
|
|
954d019895 | ||
|
|
41132af773 | ||
|
|
9a5b89da59 | ||
|
|
c12ffa21da | ||
|
|
0b5937a396 | ||
|
|
773bb0651e | ||
|
|
8817b1e2af | ||
|
|
366ee6d24b | ||
|
|
0d58869d6e | ||
|
|
52ba3c7f80 | ||
|
|
14d2bae238 | ||
|
|
e331512473 | ||
|
|
1de6a21f3a | ||
|
|
43d8c81104 | ||
|
|
89930f34d7 | ||
|
|
59ea6b120c | ||
|
|
7c312d358b | ||
|
|
ac2746f680 | ||
|
|
e2b4178f42 | ||
|
|
266954be99 | ||
|
|
2e3ae9decb | ||
|
|
6741698f71 | ||
|
|
ccae1cc430 | ||
|
|
241a5bf4e5 | ||
|
|
e36aba8c66 | ||
|
|
1a0baef147 | ||
|
|
9a49d267eb | ||
|
|
7a832f1fdb | ||
|
|
16c391c78c | ||
|
|
92aae63af2 | ||
|
|
b042644c85 | ||
|
|
97afc4bd0c | ||
|
|
a67b29a576 | ||
|
|
97c87d0a99 | ||
|
|
fedf8d9935 | ||
|
|
23bfb84e38 | ||
|
|
c7d16fbf9e | ||
|
|
033a3dd620 | ||
|
|
f5a0b2fed8 | ||
|
|
b03dcfb7de | ||
|
|
502094439c | ||
|
|
c15f812366 | ||
|
|
dd1b102282 | ||
|
|
67b3cdc7b7 | ||
|
|
051994bdf4 | ||
|
|
0f7c12b517 | ||
|
|
aa2b0090d3 | ||
|
|
00b27c20da | ||
|
|
7ecd7e84d9 | ||
|
|
49c2dbd4a7 | ||
|
|
cf46535b66 | ||
|
|
91e2e6f207 | ||
|
|
b63434ce2e | ||
|
|
dde6c42421 | ||
|
|
beb6cca88d | ||
|
|
ba2f18ce21 | ||
|
|
c928eded74 | ||
|
|
9baefc2e56 | ||
|
|
313fe2c76c | ||
|
|
53c69e7ad5 | ||
|
|
3ff935d4c4 | ||
|
|
9fa89e8596 | ||
|
|
6c20af07f7 | ||
|
|
56abd7ba70 | ||
|
|
dc1769b28a | ||
|
|
97b863101b | ||
|
|
0a1b62a760 | ||
|
|
f2fa852f1a | ||
|
|
59f4ddf5af | ||
|
|
673d857bd8 | ||
|
|
36be16b3e9 | ||
|
|
390bb1988d | ||
|
|
63deae3ab2 | ||
|
|
710374ed1e | ||
|
|
8f1dc2522a | ||
|
|
9c3dd76e25 | ||
|
|
3328087de1 | ||
|
|
ec3f5ff40b | ||
|
|
3b000f080e | ||
|
|
09046c53ef | ||
|
|
13331d3eab | ||
|
|
a2a1a557f5 | ||
|
|
fff4cc8b0d | ||
|
|
aa0fc6dfe7 | ||
|
|
c639ac0c5a | ||
|
|
45aa77079d | ||
|
|
8e57090a75 | ||
|
|
e7cb8c8b4f | ||
|
|
57002aca36 | ||
|
|
5956d3ec77 | ||
|
|
2d522de701 | ||
|
|
aef987d832 | ||
|
|
c5d90745a0 | ||
|
|
1d160762b5 | ||
|
|
b45b9e5ccf | ||
|
|
4b9931c417 | ||
|
|
34424d7a00 | ||
|
|
7cd32fc4eb | ||
|
|
c9097566e2 | ||
|
|
e26556c631 | ||
|
|
bd32dce19a | ||
|
|
152a3f2e5f | ||
|
|
4fe6815062 | ||
|
|
525979afaa | ||
|
|
93a10f33d5 | ||
|
|
c9b4fb418a | ||
|
|
2151bf8f9a | ||
|
|
fa64ef6f00 | ||
|
|
a31c0e9082 | ||
|
|
365ce29761 | ||
|
|
93ca98d3a8 | ||
|
|
6e86a498ad | ||
|
|
94cfe30b77 | ||
|
|
cca3acc035 | ||
|
|
f0e3fd9e72 | ||
|
|
8388163aaf | ||
|
|
a203214ef9 | ||
|
|
4250893d2f | ||
|
|
0c1e2a7347 | ||
|
|
d5c35a1d83 | ||
|
|
722036f10e | ||
|
|
8eab74ea81 | ||
|
|
473d38c846 | ||
|
|
a9fb1b25a8 | ||
|
|
360dbd9e5e | ||
|
|
8c4f9d913d | ||
|
|
e4b1377b0e | ||
|
|
fc5e0fb012 | ||
|
|
9a140643c8 | ||
|
|
5fbba7bc01 | ||
|
|
4cf7ab3425 | ||
|
|
b7f93bd4ea | ||
|
|
962a08700e | ||
|
|
d23daf225d | ||
|
|
e5f2b0c0a9 | ||
|
|
6aa80b07e7 | ||
|
|
be0ae2389c | ||
|
|
7d8b6d149e | ||
|
|
a47fbc18f7 | ||
|
|
47ad802ab6 | ||
|
|
8a3e786294 | ||
|
|
4018b284e3 | ||
|
|
b704d42fe4 | ||
|
|
5dab2802b3 | ||
|
|
377fbed517 | ||
|
|
eab0a73f53 | ||
|
|
558170582a | ||
|
|
10ffaec730 | ||
|
|
f17876969d | ||
|
|
81777a29d5 | ||
|
|
3944786c13 | ||
|
|
af939fad66 | ||
|
|
79f8f3eb14 | ||
|
|
9137b38fb9 | ||
|
|
4bb5ee4b17 | ||
|
|
022c8502c0 | ||
|
|
b601ba55d0 | ||
|
|
8de3571aa8 | ||
|
|
5a6bc4404a | ||
|
|
17eb4a2660 | ||
|
|
81124780d0 | ||
|
|
aed7e14d4b | ||
|
|
6835c344eb | ||
|
|
0b965d1ee4 | ||
|
|
ed184acb40 | ||
|
|
7d7eac5030 | ||
|
|
68dbb13084 | ||
|
|
27d335ebe1 | ||
|
|
900e035412 | ||
|
|
bc552d326c | ||
|
|
7ffc983edd | ||
|
|
4a81d366bb | ||
|
|
383a51dde8 | ||
|
|
2a6060e425 | ||
|
|
576269dae9 | ||
|
|
ac34e0e108 | ||
|
|
11bd4c3223 | ||
|
|
8d88a92fe4 | ||
|
|
6004a35e23 | ||
|
|
a3a633242f | ||
|
|
4ad579d4ad | ||
|
|
2666c7312f | ||
|
|
516f30a307 | ||
|
|
9d3d50c654 | ||
|
|
453fbbed1b | ||
|
|
0ce8ab7bce | ||
|
|
d72128107e | ||
|
|
3b8dc924c3 | ||
|
|
08ac287726 | ||
|
|
a8d6f40794 | ||
|
|
a2071feeb1 | ||
|
|
aa705b07f3 | ||
|
|
fbbc1981ca | ||
|
|
6528bd0e4f | ||
|
|
81a07899ae | ||
|
|
c18d8fa967 | ||
|
|
3caa91cc36 | ||
|
|
0bdf3542e4 | ||
|
|
23769371bc | ||
|
|
bccd854676 | ||
|
|
2fa0910547 | ||
|
|
c170b1b83e | ||
|
|
be6016a972 | ||
|
|
a56f66e721 | ||
|
|
e589d7f1e1 | ||
|
|
948cde1a31 | ||
|
|
3447aaa8c6 | ||
|
|
688c64ce21 | ||
|
|
7eb42dc36b | ||
|
|
ae1c1b3a47 | ||
|
|
74078552df | ||
|
|
5da8206915 | ||
|
|
f271726cd8 | ||
|
|
22f6612354 | ||
|
|
74fe5bc4dd | ||
|
|
69d7011baf | ||
|
|
0301d4462b | ||
|
|
7c009e2443 | ||
|
|
a16d9f91ee | ||
|
|
7e76c85535 | ||
|
|
3054694726 | ||
|
|
a25021d215 | ||
|
|
532833ff70 | ||
|
|
e79a66851c | ||
|
|
97825fb2c7 | ||
|
|
bd9df7e619 | ||
|
|
087f09e9a6 | ||
|
|
1257b32464 | ||
|
|
a437af44f8 | ||
|
|
9644610e04 | ||
|
|
71cbe1cf50 | ||
|
|
edad2a1ee5 | ||
|
|
0e597f5768 | ||
|
|
b28dc55237 | ||
|
|
a2dec7a05d | ||
|
|
db9fb22cf4 | ||
|
|
412a00249f | ||
|
|
ccb7a8f94f | ||
|
|
ee26e13bea | ||
|
|
493ff9c685 | ||
|
|
bbc49e1ba3 | ||
|
|
0ef39e4440 | ||
|
|
8a956bcdf6 | ||
|
|
a16ff29638 | ||
|
|
f6381e7e5e | ||
|
|
e014765797 | ||
|
|
3899684686 | ||
|
|
e11b457b79 | ||
|
|
a04cbd111c | ||
|
|
6c7d3e1eab | ||
|
|
d965b41bdd | ||
|
|
d660c12a74 | ||
|
|
43bcbf771e | ||
|
|
7f420361b1 | ||
|
|
361455678a | ||
|
|
47c1c6288c | ||
|
|
07abc9fac4 | ||
|
|
266923d9e8 | ||
|
|
622ff9d764 | ||
|
|
b75d11da3a | ||
|
|
8af49161fb | ||
|
|
ca872af3c8 | ||
|
|
aeccf45d4e | ||
|
|
dcae0eadd5 | ||
|
|
80effaa541 | ||
|
|
edd93c80a1 | ||
|
|
39646acf5b | ||
|
|
f697d2daa1 | ||
|
|
607631604f | ||
|
|
09d012a10b | ||
|
|
b303d49634 | ||
|
|
371723a5d4 | ||
|
|
4481c3bada | ||
|
|
70bb30b95a | ||
|
|
ebc641440e | ||
|
|
586b4db968 | ||
|
|
12c7981450 | ||
|
|
08c909fd41 | ||
|
|
44e43d3b47 | ||
|
|
9e8273c7f7 | ||
|
|
93735c7bf1 | ||
|
|
e37a97e2d5 | ||
|
|
8ff5450ece | ||
|
|
5d30ddac22 | ||
|
|
80f697ef2a | ||
|
|
47c7748707 | ||
|
|
9f33aa2afc | ||
|
|
1dc6600b59 | ||
|
|
1ec58c1161 | ||
|
|
d023d577b2 | ||
|
|
21d65ca0bf | ||
|
|
bcf4401858 | ||
|
|
262396d48b | ||
|
|
0a9d5f680f | ||
|
|
64239f1c04 | ||
|
|
7590d546f1 | ||
|
|
021070f066 | ||
|
|
55a4318839 | ||
|
|
90647f30f8 | ||
|
|
8cc9080d36 | ||
|
|
6e5fc91885 | ||
|
|
71de2b5ec5 | ||
|
|
7703f91ee2 | ||
|
|
ecc8abcc50 | ||
|
|
14917c9791 | ||
|
|
25c56164b0 | ||
|
|
12988b879e | ||
|
|
684e391a9a | ||
|
|
7a16cd4c37 | ||
|
|
b3117c2b02 | ||
|
|
6a75fa83b5 | ||
|
|
88a8721b89 | ||
|
|
1f12857551 | ||
|
|
71032f6c4c | ||
|
|
088b1cab83 | ||
|
|
f40a534bfb | ||
|
|
f278530239 | ||
|
|
0389aab0a3 | ||
|
|
51a66a3202 | ||
|
|
248985e51a | ||
|
|
996d83eae0 | ||
|
|
98a1329dd7 | ||
|
|
ed2ebc7d3d | ||
|
|
41634f9998 | ||
|
|
93501af046 | ||
|
|
078585db28 | ||
|
|
03e9e4c1d9 | ||
|
|
4a1d077238 | ||
|
|
f7a5e6deb8 | ||
|
|
dabb22bb6a | ||
|
|
3d03ca3d10 | ||
|
|
386992c3b8 | ||
|
|
a48f252cfa | ||
|
|
c3a311ab85 | ||
|
|
7926e1bc3c | ||
|
|
b796db648a | ||
|
|
0964ecac8c | ||
|
|
dd1ac7952b | ||
|
|
7d1cbcb0c1 | ||
|
|
98c9e67625 | ||
|
|
aeef66ce35 | ||
|
|
8cff66e8c6 | ||
|
|
10a04acf41 | ||
|
|
9923a4c4ff | ||
|
|
0dafa9e229 | ||
|
|
e83e8a8f1c | ||
|
|
72aa768235 | ||
|
|
65c74e3976 | ||
|
|
cdac34efea | ||
|
|
03fef3106d | ||
|
|
d598d0a4db | ||
|
|
ab22e1b3a9 | ||
|
|
26d520af3c | ||
|
|
fb333f3641 | ||
|
|
1cc65a47eb | ||
|
|
8d56c52991 | ||
|
|
4b88b9eed1 | ||
|
|
462b91fb08 | ||
|
|
b65f4ff963 | ||
|
|
8d27b48225 | ||
|
|
e2623c5e82 | ||
|
|
acdae42fc5 | ||
|
|
451aac806e | ||
|
|
586e6178b4 | ||
|
|
1201761ff3 | ||
|
|
bdf68f092e | ||
|
|
a179f87d54 | ||
|
|
b2944a12de | ||
|
|
bfcb36927c | ||
|
|
ccd21d5254 | ||
|
|
a7b8448107 | ||
|
|
e934be2d99 | ||
|
|
015b875a9e | ||
|
|
1247ff2543 | ||
|
|
dc831fb3f6 | ||
|
|
94c0e947f5 | ||
|
|
ed9bc835a2 | ||
|
|
2eb2e52a79 | ||
|
|
14f6f88526 | ||
|
|
1f78c74085 | ||
|
|
c494649dde | ||
|
|
460f3aebe9 | ||
|
|
d4b215a66b | ||
|
|
1a13387012 | ||
|
|
291c36df05 | ||
|
|
bed2c8a371 | ||
|
|
e65ca4ccac | ||
|
|
f9e6933840 | ||
|
|
5134fb2ec1 | ||
|
|
3a86a69964 | ||
|
|
c6fd3c47a4 | ||
|
|
a365fa6109 | ||
|
|
160451b210 | ||
|
|
2f6e3cc09d | ||
|
|
d05cc7ccec | ||
|
|
ccfd4acbda | ||
|
|
6a6084ed0e | ||
|
|
0dbb780a2f | ||
|
|
e6efa6e13e | ||
|
|
76768120d4 | ||
|
|
7d6ff83760 | ||
|
|
5bec0d2d98 | ||
|
|
aad05325a6 | ||
|
|
6e7f1bc257 | ||
|
|
634d0848c8 | ||
|
|
b7e1059227 | ||
|
|
e7904fa67a | ||
|
|
e38bc7cbce | ||
|
|
b211f8a096 | ||
|
|
b4a1a6c688 | ||
|
|
6cb4b790b9 | ||
|
|
a245bdbc2a | ||
|
|
e63451a9e7 | ||
|
|
e552607c95 | ||
|
|
c7f1c5e29c | ||
|
|
37b6e22321 | ||
|
|
6e6ae18aab | ||
|
|
9f3cda0ac3 | ||
|
|
f646975c36 | ||
|
|
801cae13ac | ||
|
|
f1ae502b1f | ||
|
|
f2e34d4836 | ||
|
|
3c6a8d718f | ||
|
|
08eb28f7b8 | ||
|
|
24509a21d4 | ||
|
|
4f41a10fef | ||
|
|
26aa8b69f9 | ||
|
|
819db1524f | ||
|
|
8ad7d06ec6 | ||
|
|
606898f569 | ||
|
|
76c6adf1cf | ||
|
|
e504c3cd46 | ||
|
|
884b59a0b3 | ||
|
|
a32dedd16c | ||
|
|
ff2b37f6e3 | ||
|
|
4328ae1d8d | ||
|
|
88372000b5 | ||
|
|
081150b477 | ||
|
|
1364b97b88 | ||
|
|
7c33a46a76 | ||
|
|
8b88e9f727 | ||
|
|
91f0728b55 | ||
|
|
7a71cea92a | ||
|
|
29a855813d | ||
|
|
66da2339d4 | ||
|
|
294254efbb | ||
|
|
188597ecaf | ||
|
|
d04f613c41 | ||
|
|
25320cd0e0 | ||
|
|
00b4f09e8a | ||
|
|
fb8d9edfdf | ||
|
|
349b9bb2bf | ||
|
|
cbff11296b | ||
|
|
dc462cdc1f | ||
|
|
22024e7c1f | ||
|
|
ebb0145256 | ||
|
|
c3215d0ba5 | ||
|
|
da83f20a28 | ||
|
|
ad4b0fff56 | ||
|
|
62b90206e8 | ||
|
|
38ac4fe849 | ||
|
|
fa7b6591cf | ||
|
|
fde432601a | ||
|
|
0c954dde27 | ||
|
|
b5a86a9045 | ||
|
|
ef7c437957 | ||
|
|
8158a509c9 | ||
|
|
dc520c6c32 | ||
|
|
907033f725 | ||
|
|
533a005764 | ||
|
|
9ee563b864 | ||
|
|
748c118ea8 | ||
|
|
69e69a77d8 | ||
|
|
5a40cec1ed | ||
|
|
01bcd460da | ||
|
|
2a96c9f9ee | ||
|
|
f610e31a87 | ||
|
|
4ec0b61de5 | ||
|
|
c7d7cec281 | ||
|
|
c4775a581e | ||
|
|
591eaeaafb | ||
|
|
1f45a846c6 | ||
|
|
db943b4109 | ||
|
|
098eadefe0 | ||
|
|
13b2e072d2 | ||
|
|
c068a300f4 | ||
|
|
60b91ac678 | ||
|
|
c979ab01af | ||
|
|
012b4025a4 | ||
|
|
ff04d9f03c | ||
|
|
ed34cd45f1 | ||
|
|
7dc8fab961 | ||
|
|
14acb1af8c | ||
|
|
678fa006de | ||
|
|
f5416ebce0 | ||
|
|
585063f6e1 | ||
|
|
494f12090f | ||
|
|
55321b8778 | ||
|
|
a6b0fa546a | ||
|
|
33ea0dbdee | ||
|
|
a559480716 | ||
|
|
bdbd9a0f5f | ||
|
|
945344b3cd | ||
|
|
5759ce9ba0 | ||
|
|
a350b666fa | ||
|
|
041409d715 | ||
|
|
98b31ed073 | ||
|
|
00cea4ff83 | ||
|
|
617bcdac9f | ||
|
|
116b3db1d1 | ||
|
|
53d2398e06 | ||
|
|
dd0e42cf72 | ||
|
|
b0d6d40c2a | ||
|
|
2d568b1c0f | ||
|
|
5b13e75fa5 | ||
|
|
23725680c9 | ||
|
|
f49141f71e | ||
|
|
fdff5e33b3 | ||
|
|
149cc499ed | ||
|
|
2e145ea916 | ||
|
|
1edec9ff89 | ||
|
|
a559a371b1 | ||
|
|
7d29c6a0f7 | ||
|
|
5ad51c36fb | ||
|
|
03dd2883f7 | ||
|
|
7208104122 | ||
|
|
405710e635 | ||
|
|
f6ba5a41da | ||
|
|
af6cfd0ea8 | ||
|
|
a3f822b7d3 | ||
|
|
afdaa4d0d8 | ||
|
|
bf5eec727e | ||
|
|
f82151f925 | ||
|
|
4b926b7c7f | ||
|
|
4aa4f1c3b3 | ||
|
|
71aff9f0e8 | ||
|
|
a40daca9ef | ||
|
|
0b97d9bae5 | ||
|
|
28e6a84acb | ||
|
|
fc62d3b44e | ||
|
|
b06d9e50eb | ||
|
|
1d4427c056 | ||
|
|
51d60a6035 | ||
|
|
f5fa4a460a | ||
|
|
977841a7f3 | ||
|
|
b000c75947 | ||
|
|
f3d9193743 | ||
|
|
0d04bf8e34 | ||
|
|
1d17690f69 | ||
|
|
4d19be8ea4 | ||
|
|
1d4dfdf271 | ||
|
|
f24a95c917 | ||
|
|
e508842da6 | ||
|
|
b0d9bbc0b1 | ||
|
|
6238770324 | ||
|
|
a8641c69cc | ||
|
|
7d9332e94f | ||
|
|
7ca17b7bd9 | ||
|
|
e5670d5e3c | ||
|
|
826c1bd894 | ||
|
|
7ea7f87a9f | ||
|
|
b91d11431d | ||
|
|
ff31b16285 | ||
|
|
81cf5333c3 | ||
|
|
9dca983e33 | ||
|
|
0f43a2fe9b | ||
|
|
ecdf8e1591 | ||
|
|
8a5de60b33 | ||
|
|
8637e270a9 | ||
|
|
c278310d1b | ||
|
|
7f58e66754 | ||
|
|
4e27f8de27 | ||
|
|
445b0438a2 | ||
|
|
23441191c3 |
57
Jamfile
@@ -1,57 +0,0 @@
|
||||
subproject libs/python ;
|
||||
|
||||
# bring in the rules for python
|
||||
SEARCH on <module@>python.jam = $(BOOST_BUILD_PATH) ;
|
||||
include <module@>python.jam ;
|
||||
|
||||
PYTHON_PROPERTIES
|
||||
+= <metrowerks><*><cxxflags>"-inline deferred"
|
||||
<cxx><*><include>$(BOOST_ROOT)/boost/compatibility/cpp_c_headers
|
||||
;
|
||||
|
||||
local export-bpl ;
|
||||
|
||||
if $(NT)
|
||||
{
|
||||
# Stick this in the property set to deal with gcc
|
||||
export-bpl = export-bpl-logic ;
|
||||
|
||||
rule export-bpl-logic ( toolset variant : properties * )
|
||||
{
|
||||
if $(toolset) != gcc
|
||||
{
|
||||
properties += <define>BOOST_PYTHON_EXPORT=__declspec(dllexport) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
properties += <define>BOOST_PYTHON_EXPORT= ;
|
||||
}
|
||||
return $(properties) ;
|
||||
}
|
||||
}
|
||||
|
||||
dll bpl
|
||||
:
|
||||
src/converter/body.cpp
|
||||
src/converter/handle.cpp
|
||||
src/converter/registry.cpp
|
||||
src/converter/wrapper.cpp
|
||||
src/converter/unwrap.cpp
|
||||
src/converter/unwrapper.cpp
|
||||
src/converter/type_id.cpp
|
||||
src/object/class.cpp
|
||||
src/object/function.cpp
|
||||
:
|
||||
$(PYTHON_PROPERTIES)
|
||||
$(export-bpl)
|
||||
# <define>BOOST_PYTHON_TRACE
|
||||
;
|
||||
|
||||
extension m1 : test/m1.cpp <lib>bpl # <define>BOOST_PYTHON_TRACE
|
||||
: <gcc><*><define>BOOST_PYTHON_EXPORT=
|
||||
: debug-python ;
|
||||
extension m2 : test/m2.cpp <lib>bpl # <define>BOOST_PYTHON_TRACE
|
||||
: <gcc><*><define>BOOST_PYTHON_EXPORT=
|
||||
: debug-python ;
|
||||
|
||||
boost-python-runtest try : test/newtest.py <lib>m1 <lib>m2 : : debug-python ;
|
||||
@@ -1,308 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<title>A New Type Conversion Mechanism for Boost.Python</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<p><img border="0" src="../../../c++boost.gif" width="277" height="86"
|
||||
alt="boost logo"></p>
|
||||
|
||||
<h1>A New Type Conversion Mechanism for Boost.Python</h1>
|
||||
|
||||
<p>By <a href="../../../people/dave_abrahams.htm">David Abrahams</a>.
|
||||
|
||||
<h2>Introduction</h2>
|
||||
|
||||
This document describes a redesign of the mechanism for automatically
|
||||
converting objects between C++ and Python. The current implementation
|
||||
uses two functions for any type <tt>T</tt>:
|
||||
|
||||
<blockquote><pre>
|
||||
U from_python(PyObject*, type<T>);
|
||||
void to_python(V);
|
||||
</pre></blockquote>
|
||||
|
||||
where U is convertible to T and T is convertible to V. These functions
|
||||
are at the heart of C++/Python interoperability in Boost.Python, so
|
||||
why would we want to change them? There are many reasons:
|
||||
|
||||
<h3>Bugs</h3>
|
||||
<p>Firstly, the current mechanism relies on a common C++ compiler
|
||||
bug. This is not just embarrassing: as compilers get to be more
|
||||
conformant, the library stops working. The issue, in detail, is the
|
||||
use of inline friend functions in templates to generate
|
||||
conversions. It is a very powerful, and legal technique as long as
|
||||
it's used correctly:
|
||||
|
||||
<blockquote><pre>
|
||||
template <class Derived>
|
||||
struct add_some_functions
|
||||
{
|
||||
friend <i>return-type</i> some_function1(..., Derived <i>cv-*-&-opt</i>, ...);
|
||||
friend <i>return-type</i> some_function2(..., Derived <i>cv-*-&-opt</i>, ...);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct some_template : add_some_functions<some_template<T> >
|
||||
{
|
||||
};
|
||||
</pre></blockquote>
|
||||
|
||||
The <tt>add_some_functions</tt> template generates free functions
|
||||
which operate on <tt>Derived</tt>, or on related types. Strictly
|
||||
speaking the related types are not just cv-qualified <tt>Derived</tt>
|
||||
values, pointers and/or references. Section 3.4.2 in the standard
|
||||
describes exactly which types you must use as parameters to these
|
||||
functions if you want the functions to be found
|
||||
(there is also a less-technical description in section 11.5.1 of
|
||||
C++PL3 <a href="#ref_1">[1]</a>). Suffice it to say that
|
||||
with the current design, the <tt>from_python</tt> and
|
||||
<tt>to_python</tt> functions are not supposed to be callable under any
|
||||
conditions!
|
||||
|
||||
<h3>Compilation and Linking Time</h3>
|
||||
|
||||
The conversion functions generated for each wrapped class using the
|
||||
above technique are not function templates, but regular functions. The
|
||||
upshot is that they must <i>all</i> be generated regardless of whether
|
||||
they are actually used. Generating all of those functions can slow
|
||||
down module compilation, and resolving the references can slow down
|
||||
linking.
|
||||
|
||||
<h3>Efficiency</h3>
|
||||
|
||||
The conversion functions are primarily used in (member) function
|
||||
wrappers to convert the arguments and return values. Being functions,
|
||||
converters have no interface which allows us to ask "will the
|
||||
conversion succeed?" without calling the function. Since the
|
||||
return value of the function must be the object to be passed as an
|
||||
argument, Boost.Python currently uses C++ exception-handling to detect
|
||||
an unsuccessful conversion. It's not a particularly good use of
|
||||
exception-handling, since the failure is not handled very far from
|
||||
where it occurred. More importantly, it means that C++ exceptions are
|
||||
thrown during overload resolution as we seek an overload that matches
|
||||
the arguments passed. Depending on the implementation, this approach
|
||||
can result in significant slowdowns.
|
||||
|
||||
<p>It is also unclear that the current library generates a minimal
|
||||
amount of code for any type conversion. Many of the conversion
|
||||
functions are nontrivial, and partly because of compiler limitations,
|
||||
they are declared <tt>inline</tt>. Also, we could have done a better
|
||||
job separating the type-specific conversion code from the code which
|
||||
is type-independent.
|
||||
|
||||
<h3>Cross-module Support</h3>
|
||||
|
||||
The current strategy requires every module to contain the definition
|
||||
of conversions it uses. In general, a new module can never supply
|
||||
conversion code which is used by another module. Ralf Grosse-Kunstleve
|
||||
designed a clever system which imports conversions directly from one
|
||||
library into another using some explicit declarations, but it has some
|
||||
disadvantages also:
|
||||
|
||||
<ol>
|
||||
<li>The system Ullrich Koethe designed for implicit conversion between
|
||||
wrapped classes related through inheritance does not currently work if
|
||||
the classes are defined in separate modules.
|
||||
|
||||
<li>The writer of the importing module is required to know the name of
|
||||
the module supplying the imported conversions.
|
||||
|
||||
<li>There can be only one way to extract any given C++ type from a
|
||||
Python object in a given module.
|
||||
</ol>
|
||||
|
||||
The first item might be addressed by moving Boost.Python into a shared
|
||||
library, but the other two cannot. Ralf turned the limitation in item
|
||||
two into a feature: the required module is loaded implicitly when a
|
||||
conversion it defines is invoked. We will probably want to provide
|
||||
that functionality anyway, but it's not clear that we should require
|
||||
the declaration of all such conversions. The final item is a more
|
||||
serious limitation. If, for example, new numeric types are defined in
|
||||
separate modules, and these types can all be converted to
|
||||
<tt>double</tt>s, we have to choose just one conversion method.
|
||||
|
||||
<h3>Ease-of-use</h3>
|
||||
|
||||
One persistent source of confusion for users of Boost.Python has been
|
||||
the fact that conversions for a class are not be visible at
|
||||
compile-time until the declaration of that class has been seen. When
|
||||
the user tries to expose a (member) function operating on or returning
|
||||
an instance of the class in question, compilation fails...even though
|
||||
the user goes on to expose the class in the same translation unit!
|
||||
|
||||
<p>
|
||||
The new system lifts all compile-time checks for the existence of
|
||||
particular type conversions and replaces them with runtime checks, in
|
||||
true Pythonic style. While this might seem cavalier, the compile-time
|
||||
checks are actually not much use in the current system if many classes
|
||||
are wrapped in separate modules, since the checks are based only on
|
||||
the user's declaration that the conversions exist.
|
||||
|
||||
<h2>The New Design</h2>
|
||||
|
||||
<h3>Motivation</h3>
|
||||
|
||||
The new design was heavily influenced by a desire to generate as
|
||||
little code as possible in extension modules. Some of Boost.Python's
|
||||
clients are enormous projects where link time is proportional to the
|
||||
amount of object code, and there are many Python extension modules. As
|
||||
such, we try to keep type-specific conversion code out of modules
|
||||
other than the one the converters are defined in, and rely as much as
|
||||
possible on centralized control through a shared library.
|
||||
|
||||
<h3>The Basics</h3>
|
||||
|
||||
The library contains a <tt>registry</tt> which maps runtime type
|
||||
identifiers (actually an extension of <tt>std::type_info</tt> which
|
||||
preserves references and constness) to entries containing type
|
||||
converters. An <tt>entry</tt> can contain only one converter from C++ to Python
|
||||
(<tt>wrapper</tt>), but many converters from Python to C++
|
||||
(<tt>unwrapper</tt>s). <font color="#ff0000">What should happen if
|
||||
multiple modules try to register wrappers for the same type?</font>. Wrappers
|
||||
and unwrappers are known as <tt>body</tt> objects, and are accessed
|
||||
by the user and the library (in its function-wrapping code) through
|
||||
corresponding <tt>handle</tt> (<tt>wrap<T></tt> and
|
||||
<tt>unwrap<T></tt>) objects. The <tt>handle</tt> objects are
|
||||
extremely lightweight, and delegate <i>all</i> of their operations to
|
||||
the corresponding <tt>body</tt>.
|
||||
|
||||
<p>
|
||||
When a <tt>handle</tt> object is constructed, it accesses the
|
||||
registry to find a corresponding <tt>body</tt> that can convert the
|
||||
handle's constructor argument. Actually the registry record for any
|
||||
type
|
||||
<tt>T</tt>used in a module is looked up only once and stored in a
|
||||
static <tt>registration<T></tt> object for efficiency. For
|
||||
example, if the handle is an <tt>unwrap<Foo&></tt> object,
|
||||
the <tt>entry</tt> for <tt>Foo&</tt> is looked up in the
|
||||
<tt>registry</tt>, and each <tt>unwrapper</tt> it contains is queried
|
||||
to determine if it can convert the
|
||||
<tt>PyObject*</tt> with which the <tt>unwrap</tt> was constructed. If
|
||||
a body object which can perform the conversion is found, a pointer to
|
||||
it is stored in the handle. A body object may at any point store
|
||||
additional data in the handle to speed up the conversion process.
|
||||
|
||||
<p>
|
||||
Now that the handle has been constructed, the user can ask it whether
|
||||
the conversion can be performed. All handles can be tested as though
|
||||
they were convertible to <tt>bool</tt>; a <tt>true</tt> value
|
||||
indicates success. If the user forges ahead and tries to do the
|
||||
conversion without checking when no conversion is possible, an
|
||||
exception will be thrown as usual. The conversion itself is performed
|
||||
by the body object.
|
||||
|
||||
<h3>Handling complex conversions</h3>
|
||||
|
||||
<p>Some conversions may require a dynamic allocation. For example,
|
||||
when a Python tuple is converted to a <tt>std::vector<double>
|
||||
const&</tt>, we need some storage into which to construct the
|
||||
vector so that a reference to it can be formed. Furthermore, multiple
|
||||
conversions of the same type may need to be "active"
|
||||
simultaneously, so we can't keep a single copy of the storage
|
||||
anywhere. We could keep the storage in the <tt>body</tt> object, and
|
||||
have the body clone itself in case the storage is used, but in that
|
||||
case the storage in the body which lives in the registry is never
|
||||
used. If the storage was actually an object of the target type (the
|
||||
safest way in C++), we'd have to find a way to construct one for the
|
||||
body in the registry, since it may not have a default constructor.
|
||||
|
||||
<p>
|
||||
The most obvious way out of this quagmire is to allocate the object using a
|
||||
<i>new-expression</i>, and store a pointer to it in the handle. Since
|
||||
the <tt>body</tt> object knows everything about the data it needs to
|
||||
allocate (if any), it is also given responsibility for destroying that
|
||||
data. When the <tt>handle</tt> is destroyed it asks the <tt>body</tt>
|
||||
object to tear down any data it may have stored there. In many ways,
|
||||
you can think of the <tt>body</tt> as a "dynamically-determined
|
||||
vtable" for the handle.
|
||||
|
||||
<h3>Eliminating Redundancy</h3>
|
||||
|
||||
If you look at the current Boost.Python code, you'll see that there
|
||||
are an enormous number of conversion functions generated for each
|
||||
wrapped class. For a given class <tt>T</tt>, functions are generated
|
||||
to extract the following types <tt>from_python</tt>:
|
||||
|
||||
<blockquote><pre>
|
||||
T*
|
||||
T const*
|
||||
T const* const&
|
||||
T* const&
|
||||
T&
|
||||
T const&
|
||||
T
|
||||
std::auto_ptr<T>&
|
||||
std::auto_ptr<T>
|
||||
std::auto_ptr<T> const&
|
||||
boost::shared_ptr<T>&
|
||||
boost::shared_ptr<T>
|
||||
boost::shared_ptr<T> const&
|
||||
</pre></blockquote>
|
||||
|
||||
Most of these are implemented in terms of just a few conversions, and
|
||||
<t>if you're lucky</t>, they will be inlined and cause no extra
|
||||
overhead. In the new system, however, a significant amount of data
|
||||
will be associated with each type that needs to be converted. We
|
||||
certainly don't want to register a separate unwrapper object for all
|
||||
of the above types.
|
||||
|
||||
<p>Fortunately, much of the redundancy can be eliminated. For example,
|
||||
if we generate an unwrapper for <tt>T&</tt>, we don't need an
|
||||
unwrapper for <tt>T const&</tt> or <tt>T</tt>. Accordingly, the user's
|
||||
request to wrap/unwrap a given type is translated at compile-time into
|
||||
a request which helps to eliminate redundancy. The rules used to
|
||||
<tt>unwrap</tt> a type are:
|
||||
|
||||
<ol>
|
||||
<li> Treat built-in types specially: when unwrapping a value or
|
||||
constant reference to one of these, use a value for the target
|
||||
type. It will bind to a const reference if neccessary, and more
|
||||
importantly, avoids having to dynamically allocate room for
|
||||
an lvalue of types which can be cheaply copied.
|
||||
<li>
|
||||
Reduce everything else to a reference to an un-cv-qualified type
|
||||
where possible. Since cv-qualification is lost on Python
|
||||
anyway, there's no point in trying to convert to a
|
||||
<tt>const&</tt>. <font color="#ff0000">What about conversions
|
||||
to values like the tuple->vector example above? It seems to me
|
||||
that we don't want to make a <tt>vector<double>&</tt>
|
||||
(non-const) converter available for that case. We may need to
|
||||
rethink this slightly.</font>
|
||||
</ol>
|
||||
|
||||
<h3>Efficient Argument Conversion</h3>
|
||||
|
||||
Since type conversions are primarily used in function wrappers, an
|
||||
optimization is provided for the case where a group of conversions are
|
||||
used together. Each <tt>handle</tt> class has a corresponding
|
||||
"<tt>_more</tt>" class which does the same job, but has a
|
||||
trivial destructor. Instead of asking each "<tt>_more</tt>"
|
||||
handle to destroy its own body, it is linked into an endogenous list
|
||||
managed by the first (ordinary) handle. The <tt>wrap</tt> and
|
||||
<tt>unwrap</tt> destructors are responsible for traversing that list
|
||||
and asking each <tt>body</tt> class to tear down its
|
||||
<tt>handle</tt>. This mechanism is also used to determine if all of
|
||||
the argument/return-value conversions can succeed with a single
|
||||
function call in the function wrapping code. <font color="#ff0000">We
|
||||
might need to handle return values in a separate step for Python
|
||||
callbacks, since the availablility of a conversion won't be known
|
||||
until the result object is retrieved.</font>
|
||||
|
||||
<br>
|
||||
<hr>
|
||||
<h2>References</h2>
|
||||
|
||||
<p><a name="ref_1">[1]</a>B. Stroustrup, The C++ Programming Language
|
||||
Special Edition Addison-Wesley, ISBN 0-201-70073-5.
|
||||
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->19 December 2001<!--webbot bot="Timestamp" endspan i-checksum="31283" --></p>
|
||||
<p>© Copyright David Abrahams, 2001</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,111 +0,0 @@
|
||||
This hierarchy contains converter handle classes.
|
||||
|
||||
|
||||
+-------------+
|
||||
| noncopyable |
|
||||
+-------------+
|
||||
^
|
||||
| A common base class used so that
|
||||
+--------+--------+ conversions can be linked into a
|
||||
| conversion_base | chain for efficient argument
|
||||
+-----------------+ conversion
|
||||
^
|
||||
|
|
||||
+---------+-----------+
|
||||
| |
|
||||
+-----------+----+ +------+-------+ only used for
|
||||
| unwrap_more<T> | | wrap_more<T> | chaining, and don't manage any
|
||||
+----------------+ +--------------+ resources.
|
||||
^ ^
|
||||
| |
|
||||
+-----+-----+ +-------+-+ These converters are what users
|
||||
| unwrap<T> | | wrap<T> | actually touch, but they do so
|
||||
+-----------+ +---------+ through a type generator which
|
||||
minimizes the number of converters
|
||||
that must be generated, so they
|
||||
|
||||
|
||||
Each unwrap<T>, unwrap_more<T>, wrap<T>, wrap_more<T> converter holds
|
||||
a reference to an appropriate converter object
|
||||
|
||||
This hierarchy contains converter body classes
|
||||
|
||||
Exposes use/release which
|
||||
are needed in case the converter
|
||||
+-----------+ in the registry needs to be
|
||||
| converter | cloned. That occurs when a
|
||||
+-----------+ unwrap target type is not
|
||||
^ contained within the Python object.
|
||||
|
|
||||
+------------------+-----+
|
||||
| |
|
||||
+--------+-------+ Exposes |
|
||||
| unwrapper_base | convertible() |
|
||||
+----------------+ |
|
||||
^ |
|
||||
| |
|
||||
+--------+----+ +-----+-----+
|
||||
| unwrapper<T>| | wrapper<T>|
|
||||
+-------------+ +-----------+
|
||||
Exposes T convert(PyObject*) Exposes PyObject* convert(T)
|
||||
|
||||
|
||||
unwrap:
|
||||
|
||||
constructed with a PyObject*, whose reference count is
|
||||
incremented.
|
||||
|
||||
find the registry entry for the target type
|
||||
|
||||
look in the collection of converters for one which claims to be
|
||||
able to convert the PyObject to the target type.
|
||||
|
||||
stick a pointer to the unwrapper in the unwrap object
|
||||
|
||||
when unwrap is queried for convertibility, it checks to see
|
||||
if it has a pointer to an unwrapper.
|
||||
|
||||
on conversion, the unwrapper is asked to allocate an
|
||||
implementation if the unwrap object isn't already holding
|
||||
one. The unwrap object "takes ownership" of the unwrapper's
|
||||
implementation. No memory allocation will actually take place
|
||||
unless this is a value conversion.
|
||||
|
||||
on destruction, the unwrapper is asked to free any implementation
|
||||
held by the unwrap object. No memory deallocation actually
|
||||
takes place unless this is a value conversion
|
||||
|
||||
on destruction, the reference count on the held PyObject is
|
||||
decremented.
|
||||
|
||||
We need to make sure that by default, you can't instantiate
|
||||
callback<> for reference and pointer return types: although the
|
||||
unwrappers may exist, they may convert by-value, which would cause
|
||||
the referent to be destroyed upon return.
|
||||
|
||||
wrap:
|
||||
|
||||
find the registry entry for the source type
|
||||
|
||||
see if there is a converter. If found, stick a pointer to it in
|
||||
the wrap object.
|
||||
|
||||
when queried for convertibility, it checks to see if it has a
|
||||
pointer to a converter.
|
||||
|
||||
on conversion, a reference to the target PyObject is held by the
|
||||
converter. Generally, the PyObject will have been created by the
|
||||
converter, but in certain cases it may be a pre-existing object,
|
||||
whose reference count will have been incremented.
|
||||
|
||||
when a wrap<T> x is used to return from a C++ function,
|
||||
x.release() is returned so that x no longer holds a reference to
|
||||
the PyObject when destroyed.
|
||||
|
||||
Otherwise, on destruction, any PyObject still held has its
|
||||
reference-count decremented.
|
||||
|
||||
|
||||
When a converter is created by the user, the appropriate element must
|
||||
be added to the registry; when it is destroyed, it must be removed
|
||||
from the registry.
|
||||
@@ -1,210 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_call.py
|
||||
|
||||
#ifndef CALL_DWA20011214_HPP
|
||||
# define CALL_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/returning.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class R>
|
||||
PyObject* call(R (*f)(), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0>
|
||||
PyObject* call(R (*f)(A0), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
PyObject* call(R (*f)(A0, A1), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
PyObject* call(R (*f)(A0, A1, A2), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* call(R (*f)(A0, A1, A2, A3), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* call(R (*f)(A0, A1, A2, A3, A4), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* call(R (*f)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
// Member functions
|
||||
template <class R, class A0>
|
||||
PyObject* call(R (A0::*f)(), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
PyObject* call(R (A0::*f)(A1), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
PyObject* call(R (A0::*f)(A1, A2), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0>
|
||||
PyObject* call(R (A0::*f)() const, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
PyObject* call(R (A0::*f)(A1) const, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
PyObject* call(R (A0::*f)(A1, A2) const, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3) const, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4) const, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0>
|
||||
PyObject* call(R (A0::*f)() volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
PyObject* call(R (A0::*f)(A1) volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
PyObject* call(R (A0::*f)(A1, A2) volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3) volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0>
|
||||
PyObject* call(R (A0::*f)() const volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
PyObject* call(R (A0::*f)(A1) const volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
PyObject* call(R (A0::*f)(A1, A2) const volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3) const volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* call(R (A0::*f)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return detail::returning<R>::call(f, args, keywords);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CALL_DWA20011214_HPP
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONVERT_DWA20011129_HPP
|
||||
# define CONVERT_DWA20011129_HPP
|
||||
|
||||
# include <boost/python/converter/target.hpp>
|
||||
# include <boost/python/converter/source.hpp>
|
||||
# include <boost/python/converter/wrap.hpp>
|
||||
# include <boost/python/converter/unwrap.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct converter_gen
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef typename converter::source<value_type>::type source;
|
||||
typedef converter::wrap_<source> wrap;
|
||||
typedef converter::wrap_more_<source> wrap_more;
|
||||
|
||||
typedef typename converter::target<value_type>::type target;
|
||||
typedef converter::unwrap_<target> unwrap;
|
||||
typedef converter::unwrap_more_<target> unwrap_more;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct wrap : detail::converter_gen<T>::wrap
|
||||
{
|
||||
typedef typename detail::converter_gen<T>::wrap base;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct wrap_more : detail::converter_gen<T>::wrap_more
|
||||
{
|
||||
typedef typename detail::converter_gen<T>::wrap_more base;
|
||||
wrap_more(converter::handle& prev);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct unwrap : detail::converter_gen<T>::unwrap
|
||||
{
|
||||
typedef typename detail::converter_gen<T>::unwrap base;
|
||||
unwrap(PyObject*);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct unwrap_more : detail::converter_gen<T>::unwrap_more
|
||||
{
|
||||
typedef typename detail::converter_gen<T>::unwrap_more base;
|
||||
unwrap_more(PyObject*, converter::handle& prev);
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T>
|
||||
inline wrap_more<T>::wrap_more(converter::handle& prev)
|
||||
: base(prev)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline unwrap<T>::unwrap(PyObject* source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline unwrap_more<T>::unwrap_more(PyObject* source, converter::handle& prev)
|
||||
: base(source, prev)
|
||||
{
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CONVERT_DWA20011129_HPP
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BODY_DWA2001127_HPP
|
||||
# define BODY_DWA2001127_HPP
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_EXPORT handle;
|
||||
|
||||
struct BOOST_PYTHON_EXPORT body
|
||||
{
|
||||
public:
|
||||
body(type_id_t key);
|
||||
virtual ~body() {}
|
||||
|
||||
// default implementation is a no-op
|
||||
virtual void destroy_handle(handle*) const;
|
||||
|
||||
type_id_t key() const;
|
||||
|
||||
private:
|
||||
type_id_t m_key;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline body::body(type_id_t key)
|
||||
: m_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
inline type_id_t body::key() const
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // BODY_DWA2001127_HPP
|
||||
@@ -1,56 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DWA20011215_HPP
|
||||
# define CLASS_DWA20011215_HPP
|
||||
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/unwrapper.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct class_unwrapper_base
|
||||
{
|
||||
class_unwrapper_base(type_id_t sought_type);
|
||||
void*
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct class_unwrapper
|
||||
{
|
||||
struct ref_unwrapper : unwrapper<T&>
|
||||
{
|
||||
bool convertible(PyObject* p) const
|
||||
{
|
||||
return p->ob_type == &SimpleType;
|
||||
}
|
||||
|
||||
simple const& convert(PyObject* p, void*&) const
|
||||
{
|
||||
return static_cast<SimpleObject*>(p)->x;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
struct const_ref_unwrapper : unwrapper<T const&>
|
||||
{
|
||||
bool convertible(PyObject* p) const
|
||||
{
|
||||
return p->ob_type == &SimpleType;
|
||||
}
|
||||
|
||||
simple const& convert(PyObject* p, void*&) const
|
||||
{
|
||||
return static_cast<SimpleObject*>(p)->x;
|
||||
}
|
||||
|
||||
};
|
||||
# endif
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CLASS_DWA20011215_HPP
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef HANDLE_DWA20011130_HPP
|
||||
# define HANDLE_DWA20011130_HPP
|
||||
# include <boost/python/export.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_EXPORT body;
|
||||
|
||||
// The common base class for unwrap_ and wrap_ handle objects. They
|
||||
// share a common base so that handles can be linked into a chain
|
||||
// within a function wrapper which is managed by a single object.
|
||||
struct BOOST_PYTHON_EXPORT handle : boost::noncopyable
|
||||
{
|
||||
public: // member functions
|
||||
|
||||
// All constructors take a body* passed from the derived class.
|
||||
//
|
||||
// Constructors taking a handle links this into a chain of
|
||||
// handles, for more efficient management in function wrappers
|
||||
handle(body* body);
|
||||
handle(body* body, handle& prev);
|
||||
|
||||
// returns true iff all handles in the chain can convert their
|
||||
// arguments
|
||||
bool convertible() const;
|
||||
|
||||
// safe_bool idiom from Peter Dimov: provides handles to/from
|
||||
// bool without enabling handles to integer types/void*.
|
||||
private:
|
||||
struct dummy { inline void nonnull() {} };
|
||||
typedef void (dummy::*safe_bool)();
|
||||
public:
|
||||
inline operator safe_bool() const;
|
||||
inline safe_bool operator!() const;
|
||||
|
||||
protected: // member functions for derived classes
|
||||
// Get the body we hold
|
||||
inline body* get_body() const;
|
||||
|
||||
// Release all bodies in the chain, in reverse order of
|
||||
// initialization. Only actually called for the head of the chain.
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
// Holds implementation
|
||||
body* m_body;
|
||||
|
||||
// handle for next argument, if any.
|
||||
handle* m_next;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline handle::handle(body* body, handle& prev)
|
||||
: m_body(body), m_next(0)
|
||||
{
|
||||
prev.m_next = this;
|
||||
}
|
||||
|
||||
inline handle::handle(body* body)
|
||||
: m_body(body), m_next(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline handle::operator handle::safe_bool() const
|
||||
{
|
||||
return convertible() ? &dummy::nonnull : 0;
|
||||
}
|
||||
|
||||
inline handle::safe_bool handle::operator!() const
|
||||
{
|
||||
return convertible() ? 0 : &dummy::nonnull;
|
||||
}
|
||||
|
||||
inline body* handle::get_body() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // HANDLE_DWA20011130_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRATION_DWA20011130_HPP
|
||||
# define REGISTRATION_DWA20011130_HPP
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# ifdef BOOST_PYTHON_TRACE
|
||||
# include <iostream>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_EXPORT wrapper_base;
|
||||
struct BOOST_PYTHON_EXPORT unwrapper_base;
|
||||
|
||||
// This class is really sort of a "templated namespace". It manages a
|
||||
// static data member which refers to the registry entry for T. This
|
||||
// reference is acquired once to reduce the burden of multiple
|
||||
// dictionary lookups at runtime.
|
||||
template <class T>
|
||||
struct registration
|
||||
{
|
||||
public: // member functions
|
||||
// Return a converter which can convert the given Python object to
|
||||
// T, or 0 if no such converter exists
|
||||
static unwrapper_base* unwrapper(PyObject*);
|
||||
|
||||
// Return a converter which can convert T to a Python object, or 0
|
||||
// if no such converter exists
|
||||
static wrapper_base* wrapper();
|
||||
|
||||
private: // helper functions
|
||||
static registry::entry* entry();
|
||||
static registry::entry* find_entry();
|
||||
|
||||
private: // data members
|
||||
static registry::entry* m_registry_entry;
|
||||
};
|
||||
|
||||
// because this is static POD data it will be initialized to zero
|
||||
template <class T>
|
||||
registry::entry* registration<T>::m_registry_entry;
|
||||
|
||||
template <class T>
|
||||
registry::entry* registration<T>::find_entry()
|
||||
{
|
||||
return registry::find(type_id<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline registry::entry* registration<T>::entry()
|
||||
{
|
||||
if (!m_registry_entry)
|
||||
m_registry_entry = find_entry();
|
||||
return m_registry_entry;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unwrapper_base* registration<T>::unwrapper(PyObject* p)
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TRACE
|
||||
std::cout << "retrieving unwrapper for " << type_id<T>() << std::endl;
|
||||
# endif
|
||||
return entry()->unwrapper(p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
wrapper_base* registration<T>::wrapper()
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TRACE
|
||||
std::cout << "retrieving wrapper for " << type_id<T>() << std::endl;
|
||||
# endif
|
||||
return entry()->wrapper();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRATION_DWA20011130_HPP
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRY_DWA20011127_HPP
|
||||
# define REGISTRY_DWA20011127_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# include <list>
|
||||
# include <memory>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_EXPORT wrapper_base;
|
||||
struct BOOST_PYTHON_EXPORT unwrapper_base;
|
||||
|
||||
// This namespace acts as a sort of singleton
|
||||
namespace registry
|
||||
{
|
||||
// These are the elements stored in the registry
|
||||
class BOOST_PYTHON_EXPORT entry
|
||||
{
|
||||
public: // member functions
|
||||
entry();
|
||||
~entry();
|
||||
|
||||
// Return a converter appropriate for converting the given
|
||||
// Python object from_python to the C++ type with which this
|
||||
// converter is associated in the registry, or 0 if no such
|
||||
// converter exists.
|
||||
unwrapper_base* unwrapper(PyObject*) const;
|
||||
|
||||
// Return a converter appropriate for converting a C++ object
|
||||
// whose type this entry is associated with in the registry to a
|
||||
// Python object, or 0 if no such converter exists.
|
||||
wrapper_base* wrapper() const;
|
||||
|
||||
// Conversion classes use these functions to register
|
||||
// themselves.
|
||||
void insert(wrapper_base&);
|
||||
void remove(wrapper_base&);
|
||||
|
||||
void insert(unwrapper_base&);
|
||||
void remove(unwrapper_base&);
|
||||
|
||||
private: // types
|
||||
typedef std::list<unwrapper_base*> unwrappers;
|
||||
|
||||
private: // helper functions
|
||||
unwrappers::iterator find(unwrapper_base const&);
|
||||
|
||||
private: // data members
|
||||
|
||||
// The collection of from_python converters for the associated
|
||||
// C++ type.
|
||||
unwrappers m_unwrappers;
|
||||
|
||||
// The unique to_python converter for the associated C++ type.
|
||||
converter::wrapper_base* m_wrapper;
|
||||
};
|
||||
|
||||
BOOST_PYTHON_EXPORT entry* find(type_id_t);
|
||||
|
||||
BOOST_PYTHON_EXPORT void insert(wrapper_base& x);
|
||||
BOOST_PYTHON_EXPORT void insert(unwrapper_base& x);
|
||||
BOOST_PYTHON_EXPORT void remove(wrapper_base& x);
|
||||
BOOST_PYTHON_EXPORT void remove(unwrapper_base& x);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRY_DWA20011127_HPP
|
||||
@@ -1,80 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SOURCE_DWA20011119_HPP
|
||||
# define SOURCE_DWA20011119_HPP
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// source --
|
||||
//
|
||||
// This type generator (see
|
||||
// ../../../more/generic_programming.html#type_generator) is used
|
||||
// to select the argument type to use when converting T to a PyObject*
|
||||
|
||||
template <class T> struct source;
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
// Since for some strange reason temporaries can't be bound to const
|
||||
// volatile references (8.5.3/5 in the C++ standard), we cannot use a
|
||||
// const volatile reference as the standard for values and references.
|
||||
template <class T>
|
||||
struct source
|
||||
{
|
||||
typedef T const& type;
|
||||
};
|
||||
|
||||
// This will handle the following:
|
||||
// T const volatile& -> T const volatile&
|
||||
// T volatile& -> T const volatile&
|
||||
// T const& -> T const&
|
||||
// T& -> T const&
|
||||
template <class T>
|
||||
struct source<T&>
|
||||
{
|
||||
typedef T const& type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct source<T*>
|
||||
{
|
||||
typedef T const* type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct source<T* const>
|
||||
{
|
||||
typedef T const* type;
|
||||
};
|
||||
|
||||
// Deal with references to pointers
|
||||
template <class T>
|
||||
struct source<T*&>
|
||||
{
|
||||
typedef T const* type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct source<T* const&>
|
||||
{
|
||||
typedef T const* type;
|
||||
};
|
||||
# else
|
||||
template <class T>
|
||||
struct source
|
||||
{
|
||||
typedef typename add_reference<
|
||||
typename add_const<T>::type
|
||||
>::type type;
|
||||
};
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // SOURCE_DWA20011119_HPP
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SOURCE_HOLDER_DWA20011215_HPP
|
||||
# define SOURCE_HOLDER_DWA20011215_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct source_holder_base
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct source_holder : source_holder_base
|
||||
{
|
||||
source_holder(T x) : value(x) {}
|
||||
T value;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // SOURCE_HOLDER_DWA20011215_HPP
|
||||
@@ -1,172 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#ifndef TARGET_DWA20011119_HPP
|
||||
# define TARGET_DWA20011119_HPP
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// target --
|
||||
//
|
||||
// This type generator (see
|
||||
// ../../../more/generic_programming.html#type_generator) is used
|
||||
// to select the return type of the appropriate converter for
|
||||
// unwrapping a given type.
|
||||
|
||||
// Strategy:
|
||||
//
|
||||
// 1. reduce everything to a common, un-cv-qualified reference
|
||||
// type where possible. This will save on registering many different
|
||||
// converter types.
|
||||
//
|
||||
// 2. Treat built-in types specially: when unwrapping a value or
|
||||
// constant reference to one of these, use a value for the target
|
||||
// type. It will bind to a const reference if neccessary, and more
|
||||
// importantly, avoids having to dynamically allocate room for
|
||||
// an lvalue of types which can be cheaply copied.
|
||||
//
|
||||
// In the tables below, "cv" stands for the set of all possible
|
||||
// cv-qualifications.
|
||||
|
||||
// Target Source
|
||||
// int int
|
||||
// int const& int
|
||||
// int& int&
|
||||
// int volatile& int volatile&
|
||||
// int const volatile& int const volatile&
|
||||
|
||||
// On compilers supporting partial specialization:
|
||||
//
|
||||
// Target Source
|
||||
// T T&
|
||||
// T cv& T&
|
||||
// T cv* T*
|
||||
// T cv*const& T*
|
||||
// T cv*& T*& <- should this be legal?
|
||||
// T cv*volatile& T*& <- should this be legal?
|
||||
// T cv*const volatile& T*& <- should this be legal?
|
||||
|
||||
// On others:
|
||||
//
|
||||
// Target Source
|
||||
// T T&
|
||||
// T cv& T cv&
|
||||
// T cv* T cv*
|
||||
// T cv*cv& T cv*cv&
|
||||
|
||||
// As you can see, in order to handle the same range of types without
|
||||
// partial specialization, more converters need to be registered.
|
||||
|
||||
template <class T>
|
||||
struct target
|
||||
{
|
||||
// Some pointer types are handled in a more sophisticated way on
|
||||
// compilers supporting partial specialization.
|
||||
BOOST_STATIC_CONSTANT(bool, use_identity = (::boost::is_scalar<T>::value));
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
use_identity
|
||||
, T
|
||||
, typename add_reference<typename remove_cv<T>::type>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
// When partial specialization is not present, we'll simply need to
|
||||
// register many more converters.
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class T>
|
||||
struct target<T&>
|
||||
{
|
||||
typedef typename remove_cv<T>::type& type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct target<T*>
|
||||
{
|
||||
typedef typename remove_cv<T>::type* type;
|
||||
};
|
||||
|
||||
// Handle T*-cv for completeness. Function arguments in a signature
|
||||
// are never actually cv-qualified, but who knows how this might be
|
||||
// used, or what compiler bugs may lurk?
|
||||
template <class T>
|
||||
struct target<T* const>
|
||||
{
|
||||
typedef typename remove_cv<T>::type* type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct target<T* volatile>
|
||||
{
|
||||
typedef typename remove_cv<T>::type* type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct target<T* const volatile>
|
||||
{
|
||||
typedef typename remove_cv<T>::type* type;
|
||||
};
|
||||
|
||||
// non-const references to pointers should be handled by the
|
||||
// specialization for T&, above.
|
||||
template <class T>
|
||||
struct target<T* const&>
|
||||
{
|
||||
typedef typename remove_cv<T>::type* type;
|
||||
};
|
||||
# endif
|
||||
|
||||
// Fortunately, we can handle T const& where T is an arithmetic type
|
||||
// by explicit specialization. These specializations will cause value
|
||||
// and const& arguments to be converted to values, rather than to
|
||||
// references.
|
||||
# define BOOST_PYTHON_UNWRAP_VALUE(T) \
|
||||
template <> \
|
||||
struct target<T> \
|
||||
{ \
|
||||
typedef T type; \
|
||||
}; \
|
||||
template <> \
|
||||
struct target<T const> \
|
||||
{ \
|
||||
typedef T type; \
|
||||
}; \
|
||||
template <> \
|
||||
struct target<T volatile> \
|
||||
{ \
|
||||
typedef T type; \
|
||||
}; \
|
||||
template <> \
|
||||
struct target<T const volatile> \
|
||||
{ \
|
||||
typedef T type; \
|
||||
}; \
|
||||
template <> \
|
||||
struct target<T const&> \
|
||||
{ \
|
||||
typedef T type; \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_UNWRAP_VALUE(char);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(unsigned char);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(signed char);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(unsigned int);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(signed int);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(unsigned short);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(signed short);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(unsigned long);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(signed long);
|
||||
BOOST_PYTHON_UNWRAP_VALUE(char const*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TARGET_DWA20011119_HPP
|
||||
@@ -1,200 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TYPE_ID_DWA20011127_HPP
|
||||
# define TYPE_ID_DWA20011127_HPP
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
# include <typeinfo>
|
||||
# include <iosfwd>
|
||||
# include <cstring>
|
||||
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// a portable mechanism for identifying types at runtime across modules.
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T> class dummy;
|
||||
}
|
||||
|
||||
// for this compiler at least, cross-shared-library type_info
|
||||
// comparisons don't work, so use typeid(x).name() instead. It's not
|
||||
// yet clear what the best default strategy is.
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3
|
||||
# define BOOST_PYTHON_TYPE_ID_NAME
|
||||
# endif
|
||||
|
||||
# if 1
|
||||
struct type_id_t : totally_ordered<type_id_t>
|
||||
{
|
||||
enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
||||
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
typedef char const* base_id_t;
|
||||
# else
|
||||
typedef std::type_info const* base_id_t;
|
||||
# endif
|
||||
|
||||
type_id_t(base_id_t, decoration decoration);
|
||||
|
||||
bool operator<(type_id_t const& rhs) const;
|
||||
bool operator==(type_id_t const& rhs) const;
|
||||
friend BOOST_PYTHON_EXPORT std::ostream& operator<<(std::ostream&, type_id_t const&);
|
||||
|
||||
private:
|
||||
decoration m_decoration;
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const<T const&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile<T volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
template <typename V>
|
||||
struct is_const_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_const<V>::value
|
||||
, type_traits::yes_type
|
||||
, type_traits::no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct is_volatile_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_volatile<V>::value
|
||||
, type_traits::yes_type
|
||||
, type_traits::no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_const_help<V>::type reference_to_const_helper(V&);
|
||||
|
||||
type_traits::no_type
|
||||
reference_to_const_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(reference_to_const_helper(t)) == sizeof(type_traits::yes_type));
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_volatile_help<V>::type reference_to_volatile_helper(V&);
|
||||
type_traits::no_type reference_to_volatile_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(reference_to_volatile_helper(t)) == sizeof(type_traits::yes_type));
|
||||
};
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class T>
|
||||
inline type_id_t type_id(detail::dummy<T>* = 0)
|
||||
{
|
||||
return type_id_t(
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
typeid(T).name()
|
||||
# else
|
||||
&typeid(T)
|
||||
# endif
|
||||
, type_id_t::decoration(
|
||||
(is_const<T>::value || is_reference_to_const<T>::value
|
||||
? type_id_t::const_ : 0)
|
||||
| (is_volatile<T>::value || is_reference_to_volatile<T>::value
|
||||
? type_id_t::volatile_ : 0)
|
||||
| (is_reference<T>::value ? type_id_t::reference : 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline type_id_t::type_id_t(base_id_t base_t, decoration decoration)
|
||||
: m_decoration(decoration)
|
||||
, m_base_type(base_t)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool type_id_t::operator<(type_id_t const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| m_decoration == rhs.m_decoration
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
&& std::strcmp(m_base_type, rhs.m_base_type) < 0;
|
||||
# else
|
||||
&& m_base_type->before(*rhs.m_base_type);
|
||||
# endif
|
||||
}
|
||||
|
||||
inline bool type_id_t::operator==(type_id_t const& rhs) const
|
||||
{
|
||||
return m_decoration == rhs.m_decoration
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
&& !std::strcmp(m_base_type, rhs.m_base_type);
|
||||
# else
|
||||
&& *m_base_type == *rhs.m_base_type;
|
||||
# endif
|
||||
}
|
||||
|
||||
# else
|
||||
// This is the type which is used to identify a type
|
||||
typedef char const* type_id_t;
|
||||
|
||||
// This is a workaround for a silly MSVC bug
|
||||
// Converts a compile-time type to its corresponding runtime identifier.
|
||||
template <class T>
|
||||
type_id_t type_id(detail::dummy<T>* = 0)
|
||||
{
|
||||
return typeid(T).name();
|
||||
}
|
||||
# endif
|
||||
|
||||
struct BOOST_PYTHON_EXPORT type_id_before
|
||||
{
|
||||
bool operator()(type_id_t const& x, type_id_t const& y) const;
|
||||
};
|
||||
|
||||
BOOST_PYTHON_EXPORT std::ostream& operator<<(std::ostream&, type_id_t const&);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TYPE_ID_DWA20011127_HPP
|
||||
@@ -1,192 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef UNWRAP_BASE_DWA20011130_HPP
|
||||
# define UNWRAP_BASE_DWA20011130_HPP
|
||||
|
||||
# include <boost/python/converter/unwrapper_base.hpp>
|
||||
# include <boost/python/converter/unwrapper.hpp>
|
||||
# include <boost/python/converter/handle.hpp>
|
||||
# include <boost/python/converter/registration.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T> struct unwrapper;
|
||||
struct BOOST_PYTHON_EXPORT body;
|
||||
|
||||
struct BOOST_PYTHON_EXPORT unwrap_base : handle
|
||||
{
|
||||
public: // member functions
|
||||
inline unwrap_base(PyObject* source, body*, handle& prev);
|
||||
inline unwrap_base(PyObject* source, body*);
|
||||
inline PyObject* source() const;
|
||||
|
||||
private: // data members
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
// These converters will be used by the function wrappers. They don't
|
||||
// manage any resources, but are instead linked into a chain which is
|
||||
// managed by an instance of unwrap_ or wrap_.
|
||||
template <class T>
|
||||
struct unwrap_more_ : unwrap_base
|
||||
{
|
||||
public: // member functions
|
||||
// Construction
|
||||
unwrap_more_(PyObject* source, handle& prev);
|
||||
|
||||
// invoke the conversion or throw an exception if unsuccessful
|
||||
T operator*();
|
||||
|
||||
protected: // constructor
|
||||
// this constructor is only for the use of unwrap_
|
||||
unwrap_more_(PyObject* source);
|
||||
|
||||
private: // helper functions
|
||||
// Return the unwrapper which will convert the given Python object
|
||||
// to T, or 0 if no such converter exists
|
||||
static unwrapper_base* lookup(PyObject*);
|
||||
|
||||
private:
|
||||
// unspecified storage which may be allocated by the unwrapper to
|
||||
// do value conversions.
|
||||
mutable void* m_storage;
|
||||
friend class unwrapper<T>;
|
||||
};
|
||||
|
||||
// specialization for PyObject*
|
||||
template <>
|
||||
struct unwrap_more_<PyObject*>
|
||||
: unwrap_base
|
||||
{
|
||||
public: // member functions
|
||||
// Construction
|
||||
unwrap_more_(PyObject* source, handle& prev)
|
||||
: unwrap_base(source, m_unwrapper, prev)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// invoke the conversion or throw an exception if unsuccessful
|
||||
PyObject* operator*()
|
||||
{
|
||||
return source();
|
||||
}
|
||||
|
||||
bool convertible(PyObject*) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected: // constructor
|
||||
// this constructor is only for the use of unwrap_
|
||||
unwrap_more_(PyObject* source)
|
||||
: unwrap_base(source, m_unwrapper)
|
||||
|
||||
{
|
||||
}
|
||||
private:
|
||||
static BOOST_PYTHON_EXPORT unwrapper_base* m_unwrapper;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct unwrap_ : unwrap_more_<T>
|
||||
{
|
||||
unwrap_(PyObject* source);
|
||||
~unwrap_();
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline unwrap_base::unwrap_base(PyObject* source, body* body, handle& prev)
|
||||
: handle(body, prev)
|
||||
, m_source(source)
|
||||
{
|
||||
}
|
||||
|
||||
inline unwrap_base::unwrap_base(PyObject* source, body* body)
|
||||
: handle(body)
|
||||
, m_source(source)
|
||||
{
|
||||
}
|
||||
|
||||
inline PyObject* unwrap_base::source() const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline unwrapper_base* unwrap_more_<T>::lookup(PyObject* source)
|
||||
{
|
||||
// Find the converters registered for T and get a unwrapper
|
||||
// appropriate for the source object
|
||||
return registration<T>::unwrapper(source);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unwrap_more_<T>::unwrap_more_(PyObject* source, handle& prev)
|
||||
: unwrap_base(source, lookup(source), prev)
|
||||
, m_storage(0)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unwrap_more_<T>::unwrap_more_(PyObject* source)
|
||||
: unwrap_base(source, lookup(source))
|
||||
, m_storage(0)
|
||||
{
|
||||
}
|
||||
|
||||
# if 0
|
||||
template <>
|
||||
inline unwrap_more_<PyObject*>::unwrap_more_(PyObject* source, handle& prev)
|
||||
: unwrap_base(source, m_unwrapper, prev)
|
||||
{
|
||||
}
|
||||
|
||||
template <>
|
||||
inline unwrap_more_<PyObject*>::unwrap_more_(PyObject* source)
|
||||
: unwrap_base(source, m_unwrapper)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
template <>
|
||||
inline PyObject* unwrap_more_<PyObject*>::operator*()
|
||||
{
|
||||
return source();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool unwrap_more_<PyObject*>::convertible(PyObject*) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
template <class T>
|
||||
inline unwrap_<T>::unwrap_(PyObject* source)
|
||||
: unwrap_more_<T>(source)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T unwrap_more_<T>::operator*()
|
||||
{
|
||||
return static_cast<unwrapper<T>*>(
|
||||
get_body())->do_conversion(this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unwrap_<T>::~unwrap_()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // UNWRAP_BASE_DWA20011130_HPP
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef UNWRAPPER_DWA2001127_HPP
|
||||
# define UNWRAPPER_DWA2001127_HPP
|
||||
|
||||
# include <boost/python/converter/unwrapper_base.hpp>
|
||||
# include <boost/python/converter/unwrap.hpp>
|
||||
# include <boost/python/converter/body.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T> struct unwrap_more_;
|
||||
|
||||
// Abstract base for all unwrappers of Ts
|
||||
template <class T>
|
||||
struct unwrapper : unwrapper_base
|
||||
{
|
||||
public:
|
||||
unwrapper();
|
||||
|
||||
T do_conversion(unwrap_more_<T> const* handle) const;
|
||||
|
||||
private:
|
||||
virtual T convert(PyObject*, void*&) const = 0;
|
||||
|
||||
private: // body required interface implementation
|
||||
void destroy_handle(handle*) const {}
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T>
|
||||
unwrapper<T>::unwrapper()
|
||||
: unwrapper_base(type_id<T>())
|
||||
{
|
||||
}
|
||||
|
||||
// We could think about making this virtual in an effort to get its
|
||||
// code generated in the module where the unwrapper is defined, but
|
||||
// it's not clear that it's a good tradeoff.
|
||||
template <class T>
|
||||
T unwrapper<T>::do_conversion(unwrap_more_<T> const* handle) const
|
||||
{
|
||||
return convert(handle->source(), handle->m_storage);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // UNWRAPPER_DWA2001127_HPP
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef UNWRAPPER_BASE_DWA20011215_HPP
|
||||
# define UNWRAPPER_BASE_DWA20011215_HPP
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/body.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_EXPORT unwrapper_base : body
|
||||
{
|
||||
public:
|
||||
unwrapper_base(type_id_t); // registers
|
||||
~unwrapper_base(); // unregisters
|
||||
virtual bool convertible(PyObject*) const = 0;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // UNWRAPPER_BASE_DWA20011215_HPP
|
||||
@@ -1,145 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef WRAP_DWA2001127_HPP
|
||||
# define WRAP_DWA2001127_HPP
|
||||
# include <boost/python/converter/registration.hpp>
|
||||
# include <boost/python/converter/handle.hpp>
|
||||
# include <boost/python/converter/body.hpp>
|
||||
# include <boost/python/converter/wrapper.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# include <boost/python/converter/source_holder.hpp>
|
||||
# include <cassert>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct BOOST_PYTHON_EXPORT wrapper_base;
|
||||
|
||||
template <class T> struct wrapper;
|
||||
|
||||
struct wrap_base : handle
|
||||
{
|
||||
public: // member functions
|
||||
wrap_base(body*, handle& prev);
|
||||
wrap_base(body*);
|
||||
PyObject* release();
|
||||
|
||||
public: // accessor, really only for wrappers
|
||||
PyObject*& target() const;
|
||||
|
||||
protected:
|
||||
void hold_result(PyObject*) const;
|
||||
|
||||
private:
|
||||
mutable PyObject* m_target;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct wrap_more_ : wrap_base
|
||||
{
|
||||
protected:
|
||||
typedef T source_t;
|
||||
|
||||
public: // member functions
|
||||
wrap_more_(handle& prev);
|
||||
|
||||
PyObject* operator()(source_t) const;
|
||||
|
||||
protected: // constructor for wrap_<T>, below
|
||||
wrap_more_();
|
||||
|
||||
private: // helper functions
|
||||
static wrapper_base* lookup();
|
||||
|
||||
private:
|
||||
friend class wrapper<T>;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct wrap_ : wrap_more_<T>
|
||||
{
|
||||
typedef typename wrap_more_<T>::source_t source_t;
|
||||
public: // member functions
|
||||
wrap_();
|
||||
~wrap_();
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
inline wrap_base::wrap_base(body* body, handle& prev)
|
||||
: handle(body, prev),
|
||||
m_target(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline wrap_base::wrap_base(body* body)
|
||||
: handle(body),
|
||||
m_target(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline PyObject*& wrap_base::target() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
inline void wrap_base::hold_result(PyObject* p) const
|
||||
{
|
||||
assert(m_target == 0);
|
||||
m_target = p;
|
||||
}
|
||||
|
||||
inline PyObject* wrap_base::release()
|
||||
{
|
||||
PyObject* result = m_target;
|
||||
m_target = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline wrapper_base* wrap_more_<T>::lookup()
|
||||
{
|
||||
// Find the converters registered for T and get a wrapper
|
||||
// appropriate for the source object
|
||||
return registration<T>::wrapper();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline wrap_more_<T>::wrap_more_(handle& prev)
|
||||
: wrap_base(lookup(), prev)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* wrap_more_<T>::operator()(source_t x) const
|
||||
{
|
||||
return static_cast<wrapper<T>*>(
|
||||
get_body())->do_conversion(*this, source_holder<T>(x));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
wrap_more_<T>::wrap_more_()
|
||||
: wrap_base(lookup())
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
wrap_<T>::wrap_()
|
||||
: wrap_more_<T>()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
wrap_<T>::~wrap_()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // WRAP_DWA2001127_HPP
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef WRAPPER_DWA2001127_HPP
|
||||
# define WRAPPER_DWA2001127_HPP
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/body.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/wrap.hpp>
|
||||
# include <boost/python/converter/source_holder.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct source_holder_base;
|
||||
struct wrap_base;
|
||||
template <class T> struct wrap_more_;
|
||||
|
||||
struct BOOST_PYTHON_EXPORT wrapper_base : body
|
||||
{
|
||||
public:
|
||||
wrapper_base(type_id_t); // registers
|
||||
~wrapper_base(); // unregisters
|
||||
|
||||
virtual PyObject* do_conversion(wrap_base const&, source_holder_base const&) const = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct wrapper : wrapper_base
|
||||
{
|
||||
public:
|
||||
wrapper();
|
||||
|
||||
PyObject* do_conversion(wrap_base const&, source_holder_base const&) const;
|
||||
|
||||
// This does the actual conversion
|
||||
virtual PyObject* convert(T source) const = 0;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
template <class T>
|
||||
wrapper<T>::wrapper()
|
||||
: wrapper_base(type_id<T>())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
PyObject* wrapper<T>::do_conversion(wrap_base const& handle_, source_holder_base const& data_) const
|
||||
{
|
||||
// Casting pointers instead of references suppresses a CWPro7 bug.
|
||||
wrap_more_<T> const& handle = *static_cast<wrap_more_<T> const*>(&handle_);
|
||||
source_holder<T> const& data = *static_cast<source_holder<T> const*>(&data_);
|
||||
if (handle.target() == 0)
|
||||
{
|
||||
handle.hold_result(convert(data.value));
|
||||
}
|
||||
return handle.target();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // WRAPPER_DWA2001127_HPP
|
||||
@@ -1,233 +0,0 @@
|
||||
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_arg_tuple_size.python
|
||||
|
||||
#ifndef ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
# define ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// Computes (at compile-time) the number of elements that a Python
|
||||
// argument tuple must have in order to be passed to a wrapped C++
|
||||
// (member) function of the given type.
|
||||
template <class F> struct arg_tuple_size;
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__BORLANDC__)
|
||||
|
||||
template <class R>
|
||||
struct arg_tuple_size<R (*)()>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
|
||||
template <class R, class A1>
|
||||
struct arg_tuple_size<R (*)(A1)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2>
|
||||
struct arg_tuple_size<R (*)(A1, A2)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3, A4)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3, A4, A5)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3, A4, A5, A6)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
struct arg_tuple_size<R (A0::*)()>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
struct arg_tuple_size<R (A0::*)(A1)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4, A5)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
// We will use the "sizeof() trick" to work around the lack of
|
||||
// partial specialization in MSVC6 and its broken-ness in borland.
|
||||
// See http://opensource.adobe.com or
|
||||
// http://groups.yahoo.com/group/boost/message/5441 for
|
||||
// more examples
|
||||
|
||||
// This little package is used to transmit the number of arguments
|
||||
// from the helper functions below to the sizeof() expression below.
|
||||
// Because we can never have an array of fewer than 1 element, we
|
||||
// add 1 to n and then subtract 1 from the result of sizeof() below.
|
||||
template <int n>
|
||||
struct char_array
|
||||
{
|
||||
char elements[n+1];
|
||||
};
|
||||
|
||||
// The following helper functions are never actually called, since
|
||||
// they are only used within a sizeof() expression, but the type of
|
||||
// their return value is used to discriminate between various free
|
||||
// and member function pointers at compile-time.
|
||||
|
||||
template <class R>
|
||||
char_array<0> arg_tuple_size_helper(R (*)());
|
||||
|
||||
template <class R, class A1>
|
||||
char_array<1> arg_tuple_size_helper(R (*)(A1));
|
||||
|
||||
template <class R, class A1, class A2>
|
||||
char_array<2> arg_tuple_size_helper(R (*)(A1, A2));
|
||||
|
||||
template <class R, class A1, class A2, class A3>
|
||||
char_array<3> arg_tuple_size_helper(R (*)(A1, A2, A3));
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4>
|
||||
char_array<4> arg_tuple_size_helper(R (*)(A1, A2, A3, A4));
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<5> arg_tuple_size_helper(R (*)(A1, A2, A3, A4, A5));
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
char_array<6> arg_tuple_size_helper(R (*)(A1, A2, A3, A4, A5, A6));
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)());
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1));
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2));
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3));
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4));
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5));
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)() const);
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5) const);
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)() volatile);
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5) volatile);
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)() const volatile);
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5) const volatile);
|
||||
|
||||
|
||||
template <class F>
|
||||
struct arg_tuple_size
|
||||
{
|
||||
// The sizeof() magic happens here
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value
|
||||
= sizeof(arg_tuple_size_helper(F(0)).elements) - 1);
|
||||
};
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CALLER_DWA20011214_HPP
|
||||
# define CALLER_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/call.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct caller
|
||||
{
|
||||
typedef PyObject* result_type;
|
||||
|
||||
template <class F>
|
||||
PyObject* operator()(F f, PyObject* args, PyObject* keywords)
|
||||
{
|
||||
return call(f, args, keywords);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CALLER_DWA20011214_HPP
|
||||
@@ -1,846 +0,0 @@
|
||||
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_returning.py
|
||||
|
||||
#ifndef RETURNING_DWA20011201_HPP
|
||||
# define RETURNING_DWA20011201_HPP
|
||||
|
||||
//# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/convert.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// Calling C++ from Python
|
||||
template <class R>
|
||||
struct returning
|
||||
{
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)(), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c0);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)() );
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c1);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1) );
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c2);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c3);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c4);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c5);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5) );
|
||||
};
|
||||
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)() const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c0);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)() );
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c1);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1) );
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c2);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c3);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c4);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c5);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5) );
|
||||
};
|
||||
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)() volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c0);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)() );
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c1);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1) );
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c2);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c3);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c4);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c5);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5) );
|
||||
};
|
||||
|
||||
|
||||
// missing const volatile type traits
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)() const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c0);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)() );
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c1);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1) );
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c2);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c3);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c4);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c5);
|
||||
if (!c0) return 0;
|
||||
return r( ((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5) );
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
static PyObject* call(R (*pf)(), PyObject*, PyObject* /* keywords */ )
|
||||
{
|
||||
// find the result converter
|
||||
wrap<R> r;
|
||||
return r( (*pf)() );
|
||||
};
|
||||
template <class A0>
|
||||
static PyObject* call(R (*pf)(A0), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c0);
|
||||
if (!c0) return 0;
|
||||
return r( (*pf)(*c0) );
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (*pf)(A0, A1), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c1);
|
||||
if (!c0) return 0;
|
||||
return r( (*pf)(*c0, *c1) );
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c2);
|
||||
if (!c0) return 0;
|
||||
return r( (*pf)(*c0, *c1, *c2) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2, A3), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c3);
|
||||
if (!c0) return 0;
|
||||
return r( (*pf)(*c0, *c1, *c2, *c3) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c4);
|
||||
if (!c0) return 0;
|
||||
return r( (*pf)(*c0, *c1, *c2, *c3, *c4) );
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
// find the result converter
|
||||
wrap_more<R> r(c5);
|
||||
if (!c0) return 0;
|
||||
return r( (*pf)(*c0, *c1, *c2, *c3, *c4, *c5) );
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct returning<void>
|
||||
{
|
||||
typedef void R;
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)(), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)();
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5);
|
||||
return detail::none();
|
||||
};
|
||||
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)() const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)();
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5);
|
||||
return detail::none();
|
||||
};
|
||||
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)() volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)();
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5);
|
||||
return detail::none();
|
||||
};
|
||||
|
||||
|
||||
// missing const volatile type traits
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class A0>
|
||||
static PyObject* call(R (A0::*pmf)() const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)();
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (A0::*pmf)(A1) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0 const volatile&> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
if (!c0) return 0;
|
||||
((*c0).*pmf)(*c1, *c2, *c3, *c4, *c5);
|
||||
return detail::none();
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
static PyObject* call(R (*pf)(), PyObject*, PyObject* /* keywords */ )
|
||||
{
|
||||
(*pf)();
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0>
|
||||
static PyObject* call(R (*pf)(A0), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
|
||||
if (!c0) return 0;
|
||||
(*pf)(*c0);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1>
|
||||
static PyObject* call(R (*pf)(A0, A1), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
|
||||
if (!c0) return 0;
|
||||
(*pf)(*c0, *c1);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
|
||||
if (!c0) return 0;
|
||||
(*pf)(*c0, *c1, *c2);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2, A3), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
|
||||
if (!c0) return 0;
|
||||
(*pf)(*c0, *c1, *c2, *c3);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
|
||||
if (!c0) return 0;
|
||||
(*pf)(*c0, *c1, *c2, *c3, *c4);
|
||||
return detail::none();
|
||||
};
|
||||
template <class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static PyObject* call(R (*pf)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ )
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
unwrap<A0> c0(PyTuple_GET_ITEM(args, 0));
|
||||
unwrap_more<A1> c1(PyTuple_GET_ITEM(args, 1), c0);
|
||||
unwrap_more<A2> c2(PyTuple_GET_ITEM(args, 2), c1);
|
||||
unwrap_more<A3> c3(PyTuple_GET_ITEM(args, 3), c2);
|
||||
unwrap_more<A4> c4(PyTuple_GET_ITEM(args, 4), c3);
|
||||
unwrap_more<A5> c5(PyTuple_GET_ITEM(args, 5), c4);
|
||||
|
||||
if (!c0) return 0;
|
||||
(*pf)(*c0, *c1, *c2, *c3, *c4, *c5);
|
||||
return detail::none();
|
||||
};
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // RETURNING_DWA20011201_HPP
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef EXPORT_DWA20011120_HPP
|
||||
# define EXPORT_DWA20011120_HPP
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/preprocessor/if.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# ifndef BOOST_PYTHON_EXPORT
|
||||
# define BOOST_PYTHON_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define BOOST_PYTHON_EXPORT
|
||||
# endif
|
||||
|
||||
#endif // EXPORT_DWA20011120_HPP
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MAKE_FUNCTION_DWA20011214_HPP
|
||||
# define MAKE_FUNCTION_DWA20011214_HPP
|
||||
|
||||
# include <boost/bind.hpp>
|
||||
# include <boost/python/object/function.hpp>
|
||||
# include <boost/python/object/make_holder.hpp>
|
||||
# include <boost/python/detail/caller.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class F>
|
||||
PyObject* make_function(F f)
|
||||
{
|
||||
return new object::function(
|
||||
object::py_function(
|
||||
bind<PyObject*>(detail::caller(), f, _1, _2)));
|
||||
}
|
||||
|
||||
template <class T, class ArgList, class Generator>
|
||||
PyObject* make_constructor(T* = 0, ArgList* = 0, Generator* = 0)
|
||||
{
|
||||
return new object::function(
|
||||
object::py_function(
|
||||
bind<PyObject*>(detail::caller()
|
||||
, object::make_holder<
|
||||
mpl::size<ArgList>::value
|
||||
>::template apply<
|
||||
T, Generator, ArgList
|
||||
>::execute
|
||||
, _1, _2)));
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MAKE_FUNCTION_DWA20011214_HPP
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MODULE_DWA2001128_HPP
|
||||
# define MODULE_DWA2001128_HPP
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" __declspec(dllexport) void init##name() \
|
||||
{ \
|
||||
/*boost::python::handle_exception(*/init_module_##name()/*)*/; \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
#else
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" void init##name() \
|
||||
{ \
|
||||
/*boost::python::handle_exception(*/init_module_##name()/*)*/; \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MODULE_DWA2001128_HPP
|
||||
@@ -1,76 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DWA20011214_HPP
|
||||
# define CLASS_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace object {
|
||||
|
||||
template <class T> struct holder;
|
||||
|
||||
// Base class for all holders
|
||||
struct BOOST_PYTHON_EXPORT holder_base : noncopyable
|
||||
{
|
||||
public:
|
||||
holder_base(converter::type_id_t id);
|
||||
virtual ~holder_base();
|
||||
virtual bool held_by_value() const = 0;
|
||||
|
||||
holder_base* next() const;
|
||||
converter::type_id_t type() const;
|
||||
|
||||
void install(PyObject* inst);
|
||||
private:
|
||||
converter::type_id_t m_type;
|
||||
holder_base* m_next;
|
||||
};
|
||||
|
||||
// Abstract base class which holds a Held, somehow. Provides a uniform
|
||||
// way to get a pointer to the held object
|
||||
template <class Held>
|
||||
struct holder : holder_base
|
||||
{
|
||||
typedef Held held_type;
|
||||
holder();
|
||||
virtual Held* target() = 0;
|
||||
};
|
||||
|
||||
// Each extension instance will be one of these
|
||||
struct instance
|
||||
{
|
||||
PyObject_HEAD
|
||||
holder_base* objects;
|
||||
};
|
||||
|
||||
extern BOOST_PYTHON_EXPORT PyTypeObject class_metatype;
|
||||
extern BOOST_PYTHON_EXPORT PyTypeObject class_type;
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
inline holder_base* holder_base::next() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline converter::type_id_t holder_base::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
template <class Held>
|
||||
holder<Held>::holder()
|
||||
: holder_base(converter::type_id<Held>())
|
||||
{
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // CLASS_DWA20011214_HPP
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONSTRUCT_DWA20011215_HPP
|
||||
# define CONSTRUCT_DWA20011215_HPP
|
||||
|
||||
namespace boost { namespace python { namespace object {
|
||||
|
||||
template <class T, class ArgList>
|
||||
struct construct
|
||||
{
|
||||
static
|
||||
template <class
|
||||
void operator()(PyObject* args, PyObject* keywords)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // CONSTRUCT_DWA20011215_HPP
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FORWARD_DWA20011215_HPP
|
||||
# define FORWARD_DWA20011215_HPP
|
||||
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace object {
|
||||
|
||||
// A little metaprogram which selects the type to pass through an
|
||||
// intermediate forwarding function when the destination argument type
|
||||
// is T.
|
||||
template <class T>
|
||||
struct forward
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_scalar<T>::value | is_reference<T>::value
|
||||
, T
|
||||
, reference_wrapper<
|
||||
typename add_const<T>::type
|
||||
>
|
||||
>::type type;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // FORWARD_DWA20011215_HPP
|
||||
@@ -1,36 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FUNCTION_DWA20011214_HPP
|
||||
# define FUNCTION_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/export.hpp>
|
||||
# include <boost/function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace object {
|
||||
|
||||
// We use boost::function to avoid generating lots of virtual tables
|
||||
typedef boost::function2<PyObject*, PyObject*, PyObject*> py_function;
|
||||
|
||||
struct BOOST_PYTHON_EXPORT function : PyObject
|
||||
{
|
||||
function(py_function);
|
||||
~function();
|
||||
|
||||
PyObject* call(PyObject*, PyObject*) const;
|
||||
private:
|
||||
py_function m_fn;
|
||||
};
|
||||
|
||||
extern BOOST_PYTHON_EXPORT PyTypeObject function_type;
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // FUNCTION_DWA20011214_HPP
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MAKE_HOLDER_DWA20011215_HPP
|
||||
# define MAKE_HOLDER_DWA20011215_HPP
|
||||
|
||||
# include <boost/mpl/at.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace object {
|
||||
|
||||
|
||||
template <class T> struct undefined;
|
||||
template <class UnaryMetaFunction, class T>
|
||||
struct eval
|
||||
{
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200
|
||||
// based on the (non-conforming) MSVC trick from MPL
|
||||
template<bool>
|
||||
struct unarymetafunction_vc : UnaryMetaFunction {};
|
||||
|
||||
// illegal C++ which causes VC to admit that unarymetafunction_vc
|
||||
// can have a nested template:
|
||||
template<>
|
||||
struct unarymetafunction_vc<true>
|
||||
{
|
||||
template<class> struct apply;
|
||||
};
|
||||
|
||||
typedef typename unarymetafunction_vc<
|
||||
::boost::mpl::detail::msvc_never_true<UnaryMetaFunction>::value
|
||||
>::template apply<T>::type type;
|
||||
# else
|
||||
typedef typename UnaryMetaFunction::template apply<T>::type type;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
template <int nargs> struct make_holder;
|
||||
|
||||
template <>
|
||||
struct make_holder<0>
|
||||
{
|
||||
template <class T, class Generator, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename eval<Generator,T>::type holder;
|
||||
static void execute(
|
||||
PyObject* p)
|
||||
{
|
||||
(new holder(p))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct make_holder<1>
|
||||
{
|
||||
template <class T, class Generator, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename eval<Generator,T>::type holder;
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
|
||||
static void execute(
|
||||
PyObject* p
|
||||
, t0 a0)
|
||||
{
|
||||
(new holder(p, f0(a0)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<2>
|
||||
{
|
||||
template <class T, class Generator, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename eval<Generator,T>::type holder;
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1)
|
||||
{
|
||||
(new holder(p, f0(a0), f1(a1)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<3>
|
||||
{
|
||||
template <class T, class Generator, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename eval<Generator,T>::type holder;
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
typedef typename mpl::at<2,ArgList>::type t2;
|
||||
typedef typename forward<t2>::type f2;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1, t2 a2)
|
||||
{
|
||||
(new holder(p, f0(a0), f1(a1), f2(a2)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // MAKE_HOLDER_DWA20011215_HPP
|
||||
@@ -1,80 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef VALUE_HOLDER_DWA20011215_HPP
|
||||
# define VALUE_HOLDER_DWA20011215_HPP
|
||||
|
||||
# include <boost/python/object/class.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace object {
|
||||
|
||||
template <class Held>
|
||||
struct value_holder : holder<Held>
|
||||
{
|
||||
// Forward construction to the held object
|
||||
value_holder(PyObject*)
|
||||
: m_held() {}
|
||||
|
||||
template <class A1>
|
||||
value_holder(PyObject*, A1 a1)
|
||||
: m_held(a1) {}
|
||||
|
||||
template <class A1, class A2>
|
||||
value_holder(PyObject*, A1 a1, A2 a2)
|
||||
: m_held(a1, a2) {}
|
||||
|
||||
template <class A1, class A2, class A3>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3)
|
||||
: m_held(a1, a2, a3) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4)
|
||||
: m_held(a1, a2, a3, a4) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
|
||||
: m_held(a1, a2, a3, a4, a5) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
|
||||
: m_held(a1, a2, a3, a4, a5, a6) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
|
||||
: m_held(a1, a2, a3, a4, a5, a6, a7) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
|
||||
: m_held(a1, a2, a3, a4, a5, a6, a7, a8) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
|
||||
: m_held(a1, a2, a3, a4, a5, a6, a7, a8, a9) {}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
|
||||
value_holder(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
|
||||
: m_held(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {}
|
||||
|
||||
private: // required holder implementation
|
||||
Held* target() { return &m_held; }
|
||||
bool held_by_value() const { return true; }
|
||||
|
||||
private: // data members
|
||||
Held m_held;
|
||||
};
|
||||
|
||||
// A generator metafunction which can be passed to make_holder
|
||||
struct value_holder_generator
|
||||
{
|
||||
template <class Held>
|
||||
struct apply
|
||||
{
|
||||
typedef value_holder<Held> type;
|
||||
};
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // VALUE_HOLDER_DWA20011215_HPP
|
||||
59
pyste/NEWS
Normal file
@@ -0,0 +1,59 @@
|
||||
3 June 2003
|
||||
Appliced a patch from Giulio Eulisse that allows unnamed enumerations to be
|
||||
exported with an AllFromHeader construct. Thanks a lot Giulio!
|
||||
|
||||
2 June 2003
|
||||
Added a new construct, add_method. See documentation.
|
||||
|
||||
23 May 2003
|
||||
Support for global variables added.
|
||||
Various bug fixes.
|
||||
|
||||
08 May 2003
|
||||
Fixed bug where in a certain cases the GCCXMLParser would end up with multiple
|
||||
declarations of the same class
|
||||
|
||||
22 Apr 2003
|
||||
- Now shows a warning when the user tries to export a forward-declared class.
|
||||
Forward-declared classes are ignored by the AllFromHeader construct.
|
||||
- Fixed a bug where classes, functions and enums where being exported, even if
|
||||
excluded from a AllFromHeader construct.
|
||||
|
||||
16 Apr 2003
|
||||
Added a more generic (but ugly) code to declare the smart pointer converters.
|
||||
|
||||
07 Apr 2003
|
||||
- Removed the warnings about forward declarations: it was not accurate enough.
|
||||
Another strategy must be thought of.
|
||||
- Fixed bug in the --multiple mode, where the order of the class instantiations
|
||||
could end up wrong.
|
||||
- Lots of fixes in the documentation, pointed out by Dirk Gerrits. Thanks Dirk!
|
||||
- Fixed support for the return_opaque_pointer policy (the support macro was not
|
||||
being declared).
|
||||
|
||||
|
||||
06 Apr 2003
|
||||
Support for the improved static data members support of Boost.Python.
|
||||
|
||||
05 Apr 2003
|
||||
New option for generating the bindings: --multiple.
|
||||
|
||||
02 Apr 2003
|
||||
Forward declarations are now detected and a warning is generated.
|
||||
|
||||
24 Mar 2003
|
||||
Default policy for functions/methods that return const T& is now
|
||||
return_value_policy<copy_const_reference>().
|
||||
|
||||
22 Mar 2003
|
||||
Exporting virtual methods of the base classes in the derived classes too.
|
||||
|
||||
21 Mar 2003
|
||||
Added manual support for boost::shared_ptr and std::auto_ptr (see doc).
|
||||
|
||||
19 Mar 2003
|
||||
Added support for int, double, float and long operators acting as expected in
|
||||
python.
|
||||
|
||||
14 Mar 2003
|
||||
Fixed bug: Wrappers for protected and virtual methods were not being generated.
|
||||
31
pyste/README
Normal file
@@ -0,0 +1,31 @@
|
||||
Pyste - Python Semi-Automatic Exporter
|
||||
======================================
|
||||
|
||||
Pyste is a Boost.Python code generator. The user specifies the classes and
|
||||
functions to be exported using a simple interface file, which following the
|
||||
Boost.Python's philosophy, is simple Python code. Pyste then uses GCCXML to
|
||||
parse all the headers and extract the necessary information to automatically
|
||||
generate C++ code.
|
||||
|
||||
The documentation can be found in the file index.html accompaning this README.
|
||||
|
||||
Enjoy!
|
||||
Bruno da Silva de Oliveira (nicodemus@globalite.com.br)
|
||||
|
||||
Thanks
|
||||
======
|
||||
|
||||
- David Abrahams, creator of Boost.Python, for tips on the syntax of the interface
|
||||
file and support.
|
||||
- Marcelo Camelo, for design tips, support and inspiration for this project.
|
||||
Also, the name was his idea. 8)
|
||||
- Brad King, creator of the excellent GCCXML (http://www.gccxml.org)
|
||||
- Fredrik Lundh, creator of the elementtree library (http://effbot.org)
|
||||
|
||||
Bugs
|
||||
====
|
||||
|
||||
Pyste is a young tool, so please help it to get better! Send bug reports to
|
||||
nicodemus@globalite.com.br, accompaining the stack trace in case of exceptions.
|
||||
If possible, run pyste with --debug, and send the resulting xmls too (pyste
|
||||
will output a xml file with the same of each header it parsed).
|
||||
2
pyste/dist/.cvsignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.zip
|
||||
*.pyc
|
||||
51
pyste/dist/create_build.py
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import fnmatch
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
|
||||
def findfiles(directory, mask):
|
||||
def visit(files, dir, names):
|
||||
for name in names:
|
||||
if fnmatch.fnmatch(name, mask):
|
||||
files.append(os.path.join(dir, name))
|
||||
files = []
|
||||
os.path.walk(directory, visit, files)
|
||||
return files
|
||||
|
||||
|
||||
def main():
|
||||
# test if PyXML is installed
|
||||
try:
|
||||
import _xmlplus.parsers.expat
|
||||
pyxml = '--includes _xmlplus.parsers.expat'
|
||||
except ImportError:
|
||||
pyxml = ''
|
||||
# create exe
|
||||
status = os.system('python setup.py py2exe %s >& build.log' % pyxml)
|
||||
if status != 0:
|
||||
raise RuntimeError, 'Error creating EXE'
|
||||
|
||||
# create distribution
|
||||
import pyste
|
||||
version = pyste.__VERSION__
|
||||
zip = ZipFile('pyste-%s.zip' % version, 'w', ZIP_DEFLATED)
|
||||
# include the base files
|
||||
dist_dir = 'dist/pyste'
|
||||
for basefile in os.listdir(dist_dir):
|
||||
zip.write(os.path.join(dist_dir, basefile), os.path.join('pyste', basefile))
|
||||
# include documentation
|
||||
for doc_file in findfiles('../doc', '*.*'):
|
||||
dest_name = os.path.join('pyste/doc', doc_file[3:])
|
||||
zip.write(doc_file, dest_name)
|
||||
zip.write('../index.html', 'pyste/doc/index.html')
|
||||
zip.close()
|
||||
# cleanup
|
||||
os.remove('build.log')
|
||||
shutil.rmtree('build')
|
||||
shutil.rmtree('dist')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.path.append('../src')
|
||||
main()
|
||||
6
pyste/dist/setup.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
from distutils.core import setup
|
||||
import py2exe
|
||||
import sys
|
||||
|
||||
sys.path.append('../src')
|
||||
setup(name='pyste', scripts=['../src/pyste.py'])
|
||||
78
pyste/doc/adding_new_methods.html
Normal file
@@ -0,0 +1,78 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Adding New Methods</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="global_variables.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Adding New Methods</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="global_variables.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Suppose that you want to add a function to a class, turning it into a method:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>World
|
||||
</span><span class=special>{
|
||||
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>) { </span><span class=keyword>this</span><span class=special>-></span><span class=identifier>msg </span><span class=special>= </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>;
|
||||
};
|
||||
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>greet</span><span class=special>(</span><span class=identifier>World</span><span class=special>& </span><span class=identifier>w</span><span class=special>)
|
||||
{
|
||||
</span><span class=keyword>return </span><span class=identifier>w</span><span class=special>.</span><span class=identifier>msg</span><span class=special>;
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Here, we want to make <tt>greet</tt> work as a method of the class <tt>World</tt>. We do
|
||||
that using the <tt>add_method</tt> construct:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>W </span><span class=special>= </span><span class=identifier>Class</span><span class=special>(</span><span class=string>"World"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>add_method</span><span class=special>(</span><span class=identifier>W</span><span class=special>, </span><span class=string>"greet"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Notice also that then you can rename it, set its policy, just like a regular
|
||||
method:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>rename</span><span class=special>(</span><span class=identifier>W</span><span class=special>.</span><span class=identifier>greet</span><span class=special>, </span><span class=literal>'Greet'</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Now from Python:</p>
|
||||
<code><pre>
|
||||
<span class=special>>>> </span><span class=identifier>import </span><span class=identifier>hello
|
||||
</span><span class=special>>>> </span><span class=identifier>w </span><span class=special>= </span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>World</span><span class=special>()
|
||||
>>> </span><span class=identifier>w</span><span class=special>.</span><span class=identifier>set</span><span class=special>(</span><span class=literal>'Ni'</span><span class=special>)
|
||||
>>> </span><span class=identifier>w</span><span class=special>.</span><span class=identifier>greet</span><span class=special>()
|
||||
</span><span class=literal>'Ni'
|
||||
</span><span class=special>>>> </span><span class=identifier>print </span><span class=literal>'Oh no! The knights who say Ni!'
|
||||
</span><span class=identifier>Oh </span><span class=identifier>no</span><span class=special>! </span><span class=identifier>The </span><span class=identifier>knights </span><span class=identifier>who </span><span class=identifier>say </span><span class=identifier>Ni</span><span class=special>!
|
||||
</span></pre></code>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="global_variables.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
77
pyste/doc/exporting_all_declarations_from_a_header.html
Normal file
@@ -0,0 +1,77 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Exporting All Declarations from a Header</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="wrappers.html">
|
||||
<link rel="next" href="smart_pointers.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Exporting All Declarations from a Header</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="wrappers.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="smart_pointers.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Pyste also supports a mechanism to export all declarations found in a header
|
||||
file. Suppose again our file, <tt>hello.h</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>World
|
||||
</span><span class=special>{
|
||||
</span><span class=identifier>World</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>): </span><span class=identifier>msg</span><span class=special>(</span><span class=identifier>msg</span><span class=special>) {}
|
||||
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>) { </span><span class=keyword>this</span><span class=special>-></span><span class=identifier>msg </span><span class=special>= </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>greet</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>;
|
||||
};
|
||||
|
||||
</span><span class=keyword>enum </span><span class=identifier>choice </span><span class=special>{ </span><span class=identifier>red</span><span class=special>, </span><span class=identifier>blue </span><span class=special>};
|
||||
|
||||
</span><span class=keyword>void </span><span class=identifier>show</span><span class=special>(</span><span class=identifier>choice </span><span class=identifier>c</span><span class=special>) { </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>cout </span><span class=special><< </span><span class=string>"value: " </span><span class=special><< (</span><span class=keyword>int</span><span class=special>)</span><span class=identifier>c </span><span class=special><< </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>endl</span><span class=special>; }
|
||||
</span></pre></code>
|
||||
<p>
|
||||
You can just use the <tt>AllFromHeader</tt> construct:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>hello </span><span class=special>= </span><span class=identifier>AllFromHeader</span><span class=special>(</span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
this will export all the declarations found in <tt>hello.h</tt>, which is equivalent
|
||||
to write:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Class</span><span class=special>(</span><span class=string>"World"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>Enum</span><span class=special>(</span><span class=string>"choice"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>Function</span><span class=special>(</span><span class=string>"show"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Note that you can still use the functions <tt>rename</tt>, <tt>set_policy</tt>, <tt>exclude</tt>, etc. Just access
|
||||
the members of the header object like this:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>rename</span><span class=special>(</span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>World</span><span class=special>.</span><span class=identifier>greet</span><span class=special>, </span><span class=string>"Greet"</span><span class=special>)
|
||||
</span><span class=identifier>exclude</span><span class=special>(</span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>World</span><span class=special>.</span><span class=identifier>set</span><span class=special>, </span><span class=string>"Set"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="wrappers.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="smart_pointers.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
50
pyste/doc/global_variables.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Global Variables</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="smart_pointers.html">
|
||||
<link rel="next" href="adding_new_methods.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Global Variables</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="smart_pointers.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="adding_new_methods.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
To export global variables, use the <tt>Var</tt> construct:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Var</span><span class=special>(</span><span class=string>"myglobal"</span><span class=special>, </span><span class=string>"foo.h"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Beware of non-const global variables: changes in Python won't reflect in C++!
|
||||
If you really must change them in Python, you will have to write some accessor
|
||||
functions, and export those.</p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="smart_pointers.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="adding_new_methods.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
74
pyste/doc/introduction.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Introduction</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="next" href="running_pyste.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Introduction</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><img src="theme/l_arr_disabled.gif" border="0"></td>
|
||||
<td width="20"><a href="running_pyste.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a name="what_is_pyste_"></a><h2>What is Pyste?</h2><p>
|
||||
Pyste is a <a href="../../index.html">
|
||||
Boost.Python</a> code generator. The user specifies the classes and
|
||||
functions to be exported using a simple <i>interface file</i>, which following the
|
||||
<a href="../../index.html">
|
||||
Boost.Python</a>'s philosophy, is simple Python code. Pyste then uses <a href="http://www.gccxml.org">
|
||||
GCCXML</a> to
|
||||
parse all the headers and extract the necessary information to automatically
|
||||
generate C++ code.</p>
|
||||
<a name="example"></a><h2>Example</h2><p>
|
||||
Let's borrow the class <tt>World</tt> from the <a href="../../doc/tutorial/doc/exposing_classes.html">
|
||||
tutorial</a>: </p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>World
|
||||
</span><span class=special>{
|
||||
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>) { </span><span class=keyword>this</span><span class=special>-></span><span class=identifier>msg </span><span class=special>= </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>greet</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>;
|
||||
};
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Here's the interface file for it, named <tt>world.pyste</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Class</span><span class=special>(</span><span class=string>"World"</span><span class=special>, </span><span class=string>"world.h"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
and that's it!</p>
|
||||
<p>
|
||||
The next step is invoke Pyste in the command-line:</p>
|
||||
<code><pre>python pyste.py --module=hello world.pyste</pre></code><p>
|
||||
this will create a file "<tt>hello.cpp</tt>" in the directory where the command was
|
||||
run. </p>
|
||||
<p>
|
||||
Pyste supports the following features:</p>
|
||||
<ul><li>Functions</li><li>Classes</li><li>Class Templates</li><li>Virtual Methods</li><li>Overloading</li><li>Attributes </li><li>Enums (both "free" enums and class enums)</li><li>Nested Classes</li><li>Support for <tt>boost::shared_ptr</tt> and <tt>std::auto_ptr</tt></li><li>Global Variables</li></ul><table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><img src="theme/l_arr_disabled.gif" border="0"></td>
|
||||
<td width="20"><a href="running_pyste.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
90
pyste/doc/policies.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Policies</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="renaming_and_excluding.html">
|
||||
<link rel="next" href="templates.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Policies</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="renaming_and_excluding.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="templates.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Even thought Pyste can identify various elements in the C++ code, like virtual
|
||||
methods, attributes, and so on, one thing that it can't do is to guess the
|
||||
semantics of functions that return pointers or references. In this case, the
|
||||
user must manually specify the policy. Policies are explained in the
|
||||
<a href="../../doc/tutorial/doc/call_policies.html">
|
||||
tutorial</a>.</p>
|
||||
<p>
|
||||
The policies in Pyste are named exactly as in <a href="../../index.html">
|
||||
Boost.Python</a>, only the syntax is
|
||||
slightly different. For instance, this policy:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>return_internal_reference</span><span class=special><</span><span class=number>1</span><span class=special>, </span><span class=identifier>with_custodian_and_ward</span><span class=special><</span><span class=number>1</span><span class=special>, </span><span class=number>2</span><span class=special>> >()
|
||||
</span></pre></code>
|
||||
<p>
|
||||
becomes in Pyste: </p>
|
||||
<code><pre>
|
||||
<span class=identifier>return_internal_reference</span><span class=special>(</span><span class=number>1</span><span class=special>, </span><span class=identifier>with_custodian_and_ward</span><span class=special>(</span><span class=number>1</span><span class=special>, </span><span class=number>2</span><span class=special>))
|
||||
</span></pre></code>
|
||||
<p>
|
||||
The user can specify policies for functions and methods with the <tt>set_policy</tt>
|
||||
function:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>set_policy</span><span class=special>(</span><span class=identifier>f</span><span class=special>, </span><span class=identifier>return_internal_reference</span><span class=special>())
|
||||
</span><span class=identifier>set_policy</span><span class=special>(</span><span class=identifier>C</span><span class=special>.</span><span class=identifier>foo</span><span class=special>, </span><span class=identifier>return_value_policy</span><span class=special>(</span><span class=identifier>manage_new_object</span><span class=special>))
|
||||
</span></pre></code>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
|
||||
<img src="theme/note.gif"></img> <b>What if a function or method needs a policy and the user
|
||||
doesn't set one?</b><br><br> If a function/method needs a policy and one was not
|
||||
set, Pyste will issue a error. The user should then go in the interface file
|
||||
and set the policy for it, otherwise the generated cpp won't compile.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
|
||||
<img src="theme/note.gif"></img>
|
||||
Note that, for functions/methods that return <tt>const T&</tt>, the policy
|
||||
<tt>return_value_policy<copy_const_reference>()</tt> wil be used by default, because
|
||||
that's normally what you want. You can change it to something else if you need
|
||||
to, though.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="renaming_and_excluding.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="templates.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
516
pyste/doc/pyste.txt
Normal file
@@ -0,0 +1,516 @@
|
||||
[doc Pyste Documentation]
|
||||
|
||||
[def GCCXML [@http://www.gccxml.org GCCXML]]
|
||||
[def Boost.Python [@../../index.html Boost.Python]]
|
||||
|
||||
[page Introduction]
|
||||
|
||||
[h2 What is Pyste?]
|
||||
|
||||
Pyste is a Boost.Python code generator. The user specifies the classes and
|
||||
functions to be exported using a simple ['interface file], which following the
|
||||
Boost.Python's philosophy, is simple Python code. Pyste then uses GCCXML to
|
||||
parse all the headers and extract the necessary information to automatically
|
||||
generate C++ code.
|
||||
|
||||
[h2 Example]
|
||||
|
||||
Let's borrow the class [^World] from the [@../../doc/tutorial/doc/exposing_classes.html tutorial]:
|
||||
|
||||
struct World
|
||||
{
|
||||
void set(std::string msg) { this->msg = msg; }
|
||||
std::string greet() { return msg; }
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
Here's the interface file for it, named [^world.pyste]:
|
||||
|
||||
Class("World", "world.h")
|
||||
|
||||
and that's it!
|
||||
|
||||
The next step is invoke Pyste in the command-line:
|
||||
|
||||
[pre python pyste.py --module=hello world.pyste]
|
||||
|
||||
this will create a file "[^hello.cpp]" in the directory where the command was
|
||||
run.
|
||||
|
||||
Pyste supports the following features:
|
||||
|
||||
* Functions
|
||||
* Classes
|
||||
* Class Templates
|
||||
* Virtual Methods
|
||||
* Overloading
|
||||
* Attributes
|
||||
* Enums (both "free" enums and class enums)
|
||||
* Nested Classes
|
||||
* Support for [^boost::shared_ptr] and [^std::auto_ptr]
|
||||
* Global Variables
|
||||
|
||||
[page Running Pyste]
|
||||
|
||||
To run Pyste, you will need:
|
||||
|
||||
* Python 2.2, available at [@http://www.python.org python's website].
|
||||
* The great [@http://effbot.org elementtree] library, from Fredrik Lundh.
|
||||
* The excellent GCCXML, from Brad King.
|
||||
|
||||
Installation for the tools is available in their respective webpages.
|
||||
|
||||
[blurb
|
||||
[$theme/note.gif] GCCXML must be accessible in the PATH environment variable, so
|
||||
that Pyste can call it. How to do this varies from platform to platform.
|
||||
]
|
||||
|
||||
[h2 Ok, now what?]
|
||||
|
||||
Well, now let's fire it up:
|
||||
|
||||
[pre
|
||||
'''
|
||||
>python pyste.py
|
||||
|
||||
Pyste version 0.6.5
|
||||
|
||||
Usage:
|
||||
pyste [options] --module=<name> interface-files
|
||||
|
||||
where options are:
|
||||
-I <path> add an include path
|
||||
-D <symbol> define symbol
|
||||
--multiple create various cpps, instead of only one
|
||||
(useful during development)
|
||||
--out specify output filename (default: <module>.cpp)
|
||||
in --multiple mode, this will be a directory
|
||||
--no-using do not declare "using namespace boost";
|
||||
use explicit declarations instead
|
||||
--pyste-ns=<name> set the namespace where new types will be declared;
|
||||
default is the empty namespace
|
||||
--debug writes the xml for each file parsed in the current
|
||||
directory
|
||||
-h, --help print this help and exit
|
||||
-v, --version print version information
|
||||
'''
|
||||
]
|
||||
|
||||
Options explained:
|
||||
|
||||
The [^-I] and [^-D] are preprocessor flags, which are needed by GCCXML to parse
|
||||
the header files correctly and by Pyste to find the header files declared in the
|
||||
interface files.
|
||||
|
||||
[^--multiple] tells Pyste to generate multiple cpps for this module (one for
|
||||
each header parsed) in the directory named by [^--out], instead of the usual
|
||||
single cpp file. This mode is useful during development of a binding, because
|
||||
you are constantly changing source files, re-generating the bindings and
|
||||
recompiling. This saves a lot of time in compiling.
|
||||
|
||||
[^--out] names the output file (default: [^<module>.cpp]), or in multiple mode,
|
||||
names a output directory for the files (default: [^<module>]).
|
||||
|
||||
[^--no-using] tells Pyste to don't declare "[^using namespace boost;]" in the
|
||||
generated cpp, using the namespace boost::python explicitly in all declarations.
|
||||
Use only if you're having a name conflict in one of the files.
|
||||
|
||||
Use [^--pyste-ns] to change the namespace where new types are declared (for
|
||||
instance, the virtual wrappers). Use only if you are having any problems. By
|
||||
default, Pyste uses the empty namespace.
|
||||
|
||||
[^--debug] will write in the current directory a xml file as outputted by GCCXML
|
||||
for each header parsed. Useful for bug reports.
|
||||
|
||||
[^-h, --help, -v, --version] are self-explaining, I believe. ;)
|
||||
|
||||
So, the usage is simple enough:
|
||||
|
||||
[pre >python pyste.py --module=mymodule file.pyste file2.pyste ...]
|
||||
|
||||
will generate a file [^mymodule.cpp] in the same dir where the command was
|
||||
executed. Now you can compile the file using the same instructions of the
|
||||
[@../../doc/tutorial/doc/building_hello_world.html tutorial]. Or, if you prefer:
|
||||
|
||||
[pre >python pyste.py --module=mymodule --multiple file.pyste file2.pyste ...]
|
||||
|
||||
will create a directory named "mymodule" in the current directory, and will
|
||||
generate a bunch of cpp files, one for each header exported. You can then
|
||||
compile them all into a single shared library (or dll).
|
||||
|
||||
[h2 Wait... how do I set those I and D flags?]
|
||||
|
||||
Don't worry: normally GCCXML is already configured correctly for your plataform,
|
||||
so the search path to the standard libraries and the standard defines should
|
||||
already be set. You only have to set the paths to other libraries that your code
|
||||
needs, like Boost, for example.
|
||||
|
||||
Plus, Pyste automatically uses the contents of the environment variable
|
||||
[^INCLUDE] if it exists. Visual C++ users should run the [^Vcvars32.bat] file,
|
||||
which for Visual C++ 6 is normally located at:
|
||||
|
||||
C:\Program Files\Microsoft Visual Studio\VC98\bin\Vcvars32.bat
|
||||
|
||||
with that, you should have little trouble setting up the flags.
|
||||
|
||||
[blurb [$theme/note.gif][*A note about Psyco][br][br]
|
||||
Although you don't have to install [@http://psyco.sourceforge.net/ Psyco] to use Pyste, if you do, Pyste will make use of it to speed up the wrapper generation. Speed ups of 30% can be achieved, so it's highly recommended.
|
||||
]
|
||||
|
||||
[page The Interface Files]
|
||||
|
||||
The interface files are the heart of Pyste. The user creates one or more
|
||||
interface files declaring the classes and functions he wants to export, and then
|
||||
invokes Pyste passing the interface files to it. Pyste then generates a single
|
||||
cpp file with Boost.Python code, with all the classes and functions exported.
|
||||
|
||||
Besides declaring the classes and functions, the user has a number of other
|
||||
options, like renaming classes and methods, excluding methods and attributes,
|
||||
and so on.
|
||||
|
||||
[h2 Basics]
|
||||
|
||||
Suppose we have a class and some functions that we want to expose to Python
|
||||
declared in the header [^hello.h]:
|
||||
|
||||
struct World
|
||||
{
|
||||
World(std::string msg): msg(msg) {}
|
||||
void set(std::string msg) { this->msg = msg; }
|
||||
std::string greet() { return msg; }
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
enum choice { red, blue };
|
||||
|
||||
namespace test {
|
||||
|
||||
void show(choice c) { std::cout << "value: " << (int)c << std::endl; }
|
||||
|
||||
}
|
||||
|
||||
We create a file named [^hello.pyste] and create instances of the classes
|
||||
[^Function], [^Class] and [^Enum]:
|
||||
|
||||
Function("test::show", "hello.h")
|
||||
Class("World", "hello.h")
|
||||
Enum("choice", "hello.h")
|
||||
|
||||
That will expose the class, the free function and the enum found in [^hello.h].
|
||||
|
||||
[page:1 Renaming and Excluding]
|
||||
|
||||
You can easily rename functions, classes, methods, attributes, etc. Just use the
|
||||
function [^rename], like this:
|
||||
|
||||
World = Class("World", "hello.h")
|
||||
rename(World, "IWorld")
|
||||
show = Function("choice", "hello.h")
|
||||
rename(show, "Show")
|
||||
|
||||
You can rename methods and attributes using this syntax:
|
||||
|
||||
rename(World.greet, "Greet")
|
||||
rename(World.set, "Set")
|
||||
choice = Enum("choice", "hello.h")
|
||||
rename(choice.red, "Red")
|
||||
rename(choice.blue, "Blue")
|
||||
|
||||
You can exclude functions, classes, methods, attributes, etc, in the same way,
|
||||
with the function [^exclude]:
|
||||
|
||||
exclude(World.greet)
|
||||
exclude(World.msg)
|
||||
|
||||
To access the operators of a class, access the member [^operator] like this
|
||||
(supposing that [^C] is a class being exported):
|
||||
|
||||
exclude(C.operator['+'])
|
||||
exclude(C.operator['*'])
|
||||
exclude(C.operator['<<'])
|
||||
|
||||
The string inside the brackets is the same as the name of the operator in C++.[br]
|
||||
|
||||
[page:1 Policies]
|
||||
|
||||
Even thought Pyste can identify various elements in the C++ code, like virtual
|
||||
methods, attributes, and so on, one thing that it can't do is to guess the
|
||||
semantics of functions that return pointers or references. In this case, the
|
||||
user must manually specify the policy. Policies are explained in the
|
||||
[@../../doc/tutorial/doc/call_policies.html tutorial].
|
||||
|
||||
The policies in Pyste are named exactly as in Boost.Python, only the syntax is
|
||||
slightly different. For instance, this policy:
|
||||
|
||||
return_internal_reference<1, with_custodian_and_ward<1, 2> >()
|
||||
|
||||
becomes in Pyste:
|
||||
|
||||
return_internal_reference(1, with_custodian_and_ward(1, 2))
|
||||
|
||||
The user can specify policies for functions and methods with the [^set_policy]
|
||||
function:
|
||||
|
||||
set_policy(f, return_internal_reference())
|
||||
set_policy(C.foo, return_value_policy(manage_new_object))
|
||||
|
||||
[blurb
|
||||
[$theme/note.gif] [*What if a function or method needs a policy and the user
|
||||
doesn't set one?][br][br] If a function/method needs a policy and one was not
|
||||
set, Pyste will issue a error. The user should then go in the interface file
|
||||
and set the policy for it, otherwise the generated cpp won't compile.
|
||||
]
|
||||
|
||||
[blurb
|
||||
[$theme/note.gif]
|
||||
Note that, for functions/methods that return [^const T&], the policy
|
||||
[^return_value_policy<copy_const_reference>()] wil be used by default, because
|
||||
that's normally what you want. You can change it to something else if you need
|
||||
to, though.
|
||||
]
|
||||
|
||||
[page:1 Templates]
|
||||
|
||||
Template classes can easily be exported too, but you can't export the template
|
||||
itself... you have to export instantiations of it! So, if you want to export a
|
||||
[^std::vector], you will have to export vectors of int, doubles, etc.
|
||||
|
||||
Suppose we have this code:
|
||||
|
||||
template <class T>
|
||||
struct Point
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
};
|
||||
|
||||
And we want to export [^Point]s of int and double:
|
||||
|
||||
Point = Template("Point", "point.h")
|
||||
Point("int")
|
||||
Point("double")
|
||||
|
||||
Pyste will assign default names for each instantiation. In this example, those
|
||||
would be "[^Point_int]" and "[^Point_double]", but most of the time users will want to
|
||||
rename the instantiations:
|
||||
|
||||
Point("int", "IPoint") // renames the instantiation
|
||||
double_inst = Point("double") // another way to do the same
|
||||
rename(double_inst, "DPoint")
|
||||
|
||||
Note that you can rename, exclude, set policies, etc, in the [^Template] object
|
||||
like you would do with a [^Function] or a [^Class]. This changes affect all
|
||||
[*future] instantiations:
|
||||
|
||||
Point = Template("Point", "point.h")
|
||||
Point("float", "FPoint") // will have x and y as data members
|
||||
rename(Point.x, "X")
|
||||
rename(Point.y, "Y")
|
||||
Point("int", "IPoint") // will have X and Y as data members
|
||||
Point("double", "DPoint") // also will have X and Y as data member
|
||||
|
||||
If you want to change a option of a particular instantiation, you can do so:
|
||||
|
||||
Point = Template("Point", "point.h")
|
||||
Point("int", "IPoint")
|
||||
d_inst = Point("double", "DPoint")
|
||||
rename(d_inst.x, "X") // only DPoint is affect by this renames,
|
||||
rename(d_inst.y, "Y") // IPoint stays intact
|
||||
|
||||
[blurb [$theme/note.gif] [*What if my template accepts more than one type?]
|
||||
[br][br]
|
||||
When you want to instantiate a template with more than one type, you can pass
|
||||
either a string with the types separated by whitespace, or a list of strings
|
||||
'''("int double" or ["int", "double"]''' would both work).
|
||||
]
|
||||
|
||||
[page:1 Wrappers]
|
||||
|
||||
Suppose you have this function:
|
||||
|
||||
std::vector<std::string> names();
|
||||
|
||||
But you don't want to export [^std::vector<std::string>], you want this function
|
||||
to return a python list of strings. Boost.Python has excellent support for
|
||||
that:
|
||||
|
||||
list names_wrapper()
|
||||
{
|
||||
list result;
|
||||
// call original function
|
||||
vector<string> v = names();
|
||||
// put all the strings inside the python list
|
||||
vector<string>::iterator it;
|
||||
for (it = v.begin(); it != v.end(); ++it){
|
||||
result.append(*it);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(test)
|
||||
{
|
||||
def("names", &names_wrapper);
|
||||
}
|
||||
|
||||
Nice heh? Pyste supports this mechanism too. You declare the [^names_wrapper]
|
||||
function in a header named "[^test_wrappers.h]" and in the interface file:
|
||||
|
||||
Include("test_wrappers.h")
|
||||
names = Function("names", "test.h")
|
||||
set_wrapper(names, "names_wrapper")
|
||||
|
||||
You can optionally declare the function in the interface file itself:
|
||||
|
||||
names_wrapper = Wrapper("names_wrapper",
|
||||
"""
|
||||
list names_wrapper()
|
||||
{
|
||||
// code to call name() and convert the vector to a list...
|
||||
}
|
||||
""")
|
||||
names = Function("names", "test.h")
|
||||
set_wrapper(names, names_wrapper)
|
||||
|
||||
The same mechanism can be used with methods too. Just remember that the first
|
||||
parameter of wrappers for methods is a pointer to the class, like in
|
||||
Boost.Python:
|
||||
|
||||
struct C
|
||||
{
|
||||
std::vector<std::string> names();
|
||||
}
|
||||
|
||||
list names_wrapper(C* c)
|
||||
{
|
||||
// same as before, calling c->names() and converting result to a list
|
||||
}
|
||||
|
||||
And then in the interface file:
|
||||
|
||||
C = Class("C", "test.h")
|
||||
set_wrapper(C.names, "names_wrapper")
|
||||
|
||||
[blurb
|
||||
[$theme/note.gif]Even though Boost.Python accepts either a pointer or a
|
||||
reference to the class in wrappers for member functions as the first parameter,
|
||||
Pyste expects them to be a [*pointer]. Doing otherwise will prevent your
|
||||
code to compile when you set a wrapper for a virtual method.
|
||||
]
|
||||
|
||||
[page:1 Exporting All Declarations from a Header]
|
||||
|
||||
Pyste also supports a mechanism to export all declarations found in a header
|
||||
file. Suppose again our file, [^hello.h]:
|
||||
|
||||
struct World
|
||||
{
|
||||
World(std::string msg): msg(msg) {}
|
||||
void set(std::string msg) { this->msg = msg; }
|
||||
std::string greet() { return msg; }
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
enum choice { red, blue };
|
||||
|
||||
void show(choice c) { std::cout << "value: " << (int)c << std::endl; }
|
||||
|
||||
You can just use the [^AllFromHeader] construct:
|
||||
|
||||
hello = AllFromHeader("hello.h")
|
||||
|
||||
this will export all the declarations found in [^hello.h], which is equivalent
|
||||
to write:
|
||||
|
||||
Class("World", "hello.h")
|
||||
Enum("choice", "hello.h")
|
||||
Function("show", "hello.h")
|
||||
|
||||
Note that you can still use the functions [^rename], [^set_policy], [^exclude], etc. Just access
|
||||
the members of the header object like this:
|
||||
|
||||
rename(hello.World.greet, "Greet")
|
||||
exclude(hello.World.set, "Set")
|
||||
|
||||
|
||||
[page:1 Smart Pointers]
|
||||
|
||||
Pyste for now has manual support for smart pointers. Suppose:
|
||||
|
||||
struct C
|
||||
{
|
||||
int value;
|
||||
};
|
||||
|
||||
boost::shared_ptr<C> newC(int value)
|
||||
{
|
||||
boost::shared_ptr<C> c( new C() );
|
||||
c->value = value;
|
||||
return c;
|
||||
}
|
||||
|
||||
void printC(boost::shared_ptr<C> c)
|
||||
{
|
||||
std::cout << c->value << std::endl;
|
||||
}
|
||||
|
||||
To make [^newC] and [^printC] work correctly, you have to tell Pyste that a
|
||||
convertor for [^boost::shared_ptr<C>] is needed.
|
||||
|
||||
C = Class('C', 'C.h')
|
||||
use_shared_ptr(C)
|
||||
Function('newC', 'C.h')
|
||||
Function('printC', 'C.h')
|
||||
|
||||
For [^std::auto_ptr]'s, use the function [^use_auto_ptr].
|
||||
|
||||
This system is temporary, and in the future the converters will automatically be
|
||||
exported if needed, without the need to tell Pyste about them explicitly.
|
||||
|
||||
|
||||
[page:1 Global Variables]
|
||||
|
||||
To export global variables, use the [^Var] construct:
|
||||
|
||||
Var("myglobal", "foo.h")
|
||||
|
||||
Beware of non-const global variables: changes in Python won't reflect in C++!
|
||||
If you really must change them in Python, you will have to write some accessor
|
||||
functions, and export those.
|
||||
|
||||
[page:1 Adding New Methods]
|
||||
|
||||
Suppose that you want to add a function to a class, turning it into a method:
|
||||
|
||||
struct World
|
||||
{
|
||||
void set(std::string msg) { this->msg = msg; }
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
std::string greet(World& w)
|
||||
{
|
||||
return w.msg;
|
||||
}
|
||||
|
||||
Here, we want to make [^greet] work as a method of the class [^World]. We do
|
||||
that using the [^add_method] construct:
|
||||
|
||||
W = Class("World", "hello.h")
|
||||
add_method(W, "greet")
|
||||
|
||||
Notice also that then you can rename it, set its policy, just like a regular
|
||||
method:
|
||||
|
||||
rename(W.greet, 'Greet')
|
||||
|
||||
Now from Python:
|
||||
|
||||
>>> import hello
|
||||
>>> w = hello.World()
|
||||
>>> w.set('Ni')
|
||||
>>> w.greet()
|
||||
'Ni'
|
||||
>>> print 'Oh no! The knights who say Ni!'
|
||||
Oh no! The knights who say Ni!
|
||||
|
||||
|
||||
76
pyste/doc/renaming_and_excluding.html
Normal file
@@ -0,0 +1,76 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Renaming and Excluding</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="the_interface_files.html">
|
||||
<link rel="next" href="policies.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Renaming and Excluding</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="the_interface_files.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="policies.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
You can easily rename functions, classes, methods, attributes, etc. Just use the
|
||||
function <tt>rename</tt>, like this:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>World </span><span class=special>= </span><span class=identifier>Class</span><span class=special>(</span><span class=string>"World"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>World</span><span class=special>, </span><span class=string>"IWorld"</span><span class=special>)
|
||||
</span><span class=identifier>show </span><span class=special>= </span><span class=identifier>Function</span><span class=special>(</span><span class=string>"choice"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>show</span><span class=special>, </span><span class=string>"Show"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
You can rename methods and attributes using this syntax:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>rename</span><span class=special>(</span><span class=identifier>World</span><span class=special>.</span><span class=identifier>greet</span><span class=special>, </span><span class=string>"Greet"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>World</span><span class=special>.</span><span class=identifier>set</span><span class=special>, </span><span class=string>"Set"</span><span class=special>)
|
||||
</span><span class=identifier>choice </span><span class=special>= </span><span class=identifier>Enum</span><span class=special>(</span><span class=string>"choice"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>choice</span><span class=special>.</span><span class=identifier>red</span><span class=special>, </span><span class=string>"Red"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>choice</span><span class=special>.</span><span class=identifier>blue</span><span class=special>, </span><span class=string>"Blue"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
You can exclude functions, classes, methods, attributes, etc, in the same way,
|
||||
with the function <tt>exclude</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>exclude</span><span class=special>(</span><span class=identifier>World</span><span class=special>.</span><span class=identifier>greet</span><span class=special>)
|
||||
</span><span class=identifier>exclude</span><span class=special>(</span><span class=identifier>World</span><span class=special>.</span><span class=identifier>msg</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
To access the operators of a class, access the member <tt>operator</tt> like this
|
||||
(supposing that <tt>C</tt> is a class being exported):</p>
|
||||
<code><pre>
|
||||
<span class=identifier>exclude</span><span class=special>(</span><span class=identifier>C</span><span class=special>.</span><span class=keyword>operator</span><span class=special>[</span><span class=literal>'+'</span><span class=special>])
|
||||
</span><span class=identifier>exclude</span><span class=special>(</span><span class=identifier>C</span><span class=special>.</span><span class=keyword>operator</span><span class=special>[</span><span class=literal>'*'</span><span class=special>])
|
||||
</span><span class=identifier>exclude</span><span class=special>(</span><span class=identifier>C</span><span class=special>.</span><span class=keyword>operator</span><span class=special>[</span><span class=literal>'<<'</span><span class=special>])
|
||||
</span></pre></code>
|
||||
<p>
|
||||
The string inside the brackets is the same as the name of the operator in C++.<br></p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="the_interface_files.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="policies.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
150
pyste/doc/running_pyste.html
Normal file
@@ -0,0 +1,150 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Running Pyste</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="introduction.html">
|
||||
<link rel="next" href="the_interface_files.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Running Pyste</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="introduction.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="the_interface_files.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
To run Pyste, you will need:</p>
|
||||
<ul><li>Python 2.2, available at <a href="http://www.python.org">
|
||||
python's website</a>.</li><li>The great <a href="http://effbot.org">
|
||||
elementtree</a> library, from Fredrik Lundh.</li><li>The excellent <a href="http://www.gccxml.org">
|
||||
GCCXML</a>, from Brad King.</li></ul><p>
|
||||
Installation for the tools is available in their respective webpages.</p>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
|
||||
<img src="theme/note.gif"></img> <a href="http://www.gccxml.org">
|
||||
GCCXML</a> must be accessible in the PATH environment variable, so
|
||||
that Pyste can call it. How to do this varies from platform to platform.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a name="ok__now_what_"></a><h2>Ok, now what?</h2><p>
|
||||
Well, now let's fire it up:</p>
|
||||
<code><pre>
|
||||
|
||||
>python pyste.py
|
||||
|
||||
Pyste version 0.6.5
|
||||
|
||||
Usage:
|
||||
pyste [options] --module=<name> interface-files
|
||||
|
||||
where options are:
|
||||
-I <path> add an include path
|
||||
-D <symbol> define symbol
|
||||
--multiple create various cpps, instead of only one
|
||||
(useful during development)
|
||||
--out specify output filename (default: <module>.cpp)
|
||||
in --multiple mode, this will be a directory
|
||||
--no-using do not declare "using namespace boost";
|
||||
use explicit declarations instead
|
||||
--pyste-ns=<name> set the namespace where new types will be declared;
|
||||
default is the empty namespace
|
||||
--debug writes the xml for each file parsed in the current
|
||||
directory
|
||||
-h, --help print this help and exit
|
||||
-v, --version print version information
|
||||
|
||||
</pre></code><p>
|
||||
Options explained:</p>
|
||||
<p>
|
||||
The <tt>-I</tt> and <tt>-D</tt> are preprocessor flags, which are needed by <a href="http://www.gccxml.org">
|
||||
GCCXML</a> to parse
|
||||
the header files correctly and by Pyste to find the header files declared in the
|
||||
interface files.</p>
|
||||
<p>
|
||||
<tt>--multiple</tt> tells Pyste to generate multiple cpps for this module (one for
|
||||
each header parsed) in the directory named by <tt>--out</tt>, instead of the usual
|
||||
single cpp file. This mode is useful during development of a binding, because
|
||||
you are constantly changing source files, re-generating the bindings and
|
||||
recompiling. This saves a lot of time in compiling.</p>
|
||||
<p>
|
||||
<tt>--out</tt> names the output file (default: <tt><module>.cpp</tt>), or in multiple mode,
|
||||
names a output directory for the files (default: <tt><module></tt>).</p>
|
||||
<p>
|
||||
<tt>--no-using</tt> tells Pyste to don't declare "<tt>using namespace boost;</tt>" in the
|
||||
generated cpp, using the namespace boost::python explicitly in all declarations.
|
||||
Use only if you're having a name conflict in one of the files.</p>
|
||||
<p>
|
||||
Use <tt>--pyste-ns</tt> to change the namespace where new types are declared (for
|
||||
instance, the virtual wrappers). Use only if you are having any problems. By
|
||||
default, Pyste uses the empty namespace.</p>
|
||||
<p>
|
||||
<tt>--debug</tt> will write in the current directory a xml file as outputted by <a href="http://www.gccxml.org">
|
||||
GCCXML</a>
|
||||
for each header parsed. Useful for bug reports.</p>
|
||||
<p>
|
||||
<tt>-h, --help, -v, --version</tt> are self-explaining, I believe. ;)</p>
|
||||
<p>
|
||||
So, the usage is simple enough:</p>
|
||||
<code><pre>>python pyste.py --module=mymodule file.pyste file2.pyste ...</pre></code><p>
|
||||
will generate a file <tt>mymodule.cpp</tt> in the same dir where the command was
|
||||
executed. Now you can compile the file using the same instructions of the
|
||||
<a href="../../doc/tutorial/doc/building_hello_world.html">
|
||||
tutorial</a>. Or, if you prefer:</p>
|
||||
<code><pre>>python pyste.py --module=mymodule --multiple file.pyste file2.pyste ...</pre></code><p>
|
||||
will create a directory named "mymodule" in the current directory, and will
|
||||
generate a bunch of cpp files, one for each header exported. You can then
|
||||
compile them all into a single shared library (or dll).</p>
|
||||
<a name="wait____how_do_i_set_those_i_and_d_flags_"></a><h2>Wait... how do I set those I and D flags?</h2><p>
|
||||
Don't worry: normally <a href="http://www.gccxml.org">
|
||||
GCCXML</a> is already configured correctly for your plataform,
|
||||
so the search path to the standard libraries and the standard defines should
|
||||
already be set. You only have to set the paths to other libraries that your code
|
||||
needs, like Boost, for example.</p>
|
||||
<p>
|
||||
Plus, Pyste automatically uses the contents of the environment variable
|
||||
<tt>INCLUDE</tt> if it exists. Visual C++ users should run the <tt>Vcvars32.bat</tt> file,
|
||||
which for Visual C++ 6 is normally located at:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>C</span><span class=special>:\</span><span class=identifier>Program </span><span class=identifier>Files</span><span class=special>\</span><span class=identifier>Microsoft </span><span class=identifier>Visual </span><span class=identifier>Studio</span><span class=special>\</span><span class=identifier>VC98</span><span class=special>\</span><span class=identifier>bin</span><span class=special>\</span><span class=identifier>Vcvars32</span><span class=special>.</span><span class=identifier>bat
|
||||
</span></pre></code>
|
||||
<p>
|
||||
with that, you should have little trouble setting up the flags.</p>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
<img src="theme/note.gif"></img><b>A note about Psyco</b><br><br>
|
||||
Although you don't have to install <a href="http://psyco.sourceforge.net/">
|
||||
Psyco</a> to use Pyste, if you do, Pyste will make use of it to speed up the wrapper generation. Speed ups of 30% can be achieved, so it's highly recommended.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="introduction.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="the_interface_files.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
75
pyste/doc/smart_pointers.html
Normal file
@@ -0,0 +1,75 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Smart Pointers</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="exporting_all_declarations_from_a_header.html">
|
||||
<link rel="next" href="global_variables.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Smart Pointers</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="exporting_all_declarations_from_a_header.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="global_variables.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Pyste for now has manual support for smart pointers. Suppose:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>C
|
||||
</span><span class=special>{
|
||||
</span><span class=keyword>int </span><span class=identifier>value</span><span class=special>;
|
||||
};
|
||||
|
||||
</span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>shared_ptr</span><span class=special><</span><span class=identifier>C</span><span class=special>> </span><span class=identifier>newC</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>value</span><span class=special>)
|
||||
{
|
||||
</span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>shared_ptr</span><span class=special><</span><span class=identifier>C</span><span class=special>> </span><span class=identifier>c</span><span class=special>( </span><span class=keyword>new </span><span class=identifier>C</span><span class=special>() );
|
||||
</span><span class=identifier>c</span><span class=special>-></span><span class=identifier>value </span><span class=special>= </span><span class=identifier>value</span><span class=special>;
|
||||
</span><span class=keyword>return </span><span class=identifier>c</span><span class=special>;
|
||||
}
|
||||
|
||||
</span><span class=keyword>void </span><span class=identifier>printC</span><span class=special>(</span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>shared_ptr</span><span class=special><</span><span class=identifier>C</span><span class=special>> </span><span class=identifier>c</span><span class=special>)
|
||||
{
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>cout </span><span class=special><< </span><span class=identifier>c</span><span class=special>-></span><span class=identifier>value </span><span class=special><< </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>endl</span><span class=special>;
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
To make <tt>newC</tt> and <tt>printC</tt> work correctly, you have to tell Pyste that a
|
||||
convertor for <tt>boost::shared_ptr<C></tt> is needed.</p>
|
||||
<code><pre>
|
||||
<span class=identifier>C </span><span class=special>= </span><span class=identifier>Class</span><span class=special>(</span><span class=literal>'C'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
|
||||
</span><span class=identifier>use_shared_ptr</span><span class=special>(</span><span class=identifier>C</span><span class=special>)
|
||||
</span><span class=identifier>Function</span><span class=special>(</span><span class=literal>'newC'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
|
||||
</span><span class=identifier>Function</span><span class=special>(</span><span class=literal>'printC'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
For <tt>std::auto_ptr</tt>'s, use the function <tt>use_auto_ptr</tt>.</p>
|
||||
<p>
|
||||
This system is temporary, and in the future the converters will automatically be
|
||||
exported if needed, without the need to tell Pyste about them explicitly.</p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="exporting_all_declarations_from_a_header.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="global_variables.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
103
pyste/doc/templates.html
Normal file
@@ -0,0 +1,103 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Templates</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="policies.html">
|
||||
<link rel="next" href="wrappers.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Templates</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="policies.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="wrappers.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Template classes can easily be exported too, but you can't export the template
|
||||
itself... you have to export instantiations of it! So, if you want to export a
|
||||
<tt>std::vector</tt>, you will have to export vectors of int, doubles, etc.</p>
|
||||
<p>
|
||||
Suppose we have this code:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>template </span><span class=special><</span><span class=keyword>class </span><span class=identifier>T</span><span class=special>>
|
||||
</span><span class=keyword>struct </span><span class=identifier>Point
|
||||
</span><span class=special>{
|
||||
</span><span class=identifier>T </span><span class=identifier>x</span><span class=special>;
|
||||
</span><span class=identifier>T </span><span class=identifier>y</span><span class=special>;
|
||||
};
|
||||
</span></pre></code>
|
||||
<p>
|
||||
And we want to export <tt>Point</tt>s of int and double:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Point </span><span class=special>= </span><span class=identifier>Template</span><span class=special>(</span><span class=string>"Point"</span><span class=special>, </span><span class=string>"point.h"</span><span class=special>)
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=string>"int"</span><span class=special>)
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=string>"double"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Pyste will assign default names for each instantiation. In this example, those
|
||||
would be "<tt>Point_int</tt>" and "<tt>Point_double</tt>", but most of the time users will want to
|
||||
rename the instantiations:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Point</span><span class=special>(</span><span class=string>"int"</span><span class=special>, </span><span class=string>"IPoint"</span><span class=special>) // </span><span class=identifier>renames </span><span class=identifier>the </span><span class=identifier>instantiation
|
||||
</span><span class=identifier>double_inst </span><span class=special>= </span><span class=identifier>Point</span><span class=special>(</span><span class=string>"double"</span><span class=special>) // </span><span class=identifier>another </span><span class=identifier>way </span><span class=identifier>to </span><span class=keyword>do </span><span class=identifier>the </span><span class=identifier>same
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>double_inst</span><span class=special>, </span><span class=string>"DPoint"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Note that you can rename, exclude, set policies, etc, in the <tt>Template</tt> object
|
||||
like you would do with a <tt>Function</tt> or a <tt>Class</tt>. This changes affect all
|
||||
<b>future</b> instantiations:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Point </span><span class=special>= </span><span class=identifier>Template</span><span class=special>(</span><span class=string>"Point"</span><span class=special>, </span><span class=string>"point.h"</span><span class=special>)
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=string>"float"</span><span class=special>, </span><span class=string>"FPoint"</span><span class=special>) // </span><span class=identifier>will </span><span class=identifier>have </span><span class=identifier>x </span><span class=keyword>and </span><span class=identifier>y </span><span class=identifier>as </span><span class=identifier>data </span><span class=identifier>members
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>Point</span><span class=special>.</span><span class=identifier>x</span><span class=special>, </span><span class=string>"X"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>Point</span><span class=special>.</span><span class=identifier>y</span><span class=special>, </span><span class=string>"Y"</span><span class=special>)
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=string>"int"</span><span class=special>, </span><span class=string>"IPoint"</span><span class=special>) // </span><span class=identifier>will </span><span class=identifier>have </span><span class=identifier>X </span><span class=keyword>and </span><span class=identifier>Y </span><span class=identifier>as </span><span class=identifier>data </span><span class=identifier>members
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=string>"double"</span><span class=special>, </span><span class=string>"DPoint"</span><span class=special>) // </span><span class=identifier>also </span><span class=identifier>will </span><span class=identifier>have </span><span class=identifier>X </span><span class=keyword>and </span><span class=identifier>Y </span><span class=identifier>as </span><span class=identifier>data </span><span class=identifier>member
|
||||
</span></pre></code>
|
||||
<p>
|
||||
If you want to change a option of a particular instantiation, you can do so:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Point </span><span class=special>= </span><span class=identifier>Template</span><span class=special>(</span><span class=string>"Point"</span><span class=special>, </span><span class=string>"point.h"</span><span class=special>)
|
||||
</span><span class=identifier>Point</span><span class=special>(</span><span class=string>"int"</span><span class=special>, </span><span class=string>"IPoint"</span><span class=special>)
|
||||
</span><span class=identifier>d_inst </span><span class=special>= </span><span class=identifier>Point</span><span class=special>(</span><span class=string>"double"</span><span class=special>, </span><span class=string>"DPoint"</span><span class=special>)
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>d_inst</span><span class=special>.</span><span class=identifier>x</span><span class=special>, </span><span class=string>"X"</span><span class=special>) // </span><span class=identifier>only </span><span class=identifier>DPoint </span><span class=identifier>is </span><span class=identifier>affect </span><span class=identifier>by </span><span class=keyword>this </span><span class=identifier>renames</span><span class=special>,
|
||||
</span><span class=identifier>rename</span><span class=special>(</span><span class=identifier>d_inst</span><span class=special>.</span><span class=identifier>y</span><span class=special>, </span><span class=string>"Y"</span><span class=special>) // </span><span class=identifier>IPoint </span><span class=identifier>stays </span><span class=identifier>intact
|
||||
</span></pre></code>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
<img src="theme/note.gif"></img> <b>What if my template accepts more than one type?</b>
|
||||
<br><br>
|
||||
When you want to instantiate a template with more than one type, you can pass
|
||||
either a string with the types separated by whitespace, or a list of strings
|
||||
("int double" or ["int", "double"] would both work).
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="policies.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="wrappers.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
81
pyste/doc/the_interface_files.html
Normal file
@@ -0,0 +1,81 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>The Interface Files</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="running_pyste.html">
|
||||
<link rel="next" href="renaming_and_excluding.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>The Interface Files</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="running_pyste.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="renaming_and_excluding.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
The interface files are the heart of Pyste. The user creates one or more
|
||||
interface files declaring the classes and functions he wants to export, and then
|
||||
invokes Pyste passing the interface files to it. Pyste then generates a single
|
||||
cpp file with <a href="../../index.html">
|
||||
Boost.Python</a> code, with all the classes and functions exported.</p>
|
||||
<p>
|
||||
Besides declaring the classes and functions, the user has a number of other
|
||||
options, like renaming classes and methods, excluding methods and attributes,
|
||||
and so on. </p>
|
||||
<a name="basics"></a><h2>Basics</h2><p>
|
||||
Suppose we have a class and some functions that we want to expose to Python
|
||||
declared in the header <tt>hello.h</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>World
|
||||
</span><span class=special>{
|
||||
</span><span class=identifier>World</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>): </span><span class=identifier>msg</span><span class=special>(</span><span class=identifier>msg</span><span class=special>) {}
|
||||
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>) { </span><span class=keyword>this</span><span class=special>-></span><span class=identifier>msg </span><span class=special>= </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>greet</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>msg</span><span class=special>; }
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>;
|
||||
};
|
||||
|
||||
</span><span class=keyword>enum </span><span class=identifier>choice </span><span class=special>{ </span><span class=identifier>red</span><span class=special>, </span><span class=identifier>blue </span><span class=special>};
|
||||
|
||||
</span><span class=keyword>namespace </span><span class=identifier>test </span><span class=special>{
|
||||
|
||||
</span><span class=keyword>void </span><span class=identifier>show</span><span class=special>(</span><span class=identifier>choice </span><span class=identifier>c</span><span class=special>) { </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>cout </span><span class=special><< </span><span class=string>"value: " </span><span class=special><< (</span><span class=keyword>int</span><span class=special>)</span><span class=identifier>c </span><span class=special><< </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>endl</span><span class=special>; }
|
||||
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
We create a file named <tt>hello.pyste</tt> and create instances of the classes
|
||||
<tt>Function</tt>, <tt>Class</tt> and <tt>Enum</tt>:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Function</span><span class=special>(</span><span class=string>"test::show"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>Class</span><span class=special>(</span><span class=string>"World"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span><span class=identifier>Enum</span><span class=special>(</span><span class=string>"choice"</span><span class=special>, </span><span class=string>"hello.h"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
That will expose the class, the free function and the enum found in <tt>hello.h</tt>. </p>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="running_pyste.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="renaming_and_excluding.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
BIN
pyste/doc/theme/alert.gif
vendored
Normal file
|
After Width: | Height: | Size: 577 B |
BIN
pyste/doc/theme/arrow.gif
vendored
Normal file
|
After Width: | Height: | Size: 70 B |
BIN
pyste/doc/theme/bkd.gif
vendored
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
pyste/doc/theme/bkd2.gif
vendored
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
pyste/doc/theme/bulb.gif
vendored
Normal file
|
After Width: | Height: | Size: 944 B |
BIN
pyste/doc/theme/bullet.gif
vendored
Normal file
|
After Width: | Height: | Size: 152 B |
BIN
pyste/doc/theme/c++boost.gif
vendored
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
pyste/doc/theme/l_arr.gif
vendored
Normal file
|
After Width: | Height: | Size: 147 B |
BIN
pyste/doc/theme/l_arr_disabled.gif
vendored
Normal file
|
After Width: | Height: | Size: 91 B |
BIN
pyste/doc/theme/note.gif
vendored
Normal file
|
After Width: | Height: | Size: 151 B |
BIN
pyste/doc/theme/r_arr.gif
vendored
Normal file
|
After Width: | Height: | Size: 147 B |
BIN
pyste/doc/theme/r_arr_disabled.gif
vendored
Normal file
|
After Width: | Height: | Size: 91 B |
BIN
pyste/doc/theme/smiley.gif
vendored
Normal file
|
After Width: | Height: | Size: 879 B |
170
pyste/doc/theme/style.css
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
body
|
||||
{
|
||||
background-image: url(bkd.gif);
|
||||
background-color: #FFFFFF;
|
||||
margin: 1em 2em 1em 2em;
|
||||
}
|
||||
|
||||
h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; }
|
||||
h2 { font: 140% sans-serif; font-weight: bold; text-align: left; }
|
||||
h3 { font: 120% sans-serif; font-weight: bold; text-align: left; }
|
||||
h4 { font: bold 100% sans-serif; font-weight: bold; text-align: left; }
|
||||
h5 { font: italic 100% sans-serif; font-weight: bold; text-align: left; }
|
||||
h6 { font: small-caps 100% sans-serif; font-weight: bold; text-align: left; }
|
||||
|
||||
pre
|
||||
{
|
||||
border-top: gray 1pt solid;
|
||||
border-right: gray 1pt solid;
|
||||
border-left: gray 1pt solid;
|
||||
border-bottom: gray 1pt solid;
|
||||
|
||||
padding-top: 2pt;
|
||||
padding-right: 2pt;
|
||||
padding-left: 2pt;
|
||||
padding-bottom: 2pt;
|
||||
|
||||
display: block;
|
||||
font-family: "courier new", courier, mono;
|
||||
background-color: #eeeeee; font-size: small
|
||||
}
|
||||
|
||||
code
|
||||
{
|
||||
font-family: "Courier New", Courier, mono;
|
||||
font-size: small
|
||||
}
|
||||
|
||||
tt
|
||||
{
|
||||
display: inline;
|
||||
font-family: "Courier New", Courier, mono;
|
||||
color: #000099;
|
||||
font-size: small
|
||||
}
|
||||
|
||||
p
|
||||
{
|
||||
text-align: justify;
|
||||
font-family: Georgia, "Times New Roman", Times, serif
|
||||
}
|
||||
|
||||
ul
|
||||
{
|
||||
list-style-image: url(bullet.gif);
|
||||
font-family: Georgia, "Times New Roman", Times, serif
|
||||
}
|
||||
|
||||
ol
|
||||
{
|
||||
font-family: Georgia, "Times New Roman", Times, serif
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
font-weight: bold;
|
||||
color: #003366;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover { color: #8080FF; }
|
||||
|
||||
.literal { color: #666666; font-style: italic}
|
||||
.keyword { color: #000099}
|
||||
.identifier {}
|
||||
.comment { font-style: italic; color: #990000}
|
||||
.special { color: #800040}
|
||||
.preprocessor { color: #FF0000}
|
||||
.string { font-style: italic; color: #666666}
|
||||
.copyright { color: #666666; font-size: small}
|
||||
.white_bkd { background-color: #FFFFFF}
|
||||
.dk_grey_bkd { background-color: #999999}
|
||||
.quotes { color: #666666; font-style: italic; font-weight: bold}
|
||||
|
||||
.note_box
|
||||
{
|
||||
display: block;
|
||||
|
||||
border-top: gray 1pt solid;
|
||||
border-right: gray 1pt solid;
|
||||
border-left: gray 1pt solid;
|
||||
border-bottom: gray 1pt solid;
|
||||
|
||||
padding-right: 12pt;
|
||||
padding-left: 12pt;
|
||||
padding-bottom: 12pt;
|
||||
padding-top: 12pt;
|
||||
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: #E2E9EF;
|
||||
font-size: small; text-align: justify
|
||||
}
|
||||
|
||||
.table_title
|
||||
{
|
||||
background-color: #648CCA;
|
||||
|
||||
font-family: Verdana, Arial, Helvetica, sans-serif; color: #FFFFFF;
|
||||
font-weight: bold
|
||||
; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px
|
||||
}
|
||||
|
||||
.table_cells
|
||||
{
|
||||
background-color: #E2E9EF;
|
||||
|
||||
font-family: Geneva, Arial, Helvetica, san-serif;
|
||||
font-size: small
|
||||
; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px
|
||||
}
|
||||
|
||||
.toc
|
||||
{
|
||||
DISPLAY: block;
|
||||
background-color: #E2E9EF
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
|
||||
border-top: gray 1pt solid;
|
||||
border-left: gray 1pt solid;
|
||||
border-bottom: gray 1pt solid;
|
||||
border-right: gray 1pt solid;
|
||||
|
||||
padding-top: 24pt;
|
||||
padding-right: 24pt;
|
||||
padding-left: 24pt;
|
||||
padding-bottom: 24pt;
|
||||
}
|
||||
|
||||
.toc_title
|
||||
{
|
||||
background-color: #648CCA;
|
||||
padding-top: 4px;
|
||||
padding-right: 4px;
|
||||
padding-bottom: 4px;
|
||||
padding-left: 4px;
|
||||
font-family: Geneva, Arial, Helvetica, san-serif;
|
||||
color: #FFFFFF;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
.toc_cells
|
||||
{
|
||||
background-color: #E2E9EF;
|
||||
padding-top: 4px;
|
||||
padding-right: 4px;
|
||||
padding-bottom: 4px;
|
||||
padding-left: 4px;
|
||||
font-family: Geneva, Arial, Helvetica, san-serif;
|
||||
font-size: small
|
||||
}
|
||||
|
||||
div.logo
|
||||
{
|
||||
float: right;
|
||||
}
|
||||
|
||||
.toc_cells_L0 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
|
||||
.toc_cells_L1 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 44px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
|
||||
.toc_cells_L2 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 88px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
|
||||
.toc_cells_L3 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 122px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
|
||||
.toc_cells_L4 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 166px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
|
||||
BIN
pyste/doc/theme/u_arr.gif
vendored
Normal file
|
After Width: | Height: | Size: 170 B |
125
pyste/doc/wrappers.html
Normal file
@@ -0,0 +1,125 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Wrappers</title>
|
||||
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
||||
<link rel="prev" href="templates.html">
|
||||
<link rel="next" href="exporting_all_declarations_from_a_header.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Wrappers</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="templates.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="exporting_all_declarations_from_a_header.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
Suppose you have this function:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>std</span><span class=special>::</span><span class=identifier>vector</span><span class=special><</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>> </span><span class=identifier>names</span><span class=special>();
|
||||
</span></pre></code>
|
||||
<p>
|
||||
But you don't want to export <tt>std::vector<std::string></tt>, you want this function
|
||||
to return a python list of strings. <a href="../../index.html">
|
||||
Boost.Python</a> has excellent support for
|
||||
that:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>list </span><span class=identifier>names_wrapper</span><span class=special>()
|
||||
{
|
||||
</span><span class=identifier>list </span><span class=identifier>result</span><span class=special>;
|
||||
// </span><span class=identifier>call </span><span class=identifier>original </span><span class=identifier>function
|
||||
</span><span class=identifier>vector</span><span class=special><</span><span class=identifier>string</span><span class=special>> </span><span class=identifier>v </span><span class=special>= </span><span class=identifier>names</span><span class=special>();
|
||||
// </span><span class=identifier>put </span><span class=identifier>all </span><span class=identifier>the </span><span class=identifier>strings </span><span class=identifier>inside </span><span class=identifier>the </span><span class=identifier>python </span><span class=identifier>list
|
||||
</span><span class=identifier>vector</span><span class=special><</span><span class=identifier>string</span><span class=special>>::</span><span class=identifier>iterator </span><span class=identifier>it</span><span class=special>;
|
||||
</span><span class=keyword>for </span><span class=special>(</span><span class=identifier>it </span><span class=special>= </span><span class=identifier>v</span><span class=special>.</span><span class=identifier>begin</span><span class=special>(); </span><span class=identifier>it </span><span class=special>!= </span><span class=identifier>v</span><span class=special>.</span><span class=identifier>end</span><span class=special>(); ++</span><span class=identifier>it</span><span class=special>){
|
||||
</span><span class=identifier>result</span><span class=special>.</span><span class=identifier>append</span><span class=special>(*</span><span class=identifier>it</span><span class=special>);
|
||||
}
|
||||
</span><span class=keyword>return </span><span class=identifier>result</span><span class=special>;
|
||||
}
|
||||
|
||||
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>test</span><span class=special>)
|
||||
{
|
||||
</span><span class=identifier>def</span><span class=special>(</span><span class=string>"names"</span><span class=special>, &</span><span class=identifier>names_wrapper</span><span class=special>);
|
||||
}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
Nice heh? Pyste supports this mechanism too. You declare the <tt>names_wrapper</tt>
|
||||
function in a header named "<tt>test_wrappers.h</tt>" and in the interface file:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>Include</span><span class=special>(</span><span class=string>"test_wrappers.h"</span><span class=special>)
|
||||
</span><span class=identifier>names </span><span class=special>= </span><span class=identifier>Function</span><span class=special>(</span><span class=string>"names"</span><span class=special>, </span><span class=string>"test.h"</span><span class=special>)
|
||||
</span><span class=identifier>set_wrapper</span><span class=special>(</span><span class=identifier>names</span><span class=special>, </span><span class=string>"names_wrapper"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
You can optionally declare the function in the interface file itself:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>names_wrapper </span><span class=special>= </span><span class=identifier>Wrapper</span><span class=special>(</span><span class=string>"names_wrapper"</span><span class=special>,
|
||||
</span><span class=string>""</span><span class=string>"
|
||||
list names_wrapper()
|
||||
{
|
||||
// code to call name() and convert the vector to a list...
|
||||
}
|
||||
"</span><span class=string>""</span><span class=special>)
|
||||
</span><span class=identifier>names </span><span class=special>= </span><span class=identifier>Function</span><span class=special>(</span><span class=string>"names"</span><span class=special>, </span><span class=string>"test.h"</span><span class=special>)
|
||||
</span><span class=identifier>set_wrapper</span><span class=special>(</span><span class=identifier>names</span><span class=special>, </span><span class=identifier>names_wrapper</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<p>
|
||||
The same mechanism can be used with methods too. Just remember that the first
|
||||
parameter of wrappers for methods is a pointer to the class, like in
|
||||
<a href="../../index.html">
|
||||
Boost.Python</a>:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>C
|
||||
</span><span class=special>{
|
||||
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>vector</span><span class=special><</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>> </span><span class=identifier>names</span><span class=special>();
|
||||
}
|
||||
|
||||
</span><span class=identifier>list </span><span class=identifier>names_wrapper</span><span class=special>(</span><span class=identifier>C</span><span class=special>* </span><span class=identifier>c</span><span class=special>)
|
||||
{
|
||||
// </span><span class=identifier>same </span><span class=identifier>as </span><span class=identifier>before</span><span class=special>, </span><span class=identifier>calling </span><span class=identifier>c</span><span class=special>-></span><span class=identifier>names</span><span class=special>() </span><span class=keyword>and </span><span class=identifier>converting </span><span class=identifier>result </span><span class=identifier>to </span><span class=identifier>a </span><span class=identifier>list
|
||||
</span><span class=special>}
|
||||
</span></pre></code>
|
||||
<p>
|
||||
And then in the interface file:</p>
|
||||
<code><pre>
|
||||
<span class=identifier>C </span><span class=special>= </span><span class=identifier>Class</span><span class=special>(</span><span class=string>"C"</span><span class=special>, </span><span class=string>"test.h"</span><span class=special>)
|
||||
</span><span class=identifier>set_wrapper</span><span class=special>(</span><span class=identifier>C</span><span class=special>.</span><span class=identifier>names</span><span class=special>, </span><span class=string>"names_wrapper"</span><span class=special>)
|
||||
</span></pre></code>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="note_box">
|
||||
|
||||
<img src="theme/note.gif"></img>Even though <a href="../../index.html">
|
||||
Boost.Python</a> accepts either a pointer or a
|
||||
reference to the class in wrappers for member functions as the first parameter,
|
||||
Pyste expects them to be a <b>pointer</b>. Doing otherwise will prevent your
|
||||
code to compile when you set a wrapper for a virtual method.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
||||
<td width="30"><a href="templates.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
||||
<td width="20"><a href="exporting_all_declarations_from_a_header.html"><img src="theme/r_arr.gif" border="0"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
86
pyste/index.html
Normal file
@@ -0,0 +1,86 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
||||
<title>Pyste Documentation</title>
|
||||
<link rel="stylesheet" href="doc/theme/style.css" type="text/css">
|
||||
<link rel="next" href="introduction.html">
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" height="48" border="0" cellspacing="2">
|
||||
<tr>
|
||||
<td><img src="doc/theme/c%2B%2Bboost.gif">
|
||||
</td>
|
||||
<td width="85%">
|
||||
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Pyste Documentation</b></font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table width="80%" border="0" align="center">
|
||||
<tr>
|
||||
<td class="toc_title">Table of contents</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L0">
|
||||
<a href="doc/introduction.html">Introduction</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L0">
|
||||
<a href="doc/running_pyste.html">Running Pyste</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L0">
|
||||
<a href="doc/the_interface_files.html">The Interface Files</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/renaming_and_excluding.html">Renaming and Excluding</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/policies.html">Policies</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/templates.html">Templates</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/wrappers.html">Wrappers</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/exporting_all_declarations_from_a_header.html">Exporting All Declarations from a Header</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/smart_pointers.html">Smart Pointers</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/global_variables.html">Global Variables</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="toc_cells_L1">
|
||||
<a href="doc/adding_new_methods.html">Adding New Methods</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
|
||||
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
||||
is granted provided this copyright notice appears in all copies. This document
|
||||
is provided "as is" without express or implied warranty, and with
|
||||
no claim as to its suitability for any purpose. </font> </p>
|
||||
</body>
|
||||
</html>
|
||||
1
pyste/src/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
*.pyc
|
||||
858
pyste/src/ClassExporter.py
Normal file
@@ -0,0 +1,858 @@
|
||||
import exporters
|
||||
from Exporter import Exporter
|
||||
from declarations import *
|
||||
from settings import *
|
||||
from policies import *
|
||||
from SingleCodeUnit import SingleCodeUnit
|
||||
from EnumExporter import EnumExporter
|
||||
from utils import makeid, enumerate
|
||||
from copy import deepcopy
|
||||
import exporterutils
|
||||
import re
|
||||
|
||||
#==============================================================================
|
||||
# ClassExporter
|
||||
#==============================================================================
|
||||
class ClassExporter(Exporter):
|
||||
'Generates boost.python code to export a class declaration'
|
||||
|
||||
|
||||
def __init__(self, info, parser_tail=None):
|
||||
Exporter.__init__(self, info, parser_tail)
|
||||
# sections of code
|
||||
self.sections = {}
|
||||
# template: each item in the list is an item into the class_<...>
|
||||
# section.
|
||||
self.sections['template'] = []
|
||||
# constructor: each item in the list is a parameter to the class_
|
||||
# constructor, like class_<C>(...)
|
||||
self.sections['constructor'] = []
|
||||
# inside: everything within the class_<> statement
|
||||
self.sections['inside'] = []
|
||||
# scope: items outside the class statement but within its scope.
|
||||
# scope* s = new scope(class<>());
|
||||
# ...
|
||||
# delete s;
|
||||
self.sections['scope'] = []
|
||||
# declarations: outside the BOOST_PYTHON_MODULE macro
|
||||
self.sections['declaration'] = []
|
||||
self.sections['declaration-outside'] = []
|
||||
self.sections['include'] = []
|
||||
# a list of Constructor instances
|
||||
self.constructors = []
|
||||
self.wrapper_generator = None
|
||||
# a list of code units, generated by nested declarations
|
||||
self.nested_codeunits = []
|
||||
self._exported_opaque_pointers = {}
|
||||
|
||||
|
||||
def ScopeName(self):
|
||||
return makeid(self.class_.FullName()) + '_scope'
|
||||
|
||||
|
||||
def Unit(self):
|
||||
return makeid(self.class_.name)
|
||||
|
||||
|
||||
def Name(self):
|
||||
return self.class_.FullName()
|
||||
|
||||
|
||||
def SetDeclarations(self, declarations):
|
||||
Exporter.SetDeclarations(self, declarations)
|
||||
decl = self.GetDeclaration(self.info.name)
|
||||
if isinstance(decl, Typedef):
|
||||
self.class_ = self.GetDeclaration(decl.type.name)
|
||||
if not self.info.rename:
|
||||
self.info.rename = decl.name
|
||||
else:
|
||||
self.class_ = decl
|
||||
self.public_members = \
|
||||
[x for x in self.class_.members if x.visibility == Scope.public]
|
||||
|
||||
|
||||
def ClassBases(self):
|
||||
bases = []
|
||||
def GetBases(class_):
|
||||
this_bases = [self.GetDeclaration(x.name) for x in class_.bases]
|
||||
bases.extend(this_bases)
|
||||
for base in this_bases:
|
||||
GetBases(base)
|
||||
|
||||
GetBases(self.class_)
|
||||
return bases
|
||||
|
||||
|
||||
def Order(self):
|
||||
'''Return the TOTAL number of bases that this class has, including the
|
||||
bases' bases. Do this because base classes must be instantialized
|
||||
before the derived classes in the module definition.
|
||||
'''
|
||||
return '%s_%s' % (len(self.ClassBases()), self.class_.FullName())
|
||||
|
||||
|
||||
def Export(self, codeunit, exported_names):
|
||||
if not self.info.exclude:
|
||||
self.CheckIsForwardDeclared()
|
||||
self.CheckForwardDeclarations()
|
||||
self.ExportBasics()
|
||||
self.ExportBases(exported_names)
|
||||
self.ExportConstructors()
|
||||
self.ExportVariables()
|
||||
self.ExportMethods()
|
||||
self.ExportVirtualMethods()
|
||||
self.ExportOperators()
|
||||
self.ExportNestedClasses(exported_names)
|
||||
self.ExportNestedEnums()
|
||||
self.ExportSmartPointer()
|
||||
self.ExportOpaquePointerPolicies()
|
||||
self.Write(codeunit)
|
||||
|
||||
|
||||
def CheckIsForwardDeclared(self):
|
||||
if self.class_.incomplete:
|
||||
print "--> Error: Class %s is forward declared! " \
|
||||
"Please use the header with its complete definition." % self.class_.FullName()
|
||||
print
|
||||
|
||||
|
||||
def CheckForwardDeclarations(self):
|
||||
for m in self.public_members:
|
||||
if isinstance(m, Function):
|
||||
exporterutils.WarnForwardDeclarations(m)
|
||||
|
||||
|
||||
def Write(self, codeunit):
|
||||
indent = self.INDENT
|
||||
boost_ns = namespaces.python
|
||||
pyste_ns = namespaces.pyste
|
||||
code = ''
|
||||
# begin a scope for this class if needed
|
||||
nested_codeunits = self.nested_codeunits
|
||||
needs_scope = self.sections['scope'] or nested_codeunits
|
||||
if needs_scope:
|
||||
scope_name = self.ScopeName()
|
||||
code += indent + boost_ns + 'scope* %s = new %sscope(\n' %\
|
||||
(scope_name, boost_ns)
|
||||
# export the template section
|
||||
template_params = ', '.join(self.sections['template'])
|
||||
code += indent + boost_ns + 'class_< %s >' % template_params
|
||||
# export the constructor section
|
||||
constructor_params = ', '.join(self.sections['constructor'])
|
||||
code += '(%s)\n' % constructor_params
|
||||
# export the inside section
|
||||
in_indent = indent*2
|
||||
for line in self.sections['inside']:
|
||||
code += in_indent + line + '\n'
|
||||
# write the scope section and end it
|
||||
if not needs_scope:
|
||||
code += indent + ';\n'
|
||||
else:
|
||||
code += indent + ');\n'
|
||||
for line in self.sections['scope']:
|
||||
code += indent + line + '\n'
|
||||
# write the contents of the nested classes
|
||||
for nested_unit in nested_codeunits:
|
||||
code += '\n' + nested_unit.Section('module')
|
||||
# close the scope
|
||||
code += indent + 'delete %s;\n' % scope_name
|
||||
|
||||
# write the code to the module section in the codeunit
|
||||
codeunit.Write('module', code + '\n')
|
||||
|
||||
# write the declarations to the codeunit
|
||||
declarations = '\n'.join(self.sections['declaration'])
|
||||
for nested_unit in nested_codeunits:
|
||||
declarations += nested_unit.Section('declaration')
|
||||
if declarations:
|
||||
codeunit.Write('declaration', declarations + '\n')
|
||||
declarations_outside = '\n'.join(self.sections['declaration-outside'])
|
||||
if declarations_outside:
|
||||
codeunit.Write('declaration-outside', declarations_outside + '\n')
|
||||
|
||||
# write the includes to the codeunit
|
||||
includes = '\n'.join(self.sections['include'])
|
||||
for nested_unit in nested_codeunits:
|
||||
includes += nested_unit.Section('include')
|
||||
if includes:
|
||||
codeunit.Write('include', includes)
|
||||
|
||||
|
||||
def Add(self, section, item):
|
||||
'Add the item into the corresponding section'
|
||||
self.sections[section].append(item)
|
||||
|
||||
|
||||
def ExportBasics(self):
|
||||
'Export the name of the class and its class_ statement'
|
||||
self.Add('template', self.class_.FullName())
|
||||
name = self.info.rename or self.class_.name
|
||||
self.Add('constructor', '"%s"' % name)
|
||||
|
||||
|
||||
def ExportBases(self, exported_names):
|
||||
'Expose the bases of the class into the template section'
|
||||
bases = self.class_.bases
|
||||
bases_list = []
|
||||
for base in bases:
|
||||
if base.visibility == Scope.public and base.name in exported_names:
|
||||
bases_list.append(base.name)
|
||||
if bases_list:
|
||||
code = namespaces.python + 'bases< %s > ' % \
|
||||
(', '.join(bases_list))
|
||||
self.Add('template', code)
|
||||
|
||||
|
||||
def ExportConstructors(self):
|
||||
'''Exports all the public contructors of the class, plus indicates if the
|
||||
class is noncopyable.
|
||||
'''
|
||||
py_ns = namespaces.python
|
||||
indent = self.INDENT
|
||||
|
||||
def init_code(cons):
|
||||
'return the init<>() code for the given contructor'
|
||||
param_list = [p.FullName() for p in cons.parameters]
|
||||
min_params_list = param_list[:cons.minArgs]
|
||||
max_params_list = param_list[cons.minArgs:]
|
||||
min_params = ', '.join(min_params_list)
|
||||
max_params = ', '.join(max_params_list)
|
||||
init = py_ns + 'init< '
|
||||
init += min_params
|
||||
if max_params:
|
||||
if min_params:
|
||||
init += ', '
|
||||
init += py_ns + ('optional< %s >' % max_params)
|
||||
init += ' >()'
|
||||
return init
|
||||
|
||||
constructors = [x for x in self.public_members if isinstance(x, Constructor)]
|
||||
self.constructors = constructors[:]
|
||||
# don't export the copy constructor if the class is abstract
|
||||
if self.class_.abstract:
|
||||
for cons in constructors:
|
||||
if cons.IsCopy():
|
||||
constructors.remove(cons)
|
||||
break
|
||||
if not constructors:
|
||||
# declare no_init
|
||||
self.Add('constructor', py_ns + 'no_init')
|
||||
else:
|
||||
# write the constructor with less parameters to the constructor section
|
||||
smaller = None
|
||||
for cons in constructors:
|
||||
if smaller is None or len(cons.parameters) < len(smaller.parameters):
|
||||
smaller = cons
|
||||
assert smaller is not None
|
||||
self.Add('constructor', init_code(smaller))
|
||||
constructors.remove(smaller)
|
||||
# write the rest to the inside section, using def()
|
||||
for cons in constructors:
|
||||
code = '.def(%s)' % init_code(cons)
|
||||
self.Add('inside', code)
|
||||
# check if the class is copyable
|
||||
if not self.class_.HasCopyConstructor() or self.class_.abstract:
|
||||
self.Add('template', namespaces.boost + 'noncopyable')
|
||||
|
||||
|
||||
def ExportVariables(self):
|
||||
'Export the variables of the class, both static and simple variables'
|
||||
vars = [x for x in self.public_members if isinstance(x, Variable)]
|
||||
for var in vars:
|
||||
if self.info[var.name].exclude:
|
||||
continue
|
||||
name = self.info[var.name].rename or var.name
|
||||
fullname = var.FullName()
|
||||
if var.type.const:
|
||||
def_ = '.def_readonly'
|
||||
else:
|
||||
def_ = '.def_readwrite'
|
||||
code = '%s("%s", &%s)' % (def_, name, fullname)
|
||||
self.Add('inside', code)
|
||||
|
||||
|
||||
def OverloadName(self, method):
|
||||
'Returns the name of the overloads struct for the given method'
|
||||
name = makeid(method.FullName())
|
||||
overloads = '_overloads_%i_%i' % (method.minArgs, method.maxArgs)
|
||||
return name + overloads
|
||||
|
||||
|
||||
def GetAddedMethods(self):
|
||||
added_methods = self.info.__added__
|
||||
result = []
|
||||
if added_methods:
|
||||
for name, rename in added_methods:
|
||||
decl = self.GetDeclaration(name)
|
||||
self.info[name].rename = rename
|
||||
result.append(decl)
|
||||
return result
|
||||
|
||||
|
||||
def ExportMethods(self):
|
||||
'''Export all the non-virtual methods of this class, plus any function
|
||||
that is to be exported as a method'''
|
||||
|
||||
declared = {}
|
||||
def DeclareOverloads(m):
|
||||
'Declares the macro for the generation of the overloads'
|
||||
if (isinstance(m, Method) and m.static) or type(m) == Function:
|
||||
func = m.FullName()
|
||||
macro = 'BOOST_PYTHON_FUNCTION_OVERLOADS'
|
||||
else:
|
||||
func = m.name
|
||||
macro = 'BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS'
|
||||
code = '%s(%s, %s, %i, %i)\n' % (macro, self.OverloadName(m), func, m.minArgs, m.maxArgs)
|
||||
if code not in declared:
|
||||
declared[code] = True
|
||||
self.Add('declaration', code)
|
||||
|
||||
|
||||
def Pointer(m):
|
||||
'returns the correct pointer declaration for the method m'
|
||||
# check if this method has a wrapper set for him
|
||||
wrapper = self.info[method.name].wrapper
|
||||
if wrapper:
|
||||
return '&' + wrapper.FullName()
|
||||
# return normal pointers to the methods of the class
|
||||
if isinstance(m, Method):
|
||||
is_unique = self.class_.IsUnique(m.name)
|
||||
else:
|
||||
# function
|
||||
is_unique = len(self.GetDeclarations(m.FullName())) == 1
|
||||
if is_unique:
|
||||
return '&' + method.FullName()
|
||||
else:
|
||||
return method.PointerDeclaration()
|
||||
|
||||
def IsExportable(m):
|
||||
'Returns true if the given method is exportable by this routine'
|
||||
ignore = (Constructor, ClassOperator, Destructor)
|
||||
return isinstance(m, Function) and not isinstance(m, ignore) and not m.virtual
|
||||
|
||||
methods = [x for x in self.public_members if IsExportable(x)]
|
||||
methods.extend(self.GetAddedMethods())
|
||||
|
||||
for method in methods:
|
||||
method_info = self.info[method.name]
|
||||
|
||||
# skip this method if it was excluded by the user
|
||||
if method_info.exclude:
|
||||
continue
|
||||
|
||||
# rename the method if the user requested
|
||||
name = method_info.rename or method.name
|
||||
|
||||
# warn the user if this method needs a policy and doesn't have one
|
||||
method_info.policy = exporterutils.HandlePolicy(method, method_info.policy)
|
||||
|
||||
# check for policies
|
||||
policy = method_info.policy or ''
|
||||
if policy:
|
||||
policy = ', %s%s()' % (namespaces.python, policy.Code())
|
||||
# check for overloads
|
||||
overload = ''
|
||||
if method.minArgs != method.maxArgs:
|
||||
# add the overloads for this method
|
||||
DeclareOverloads(method)
|
||||
overload_name = self.OverloadName(method)
|
||||
overload = ', %s%s()' % (namespaces.pyste, overload_name)
|
||||
|
||||
# build the .def string to export the method
|
||||
pointer = Pointer(method)
|
||||
code = '.def("%s", %s' % (name, pointer)
|
||||
code += policy
|
||||
code += overload
|
||||
code += ')'
|
||||
self.Add('inside', code)
|
||||
# static method
|
||||
if isinstance(method, Method) and method.static:
|
||||
code = '.staticmethod("%s")' % name
|
||||
self.Add('inside', code)
|
||||
# add wrapper code if this method has one
|
||||
wrapper = method_info.wrapper
|
||||
if wrapper and wrapper.code:
|
||||
self.Add('declaration', wrapper.code)
|
||||
|
||||
|
||||
def ExportVirtualMethods(self):
|
||||
# check if this class has any virtual methods
|
||||
has_virtual_methods = False
|
||||
for member in self.class_.members:
|
||||
if type(member) == Method and member.virtual:
|
||||
has_virtual_methods = True
|
||||
break
|
||||
|
||||
if has_virtual_methods:
|
||||
generator = _VirtualWrapperGenerator(self.class_, self.ClassBases(), self.info)
|
||||
self.Add('template', generator.FullName())
|
||||
for definition in generator.GenerateDefinitions():
|
||||
self.Add('inside', definition)
|
||||
self.Add('declaration', generator.GenerateVirtualWrapper(self.INDENT))
|
||||
|
||||
|
||||
# operators natively supported by boost
|
||||
BOOST_SUPPORTED_OPERATORS = '+ - * / % ^ & ! ~ | < > == != <= >= << >> && || += -='\
|
||||
'*= /= %= ^= &= |= <<= >>='.split()
|
||||
# create a map for faster lookup
|
||||
BOOST_SUPPORTED_OPERATORS = dict(zip(BOOST_SUPPORTED_OPERATORS, range(len(BOOST_SUPPORTED_OPERATORS))))
|
||||
|
||||
# a dict of operators that are not directly supported by boost, but can be exposed
|
||||
# simply as a function with a special signature
|
||||
BOOST_RENAME_OPERATORS = {
|
||||
'()' : '__call__',
|
||||
}
|
||||
|
||||
# converters which have a special name in python
|
||||
# it's a map of a regular expression of the converter's result to the
|
||||
# appropriate python name
|
||||
SPECIAL_CONVERTERS = {
|
||||
re.compile(r'(const)?\s*double$') : '__float__',
|
||||
re.compile(r'(const)?\s*float$') : '__float__',
|
||||
re.compile(r'(const)?\s*int$') : '__int__',
|
||||
re.compile(r'(const)?\s*long$') : '__long__',
|
||||
re.compile(r'(const)?\s*char\s*\*?$') : '__str__',
|
||||
re.compile(r'(const)?.*::basic_string<.*>\s*(\*|\&)?$') : '__str__',
|
||||
}
|
||||
|
||||
|
||||
def ExportOperators(self):
|
||||
'Export all member operators and free operators related to this class'
|
||||
|
||||
def GetFreeOperators():
|
||||
'Get all the free (global) operators related to this class'
|
||||
operators = []
|
||||
for decl in self.declarations:
|
||||
if isinstance(decl, Operator):
|
||||
# check if one of the params is this class
|
||||
for param in decl.parameters:
|
||||
if param.name == self.class_.FullName():
|
||||
operators.append(decl)
|
||||
break
|
||||
return operators
|
||||
|
||||
def GetOperand(param):
|
||||
'Returns the operand of this parameter (either "self", or "other<type>")'
|
||||
if param.name == self.class_.FullName():
|
||||
return namespaces.python + 'self'
|
||||
else:
|
||||
return namespaces.python + ('other< %s >()' % param.name)
|
||||
|
||||
|
||||
def HandleSpecialOperator(operator):
|
||||
# gatter information about the operator and its parameters
|
||||
result_name = operator.result.name
|
||||
param1_name = ''
|
||||
if operator.parameters:
|
||||
param1_name = operator.parameters[0].name
|
||||
|
||||
# check for str
|
||||
ostream = 'basic_ostream'
|
||||
is_str = result_name.find(ostream) != -1 and param1_name.find(ostream) != -1
|
||||
if is_str:
|
||||
namespace = namespaces.python + 'self_ns::'
|
||||
self_ = namespaces.python + 'self'
|
||||
return '.def(%sstr(%s))' % (namespace, self_)
|
||||
|
||||
# is not a special operator
|
||||
return None
|
||||
|
||||
|
||||
|
||||
frees = GetFreeOperators()
|
||||
members = [x for x in self.public_members if type(x) == ClassOperator]
|
||||
all_operators = frees + members
|
||||
operators = [x for x in all_operators if not self.info['operator'][x.name].exclude]
|
||||
|
||||
for operator in operators:
|
||||
# gatter information about the operator, for use later
|
||||
wrapper = self.info['operator'][operator.name].wrapper
|
||||
if wrapper:
|
||||
pointer = '&' + wrapper.FullName()
|
||||
if wrapper.code:
|
||||
self.Add('declaration', wrapper.code)
|
||||
elif isinstance(operator, ClassOperator) and self.class_.IsUnique(operator.name):
|
||||
pointer = '&' + operator.FullName()
|
||||
else:
|
||||
pointer = operator.PointerDeclaration()
|
||||
rename = self.info['operator'][operator.name].rename
|
||||
|
||||
# check if this operator will be exported as a method
|
||||
export_as_method = wrapper or rename or operator.name in self.BOOST_RENAME_OPERATORS
|
||||
|
||||
# check if this operator has a special representation in boost
|
||||
special_code = HandleSpecialOperator(operator)
|
||||
has_special_representation = special_code is not None
|
||||
|
||||
if export_as_method:
|
||||
# export this operator as a normal method, renaming or using the given wrapper
|
||||
if not rename:
|
||||
if wrapper:
|
||||
rename = wrapper.name
|
||||
else:
|
||||
rename = self.BOOST_RENAME_OPERATORS[operator.name]
|
||||
policy = ''
|
||||
policy_obj = self.info['operator'][operator.name].policy
|
||||
if policy_obj:
|
||||
policy = ', %s()' % policy_obj.Code()
|
||||
self.Add('inside', '.def("%s", %s%s)' % (rename, pointer, policy))
|
||||
|
||||
elif has_special_representation:
|
||||
self.Add('inside', special_code)
|
||||
|
||||
elif operator.name in self.BOOST_SUPPORTED_OPERATORS:
|
||||
# export this operator using boost's facilities
|
||||
op = operator
|
||||
is_unary = isinstance(op, Operator) and len(op.parameters) == 1 or\
|
||||
isinstance(op, ClassOperator) and len(op.parameters) == 0
|
||||
if is_unary:
|
||||
self.Add('inside', '.def( %s%sself )' % \
|
||||
(operator.name, namespaces.python))
|
||||
else:
|
||||
# binary operator
|
||||
if len(operator.parameters) == 2:
|
||||
left_operand = GetOperand(operator.parameters[0])
|
||||
right_operand = GetOperand(operator.parameters[1])
|
||||
else:
|
||||
left_operand = namespaces.python + 'self'
|
||||
right_operand = GetOperand(operator.parameters[0])
|
||||
self.Add('inside', '.def( %s %s %s )' % \
|
||||
(left_operand, operator.name, right_operand))
|
||||
|
||||
# export the converters.
|
||||
# export them as simple functions with a pre-determined name
|
||||
|
||||
converters = [x for x in self.public_members if type(x) == ConverterOperator]
|
||||
|
||||
def ConverterMethodName(converter):
|
||||
result_fullname = converter.result.FullName()
|
||||
result_name = converter.result.name
|
||||
for regex, method_name in self.SPECIAL_CONVERTERS.items():
|
||||
if regex.match(result_fullname):
|
||||
return method_name
|
||||
else:
|
||||
# extract the last name from the full name
|
||||
result_name = makeid(result_name)
|
||||
return 'to_' + result_name
|
||||
|
||||
for converter in converters:
|
||||
info = self.info['operator'][converter.result.FullName()]
|
||||
# check if this operator should be excluded
|
||||
if info.exclude:
|
||||
continue
|
||||
|
||||
special_code = HandleSpecialOperator(converter)
|
||||
if info.rename or not special_code:
|
||||
# export as method
|
||||
name = info.rename or ConverterMethodName(converter)
|
||||
if self.class_.IsUnique(converter.name):
|
||||
pointer = '&' + converter.FullName()
|
||||
else:
|
||||
pointer = converter.PointerDeclaration()
|
||||
policy_code = ''
|
||||
if info.policy:
|
||||
policy_code = ', %s()' % info.policy.Code()
|
||||
self.Add('inside', '.def("%s", %s%s)' % (name, pointer, policy_code))
|
||||
|
||||
elif special_code:
|
||||
self.Add('inside', special_code)
|
||||
|
||||
|
||||
|
||||
def ExportNestedClasses(self, exported_names):
|
||||
nested_classes = [x for x in self.public_members if isinstance(x, NestedClass)]
|
||||
for nested_class in nested_classes:
|
||||
nested_info = self.info[nested_class.name]
|
||||
nested_info.include = self.info.include
|
||||
nested_info.name = nested_class.FullName()
|
||||
exporter = ClassExporter(nested_info)
|
||||
exporter.SetDeclarations(self.declarations + [nested_class])
|
||||
codeunit = SingleCodeUnit(None, None)
|
||||
exporter.Export(codeunit, exported_names)
|
||||
self.nested_codeunits.append(codeunit)
|
||||
|
||||
|
||||
def ExportNestedEnums(self):
|
||||
nested_enums = [x for x in self.public_members if isinstance(x, ClassEnumeration)]
|
||||
for enum in nested_enums:
|
||||
enum_info = self.info[enum.name]
|
||||
enum_info.include = self.info.include
|
||||
enum_info.name = enum.FullName()
|
||||
exporter = EnumExporter(enum_info)
|
||||
exporter.SetDeclarations(self.declarations + [enum])
|
||||
codeunit = SingleCodeUnit(None, None)
|
||||
exporter.Export(codeunit, None)
|
||||
self.nested_codeunits.append(codeunit)
|
||||
|
||||
|
||||
def ExportSmartPointer(self):
|
||||
smart_ptr = self.info.smart_ptr
|
||||
if smart_ptr:
|
||||
class_name = self.class_.FullName()
|
||||
smart_ptr = smart_ptr % class_name
|
||||
#self.Add('template', smart_ptr)
|
||||
|
||||
self.Add('scope', '// Temporary code for smart pointers')
|
||||
self.Add('scope', namespaces.python + 'objects::class_value_wrapper< ')
|
||||
self.Add('scope', ' %s, objects::make_ptr_instance< ' % smart_ptr)
|
||||
self.Add('scope', ' %s, objects::pointer_holder< ' % class_name)
|
||||
self.Add('scope', ' %s, %s >' % (smart_ptr, class_name))
|
||||
self.Add('scope', ' >')
|
||||
self.Add('scope', '>();')
|
||||
|
||||
|
||||
def ExportOpaquePointerPolicies(self):
|
||||
# check all methods for 'return_opaque_pointer' policies
|
||||
methods = [x for x in self.public_members if isinstance(x, Method)]
|
||||
for method in methods:
|
||||
return_opaque_policy = return_value_policy(return_opaque_pointer)
|
||||
if self.info[method.name].policy == return_opaque_policy:
|
||||
macro = 'BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(%s)' % method.result.name
|
||||
if macro not in self._exported_opaque_pointers:
|
||||
self.Add('declaration-outside', macro)
|
||||
self._exported_opaque_pointers[macro] = 1
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# Virtual Wrapper utils
|
||||
#==============================================================================
|
||||
|
||||
def _ParamsInfo(m, count=None):
|
||||
if count is None:
|
||||
count = len(m.parameters)
|
||||
param_names = ['p%i' % i for i in range(count)]
|
||||
param_types = [x.FullName() for x in m.parameters[:count]]
|
||||
params = ['%s %s' % (t, n) for t, n in zip(param_types, param_names)]
|
||||
#for i, p in enumerate(m.parameters[:count]):
|
||||
# if p.default is not None:
|
||||
# #params[i] += '=%s' % p.default
|
||||
# params[i] += '=%s' % (p.name + '()')
|
||||
params = ', '.join(params)
|
||||
return params, param_names, param_types
|
||||
|
||||
|
||||
class _VirtualWrapperGenerator(object):
|
||||
'Generates code to export the virtual methods of the given class'
|
||||
|
||||
def __init__(self, class_, bases, info):
|
||||
self.class_ = class_
|
||||
self.bases = bases[:]
|
||||
self.info = info
|
||||
self.wrapper_name = makeid(class_.FullName()) + '_Wrapper'
|
||||
self.virtual_methods = None
|
||||
self._method_count = {}
|
||||
self.GenerateVirtualMethods()
|
||||
|
||||
|
||||
def DefaultImplementationNames(self, method):
|
||||
'''Returns a list of default implementations for this method, one for each
|
||||
number of default arguments. Always returns at least one name, and return from
|
||||
the one with most arguments to the one with the least.
|
||||
'''
|
||||
base_name = 'default_' + method.name
|
||||
minArgs = method.minArgs
|
||||
maxArgs = method.maxArgs
|
||||
if minArgs == maxArgs:
|
||||
return [base_name]
|
||||
else:
|
||||
return [base_name + ('_%i' % i) for i in range(minArgs, maxArgs+1)]
|
||||
|
||||
|
||||
def Declaration(self, method, indent):
|
||||
'''Returns a string with the declarations of the virtual wrapper and
|
||||
its default implementations. This string must be put inside the Wrapper
|
||||
body.
|
||||
'''
|
||||
pyste = namespaces.pyste
|
||||
python = namespaces.python
|
||||
rename = self.info[method.name].rename or method.name
|
||||
result = method.result.FullName()
|
||||
return_str = 'return '
|
||||
if result == 'void':
|
||||
return_str = ''
|
||||
params, param_names, param_types = _ParamsInfo(method)
|
||||
constantness = ''
|
||||
if method.const:
|
||||
constantness = ' const'
|
||||
|
||||
# call_method callback
|
||||
decl = indent + '%s %s(%s)%s {\n' % (result, method.name, params, constantness)
|
||||
param_names_str = ', '.join(param_names)
|
||||
if param_names_str:
|
||||
param_names_str = ', ' + param_names_str
|
||||
decl += indent*2 + '%s%scall_method< %s >(self, "%s"%s);\n' %\
|
||||
(return_str, python, result, rename, param_names_str)
|
||||
decl += indent + '}\n'
|
||||
|
||||
# default implementations (with overloading)
|
||||
def DefaultImpl(method, param_names):
|
||||
'Return the body of a default implementation wrapper'
|
||||
wrapper = self.info[method.name].wrapper
|
||||
if not wrapper:
|
||||
# return the default implementation of the class
|
||||
return '%s%s::%s(%s);\n' % \
|
||||
(return_str, self.class_.FullName(), method.name, ', '.join(param_names))
|
||||
else:
|
||||
# return a call for the wrapper
|
||||
params = ', '.join(['this'] + param_names)
|
||||
return '%s%s(%s);\n' % (return_str, wrapper.FullName(), params)
|
||||
|
||||
if not method.abstract and method.visibility != Scope.private:
|
||||
minArgs = method.minArgs
|
||||
maxArgs = method.maxArgs
|
||||
impl_names = self.DefaultImplementationNames(method)
|
||||
for impl_name, argNum in zip(impl_names, range(minArgs, maxArgs+1)):
|
||||
params, param_names, param_types = _ParamsInfo(method, argNum)
|
||||
decl += '\n'
|
||||
decl += indent + '%s %s(%s)%s {\n' % (result, impl_name, params, constantness)
|
||||
decl += indent*2 + DefaultImpl(method, param_names)
|
||||
decl += indent + '}\n'
|
||||
return decl
|
||||
|
||||
|
||||
def MethodDefinition(self, method):
|
||||
'''Returns a list of lines, which should be put inside the class_
|
||||
statement to export this method.'''
|
||||
# dont define abstract methods
|
||||
pyste = namespaces.pyste
|
||||
rename = self.info[method.name].rename or method.name
|
||||
default_names = self.DefaultImplementationNames(method)
|
||||
class_name = self.class_.FullName()
|
||||
wrapper_name = pyste + self.wrapper_name
|
||||
result = method.result.FullName()
|
||||
is_method_unique = self.IsMethodUnique(method.name)
|
||||
constantness = ''
|
||||
if method.const:
|
||||
constantness = ' const'
|
||||
|
||||
# create a list of default-impl pointers
|
||||
minArgs = method.minArgs
|
||||
maxArgs = method.maxArgs
|
||||
if is_method_unique:
|
||||
default_pointers = ['&%s::%s' % (wrapper_name, x) for x in default_names]
|
||||
else:
|
||||
default_pointers = []
|
||||
for impl_name, argNum in zip(default_names, range(minArgs, maxArgs+1)):
|
||||
param_list = [x.FullName() for x in method.parameters[:argNum]]
|
||||
params = ', '.join(param_list)
|
||||
signature = '%s (%s::*)(%s)%s' % (result, wrapper_name, params, constantness)
|
||||
default_pointer = '(%s)&%s::%s' % (signature, wrapper_name, impl_name)
|
||||
default_pointers.append(default_pointer)
|
||||
|
||||
# get the pointer of the method
|
||||
if is_method_unique:
|
||||
pointer = '&' + method.FullName()
|
||||
else:
|
||||
pointer = method.PointerDeclaration()
|
||||
|
||||
# generate the defs
|
||||
definitions = []
|
||||
# basic def
|
||||
definitions.append('.def("%s", %s, %s)' % (rename, pointer, default_pointers[-1]))
|
||||
for default_pointer in default_pointers[:-1]:
|
||||
definitions.append('.def("%s", %s)' % (rename, default_pointer))
|
||||
return definitions
|
||||
|
||||
|
||||
def FullName(self):
|
||||
return namespaces.pyste + self.wrapper_name
|
||||
|
||||
|
||||
def GenerateVirtualMethods(self):
|
||||
'''To correctly export all virtual methods, we must also make wrappers
|
||||
for the virtual methods of the bases of this class, as if the methods
|
||||
were from this class itself.
|
||||
This method creates the instance variable self.virtual_methods.
|
||||
'''
|
||||
def IsVirtual(m):
|
||||
return type(m) is Method and m.virtual and m.visibility != Scope.private
|
||||
|
||||
all_methods = [x for x in self.class_.members if IsVirtual(x)]
|
||||
for base in self.bases:
|
||||
base_methods = [x.Copy() for x in base if IsVirtual(x)]
|
||||
for base_method in base_methods:
|
||||
base_method.class_ = self.class_.FullName()
|
||||
all_methods.append(base_method)
|
||||
|
||||
# extract the virtual methods, avoiding duplications. The duplication
|
||||
# must take in account the full signature without the class name, so
|
||||
# that inherited members are correctly excluded if the subclass overrides
|
||||
# them.
|
||||
def MethodSig(method):
|
||||
if method.const:
|
||||
const = 'const'
|
||||
else:
|
||||
const = ''
|
||||
if method.result:
|
||||
result = method.result.FullName()
|
||||
else:
|
||||
result = ''
|
||||
params = ', '.join([x.FullName() for x in method.parameters])
|
||||
return '%s %s(%s) %s' % (result, method.name, params, const)
|
||||
|
||||
self.virtual_methods = []
|
||||
already_added = {}
|
||||
for member in all_methods:
|
||||
sig = MethodSig(member)
|
||||
if IsVirtual(member) and not sig in already_added:
|
||||
self.virtual_methods.append(member)
|
||||
already_added[sig] = 0
|
||||
|
||||
|
||||
def IsMethodUnique(self, method):
|
||||
if not self._method_count:
|
||||
for m in self.virtual_methods:
|
||||
self._method_count[m.name] = self._method_count.get(m.name, 0) + 1
|
||||
return self._method_count[method] == 1
|
||||
|
||||
|
||||
def Constructors(self):
|
||||
def IsValid(m):
|
||||
return isinstance(m, Constructor) and m.visibility == Scope.public
|
||||
return [m for m in self.class_.members if IsValid(m)]
|
||||
|
||||
|
||||
def GenerateDefinitions(self):
|
||||
defs = []
|
||||
for method in self.virtual_methods:
|
||||
exclude = self.info[method.name].exclude
|
||||
# generate definitions only for public methods and non-abstract methods
|
||||
if method.visibility == Scope.public and not method.abstract and not exclude:
|
||||
defs.extend(self.MethodDefinition(method))
|
||||
return defs
|
||||
|
||||
|
||||
def GenerateVirtualWrapper(self, indent):
|
||||
'Return the wrapper for this class'
|
||||
|
||||
# generate the class code
|
||||
class_name = self.class_.FullName()
|
||||
code = 'struct %s: %s\n' % (self.wrapper_name, class_name)
|
||||
code += '{\n'
|
||||
# generate constructors (with the overloads for each one)
|
||||
for cons in self.Constructors(): # only public constructors
|
||||
minArgs = cons.minArgs
|
||||
maxArgs = cons.maxArgs
|
||||
# from the min number of arguments to the max number, generate
|
||||
# all version of the given constructor
|
||||
cons_code = ''
|
||||
for argNum in range(minArgs, maxArgs+1):
|
||||
params, param_names, param_types = _ParamsInfo(cons, argNum)
|
||||
if params:
|
||||
params = ', ' + params
|
||||
cons_code += indent + '%s(PyObject* self_%s):\n' % \
|
||||
(self.wrapper_name, params)
|
||||
cons_code += indent*2 + '%s(%s), self(self_) {}\n\n' % \
|
||||
(class_name, ', '.join(param_names))
|
||||
code += cons_code
|
||||
# generate the body
|
||||
body = []
|
||||
for method in self.virtual_methods:
|
||||
if not self.info[method.name].exclude:
|
||||
body.append(self.Declaration(method, indent))
|
||||
body = '\n'.join(body)
|
||||
code += body + '\n'
|
||||
# add the self member
|
||||
code += indent + 'PyObject* self;\n'
|
||||
code += '};\n'
|
||||
return code
|
||||
117
pyste/src/CppParser.py
Normal file
@@ -0,0 +1,117 @@
|
||||
from GCCXMLParser import ParseDeclarations
|
||||
import tempfile
|
||||
import shutil
|
||||
import os
|
||||
import os.path
|
||||
import settings
|
||||
|
||||
class CppParserError(Exception): pass
|
||||
|
||||
|
||||
class CppParser:
|
||||
'Parses a header file and returns a list of declarations'
|
||||
|
||||
def __init__(self, includes=None, defines=None):
|
||||
'includes and defines ar the directives given to gcc'
|
||||
if includes is None:
|
||||
includes = []
|
||||
if defines is None:
|
||||
defines = []
|
||||
self.includes = includes
|
||||
self.defines = defines
|
||||
self._cache = []
|
||||
self._CACHE_SIZE = 5
|
||||
|
||||
|
||||
def _includeparams(self, filename):
|
||||
includes = self.includes[:]
|
||||
filedir = os.path.dirname(filename)
|
||||
if not filedir:
|
||||
filedir = '.'
|
||||
includes.insert(0, filedir)
|
||||
includes = ['-I "%s"' % x for x in includes]
|
||||
return ' '.join(includes)
|
||||
|
||||
|
||||
def _defineparams(self):
|
||||
defines = ['-D "%s"' % x for x in self.defines]
|
||||
return ' '.join(defines)
|
||||
|
||||
|
||||
def UpdateCache(self, include, tail, decl_name, declarations, header):
|
||||
self._cache.append((include, tail, decl_name, declarations, header))
|
||||
if len(self._cache) > self._CACHE_SIZE:
|
||||
self._cache.pop(0)
|
||||
|
||||
|
||||
def Cache(self, include, tail, decl_name):
|
||||
for cache_include, cache_tail, cache_decl, declarations, header in self._cache:
|
||||
if cache_include == include \
|
||||
and cache_tail == tail \
|
||||
and cache_decl == decl_name:
|
||||
return declarations, header
|
||||
return None
|
||||
|
||||
|
||||
def FindFileName(self, include):
|
||||
if os.path.isfile(include):
|
||||
return include
|
||||
for path in self.includes:
|
||||
filename = os.path.join(path, include)
|
||||
if os.path.isfile(filename):
|
||||
return filename
|
||||
name = os.path.basename(include)
|
||||
raise RuntimeError, 'Header file "%s" not found!' % name
|
||||
|
||||
|
||||
def parse(self, include, tail=None, decl_name=None):
|
||||
'''Parses the given filename, and returns (declaration, header). The
|
||||
header returned is normally the same as the given to this method,
|
||||
except if tail is not None: in this case, the header is copied to a temp
|
||||
filename and the tail code is appended to it before being passed on to gcc.
|
||||
This temp filename is then returned.
|
||||
'''
|
||||
# check if this header was already parsed
|
||||
cached = self.Cache(include, tail, decl_name)
|
||||
if cached:
|
||||
return cached
|
||||
filename = self.FindFileName(include)
|
||||
# copy file to temp folder, if needed
|
||||
if tail:
|
||||
tempfilename = tempfile.mktemp('.h')
|
||||
infilename = tempfilename
|
||||
shutil.copyfile(filename, infilename)
|
||||
f = file(infilename, 'a')
|
||||
f.write('\n\n'+tail)
|
||||
f.close()
|
||||
else:
|
||||
infilename = filename
|
||||
xmlfile = tempfile.mktemp('.xml')
|
||||
try:
|
||||
# get the params
|
||||
includes = self._includeparams(filename)
|
||||
defines = self._defineparams()
|
||||
# call gccxml
|
||||
cmd = 'gccxml %s %s %s -fxml=%s' \
|
||||
% (includes, defines, infilename, xmlfile)
|
||||
if decl_name is not None:
|
||||
cmd += ' "-fxml-start=%s"' % decl_name
|
||||
status = os.system(cmd)
|
||||
if status != 0 or not os.path.isfile(xmlfile):
|
||||
raise CppParserError, 'Error executing gccxml'
|
||||
# parse the resulting xml
|
||||
declarations = ParseDeclarations(xmlfile)
|
||||
# cache the results
|
||||
self.UpdateCache(include, tail, decl_name, declarations, infilename)
|
||||
# return the declarations
|
||||
return declarations, infilename
|
||||
finally:
|
||||
if settings.DEBUG and os.path.isfile(xmlfile):
|
||||
filename = os.path.basename(include)
|
||||
shutil.copy(xmlfile, os.path.splitext(filename)[0] + '.xml')
|
||||
# delete the temporary files
|
||||
try:
|
||||
os.remove(xmlfile)
|
||||
if tail:
|
||||
os.remove(tempfilename)
|
||||
except OSError: pass
|
||||
44
pyste/src/EnumExporter.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from Exporter import Exporter
|
||||
from settings import *
|
||||
import utils
|
||||
|
||||
#==============================================================================
|
||||
# EnumExporter
|
||||
#==============================================================================
|
||||
class EnumExporter(Exporter):
|
||||
'Exports enumerators'
|
||||
|
||||
def __init__(self, info):
|
||||
Exporter.__init__(self, info)
|
||||
|
||||
|
||||
def SetDeclarations(self, declarations):
|
||||
Exporter.SetDeclarations(self, declarations)
|
||||
self.enum = self.GetDeclaration(self.info.name)
|
||||
|
||||
|
||||
def Export(self, codeunit, expoted_names):
|
||||
if not self.info.exclude:
|
||||
indent = self.INDENT
|
||||
in_indent = self.INDENT*2
|
||||
rename = self.info.rename or self.enum.name
|
||||
full_name = self.enum.FullName()
|
||||
if rename == "$_0" or rename == '._0':
|
||||
full_name = "int"
|
||||
rename = "unnamed"
|
||||
code = indent + namespaces.python
|
||||
code += 'enum_< %s >("%s")\n' % (full_name, rename)
|
||||
for name in self.enum.values:
|
||||
rename = self.info[name].rename or name
|
||||
value_fullname = self.enum.ValueFullName(name)
|
||||
code += in_indent + '.value("%s", %s)\n' % (rename, value_fullname)
|
||||
code += indent + ';\n\n'
|
||||
codeunit.Write('module', code)
|
||||
|
||||
|
||||
def Unit(self):
|
||||
return utils.makeid(self.info.include)
|
||||
|
||||
|
||||
def Order(self):
|
||||
return self.info.name
|
||||
72
pyste/src/Exporter.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import os.path
|
||||
|
||||
#==============================================================================
|
||||
# Exporter
|
||||
#==============================================================================
|
||||
class Exporter:
|
||||
'Base class for objects capable to generate boost.python code.'
|
||||
|
||||
INDENT = ' ' * 4
|
||||
|
||||
def __init__(self, info, parser_tail=None):
|
||||
self.info = info
|
||||
self.parser_tail = parser_tail
|
||||
|
||||
|
||||
def Name(self):
|
||||
return self.info.name
|
||||
|
||||
|
||||
def Parse(self, parser):
|
||||
self.parser = parser
|
||||
header = self.info.include
|
||||
tail = self.parser_tail
|
||||
declarations, parser_header = parser.parse(header, tail)
|
||||
self.parser_header = parser_header
|
||||
self.SetDeclarations(declarations)
|
||||
|
||||
|
||||
def SetDeclarations(self, declarations):
|
||||
self.declarations = declarations
|
||||
|
||||
|
||||
def GenerateCode(self, codeunit, exported_names):
|
||||
self.WriteInclude(codeunit)
|
||||
self.Export(codeunit, exported_names)
|
||||
|
||||
|
||||
def WriteInclude(self, codeunit):
|
||||
codeunit.Write('include', '#include <%s>\n' % self.info.include)
|
||||
|
||||
|
||||
def Export(self, codeunit, exported_names):
|
||||
'subclasses must override this to do the real work'
|
||||
pass
|
||||
|
||||
|
||||
def Unit(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def GetDeclarations(self, fullname):
|
||||
decls = [x for x in self.declarations if x.FullName() == fullname]
|
||||
if not decls:
|
||||
raise RuntimeError, 'no %s declaration found!' % fullname
|
||||
return decls
|
||||
|
||||
|
||||
def GetDeclaration(self, fullname):
|
||||
decls = self.GetDeclarations(fullname)
|
||||
assert len(decls) == 1
|
||||
return decls[0]
|
||||
|
||||
|
||||
def Order(self):
|
||||
'''Returns a string that uniquely identifies this instance. All
|
||||
exporters will be sorted by Order before being exported.
|
||||
'''
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def Unit(self):
|
||||
return self.info.include
|
||||
95
pyste/src/FunctionExporter.py
Normal file
@@ -0,0 +1,95 @@
|
||||
from Exporter import Exporter
|
||||
from policies import *
|
||||
from declarations import *
|
||||
from settings import *
|
||||
import utils
|
||||
import exporterutils
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# FunctionExporter
|
||||
#==============================================================================
|
||||
class FunctionExporter(Exporter):
|
||||
'Generates boost.python code to export the given function.'
|
||||
|
||||
def __init__(self, info, tail=None):
|
||||
Exporter.__init__(self, info, tail)
|
||||
self._exported_opaque_pointers = {}
|
||||
|
||||
|
||||
def Export(self, codeunit, exported_names):
|
||||
if not self.info.exclude:
|
||||
decls = self.GetDeclarations(self.info.name)
|
||||
for decl in decls:
|
||||
self.info.policy = exporterutils.HandlePolicy(decl, self.info.policy)
|
||||
exporterutils.WarnForwardDeclarations(decl)
|
||||
self.ExportDeclaration(decl, len(decls) == 1, codeunit)
|
||||
self.ExportOpaquePointer(decl, codeunit)
|
||||
self.GenerateOverloads(decls, codeunit)
|
||||
|
||||
|
||||
def ExportDeclaration(self, decl, unique, codeunit):
|
||||
name = self.info.rename or decl.name
|
||||
defs = namespaces.python + 'def("%s", ' % name
|
||||
wrapper = self.info.wrapper
|
||||
if wrapper:
|
||||
pointer = '&' + wrapper.FullName()
|
||||
elif not unique:
|
||||
pointer = decl.PointerDeclaration()
|
||||
else:
|
||||
pointer = '&' + decl.FullName()
|
||||
defs += pointer
|
||||
defs += self.PolicyCode()
|
||||
overload = self.OverloadName(decl)
|
||||
if overload:
|
||||
defs += ', %s()' % (namespaces.pyste + overload)
|
||||
defs += ');'
|
||||
codeunit.Write('module', self.INDENT + defs + '\n')
|
||||
# add the code of the wrapper
|
||||
if wrapper and wrapper.code:
|
||||
codeunit.Write('declaration', code + '\n')
|
||||
|
||||
|
||||
def OverloadName(self, decl):
|
||||
if decl.minArgs != decl.maxArgs:
|
||||
return '%s_overloads_%i_%i' % \
|
||||
(decl.name, decl.minArgs, decl.maxArgs)
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def GenerateOverloads(self, declarations, codeunit):
|
||||
codes = {}
|
||||
for decl in declarations:
|
||||
overload = self.OverloadName(decl)
|
||||
if overload and overload not in codes:
|
||||
code = 'BOOST_PYTHON_FUNCTION_OVERLOADS(%s, %s, %i, %i)' %\
|
||||
(overload, decl.FullName(), decl.minArgs, decl.maxArgs)
|
||||
codeunit.Write('declaration', code + '\n')
|
||||
codes[overload] = None
|
||||
|
||||
|
||||
def PolicyCode(self):
|
||||
policy = self.info.policy
|
||||
if policy is not None:
|
||||
assert isinstance(policy, Policy)
|
||||
return ', %s()' % policy.Code()
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def ExportOpaquePointer(self, function, codeunit):
|
||||
if self.info.policy == return_value_policy(return_opaque_pointer):
|
||||
type = function.result.name
|
||||
macro = 'BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(%s)' % type
|
||||
if macro not in self._exported_opaque_pointers:
|
||||
codeunit.Write('declaration-outside', macro)
|
||||
self._exported_opaque_pointers[macro] = 1
|
||||
|
||||
|
||||
def Order(self):
|
||||
return self.info.name
|
||||
|
||||
|
||||
def Unit(self):
|
||||
return utils.makeid(self.info.include)
|
||||
417
pyste/src/GCCXMLParser.py
Normal file
@@ -0,0 +1,417 @@
|
||||
from declarations import *
|
||||
from elementtree.ElementTree import ElementTree
|
||||
from xml.parsers.expat import ExpatError
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
class InvalidXMLError(Exception): pass
|
||||
|
||||
class ParserError(Exception): pass
|
||||
|
||||
class InvalidContextError(ParserError): pass
|
||||
|
||||
|
||||
class GCCXMLParser(object):
|
||||
'Parse a GCC_XML file and extract the top-level declarations.'
|
||||
|
||||
interested_tags = {'Class':0, 'Function':0, 'Variable':0, 'Enumeration':0}
|
||||
|
||||
def Parse(self, filename):
|
||||
self.elements = self.GetElementsFromXML(filename)
|
||||
# high level declarations
|
||||
self.declarations = []
|
||||
# parse the elements
|
||||
for id in self.elements:
|
||||
element, decl = self.elements[id]
|
||||
if decl is None:
|
||||
try:
|
||||
self.ParseElement(id, element)
|
||||
except InvalidContextError:
|
||||
pass # ignore those nodes with invalid context
|
||||
# (workaround gccxml bug)
|
||||
|
||||
|
||||
def Declarations(self):
|
||||
return self.declarations
|
||||
|
||||
|
||||
def AddDecl(self, decl):
|
||||
self.declarations.append(decl)
|
||||
|
||||
|
||||
def ParseElement(self, id, element):
|
||||
method = 'Parse' + element.tag
|
||||
if hasattr(self, method):
|
||||
func = getattr(self, method)
|
||||
func(id, element)
|
||||
|
||||
|
||||
def GetElementsFromXML(self,filename):
|
||||
'Extracts a dictionary of elements from the gcc_xml file.'
|
||||
|
||||
tree = ElementTree()
|
||||
try:
|
||||
tree.parse(filename)
|
||||
except ExpatError:
|
||||
raise InvalidXMLError, 'Not a XML file: %s' % filename
|
||||
|
||||
root = tree.getroot()
|
||||
if root.tag != 'GCC_XML':
|
||||
raise InvalidXMLError, 'Not a valid GCC_XML file'
|
||||
|
||||
# build a dictionary of id -> element, None
|
||||
elementlist = root.getchildren()
|
||||
elements = {}
|
||||
for element in elementlist:
|
||||
id = element.get('id')
|
||||
if id:
|
||||
elements[id] = element, None
|
||||
return elements
|
||||
|
||||
|
||||
def GetDecl(self, id):
|
||||
if id not in self.elements:
|
||||
if id == '_0':
|
||||
raise InvalidContextError, 'Invalid context found in the xml file.'
|
||||
else:
|
||||
msg = 'ID not found in elements: %s' % id
|
||||
raise ParserError, msg
|
||||
|
||||
elem, decl = self.elements[id]
|
||||
if decl is None:
|
||||
self.ParseElement(id, elem)
|
||||
elem, decl = self.elements[id]
|
||||
if decl is None:
|
||||
raise ParserError, 'Could not parse element: %s' % elem.tag
|
||||
return decl
|
||||
|
||||
|
||||
def GetType(self, id):
|
||||
def Check(id, feature):
|
||||
pos = id.find(feature)
|
||||
if pos != -1:
|
||||
id = id[:pos] + id[pos+1:]
|
||||
return True, id
|
||||
else:
|
||||
return False, id
|
||||
const, id = Check(id, 'c')
|
||||
volatile, id = Check(id, 'v')
|
||||
restricted, id = Check(id, 'r')
|
||||
decl = self.GetDecl(id)
|
||||
if isinstance(decl, Type):
|
||||
res = decl.Copy()
|
||||
if const:
|
||||
res.const = const
|
||||
if volatile:
|
||||
res.volatile = volatile
|
||||
if restricted:
|
||||
res.restricted = restricted
|
||||
else:
|
||||
res = Type(decl.FullName(), const)
|
||||
res.volatile = volatile
|
||||
res.restricted = restricted
|
||||
res.incomplete = decl.incomplete
|
||||
return res
|
||||
|
||||
|
||||
def GetLocation(self, location):
|
||||
file, line = location.split(':')
|
||||
file = self.GetDecl(file)
|
||||
return file, int(line)
|
||||
|
||||
|
||||
def Update(self, id, decl):
|
||||
element, _ = self.elements[id]
|
||||
self.elements[id] = element, decl
|
||||
|
||||
|
||||
def ParseNamespace(self, id, element):
|
||||
namespace = element.get('name')
|
||||
context = element.get('context')
|
||||
if context:
|
||||
outerns = self.GetDecl(context)
|
||||
if not outerns.endswith('::'):
|
||||
outerns += '::'
|
||||
namespace = outerns + namespace
|
||||
if namespace.startswith('::'):
|
||||
namespace = namespace[2:]
|
||||
self.Update(id, namespace)
|
||||
|
||||
|
||||
def ParseFile(self, id, element):
|
||||
filename = element.get('name')
|
||||
self.Update(id, filename)
|
||||
|
||||
|
||||
def ParseVariable(self, id, element):
|
||||
# in gcc_xml, a static Field is declared as a Variable, so we check
|
||||
# this and call the Field parser if apply.
|
||||
context = self.GetDecl(element.get('context'))
|
||||
if isinstance(context, Class):
|
||||
self.ParseField(id, element)
|
||||
elem, decl = self.elements[id]
|
||||
decl.static = True
|
||||
else:
|
||||
namespace = context
|
||||
name = element.get('name')
|
||||
type_ = self.GetType(element.get('type'))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
variable = Variable(type_, name, namespace)
|
||||
variable.location = location
|
||||
self.AddDecl(variable)
|
||||
self.Update(id, variable)
|
||||
|
||||
|
||||
def GetArguments(self, element):
|
||||
args = []
|
||||
for child in element:
|
||||
if child.tag == 'Argument':
|
||||
type_ = self.GetType(child.get('type'))
|
||||
type_.default = child.get('default')
|
||||
args.append(type_)
|
||||
return args
|
||||
|
||||
|
||||
def ParseFunction(self, id, element, functionType=Function):
|
||||
'''functionType is used because a Operator is identical to a normal
|
||||
function, only the type of the function changes.'''
|
||||
name = element.get('name')
|
||||
returns = self.GetType(element.get('returns'))
|
||||
namespace = self.GetDecl(element.get('context'))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
params = self.GetArguments(element)
|
||||
function = functionType(name, namespace, returns, params)
|
||||
function.location = location
|
||||
self.AddDecl(function)
|
||||
self.Update(id, function)
|
||||
|
||||
|
||||
def ParseOperatorFunction(self, id, element):
|
||||
self.ParseFunction(id, element, Operator)
|
||||
|
||||
|
||||
def GetBases(self, bases):
|
||||
'Parses the string "bases" from the xml into a list of Base instances.'
|
||||
|
||||
if bases is None:
|
||||
return []
|
||||
bases = bases.split()
|
||||
baseobjs = []
|
||||
for base in bases:
|
||||
# get the visibility
|
||||
split = base.split(':')
|
||||
if len(split) == 2:
|
||||
visib = split[0]
|
||||
base = split[1]
|
||||
else:
|
||||
visib = Scope.public
|
||||
decl = self.GetDecl(base)
|
||||
baseobj = Base(decl.FullName(), visib)
|
||||
baseobjs.append(baseobj)
|
||||
return baseobjs
|
||||
|
||||
|
||||
def GetMembers(self, members):
|
||||
# members must be a string with the ids of the members
|
||||
if members is None:
|
||||
return []
|
||||
memberobjs = []
|
||||
for member in members.split():
|
||||
memberobjs.append(self.GetDecl(member))
|
||||
return memberobjs
|
||||
|
||||
|
||||
def ParseClass(self, id, element):
|
||||
name = element.get('name')
|
||||
abstract = bool(int(element.get('abstract', '0')))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
context = self.GetDecl(element.get('context'))
|
||||
incomplete = bool(element.get('incomplete', False))
|
||||
if isinstance(context, str):
|
||||
class_ = Class(name, context, [], abstract, [])
|
||||
self.AddDecl(class_)
|
||||
else:
|
||||
# a nested class
|
||||
visib = element.get('access', Scope.public)
|
||||
class_ = NestedClass(
|
||||
name, context.FullName(), visib, [], abstract, [])
|
||||
# we have to add the declaration of the class before trying
|
||||
# to parse its members and bases, to avoid recursion.
|
||||
class_.location = location
|
||||
class_.incomplete = incomplete
|
||||
self.Update(id, class_)
|
||||
# now we can get the members and the bases
|
||||
class_.bases = self.GetBases(element.get('bases'))
|
||||
class_.members = self.GetMembers(element.get('members'))
|
||||
|
||||
|
||||
def ParseStruct(self, id, element):
|
||||
self.ParseClass(id, element)
|
||||
|
||||
|
||||
def ParseFundamentalType(self, id, element):
|
||||
name = element.get('name')
|
||||
type_ = FundamentalType(name)
|
||||
self.Update(id, type_)
|
||||
|
||||
|
||||
def ParseArrayType(self, id, element):
|
||||
type_ = self.GetType(element.get('type'))
|
||||
min = element.get('min')
|
||||
max = element.get('max')
|
||||
array = ArrayType(type_.name, type_.const)
|
||||
array.min = min
|
||||
array.max = max
|
||||
self.Update(id, array)
|
||||
|
||||
|
||||
def ParseReferenceType(self, id, element):
|
||||
type_ = self.GetType(element.get('type'))
|
||||
expand = not isinstance(type_, FunctionType)
|
||||
ref = ReferenceType(type_.name, type_.const, None, type_.incomplete, expand)
|
||||
self.Update(id, ref)
|
||||
|
||||
|
||||
def ParsePointerType(self, id, element):
|
||||
type_ = self.GetType(element.get('type'))
|
||||
expand = not isinstance(type_, FunctionType)
|
||||
ref = PointerType(type_.name, type_.const, None, type_.incomplete, expand)
|
||||
self.Update(id, ref)
|
||||
|
||||
|
||||
def ParseFunctionType(self, id, element):
|
||||
result = self.GetType(element.get('returns'))
|
||||
args = self.GetArguments(element)
|
||||
func = FunctionType(result, args)
|
||||
self.Update(id, func)
|
||||
|
||||
|
||||
def ParseMethodType(self, id, element):
|
||||
class_ = self.GetDecl(element.get('basetype')).FullName()
|
||||
result = self.GetType(element.get('returns'))
|
||||
args = self.GetArguments(element)
|
||||
method = MethodType(result, args, class_)
|
||||
self.Update(id, method)
|
||||
|
||||
|
||||
def ParseField(self, id, element):
|
||||
name = element.get('name')
|
||||
visib = element.get('access', Scope.public)
|
||||
classname = self.GetDecl(element.get('context')).FullName()
|
||||
type_ = self.GetType(element.get('type'))
|
||||
static = bool(int(element.get('extern', '0')))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
var = ClassVariable(type_, name, classname, visib, static)
|
||||
var.location = location
|
||||
self.Update(id, var)
|
||||
|
||||
|
||||
def ParseMethod(self, id, element, methodType=Method):
|
||||
name = element.get('name')
|
||||
result = self.GetType(element.get('returns'))
|
||||
classname = self.GetDecl(element.get('context')).FullName()
|
||||
visib = element.get('access', Scope.public)
|
||||
static = bool(int(element.get('static', '0')))
|
||||
virtual = bool(int(element.get('virtual', '0')))
|
||||
abstract = bool(int(element.get('pure_virtual', '0')))
|
||||
const = bool(int(element.get('const', '0')))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
params = self.GetArguments(element)
|
||||
method = methodType(
|
||||
name, classname, result, params, visib, virtual, abstract, static, const)
|
||||
method.location = location
|
||||
self.Update(id, method)
|
||||
|
||||
|
||||
def ParseOperatorMethod(self, id, element):
|
||||
self.ParseMethod(id, element, ClassOperator)
|
||||
|
||||
|
||||
def ParseConstructor(self, id, element):
|
||||
name = element.get('name')
|
||||
visib = element.get('access', Scope.public)
|
||||
classname = self.GetDecl(element.get('context')).FullName()
|
||||
location = self.GetLocation(element.get('location'))
|
||||
params = self.GetArguments(element)
|
||||
ctor = Constructor(name, classname, params, visib)
|
||||
ctor.location = location
|
||||
self.Update(id, ctor)
|
||||
|
||||
|
||||
def ParseDestructor(self, id, element):
|
||||
name = element.get('name')
|
||||
visib = element.get('access', Scope.public)
|
||||
classname = self.GetDecl(element.get('context')).FullName()
|
||||
virtual = bool(int(element.get('virtual', '0')))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
des = Destructor(name, classname, visib, virtual)
|
||||
des.location = location
|
||||
self.Update(id, des)
|
||||
|
||||
|
||||
def ParseConverter(self, id, element):
|
||||
self.ParseMethod(id, element, ConverterOperator)
|
||||
|
||||
|
||||
def ParseTypedef(self, id, element):
|
||||
name = element.get('name')
|
||||
type = self.GetType(element.get('type'))
|
||||
context = self.GetDecl(element.get('context'))
|
||||
if isinstance(context, Class):
|
||||
context = context.FullName()
|
||||
typedef = Typedef(type, name, context)
|
||||
self.Update(id, typedef)
|
||||
self.AddDecl(typedef)
|
||||
|
||||
|
||||
def ParseEnumeration(self, id, element):
|
||||
name = element.get('name')
|
||||
location = self.GetLocation(element.get('location'))
|
||||
context = self.GetDecl(element.get('context'))
|
||||
if isinstance(context, str):
|
||||
enum = Enumeration(name, context)
|
||||
self.AddDecl(enum) # in this case, is a top level decl
|
||||
else:
|
||||
visib = element.get('access', Scope.public)
|
||||
enum = ClassEnumeration(name, context.FullName(), visib)
|
||||
|
||||
enum.location = location
|
||||
for child in element:
|
||||
if child.tag == 'EnumValue':
|
||||
name = child.get('name')
|
||||
value = int(child.get('init'))
|
||||
enum.values[name] = value
|
||||
self.Update(id, enum)
|
||||
|
||||
|
||||
def ParseUnimplemented(self, id, element):
|
||||
'No idea of what this is'
|
||||
self.Update(id, Declaration('', ''))
|
||||
|
||||
|
||||
def ParseUnion(self, id, element):
|
||||
name = element.get('name')
|
||||
context = self.GetDecl(element.get('context'))
|
||||
location = self.GetLocation(element.get('location'))
|
||||
if isinstance(context, str):
|
||||
# a free union
|
||||
union = Union(name, context)
|
||||
self.AddDecl(union)
|
||||
else:
|
||||
visib = element.get('access', Scope.public)
|
||||
union = ClassUnion(name, context.FullName(), visib)
|
||||
union.location = location
|
||||
self.Update(id, union)
|
||||
|
||||
|
||||
|
||||
def ParseDeclarations(filename):
|
||||
'Returns a list of the top declarations found in the gcc_xml file.'
|
||||
|
||||
parser = GCCXMLParser()
|
||||
parser.Parse(filename)
|
||||
return parser.Declarations()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ParseDeclarations(r'D:\Programming\Libraries\boost-cvs\boost\libs\python\pyste\example\test.xml')
|
||||
77
pyste/src/HeaderExporter.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from Exporter import Exporter
|
||||
from ClassExporter import ClassExporter
|
||||
from FunctionExporter import FunctionExporter
|
||||
from EnumExporter import EnumExporter
|
||||
from VarExporter import VarExporter
|
||||
from infos import *
|
||||
from declarations import *
|
||||
import os.path
|
||||
import exporters
|
||||
|
||||
#==============================================================================
|
||||
# HeaderExporter
|
||||
#==============================================================================
|
||||
class HeaderExporter(Exporter):
|
||||
'Exports all declarations found in the given header'
|
||||
|
||||
def __init__(self, info, parser_tail=None):
|
||||
Exporter.__init__(self, info, parser_tail)
|
||||
|
||||
|
||||
def WriteInclude(self, codeunit):
|
||||
pass
|
||||
|
||||
|
||||
def SetDeclarations(self, declarations):
|
||||
def IsInternalName(name):
|
||||
'''Returns true if the given name looks like a internal compiler
|
||||
structure'''
|
||||
return name.startswith('_')
|
||||
|
||||
Exporter.SetDeclarations(self, declarations)
|
||||
header = os.path.normpath(self.parser_header)
|
||||
for decl in declarations:
|
||||
# check if this declaration is in the header
|
||||
location = os.path.normpath(decl.location[0])
|
||||
if location != header or IsInternalName(decl.name):
|
||||
continue
|
||||
# ok, check the type of the declaration and export it accordingly
|
||||
self.HandleDeclaration(decl)
|
||||
|
||||
|
||||
def HandleDeclaration(self, decl):
|
||||
'''Dispatch the declaration to the appropriate method, that must create
|
||||
a suitable info object for a Exporter, create a Exporter, set its
|
||||
declarations and append it to the list of exporters.
|
||||
'''
|
||||
dispatch_table = {
|
||||
Class : ClassExporter,
|
||||
Enumeration : EnumExporter,
|
||||
Function : FunctionExporter,
|
||||
Variable : VarExporter,
|
||||
}
|
||||
|
||||
exporter_class = dispatch_table.get(type(decl))
|
||||
if exporter_class is not None:
|
||||
self.HandleExporter(decl, exporter_class)
|
||||
|
||||
|
||||
def HandleExporter(self, decl, exporter_type):
|
||||
# only export complete declarations
|
||||
if not getattr(decl, "incomplete", False):
|
||||
info = self.info[decl.name]
|
||||
info.name = decl.FullName()
|
||||
info.include = self.info.include
|
||||
exporter = exporter_type(info)
|
||||
exporter.SetDeclarations(self.declarations)
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
def Unit(self):
|
||||
return None # doesn't write anything by himself
|
||||
|
||||
|
||||
def Order(self):
|
||||
return self.info.include
|
||||
|
||||
|
||||
24
pyste/src/IncludeExporter.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os.path
|
||||
from Exporter import Exporter
|
||||
|
||||
#==============================================================================
|
||||
# IncludeExporter
|
||||
#==============================================================================
|
||||
class IncludeExporter(Exporter):
|
||||
'''Writes an include declaration to the module. Useful to add extra code
|
||||
for use in the Wrappers.
|
||||
This class just reimplements the Parse method to do nothing: the
|
||||
WriteInclude in Exporter already does the work for us.
|
||||
'''
|
||||
|
||||
def __init__(self, info, parser_tail=None):
|
||||
Exporter.__init__(self, info, parser_tail)
|
||||
|
||||
def Parse(self, parser):
|
||||
pass
|
||||
|
||||
def Order(self):
|
||||
return self.info.include
|
||||
|
||||
def Unit(self):
|
||||
return '__all__' # include it in all generated cpps (multiple mode)
|
||||
104
pyste/src/MultipleCodeUnit.py
Normal file
@@ -0,0 +1,104 @@
|
||||
from SingleCodeUnit import SingleCodeUnit
|
||||
import os
|
||||
import utils
|
||||
from SmartFile import SmartFile
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# MultipleCodeUnit
|
||||
#==============================================================================
|
||||
class MultipleCodeUnit(object):
|
||||
'''
|
||||
Represents a bunch of cpp files, where each cpp file represents a header
|
||||
to be exported by pyste. Another cpp, named <module>.cpp is created too.
|
||||
'''
|
||||
|
||||
def __init__(self, modulename, outdir):
|
||||
self.modulename = modulename
|
||||
self.outdir = outdir
|
||||
self.codeunits = {} # maps from a header to a SingleCodeUnit
|
||||
self.functions = []
|
||||
self._current = None
|
||||
|
||||
|
||||
def _FunctionName(self, code_unit_name):
|
||||
return '_Export_%s' % utils.makeid(code_unit_name)
|
||||
|
||||
|
||||
def _FileName(self, code_unit_name):
|
||||
filename = os.path.basename(code_unit_name)
|
||||
filename = '_%s.cpp' % os.path.splitext(filename)[0]
|
||||
return os.path.join(self.outdir, filename)
|
||||
|
||||
|
||||
def SetCurrent(self, code_unit_name):
|
||||
'Changes the current code unit'
|
||||
try:
|
||||
if code_unit_name is not None:
|
||||
codeunit = self.codeunits[code_unit_name]
|
||||
else:
|
||||
codeunit = None
|
||||
except KeyError:
|
||||
filename = self._FileName(code_unit_name)
|
||||
function_name = self._FunctionName(code_unit_name)
|
||||
codeunit = SingleCodeUnit(None, filename)
|
||||
codeunit.module_definition = 'void %s()' % function_name
|
||||
self.codeunits[code_unit_name] = codeunit
|
||||
if code_unit_name != '__all__':
|
||||
self.functions.append(function_name)
|
||||
self._current = codeunit
|
||||
|
||||
|
||||
def Current(self):
|
||||
return self._current
|
||||
|
||||
current = property(Current, SetCurrent)
|
||||
|
||||
|
||||
def Write(self, section, code):
|
||||
if self._current is not None:
|
||||
self.current.Write(section, code)
|
||||
|
||||
|
||||
def Section(self, section):
|
||||
if self._current is not None:
|
||||
return self.current.Section(section)
|
||||
|
||||
|
||||
def _CreateOutputDir(self):
|
||||
try:
|
||||
os.mkdir(self.outdir)
|
||||
except OSError: pass # already created
|
||||
|
||||
|
||||
def Save(self):
|
||||
# create the directory where all the files will go
|
||||
self._CreateOutputDir();
|
||||
# write all the codeunits, merging first the contents of
|
||||
# the special code unit named __all__
|
||||
__all__ = self.codeunits.get('__all__')
|
||||
for name, codeunit in self.codeunits.items():
|
||||
if name != '__all__':
|
||||
if __all__:
|
||||
codeunit.Merge(__all__)
|
||||
codeunit.Save()
|
||||
# generate the main cpp
|
||||
filename = os.path.join(self.outdir, self.modulename + '.cpp')
|
||||
fout = SmartFile(filename, 'w')
|
||||
fout.write(utils.left_equals('Include'))
|
||||
fout.write('#include <boost/python.hpp>\n\n')
|
||||
fout.write(utils.left_equals('Exports'))
|
||||
for function in self.functions:
|
||||
fout.write('void %s();\n' % function)
|
||||
fout.write('\n')
|
||||
fout.write(utils.left_equals('Module'))
|
||||
fout.write('BOOST_PYTHON_MODULE(%s)\n' % self.modulename)
|
||||
fout.write('{\n')
|
||||
indent = ' ' * 4
|
||||
for function in self.functions:
|
||||
fout.write(indent)
|
||||
fout.write('%s();\n' % function)
|
||||
fout.write('}\n')
|
||||
|
||||
|
||||
|
||||
84
pyste/src/SingleCodeUnit.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from settings import namespaces
|
||||
import settings
|
||||
from utils import remove_duplicated_lines, left_equals
|
||||
from SmartFile import SmartFile
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# SingleCodeUnit
|
||||
#==============================================================================
|
||||
class SingleCodeUnit:
|
||||
'''
|
||||
Represents a cpp file, where other objects can write in one of the
|
||||
predefined sections.
|
||||
The avaiable sections are:
|
||||
include - The include area of the cpp file
|
||||
declaration - The part before the module definition
|
||||
module - Inside the BOOST_PYTHON_MODULE macro
|
||||
'''
|
||||
|
||||
def __init__(self, modulename, filename):
|
||||
self.modulename = modulename
|
||||
self.filename = filename
|
||||
# define the avaiable sections
|
||||
self.code = {}
|
||||
# include section
|
||||
self.code['include'] = ''
|
||||
# declaration section (inside namespace)
|
||||
self.code['declaration'] = ''
|
||||
# declaration (outside namespace)
|
||||
self.code['declaration-outside'] = ''
|
||||
# inside BOOST_PYTHON_MACRO
|
||||
self.code['module'] = ''
|
||||
# create the default module definition
|
||||
self.module_definition = 'BOOST_PYTHON_MODULE(%s)' % modulename
|
||||
|
||||
|
||||
def Write(self, section, code):
|
||||
'write the given code in the section of the code unit'
|
||||
if section not in self.code:
|
||||
raise RuntimeError, 'Invalid CodeUnit section: %s' % section
|
||||
self.code[section] += code
|
||||
|
||||
|
||||
def Merge(self, other):
|
||||
for section in ('include', 'declaration', 'declaration-outside', 'module'):
|
||||
self.code[section] = self.code[section] + other.code[section]
|
||||
|
||||
|
||||
def Section(self, section):
|
||||
return self.code[section]
|
||||
|
||||
|
||||
def Save(self):
|
||||
'Writes this code unit to the filename'
|
||||
space = '\n\n'
|
||||
fout = SmartFile(self.filename, 'w')
|
||||
# includes
|
||||
includes = remove_duplicated_lines(self.code['include'])
|
||||
fout.write('\n' + left_equals('Includes'))
|
||||
fout.write('#include <boost/python.hpp>\n')
|
||||
fout.write(includes)
|
||||
fout.write(space)
|
||||
# using
|
||||
if settings.USING_BOOST_NS:
|
||||
fout.write(left_equals('Using'))
|
||||
fout.write('using namespace boost::python;\n\n')
|
||||
# declarations
|
||||
declaration = self.code['declaration']
|
||||
declaration_outside = self.code['declaration-outside']
|
||||
if declaration_outside or declaration:
|
||||
fout.write(left_equals('Declarations'))
|
||||
fout.write(declaration_outside + '\n\n')
|
||||
if declaration:
|
||||
pyste_namespace = namespaces.pyste[:-2]
|
||||
fout.write('namespace %s {\n\n\n' % pyste_namespace)
|
||||
fout.write(declaration)
|
||||
fout.write('\n\n}// namespace %s\n' % pyste_namespace)
|
||||
fout.write(space)
|
||||
# module
|
||||
fout.write(left_equals('Module'))
|
||||
fout.write(self.module_definition + '\n')
|
||||
fout.write('{\n')
|
||||
fout.write(self.code['module'])
|
||||
fout.write('}\n')
|
||||
55
pyste/src/SmartFile.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
import md5
|
||||
|
||||
#==============================================================================
|
||||
# SmartFile
|
||||
#==============================================================================
|
||||
class SmartFile(object):
|
||||
'''
|
||||
A file-like object used for writing files. The given file will only be
|
||||
actually written to disk if there's not a file with the same name, or if
|
||||
the existing file is *different* from the file to be written.
|
||||
'''
|
||||
|
||||
def __init__(self, filename, mode='w'):
|
||||
self.filename = filename
|
||||
self.mode = mode
|
||||
self._contents = []
|
||||
self._closed = False
|
||||
|
||||
|
||||
def __del__(self):
|
||||
if not self._closed:
|
||||
self.close()
|
||||
|
||||
|
||||
def write(self, string):
|
||||
self._contents.append(string)
|
||||
|
||||
|
||||
def _dowrite(self, contents):
|
||||
f = file(self.filename, self.mode)
|
||||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
|
||||
def _GetMD5(self, string):
|
||||
return md5.new(string).digest()
|
||||
|
||||
|
||||
def close(self):
|
||||
# if the filename doesn't exist, write the file right away
|
||||
this_contents = ''.join(self._contents)
|
||||
if not os.path.isfile(self.filename):
|
||||
self._dowrite(this_contents)
|
||||
else:
|
||||
# read the contents of the file already in disk
|
||||
f = file(self.filename)
|
||||
other_contents = f.read()
|
||||
f.close()
|
||||
# test the md5 for both files
|
||||
this_md5 = self._GetMD5(this_contents)
|
||||
other_md5 = self._GetMD5(other_contents)
|
||||
if this_md5 != other_md5:
|
||||
self._dowrite(this_contents)
|
||||
self._closed = True
|
||||
35
pyste/src/VarExporter.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from Exporter import Exporter
|
||||
from settings import *
|
||||
import utils
|
||||
|
||||
#==============================================================================
|
||||
# VarExporter
|
||||
#==============================================================================
|
||||
class VarExporter(Exporter):
|
||||
'''Exports a global variable.
|
||||
'''
|
||||
|
||||
def __init__(self, info):
|
||||
Exporter.__init__(self, info)
|
||||
|
||||
|
||||
def Export(self, codeunit, exported_names):
|
||||
if self.info.exclude: return
|
||||
decl = self.GetDeclaration(self.info.name)
|
||||
if not decl.type.const:
|
||||
msg = '---> Warning: The global variable "%s" is non-const:\n' \
|
||||
' changes in Python will not reflect in C++.'
|
||||
print msg % self.info.name
|
||||
print
|
||||
rename = self.info.rename or self.info.name
|
||||
code = self.INDENT + namespaces.python
|
||||
code += 'scope().attr("%s") = %s;\n' % (rename, self.info.name)
|
||||
codeunit.Write('module', code)
|
||||
|
||||
|
||||
def Order(self):
|
||||
return self.info.name
|
||||
|
||||
|
||||
def Unit(self):
|
||||
return utils.makeid(self.info.include)
|
||||
554
pyste/src/declarations.py
Normal file
@@ -0,0 +1,554 @@
|
||||
'''
|
||||
Module declarations
|
||||
|
||||
Defines classes that represent declarations found in C++ header files.
|
||||
|
||||
'''
|
||||
|
||||
class Declaration(object):
|
||||
'Represents a basic declaration.'
|
||||
|
||||
__slots__ = 'name namespace location incomplete'.split()
|
||||
|
||||
def __init__(self, name, namespace):
|
||||
# the declaration name
|
||||
self.name = name
|
||||
# all the namespaces, separated by '::' = 'boost::inner'
|
||||
self.namespace = namespace
|
||||
# tuple (filename, line)
|
||||
self.location = '', -1
|
||||
# if a declaration is incomplete it means that it was
|
||||
# forward declared
|
||||
self.incomplete = False
|
||||
|
||||
|
||||
def FullName(self):
|
||||
'Returns the full qualified name: "boost::inner::Test"'
|
||||
namespace = self.namespace or ''
|
||||
#if not namespace:
|
||||
# namespace = ''
|
||||
if namespace and not namespace.endswith('::'):
|
||||
namespace += '::'
|
||||
return namespace + self.name
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return '<Declaration %s at %s>' % (self.FullName(), id(self))
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return 'Declaration of %s' % self.FullName()
|
||||
|
||||
|
||||
|
||||
class Class(Declaration):
|
||||
'The declaration of a class or struct.'
|
||||
|
||||
__slots__= 'members abstract bases _members_count'.split()
|
||||
def __init__(self, name, namespace, members, abstract, bases):
|
||||
Declaration.__init__(self, name, namespace)
|
||||
# list of members
|
||||
self.members = members
|
||||
# whatever the class has any abstract methods
|
||||
self.abstract = abstract
|
||||
# instances of Base
|
||||
self.bases = bases
|
||||
self._members_count = {}
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.members)
|
||||
|
||||
|
||||
def IsAbstract(self):
|
||||
'Returns True if any method of this class is abstract'
|
||||
for member in self.members:
|
||||
if isinstance(member, Method):
|
||||
if member.abstract:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def RawName(self):
|
||||
'Returns the raw name of a template class. name = Foo<int>, raw = Foo'
|
||||
lesspos = self.name.find('<')
|
||||
if lesspos != -1:
|
||||
return self.name[:lesspos]
|
||||
else:
|
||||
return self.name
|
||||
|
||||
|
||||
def Constructors(self, publics_only=True):
|
||||
constructors = []
|
||||
for member in self:
|
||||
if isinstance(member, Constructor):
|
||||
if publics_only and member.visibility != Scope.public:
|
||||
continue
|
||||
constructors.append(member)
|
||||
return constructors
|
||||
|
||||
|
||||
def HasCopyConstructor(self):
|
||||
for cons in self.Constructors():
|
||||
if cons.IsCopy():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def HasDefaultConstructor(self):
|
||||
for cons in self.Constructors():
|
||||
if cons.IsDefault():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def IsUnique(self, member_name):
|
||||
if not self._members_count:
|
||||
for m in self:
|
||||
self._members_count[m.name] = self._members_count.get(m.name, 0) + 1
|
||||
try:
|
||||
return self._members_count[member_name] == 1
|
||||
except KeyError:
|
||||
print self._members_count
|
||||
print 'Key', member_name
|
||||
|
||||
|
||||
|
||||
class NestedClass(Class):
|
||||
'The declaration of a class/struct inside another class/struct.'
|
||||
|
||||
__slots__= 'class_ visibility'.split()
|
||||
|
||||
def __init__(self, name, class_, visib, members, abstract, bases):
|
||||
Class.__init__(self, name, None, members, abstract, bases)
|
||||
self.class_ = class_
|
||||
self.visibility = visib
|
||||
|
||||
|
||||
def FullName(self):
|
||||
return '%s::%s' % (self.class_, self.name)
|
||||
|
||||
|
||||
|
||||
class Base:
|
||||
'Represents a base class of another class.'
|
||||
|
||||
__slots__= 'name visibility'.split()
|
||||
|
||||
def __init__(self, name, visibility=None):
|
||||
# class_ is the full name of the base class
|
||||
self.name = name
|
||||
# visibility of the derivation
|
||||
if visibility is None:
|
||||
visibility = Scope.public
|
||||
self.visibility = visibility
|
||||
|
||||
|
||||
|
||||
class Scope:
|
||||
public = 'public'
|
||||
private = 'private'
|
||||
protected = 'protected'
|
||||
|
||||
|
||||
|
||||
class Function(Declaration):
|
||||
'The declaration of a function.'
|
||||
|
||||
__slots__= 'result parameters'.split()
|
||||
|
||||
def __init__(self, name, namespace, result, params):
|
||||
Declaration.__init__(self, name, namespace)
|
||||
# the result type: instance of Type, or None (constructors)
|
||||
self.result = result
|
||||
# the parameters: instances of Type
|
||||
self.parameters = params
|
||||
|
||||
|
||||
def PointerDeclaration(self):
|
||||
'returns a declaration of a pointer to this function'
|
||||
result = self.result.FullName()
|
||||
params = ', '.join([x.FullName() for x in self.parameters])
|
||||
return '(%s (*)(%s))&%s' % (result, params, self.FullName())
|
||||
|
||||
|
||||
def _MinArgs(self):
|
||||
min = 0
|
||||
for arg in self.parameters:
|
||||
if arg.default is None:
|
||||
min += 1
|
||||
return min
|
||||
|
||||
minArgs = property(_MinArgs)
|
||||
|
||||
|
||||
def _MaxArgs(self):
|
||||
return len(self.parameters)
|
||||
|
||||
maxArgs = property(_MaxArgs)
|
||||
|
||||
|
||||
def Copy(self):
|
||||
return self.__class__(
|
||||
self.name, self.namespace, self.result, self.params[:])
|
||||
|
||||
|
||||
class Operator(Function):
|
||||
'The declaration of a custom operator.'
|
||||
|
||||
def FullName(self):
|
||||
namespace = self.namespace or ''
|
||||
if not namespace.endswith('::'):
|
||||
namespace += '::'
|
||||
return namespace + 'operator' + self.name
|
||||
|
||||
|
||||
class Method(Function):
|
||||
'The declaration of a method.'
|
||||
|
||||
__slots__= 'visibility virtual abstract static class_ const'.split()
|
||||
|
||||
def __init__(self, name, class_, result, params, visib, virtual, abstract, static, const):
|
||||
Function.__init__(self, name, None, result, params)
|
||||
self.visibility = visib
|
||||
self.virtual = virtual
|
||||
self.abstract = abstract
|
||||
self.static = static
|
||||
self.class_ = class_
|
||||
self.const = const
|
||||
|
||||
|
||||
def FullName(self):
|
||||
return self.class_ + '::' + self.name
|
||||
|
||||
|
||||
def PointerDeclaration(self):
|
||||
'returns a declaration of a pointer to this function'
|
||||
if self.static:
|
||||
# static methods are like normal functions
|
||||
return Function.PointerDeclaration(self)
|
||||
else:
|
||||
# using syntax of methods
|
||||
result = self.result.FullName()
|
||||
params = ', '.join([x.FullName() for x in self.parameters])
|
||||
const = ''
|
||||
if self.const:
|
||||
const = 'const'
|
||||
return '(%s (%s::*)(%s) %s)&%s' %\
|
||||
(result, self.class_, params, const, self.FullName())
|
||||
|
||||
|
||||
def Copy(self):
|
||||
return self.__class__(
|
||||
self.name,
|
||||
self.class_,
|
||||
self.result,
|
||||
self.parameters[:],
|
||||
self.visibility,
|
||||
self.virtual,
|
||||
self.abstract,
|
||||
self.static,
|
||||
self.const)
|
||||
|
||||
|
||||
class Constructor(Method):
|
||||
'A constructor of a class.'
|
||||
|
||||
def __init__(self, name, class_, params, visib):
|
||||
Method.__init__(self, name, class_, None, params, visib, False, False, False, False)
|
||||
|
||||
|
||||
def IsDefault(self):
|
||||
return len(self.parameters) == 0
|
||||
|
||||
|
||||
def IsCopy(self):
|
||||
if len(self.parameters) != 1:
|
||||
return False
|
||||
param = self.parameters[0]
|
||||
class_as_param = self.parameters[0].name == self.class_
|
||||
param_reference = isinstance(param, ReferenceType)
|
||||
return param_reference and class_as_param and param.const
|
||||
|
||||
|
||||
class Destructor(Method):
|
||||
'The destructor of a class.'
|
||||
|
||||
def __init__(self, name, class_, visib, virtual):
|
||||
Method.__init__(self, name, class_, None, [], visib, virtual, False, False, False)
|
||||
|
||||
def FullName(self):
|
||||
return self.class_ + '::~' + self.name
|
||||
|
||||
|
||||
|
||||
class ClassOperator(Method):
|
||||
'The declaration of a custom operator in a class.'
|
||||
|
||||
def FullName(self):
|
||||
return self.class_ + '::operator ' + self.name
|
||||
|
||||
|
||||
|
||||
class ConverterOperator(ClassOperator):
|
||||
'An operator in the form "operator OtherClass()".'
|
||||
|
||||
def FullName(self):
|
||||
return self.class_ + '::operator ' + self.result.FullName()
|
||||
|
||||
|
||||
|
||||
class Type(Declaration):
|
||||
'Represents a type.'
|
||||
|
||||
__slots__= 'const default volatile restricted incomplete'.split()
|
||||
|
||||
def __init__(self, name, const=False, default=None, incomplete=False):
|
||||
Declaration.__init__(self, name, None)
|
||||
# whatever the type is constant or not
|
||||
self.const = const
|
||||
# used when the Type is a function argument
|
||||
self.default = default
|
||||
self.volatile = False
|
||||
self.restricted = False
|
||||
self.incomplete = incomplete
|
||||
|
||||
def __repr__(self):
|
||||
if self.const:
|
||||
const = 'const '
|
||||
else:
|
||||
const = ''
|
||||
return '<Type ' + const + self.name + '>'
|
||||
|
||||
|
||||
def FullName(self):
|
||||
if self.const:
|
||||
const = 'const '
|
||||
else:
|
||||
const = ''
|
||||
return const + self.name
|
||||
|
||||
|
||||
def Copy(self):
|
||||
t = self.__class__(self.name, self.const, self.default, self.incomplete)
|
||||
t.volatile = self.volatile
|
||||
t.restricted = self.restricted
|
||||
return t
|
||||
|
||||
|
||||
class ArrayType(Type):
|
||||
'Represents an array.'
|
||||
|
||||
__slots__= 'min max'.split()
|
||||
|
||||
def __init__(self, name, const=False, default=None, incomplete=False):
|
||||
'min and max can be None.'
|
||||
Type.__init__(self, name, const)
|
||||
self.min = None
|
||||
self.max = None
|
||||
|
||||
def Copy(self):
|
||||
t = Type.Copy(self)
|
||||
t.min = self.min
|
||||
t.max = self.max
|
||||
return t
|
||||
|
||||
|
||||
|
||||
class ReferenceType(Type):
|
||||
'A reference type.'
|
||||
|
||||
__slots__= 'expand'.split()
|
||||
|
||||
def __init__(self, name, const=False, default=None, incomplete=False, expandRef=True):
|
||||
Type.__init__(self, name, const, default, incomplete)
|
||||
self.expand = expandRef
|
||||
|
||||
|
||||
def FullName(self):
|
||||
'expand is False for function pointers'
|
||||
expand = ' &'
|
||||
if not self.expand:
|
||||
expand = ''
|
||||
return Type.FullName(self) + expand
|
||||
|
||||
|
||||
def Copy(self):
|
||||
t = Type.Copy(self)
|
||||
t.expand = self.expand
|
||||
return t
|
||||
|
||||
|
||||
|
||||
class PointerType(Type):
|
||||
'A pointer type.'
|
||||
|
||||
__slots__= 'expand'.split()
|
||||
|
||||
def __init__(self, name, const=False, default=None, incomplete=False, expandPointer=False):
|
||||
Type.__init__(self, name, const, default, incomplete)
|
||||
self.expand = expandPointer
|
||||
|
||||
|
||||
def FullName(self):
|
||||
'expand is False for function pointer'
|
||||
expand = ' *'
|
||||
if not self.expand:
|
||||
expand = ''
|
||||
return Type.FullName(self) + expand
|
||||
|
||||
def Copy(self):
|
||||
t = Type.Copy(self)
|
||||
t.expand = self.expand
|
||||
return t
|
||||
|
||||
|
||||
|
||||
class FundamentalType(Type):
|
||||
'One of the fundamental types (int, void...).'
|
||||
|
||||
def __init__(self, name, const=False, default=None, incomplete=False):
|
||||
Type.__init__(self, name, const, default, incomplete)
|
||||
|
||||
|
||||
|
||||
class FunctionType(Type):
|
||||
'A pointer to a function.'
|
||||
|
||||
__slots__= 'result parameters name'.split()
|
||||
|
||||
def __init__(self, result, parameters):
|
||||
Type.__init__(self, '', False)
|
||||
self.result = result
|
||||
self.parameters = parameters
|
||||
self.name = self.FullName()
|
||||
|
||||
|
||||
def FullName(self):
|
||||
full = '%s (*)' % self.result.FullName()
|
||||
params = [x.FullName() for x in self.parameters]
|
||||
full += '(%s)' % ', '.join(params)
|
||||
return full
|
||||
|
||||
|
||||
def Copy(self):
|
||||
return FunctionType(self.result, self.parameters[:])
|
||||
|
||||
|
||||
class MethodType(FunctionType):
|
||||
'A pointer to a member function of a class.'
|
||||
|
||||
__slots__= 'result parameters class_ name'.split()
|
||||
|
||||
def __init__(self, result, parameters, class_):
|
||||
Type.__init__(self, '', False)
|
||||
self.result = result
|
||||
self.parameters = parameters
|
||||
self.class_ = class_
|
||||
self.name = self.FullName()
|
||||
|
||||
def FullName(self):
|
||||
full = '%s (%s::*)' % (self.result.FullName(), self.class_)
|
||||
params = [x.FullName() for x in self.parameters]
|
||||
full += '(%s)' % ', '.join(params)
|
||||
return full
|
||||
|
||||
def Copy(self):
|
||||
return MethodType(self.result, self.parameters[:], self.class_)
|
||||
|
||||
|
||||
class Variable(Declaration):
|
||||
'Represents a global variable.'
|
||||
|
||||
__slots__= 'type'.split()
|
||||
|
||||
def __init__(self, type, name, namespace):
|
||||
Declaration.__init__(self, name, namespace)
|
||||
# instance of Type
|
||||
self.type = type
|
||||
|
||||
|
||||
|
||||
class ClassVariable(Variable):
|
||||
'Represents a class variable.'
|
||||
|
||||
__slots__= 'visibility static class_'.split()
|
||||
|
||||
def __init__(self, type, name, class_, visib, static):
|
||||
Variable.__init__(self, type, name, None)
|
||||
self.visibility = visib
|
||||
self.static = static
|
||||
self.class_ = class_
|
||||
|
||||
|
||||
def FullName(self):
|
||||
return self.class_ + '::' + self.name
|
||||
|
||||
|
||||
|
||||
class Enumeration(Declaration):
|
||||
|
||||
__slots__= 'values'.split()
|
||||
|
||||
def __init__(self, name, namespace):
|
||||
Declaration.__init__(self, name, namespace)
|
||||
self.values = {} # dict of str => int
|
||||
|
||||
def ValueFullName(self, name):
|
||||
assert name in self.values
|
||||
namespace = self.namespace
|
||||
if namespace:
|
||||
namespace += '::'
|
||||
return namespace + name
|
||||
|
||||
|
||||
|
||||
class ClassEnumeration(Enumeration):
|
||||
|
||||
__slots__= 'class_ visibility'.split()
|
||||
|
||||
def __init__(self, name, class_, visib):
|
||||
Enumeration.__init__(self, name, None)
|
||||
self.class_ = class_
|
||||
self.visibility = visib
|
||||
|
||||
|
||||
def FullName(self):
|
||||
return '%s::%s' % (self.class_, self.name)
|
||||
|
||||
|
||||
def ValueFullName(self, name):
|
||||
assert name in self.values
|
||||
return '%s::%s' % (self.class_, name)
|
||||
|
||||
|
||||
|
||||
class Typedef(Declaration):
|
||||
|
||||
__slots__= 'type visibility'.split()
|
||||
|
||||
def __init__(self, type, name, namespace):
|
||||
Declaration.__init__(self, name, namespace)
|
||||
self.type = type
|
||||
self.visibility = Scope.public
|
||||
|
||||
|
||||
class Union(Declaration):
|
||||
'Shallow declaration, because Unions are not supported yet'
|
||||
def __init__(self, name, namespace):
|
||||
Declaration.__init__(self, name, namespace)
|
||||
|
||||
|
||||
class ClassUnion(Union):
|
||||
|
||||
__slots__= 'class_ visibility'.split()
|
||||
|
||||
def __init__(self, name, class_, visib):
|
||||
Union.__init__(self, name, None)
|
||||
self.class_ = class_
|
||||
self.visibility = visib
|
||||
|
||||
def FullName(self):
|
||||
return '%s::%s' % (self.class_, self.name)
|
||||
|
||||
|
||||
3
pyste/src/exporters.py
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
# a list of Exporter instances
|
||||
exporters = []
|
||||
91
pyste/src/exporterutils.py
Normal file
@@ -0,0 +1,91 @@
|
||||
'''
|
||||
Various helpers for interface files.
|
||||
'''
|
||||
|
||||
from settings import *
|
||||
from policies import *
|
||||
from declarations import *
|
||||
|
||||
#==============================================================================
|
||||
# FunctionWrapper
|
||||
#==============================================================================
|
||||
class FunctionWrapper(object):
|
||||
'''Holds information about a wrapper for a function or a method. It is
|
||||
divided in 2 parts: the name of the Wrapper, and its code. The code is
|
||||
placed in the declaration section of the module, while the name is used to
|
||||
def' the function or method (with the pyste namespace prepend to it). If
|
||||
code is None, the name is left unchanged.
|
||||
'''
|
||||
|
||||
def __init__(self, name, code=None):
|
||||
self.name = name
|
||||
self.code = code
|
||||
|
||||
def FullName(self):
|
||||
if self.code:
|
||||
return namespaces.pyste + self.name
|
||||
else:
|
||||
return self.name
|
||||
|
||||
|
||||
_printed_warnings = {} # used to avoid double-prints of warnings
|
||||
|
||||
#==============================================================================
|
||||
# HandlePolicy
|
||||
#==============================================================================
|
||||
def HandlePolicy(function, policy):
|
||||
'''Show a warning to the user if the function needs a policy and doesn't
|
||||
have one. Return a policy to the function, which is the given policy itself
|
||||
if it is not None, or a default policy for this method.
|
||||
'''
|
||||
|
||||
def IsString(type):
|
||||
'Return True if the Type instance can be considered a string'
|
||||
return type.const and type.name == 'char' and isinstance(type, PointerType)
|
||||
|
||||
def IsPyObject(type):
|
||||
return type.FullName() == '_object *' # internal name of PyObject
|
||||
|
||||
result = function.result
|
||||
# if the function returns const char*, a policy is not needed
|
||||
if IsString(result) or IsPyObject(result):
|
||||
return policy
|
||||
# if returns a const T&, set the default policy
|
||||
if policy is None and result.const and isinstance(result, ReferenceType):
|
||||
policy = return_value_policy(copy_const_reference)
|
||||
# basic test if the result type demands a policy
|
||||
needs_policy = isinstance(result, (ReferenceType, PointerType))
|
||||
# show a warning to the user, if needed
|
||||
if needs_policy and policy is None:
|
||||
global _printed_warnings
|
||||
warning = '---> Error: %s returns a pointer or a reference, ' \
|
||||
'but no policy was specified.' % function.FullName()
|
||||
if warning not in _printed_warnings:
|
||||
print warning
|
||||
print
|
||||
# avoid double prints of the same warning
|
||||
_printed_warnings[warning] = 1
|
||||
return policy
|
||||
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# WarnForwardDeclarations
|
||||
#==============================================================================
|
||||
def WarnForwardDeclarations(function):
|
||||
'''Checks if any of the parameters or the result of the function are
|
||||
incomplete types.'''
|
||||
|
||||
types = [function.result] + function.parameters
|
||||
types = [x for x in types if x]
|
||||
for type in types:
|
||||
if type.incomplete:
|
||||
msg = '---> Error: %s is forward declared. Please include the ' \
|
||||
'appropriate header with its definition' % type.name
|
||||
# disable this for now... it was reporting too many false
|
||||
# forward declarations to be useful
|
||||
if 0 and msg not in _printed_warnings:
|
||||
print msg
|
||||
print
|
||||
_printed_warnings[msg] = 1
|
||||
|
||||
217
pyste/src/infos.py
Normal file
@@ -0,0 +1,217 @@
|
||||
import os.path
|
||||
import copy
|
||||
import exporters
|
||||
from ClassExporter import ClassExporter
|
||||
from FunctionExporter import FunctionExporter
|
||||
from IncludeExporter import IncludeExporter
|
||||
from EnumExporter import EnumExporter
|
||||
from HeaderExporter import HeaderExporter
|
||||
from VarExporter import VarExporter
|
||||
from exporterutils import FunctionWrapper
|
||||
from utils import makeid
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# DeclarationInfo
|
||||
#==============================================================================
|
||||
class DeclarationInfo:
|
||||
|
||||
def __init__(self, otherInfo=None):
|
||||
self.__infos = {}
|
||||
self.__attributes = {}
|
||||
if otherInfo is not None:
|
||||
self.__infos = copy.deepcopy(otherInfo.__infos)
|
||||
self.__attributes = copy.deepcopy(otherInfo.__attributes)
|
||||
|
||||
|
||||
def __getitem__(self, name):
|
||||
'Used to access sub-infos'
|
||||
if name.startswith('__'):
|
||||
raise AttributeError
|
||||
default = DeclarationInfo()
|
||||
default._Attribute('name', name)
|
||||
return self.__infos.setdefault(name, default)
|
||||
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self[name]
|
||||
|
||||
|
||||
def _Attribute(self, name, value=None):
|
||||
if value is None:
|
||||
# get value
|
||||
return self.__attributes.get(name)
|
||||
else:
|
||||
# set value
|
||||
self.__attributes[name] = value
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# FunctionInfo
|
||||
#==============================================================================
|
||||
class FunctionInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, name, include, tail=None, otherOption=None):
|
||||
DeclarationInfo.__init__(self, otherOption)
|
||||
self._Attribute('name', name)
|
||||
self._Attribute('include', include)
|
||||
self._Attribute('exclude', False)
|
||||
# create a FunctionExporter
|
||||
exporter = FunctionExporter(InfoWrapper(self), tail)
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# ClassInfo
|
||||
#==============================================================================
|
||||
class ClassInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, name, include, tail=None, otherInfo=None):
|
||||
DeclarationInfo.__init__(self, otherInfo)
|
||||
self._Attribute('name', name)
|
||||
self._Attribute('include', include)
|
||||
self._Attribute('exclude', False)
|
||||
# create a ClassExporter
|
||||
exporter = ClassExporter(InfoWrapper(self), tail)
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# IncludeInfo
|
||||
#==============================================================================
|
||||
class IncludeInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, include):
|
||||
DeclarationInfo.__init__(self)
|
||||
self._Attribute('include', include)
|
||||
exporter = IncludeExporter(InfoWrapper(self))
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# templates
|
||||
#==============================================================================
|
||||
def GenerateName(name, type_list):
|
||||
name = name.replace('::', '_')
|
||||
names = [name] + type_list
|
||||
return makeid('_'.join(names))
|
||||
|
||||
|
||||
class ClassTemplateInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, name, include):
|
||||
DeclarationInfo.__init__(self)
|
||||
self._Attribute('name', name)
|
||||
self._Attribute('include', include)
|
||||
|
||||
|
||||
def Instantiate(self, type_list, rename=None):
|
||||
if not rename:
|
||||
rename = GenerateName(self._Attribute('name'), type_list)
|
||||
# generate code to instantiate the template
|
||||
types = ', '.join(type_list)
|
||||
tail = 'typedef %s< %s > %s;\n' % (self._Attribute('name'), types, rename)
|
||||
tail += 'void __instantiate_%s()\n' % rename
|
||||
tail += '{ sizeof(%s); }\n\n' % rename
|
||||
# create a ClassInfo
|
||||
class_ = ClassInfo(rename, self._Attribute('include'), tail, self)
|
||||
return class_
|
||||
|
||||
|
||||
def __call__(self, types, rename=None):
|
||||
if isinstance(types, str):
|
||||
types = types.split()
|
||||
return self.Instantiate(types, rename)
|
||||
|
||||
#==============================================================================
|
||||
# EnumInfo
|
||||
#==============================================================================
|
||||
class EnumInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, name, include):
|
||||
DeclarationInfo.__init__(self)
|
||||
self._Attribute('name', name)
|
||||
self._Attribute('include', include)
|
||||
self._Attribute('exclude', False)
|
||||
exporter = EnumExporter(InfoWrapper(self))
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# HeaderInfo
|
||||
#==============================================================================
|
||||
class HeaderInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, include):
|
||||
DeclarationInfo.__init__(self)
|
||||
self._Attribute('include', include)
|
||||
exporter = HeaderExporter(InfoWrapper(self))
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# VarInfo
|
||||
#==============================================================================
|
||||
class VarInfo(DeclarationInfo):
|
||||
|
||||
def __init__(self, name, include):
|
||||
DeclarationInfo.__init__(self)
|
||||
self._Attribute('name', name)
|
||||
self._Attribute('include', include)
|
||||
exporter = VarExporter(InfoWrapper(self))
|
||||
exporters.exporters.append(exporter)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# InfoWrapper
|
||||
#==============================================================================
|
||||
class InfoWrapper:
|
||||
'Provides a nicer interface for a info'
|
||||
|
||||
def __init__(self, info):
|
||||
self.__dict__['_info'] = info # so __setattr__ is not called
|
||||
|
||||
def __getitem__(self, name):
|
||||
return InfoWrapper(self._info[name])
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self._info._Attribute(name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
self._info._Attribute(name, value)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# Functions
|
||||
#==============================================================================
|
||||
def exclude(info):
|
||||
info._Attribute('exclude', True)
|
||||
|
||||
def set_policy(info, policy):
|
||||
info._Attribute('policy', policy)
|
||||
|
||||
def rename(info, name):
|
||||
info._Attribute('rename', name)
|
||||
|
||||
def set_wrapper(info, wrapper):
|
||||
if isinstance(wrapper, str):
|
||||
wrapper = FunctionWrapper(wrapper)
|
||||
info._Attribute('wrapper', wrapper)
|
||||
|
||||
def instantiate(template, types, rename=None):
|
||||
if isinstance(types, str):
|
||||
types = types.split()
|
||||
return template.Instantiate(types, rename)
|
||||
|
||||
def use_shared_ptr(info):
|
||||
info._Attribute('smart_ptr', 'boost::shared_ptr< %s >')
|
||||
|
||||
def use_auto_ptr(info):
|
||||
info._Attribute('smart_ptr', 'std::auto_ptr< %s >')
|
||||
|
||||
def add_method(info, name, rename=None):
|
||||
added = info._Attribute('__added__')
|
||||
if added is None:
|
||||
info._Attribute('__added__', [(name, rename)])
|
||||
else:
|
||||
added.append((name, rename))
|
||||
83
pyste/src/policies.py
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
|
||||
class Policy:
|
||||
'Represents one of the call policies of boost.python.'
|
||||
|
||||
def __init__(self):
|
||||
raise RuntimeError, "Can't create an instance of the class Policy"
|
||||
|
||||
|
||||
def Code(self):
|
||||
'Returns the string corresponding to a instancialization of the policy.'
|
||||
pass
|
||||
|
||||
|
||||
def _next(self):
|
||||
if self.next is not None:
|
||||
return ', %s >' % self.next.Code()
|
||||
else:
|
||||
return ' >'
|
||||
|
||||
|
||||
def __eq__(self, other):
|
||||
try:
|
||||
return self.Code() == other.Code()
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
class return_internal_reference(Policy):
|
||||
'Ties the return value to one of the parameters.'
|
||||
|
||||
def __init__(self, param=1, next=None):
|
||||
'''
|
||||
param is the position of the parameter, or None for "self".
|
||||
next indicates the next policy, or None.
|
||||
'''
|
||||
self.param = param
|
||||
self.next=next
|
||||
|
||||
|
||||
def Code(self):
|
||||
c = 'return_internal_reference< %i' % self.param
|
||||
c += self._next()
|
||||
return c
|
||||
|
||||
|
||||
|
||||
class with_custodian_and_ward(Policy):
|
||||
'Ties lifetime of two arguments of a function.'
|
||||
|
||||
def __init__(self, custodian, ward, next=None):
|
||||
self.custodian = custodian
|
||||
self.ward = ward
|
||||
self.next = next
|
||||
|
||||
def Code(self):
|
||||
c = 'with_custodian_and_ward< %i, %i' % (self.custodian, self.ward)
|
||||
c += self._next()
|
||||
return c
|
||||
|
||||
|
||||
|
||||
class return_value_policy(Policy):
|
||||
'Policy to convert return values.'
|
||||
|
||||
def __init__(self, which, next=None):
|
||||
self.which = which
|
||||
self.next = next
|
||||
|
||||
|
||||
def Code(self):
|
||||
c = 'return_value_policy< %s' % self.which
|
||||
c += self._next()
|
||||
return c
|
||||
|
||||
|
||||
# values for return_value_policy
|
||||
reference_existing_object = 'reference_existing_object'
|
||||
copy_const_reference = 'copy_const_reference'
|
||||
copy_non_const_reference = 'copy_non_const_reference'
|
||||
manage_new_object = 'manage_new_object'
|
||||
return_opaque_pointer = 'return_opaque_pointer'
|
||||
17
pyste/src/pyste-profile.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import profile
|
||||
import pstats
|
||||
import pyste
|
||||
|
||||
import psyco
|
||||
import elementtree.XMLTreeBuilder as XMLTreeBuilder
|
||||
import GCCXMLParser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#psyco.bind(XMLTreeBuilder.fixtext)
|
||||
#psyco.bind(XMLTreeBuilder.fixname)
|
||||
#psyco.bind(XMLTreeBuilder.TreeBuilder)
|
||||
#psyco.bind(GCCXMLParser.GCCXMLParser)
|
||||
profile.run('pyste.Main()', 'profile')
|
||||
p = pstats.Stats('profile')
|
||||
p.strip_dirs().sort_stats(-1).print_stats()
|
||||
204
pyste/src/pyste.py
Normal file
@@ -0,0 +1,204 @@
|
||||
'''
|
||||
Pyste version %s
|
||||
|
||||
Usage:
|
||||
pyste [options] interface-files
|
||||
|
||||
where options are:
|
||||
--module=<name> the name of the module that will be generated.
|
||||
Defaults to the first interface filename, without
|
||||
the extension.
|
||||
-I <path> add an include path
|
||||
-D <symbol> define symbol
|
||||
--multiple create various cpps, instead of only one
|
||||
(useful during development)
|
||||
--out specify output filename (default: <module>.cpp)
|
||||
in --multiple mode, this will be a directory
|
||||
--no-using do not declare "using namespace boost";
|
||||
use explicit declarations instead
|
||||
--pyste-ns=<name> set the namespace where new types will be declared;
|
||||
default is the empty namespace
|
||||
--debug writes the xml for each file parsed in the current
|
||||
directory
|
||||
-h, --help print this help and exit
|
||||
-v, --version print version information
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
import exporters
|
||||
import SingleCodeUnit
|
||||
import MultipleCodeUnit
|
||||
import infos
|
||||
import exporterutils
|
||||
import settings
|
||||
from policies import *
|
||||
from CppParser import CppParser, CppParserError
|
||||
import time
|
||||
|
||||
__VERSION__ = '0.9.1'
|
||||
|
||||
def RecursiveIncludes(include):
|
||||
'Return a list containg the include dir and all its subdirectories'
|
||||
dirs = [include]
|
||||
def visit(arg, dir, names):
|
||||
# ignore CVS dirs
|
||||
if os.path.split(dir)[1] != 'CVS':
|
||||
dirs.append(dir)
|
||||
os.path.walk(include, visit, None)
|
||||
return dirs
|
||||
|
||||
|
||||
def GetDefaultIncludes():
|
||||
if 'INCLUDE' in os.environ:
|
||||
include = os.environ['INCLUDE']
|
||||
return include.split(os.pathsep)
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def ParseArguments():
|
||||
|
||||
def Usage():
|
||||
print __doc__ % __VERSION__
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
options, files = getopt.getopt(
|
||||
sys.argv[1:],
|
||||
'R:I:D:vh',
|
||||
['module=', 'multiple', 'out=', 'no-using', 'pyste-ns=', 'debug', 'version', 'help'])
|
||||
except getopt.GetoptError, e:
|
||||
print
|
||||
print 'ERROR:', e
|
||||
Usage()
|
||||
includes = GetDefaultIncludes()
|
||||
defines = []
|
||||
module = None
|
||||
out = None
|
||||
multiple = False
|
||||
for opt, value in options:
|
||||
if opt == '-I':
|
||||
includes.append(value)
|
||||
elif opt == '-D':
|
||||
defines.append(value)
|
||||
elif opt == '-R':
|
||||
includes.extend(RecursiveIncludes(value))
|
||||
elif opt == '--module':
|
||||
module = value
|
||||
elif opt == '--out':
|
||||
out = value
|
||||
elif opt == '--no-using':
|
||||
settings.namespaces.python = 'boost::python::'
|
||||
settings.USING_BOOST_NS = False
|
||||
elif opt == '--pyste-ns':
|
||||
settings.namespaces.pyste = value + '::'
|
||||
elif opt == '--debug':
|
||||
settings.DEBUG = True
|
||||
elif opt == '--multiple':
|
||||
multiple = True
|
||||
elif opt in ['-h', '--help']:
|
||||
Usage()
|
||||
elif opt in ['-v', '--version']:
|
||||
print 'Pyste version %s' % __VERSION__
|
||||
sys.exit(2)
|
||||
else:
|
||||
print 'Unknown option:', opt
|
||||
Usage()
|
||||
|
||||
if not files:
|
||||
Usage()
|
||||
if not module:
|
||||
module = os.path.splitext(files[0])[0]
|
||||
if not out:
|
||||
out = module
|
||||
if not multiple:
|
||||
out += '.cpp'
|
||||
return includes, defines, module, out, files, multiple
|
||||
|
||||
|
||||
def CreateContext():
|
||||
'create the context where a interface file will be executed'
|
||||
context = {}
|
||||
# infos
|
||||
context['Function'] = infos.FunctionInfo
|
||||
context['Class'] = infos.ClassInfo
|
||||
context['Include'] = infos.IncludeInfo
|
||||
context['Template'] = infos.ClassTemplateInfo
|
||||
context['Enum'] = infos.EnumInfo
|
||||
context['AllFromHeader'] = infos.HeaderInfo
|
||||
context['Var'] = infos.VarInfo
|
||||
# functions
|
||||
context['rename'] = infos.rename
|
||||
context['set_policy'] = infos.set_policy
|
||||
context['exclude'] = infos.exclude
|
||||
context['set_wrapper'] = infos.set_wrapper
|
||||
context['use_shared_ptr'] = infos.use_shared_ptr
|
||||
context['use_auto_ptr'] = infos.use_auto_ptr
|
||||
context['add_method'] = infos.add_method
|
||||
# policies
|
||||
context['return_internal_reference'] = return_internal_reference
|
||||
context['with_custodian_and_ward'] = with_custodian_and_ward
|
||||
context['return_value_policy'] = return_value_policy
|
||||
context['reference_existing_object'] = reference_existing_object
|
||||
context['copy_const_reference'] = copy_const_reference
|
||||
context['copy_non_const_reference'] = copy_non_const_reference
|
||||
context['return_opaque_pointer'] = return_opaque_pointer
|
||||
context['manage_new_object'] = manage_new_object
|
||||
# utils
|
||||
context['Wrapper'] = exporterutils.FunctionWrapper
|
||||
return context
|
||||
|
||||
|
||||
def Main():
|
||||
includes, defines, module, out, interfaces, multiple = ParseArguments()
|
||||
# execute the interface files
|
||||
for interface in interfaces:
|
||||
context = CreateContext()
|
||||
execfile(interface, context)
|
||||
# parse all the C++ code
|
||||
parser = CppParser(includes, defines)
|
||||
exports = exporters.exporters[:]
|
||||
for export in exports:
|
||||
try:
|
||||
export.Parse(parser)
|
||||
except CppParserError, e:
|
||||
print '\n'
|
||||
print '***', e, ': exitting'
|
||||
return 2
|
||||
print
|
||||
# sort the exporters by its order
|
||||
exports = [(x.Order(), x) for x in exporters.exporters]
|
||||
exports.sort()
|
||||
exports = [x for _, x in exports]
|
||||
# now generate the wrapper code
|
||||
if multiple:
|
||||
codeunit = MultipleCodeUnit.MultipleCodeUnit(module, out)
|
||||
else:
|
||||
codeunit = SingleCodeUnit.SingleCodeUnit(module, out)
|
||||
exported_names = []
|
||||
for export in exports:
|
||||
if multiple:
|
||||
codeunit.SetCurrent(export.Unit())
|
||||
export.GenerateCode(codeunit, exported_names)
|
||||
exported_names.append(export.Name())
|
||||
codeunit.Save()
|
||||
print 'Module %s generated' % module
|
||||
return 0
|
||||
|
||||
|
||||
def UsePsyco():
|
||||
'Tries to use psyco if possible'
|
||||
try:
|
||||
import psyco
|
||||
psyco.profile()
|
||||
except: pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
start = time.clock()
|
||||
UsePsyco()
|
||||
status = Main()
|
||||
print '%0.2f seconds' % (time.clock()-start)
|
||||
sys.exit(status)
|
||||
13
pyste/src/settings.py
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#==============================================================================
|
||||
# Global information
|
||||
#==============================================================================
|
||||
|
||||
DEBUG = False
|
||||
USING_BOOST_NS = True
|
||||
|
||||
class namespaces:
|
||||
boost = 'boost::'
|
||||
pyste = ''
|
||||
python = '' # default is to not use boost::python namespace explicitly, so
|
||||
# use the "using namespace" statement instead
|
||||
47
pyste/src/utils.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from __future__ import generators
|
||||
import string
|
||||
|
||||
#==============================================================================
|
||||
# enumerate
|
||||
#==============================================================================
|
||||
def enumerate(seq):
|
||||
i = 0
|
||||
for x in seq:
|
||||
yield i, x
|
||||
i += 1
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# makeid
|
||||
#==============================================================================
|
||||
_valid_chars = string.ascii_letters + string.digits + '_'
|
||||
_valid_chars = dict(zip(_valid_chars, _valid_chars))
|
||||
|
||||
def makeid(name):
|
||||
'Returns the name as a valid identifier'
|
||||
newname = []
|
||||
for char in name:
|
||||
if char not in _valid_chars:
|
||||
char = '_'
|
||||
newname.append(char)
|
||||
newname = ''.join(newname)
|
||||
# avoid duplications of '_' chars
|
||||
names = [x for x in newname.split('_') if x]
|
||||
return '_'.join(names)
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# remove_duplicated_lines
|
||||
#==============================================================================
|
||||
def remove_duplicated_lines(text):
|
||||
includes = text.splitlines()
|
||||
d = dict([(include, 0) for include in includes])
|
||||
return '\n'.join(d.keys())
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# left_equals
|
||||
#==============================================================================
|
||||
def left_equals(s):
|
||||
s = '// %s ' % s
|
||||
return s + ('='*(80-len(s))) + '\n'
|
||||
7
pyste/tests/.cvsignore
Normal file
@@ -0,0 +1,7 @@
|
||||
*.pyc
|
||||
*.exp
|
||||
*.lib
|
||||
*.obj
|
||||
*.arg
|
||||
*.dll
|
||||
.sconsign
|
||||
338
pyste/tests/GCCXMLParserUT.py
Normal file
@@ -0,0 +1,338 @@
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import unittest
|
||||
import tempfile
|
||||
import os.path
|
||||
import GCCXMLParser
|
||||
from declarations import *
|
||||
|
||||
|
||||
class Tester(unittest.TestCase):
|
||||
|
||||
def TestConstructor(self, class_, method, visib):
|
||||
self.assert_(isinstance(method, Constructor))
|
||||
self.assertEqual(method.FullName(), class_.FullName() + '::' + method.name)
|
||||
self.assertEqual(method.result, None)
|
||||
self.assertEqual(method.visibility, visib)
|
||||
self.assert_(not method.virtual)
|
||||
self.assert_(not method.abstract)
|
||||
self.assert_(not method.static)
|
||||
|
||||
def TestDefaultConstructor(self, class_, method, visib):
|
||||
self.TestConstructor(class_, method, visib)
|
||||
self.assert_(method.IsDefault())
|
||||
|
||||
def TestCopyConstructor(self, class_, method, visib):
|
||||
self.TestConstructor(class_, method, visib)
|
||||
self.assertEqual(len(method.parameters), 1)
|
||||
param = method.parameters[0]
|
||||
self.TestType(
|
||||
param,
|
||||
ReferenceType,
|
||||
class_.FullName(),
|
||||
'const %s &' % class_.FullName(),
|
||||
True)
|
||||
self.assert_(method.IsCopy())
|
||||
|
||||
|
||||
def TestType(self, type_, classtype_, name, fullname, const):
|
||||
self.assert_(isinstance(type_, classtype_))
|
||||
self.assertEqual(type_.name, name)
|
||||
self.assertEqual(type_.namespace, None)
|
||||
self.assertEqual(type_.FullName(), fullname)
|
||||
self.assertEqual(type_.const, const)
|
||||
|
||||
|
||||
class ClassBaseTest(Tester):
|
||||
|
||||
def setUp(self):
|
||||
self.base = GetDecl('Base')
|
||||
|
||||
def testClass(self):
|
||||
'test the properties of the class Base'
|
||||
self.assert_(isinstance(self.base, Class))
|
||||
self.assert_(self.base.abstract)
|
||||
self.assertEqual(self.base.RawName(), 'Base')
|
||||
|
||||
|
||||
def testFoo(self):
|
||||
'test function foo in class Base'
|
||||
foo = GetMember(self.base, 'foo')
|
||||
self.assert_(isinstance(foo, Method))
|
||||
self.assertEqual(foo.visibility, Scope.public)
|
||||
self.assert_(foo.virtual)
|
||||
self.assert_(foo.abstract)
|
||||
self.failIf(foo.static)
|
||||
self.assertEqual(foo.class_, 'test::Base')
|
||||
self.failIf(foo.const)
|
||||
self.assertEqual(foo.FullName(), 'test::Base::foo')
|
||||
self.assertEqual(foo.result.name, 'void')
|
||||
self.assertEqual(len(foo.parameters), 1)
|
||||
param = foo.parameters[0]
|
||||
self.TestType(param, FundamentalType, 'int', 'int', False)
|
||||
self.assertEqual(foo.namespace, None)
|
||||
self.assertEqual(
|
||||
foo.PointerDeclaration(), '(void (test::Base::*)(int) )&test::Base::foo')
|
||||
|
||||
def testX(self):
|
||||
'test the member x in class Base'
|
||||
x = GetMember(self.base, 'x')
|
||||
self.assertEqual(x.class_, 'test::Base')
|
||||
self.assertEqual(x.FullName(), 'test::Base::x')
|
||||
self.assertEqual(x.namespace, None)
|
||||
self.assertEqual(x.visibility, Scope.private)
|
||||
self.TestType(x.type, FundamentalType, 'int', 'int', False)
|
||||
self.assertEqual(x.static, False)
|
||||
|
||||
def testConstructors(self):
|
||||
'test constructors in class Base'
|
||||
constructors = GetMembers(self.base, 'Base')
|
||||
for cons in constructors:
|
||||
if len(cons.parameters) == 0:
|
||||
self.TestDefaultConstructor(self.base, cons, Scope.public)
|
||||
elif len(cons.parameters) == 1: # copy constructor
|
||||
self.TestCopyConstructor(self.base, cons, Scope.public)
|
||||
elif len(cons.parameters) == 2: # other constructor
|
||||
intp, floatp = cons.parameters
|
||||
self.TestType(intp, FundamentalType, 'int', 'int', False)
|
||||
self.TestType(floatp, FundamentalType, 'float', 'float', False)
|
||||
|
||||
def testSimple(self):
|
||||
'test function simple in class Base'
|
||||
simple = GetMember(self.base, 'simple')
|
||||
self.assert_(isinstance(simple, Method))
|
||||
self.assertEqual(simple.visibility, Scope.protected)
|
||||
self.assertEqual(simple.FullName(), 'test::Base::simple')
|
||||
self.assertEqual(len(simple.parameters), 1)
|
||||
param = simple.parameters[0]
|
||||
self.TestType(param, ReferenceType, 'std::string', 'const std::string &', True)
|
||||
self.TestType(simple.result, FundamentalType, 'bool', 'bool', False)
|
||||
self.assertEqual(
|
||||
simple.PointerDeclaration(),
|
||||
'(bool (test::Base::*)(const std::string &) )&test::Base::simple')
|
||||
|
||||
|
||||
def testZ(self):
|
||||
z = GetMember(self.base, 'z')
|
||||
self.assert_(isinstance(z, Variable))
|
||||
self.assertEqual(z.visibility, Scope.public)
|
||||
self.assertEqual(z.FullName(), 'test::Base::z')
|
||||
self.assertEqual(z.type.name, 'int')
|
||||
self.assertEqual(z.type.const, False)
|
||||
self.assert_(z.static)
|
||||
|
||||
|
||||
class ClassTemplateTest(Tester):
|
||||
|
||||
def setUp(self):
|
||||
self.template = GetDecl('Template<int>')
|
||||
|
||||
def testClass(self):
|
||||
'test the properties of the Template<int> class'
|
||||
self.assert_(isinstance(self.template, Class))
|
||||
self.assert_(not self.template.abstract)
|
||||
self.assertEqual(self.template.FullName(), 'Template<int>')
|
||||
self.assertEqual(self.template.namespace, '')
|
||||
self.assertEqual(self.template.name, 'Template<int>')
|
||||
self.assertEqual(self.template.RawName(), 'Template')
|
||||
|
||||
def testConstructors(self):
|
||||
'test the automatic constructors of the class Template<int>'
|
||||
constructors = GetMembers(self.template, 'Template')
|
||||
for cons in constructors:
|
||||
if len(cons.parameters) == 0:
|
||||
self.TestDefaultConstructor(self.template, cons, Scope.public)
|
||||
elif len(cons.parameters) == 1:
|
||||
self.TestCopyConstructor(self.template, cons, Scope.public)
|
||||
|
||||
|
||||
def testValue(self):
|
||||
'test the class variable value'
|
||||
value = GetMember(self.template, 'value')
|
||||
self.assert_(isinstance(value, ClassVariable))
|
||||
self.assert_(value.name, 'value')
|
||||
self.TestType(value.type, FundamentalType, 'int', 'int', False)
|
||||
self.assert_(not value.static)
|
||||
self.assertEqual(value.visibility, Scope.public)
|
||||
self.assertEqual(value.class_, 'Template<int>')
|
||||
self.assertEqual(value.FullName(), 'Template<int>::value')
|
||||
|
||||
def testBase(self):
|
||||
'test the superclasses of Template<int>'
|
||||
bases = self.template.bases
|
||||
self.assertEqual(len(bases), 1)
|
||||
base = bases[0]
|
||||
self.assert_(isinstance(base, Base))
|
||||
self.assertEqual(base.name, 'test::Base')
|
||||
self.assertEqual(base.visibility, Scope.protected)
|
||||
|
||||
|
||||
|
||||
class FreeFuncTest(Tester):
|
||||
|
||||
def setUp(self):
|
||||
self.func = GetDecl('FreeFunc')
|
||||
|
||||
def testFunc(self):
|
||||
'test attributes of FreeFunc'
|
||||
self.assert_(isinstance(self.func, Function))
|
||||
self.assertEqual(self.func.name, 'FreeFunc')
|
||||
self.assertEqual(self.func.FullName(), 'test::FreeFunc')
|
||||
self.assertEqual(self.func.namespace, 'test')
|
||||
self.assertEqual(
|
||||
self.func.PointerDeclaration(),
|
||||
'(const test::Base & (*)(const std::string &, int))&test::FreeFunc')
|
||||
|
||||
|
||||
def testResult(self):
|
||||
'test the return value of FreeFunc'
|
||||
res = self.func.result
|
||||
self.TestType(res, ReferenceType, 'test::Base', 'const test::Base &', True)
|
||||
|
||||
def testParameters(self):
|
||||
'test the parameters of FreeFunc'
|
||||
self.assertEqual(len(self.func.parameters), 2)
|
||||
strp, intp = self.func.parameters
|
||||
self.TestType(strp, ReferenceType, 'std::string', 'const std::string &', True)
|
||||
self.assertEqual(strp.default, None)
|
||||
self.TestType(intp, FundamentalType, 'int', 'int', False)
|
||||
self.assertEqual(intp.default, '10')
|
||||
|
||||
|
||||
|
||||
class testFunctionPointers(Tester):
|
||||
|
||||
def testMethodPointer(self):
|
||||
'test declaration of a pointer-to-method'
|
||||
meth = GetDecl('MethodTester')
|
||||
param = meth.parameters[0]
|
||||
fullname = 'void (test::Base::*)(int)'
|
||||
self.TestType(param, PointerType, fullname, fullname, False)
|
||||
|
||||
def testFunctionPointer(self):
|
||||
'test declaration of a pointer-to-function'
|
||||
func = GetDecl('FunctionTester')
|
||||
param = func.parameters[0]
|
||||
fullname = 'void (*)(int)'
|
||||
self.TestType(param, PointerType, fullname, fullname, False)
|
||||
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Support routines
|
||||
# =============================================================================
|
||||
|
||||
cppcode = '''
|
||||
namespace std {
|
||||
class string;
|
||||
}
|
||||
namespace test {
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
Base();
|
||||
Base(const Base&);
|
||||
Base(int, float);
|
||||
|
||||
virtual void foo(int = 0.0) = 0;
|
||||
static int z;
|
||||
protected:
|
||||
bool simple(const std::string&);
|
||||
private:
|
||||
int x;
|
||||
};
|
||||
|
||||
void MethodTester( void (Base::*)(int) );
|
||||
void FunctionTester( void (*)(int) );
|
||||
|
||||
|
||||
const Base & FreeFunc(const std::string&, int=10);
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct Template: protected test::Base
|
||||
{
|
||||
T value;
|
||||
virtual void foo(int);
|
||||
};
|
||||
|
||||
Template<int> __aTemplateInt;
|
||||
'''
|
||||
|
||||
def GetXMLFile():
|
||||
'''Generates an gccxml file using the code from the global cppcode.
|
||||
Returns the xml's filename.'''
|
||||
# write the code to a header file
|
||||
tmpfile = tempfile.mktemp() + '.h'
|
||||
f = file(tmpfile, 'w')
|
||||
f.write(cppcode)
|
||||
f.close()
|
||||
# run gccxml
|
||||
outfile = tmpfile + '.xml'
|
||||
if os.system('gccxml "%s" "-fxml=%s"' % (tmpfile, outfile)) != 0:
|
||||
raise RuntimeError, 'Error executing GCCXML.'
|
||||
# read the output file into the xmlcode
|
||||
f = file(outfile)
|
||||
xmlcode = f.read()
|
||||
#print xmlcode
|
||||
f.close()
|
||||
# remove the header
|
||||
os.remove(tmpfile)
|
||||
return outfile
|
||||
|
||||
|
||||
|
||||
def GetDeclarations():
|
||||
'Uses the GCCXMLParser module to get the declarations.'
|
||||
xmlfile = GetXMLFile()
|
||||
declarations = GCCXMLParser.ParseDeclarations(xmlfile)
|
||||
os.remove(xmlfile)
|
||||
return declarations
|
||||
|
||||
# the declarations to be analysed
|
||||
declarations = GetDeclarations()
|
||||
|
||||
|
||||
def GetDecl(name):
|
||||
'returns one of the top declarations given its name'
|
||||
for decl in declarations:
|
||||
if decl.name == name:
|
||||
return decl
|
||||
else:
|
||||
raise RuntimeError, 'Declaration not found: %s' % name
|
||||
|
||||
|
||||
def GetMember(class_, name):
|
||||
'gets the member of the given class by its name'
|
||||
|
||||
res = None
|
||||
multipleFound = False
|
||||
for member in class_:
|
||||
if member.name == name:
|
||||
if res is not None:
|
||||
multipleFound = True
|
||||
break
|
||||
res = member
|
||||
if res is None or multipleFound:
|
||||
raise RuntimeError, \
|
||||
'No member or more than one member found in class %s: %s' \
|
||||
% (class_.name, name)
|
||||
return res
|
||||
|
||||
|
||||
def GetMembers(class_, name):
|
||||
'gets the members of the given class by its name'
|
||||
res = []
|
||||
for member in class_:
|
||||
if member.name == name:
|
||||
res.append(member)
|
||||
if len(res) in (0, 1):
|
||||
raise RuntimeError, \
|
||||
'GetMembers: 0 or 1 members found in class %s: %s' \
|
||||
% (class_.name, name)
|
||||
return res
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
80
pyste/tests/SmartFileUT.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import sys
|
||||
sys.path.append('../src')
|
||||
from SmartFile import *
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
class SmartFileTest(unittest.TestCase):
|
||||
|
||||
FILENAME = tempfile.mktemp()
|
||||
|
||||
def setUp(self):
|
||||
self._Clean()
|
||||
|
||||
def tearDown(self):
|
||||
self._Clean()
|
||||
|
||||
def _Clean(self):
|
||||
try:
|
||||
os.remove(self.FILENAME)
|
||||
except OSError: pass
|
||||
|
||||
|
||||
def testNonExistant(self):
|
||||
"Must override the file, as there's no file in the disk yet"
|
||||
self.assert_(not os.path.isfile(self.FILENAME))
|
||||
f = SmartFile(self.FILENAME, 'w')
|
||||
f.write('Testing 123\nTesting again.')
|
||||
f.close()
|
||||
self.assert_(os.path.isfile(self.FILENAME))
|
||||
|
||||
|
||||
def testOverride(self):
|
||||
"Must override the file, because the contents are different"
|
||||
contents = 'Contents!\nContents!'
|
||||
# create the file normally first
|
||||
f = file(self.FILENAME, 'w')
|
||||
f.write(contents)
|
||||
f.close()
|
||||
file_time = os.path.getmtime(self.FILENAME)
|
||||
self.assert_(os.path.isfile(self.FILENAME))
|
||||
time.sleep(2)
|
||||
f = SmartFile(self.FILENAME, 'w')
|
||||
f.write(contents + '_')
|
||||
f.close()
|
||||
new_file_time = os.path.getmtime(self.FILENAME)
|
||||
self.assert_(new_file_time != file_time)
|
||||
|
||||
|
||||
def testNoOverride(self):
|
||||
"Must not override the file, because the contents are the same"
|
||||
contents = 'Contents!\nContents!'
|
||||
# create the file normally first
|
||||
f = file(self.FILENAME, 'w')
|
||||
f.write(contents)
|
||||
f.close()
|
||||
file_time = os.path.getmtime(self.FILENAME)
|
||||
self.assert_(os.path.isfile(self.FILENAME))
|
||||
time.sleep(2)
|
||||
f = SmartFile(self.FILENAME, 'w')
|
||||
f.write(contents)
|
||||
f.close()
|
||||
new_file_time = os.path.getmtime(self.FILENAME)
|
||||
self.assert_(new_file_time == file_time)
|
||||
|
||||
|
||||
def testAutoClose(self):
|
||||
"Must be closed when garbage-collected"
|
||||
def foo():
|
||||
f = SmartFile(self.FILENAME)
|
||||
f.write('testing')
|
||||
self.assert_(not os.path.isfile(self.FILENAME))
|
||||
foo()
|
||||
self.assert_(os.path.isfile(self.FILENAME))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
13
pyste/tests/add_test.h
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace add_test {
|
||||
|
||||
struct C
|
||||
{
|
||||
int x;
|
||||
};
|
||||
|
||||
const int get_x(C& c)
|
||||
{
|
||||
return c.x;
|
||||
}
|
||||
|
||||
}
|
||||
2
pyste/tests/add_test.pyste
Normal file
@@ -0,0 +1,2 @@
|
||||
C = Class('add_test::C', 'add_test.h')
|
||||
add_method(C, 'add_test::get_x')
|
||||
12
pyste/tests/add_testUT.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import unittest
|
||||
from _add_test import *
|
||||
|
||||
class AddMethodTest(unittest.TestCase):
|
||||
|
||||
def testIt(self):
|
||||
c = C()
|
||||
c.x = 10
|
||||
self.assertEqual(c.get_x(), 10)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
8
pyste/tests/basic.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "basic.h"
|
||||
|
||||
namespace basic {
|
||||
|
||||
int C::static_value = 3;
|
||||
const int C::const_static_value = 100;
|
||||
|
||||
}
|
||||
59
pyste/tests/basic.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef BASIC_H
|
||||
#define BASIC_H
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace basic {
|
||||
|
||||
struct C
|
||||
{
|
||||
// test virtuallity
|
||||
C(): value(1), const_value(0) {}
|
||||
virtual int f(int x = 10)
|
||||
{
|
||||
return x*2;
|
||||
}
|
||||
|
||||
int foo(int x=1){
|
||||
return x+1;
|
||||
}
|
||||
|
||||
const std::string& name() { return _name; }
|
||||
void set_name(const std::string& name) { _name = name; }
|
||||
std::string _name;
|
||||
|
||||
// test data members
|
||||
static int static_value;
|
||||
static const int const_static_value;
|
||||
|
||||
int value;
|
||||
const int const_value;
|
||||
|
||||
// test static functions
|
||||
static int mul(int x=2, int y=3) { return x*y; }
|
||||
};
|
||||
|
||||
inline int call_f(C& c)
|
||||
{
|
||||
return c.f();
|
||||
}
|
||||
|
||||
inline int call_f(C& c, int x)
|
||||
{
|
||||
return c.f(x);
|
||||
}
|
||||
|
||||
inline int get_static()
|
||||
{
|
||||
return C::static_value;
|
||||
}
|
||||
|
||||
inline int get_value(C& c)
|
||||
{
|
||||
return c.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
5
pyste/tests/basic.pyste
Normal file
@@ -0,0 +1,5 @@
|
||||
Class('basic::C', 'basic.h')
|
||||
Function('basic::call_f', 'basic.h')
|
||||
Function('basic::get_static', 'basic.h')
|
||||
Function('basic::get_value', 'basic.h')
|
||||
|
||||
66
pyste/tests/basicUT.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import unittest
|
||||
from _basic import *
|
||||
|
||||
class BasicExampleTest(unittest.TestCase):
|
||||
|
||||
def testIt(self):
|
||||
|
||||
# test virtual functions
|
||||
class D(C):
|
||||
def f(self, x=10):
|
||||
return x+1
|
||||
|
||||
d = D()
|
||||
c = C()
|
||||
|
||||
self.assertEqual(c.f(), 20)
|
||||
self.assertEqual(c.f(3), 6)
|
||||
self.assertEqual(d.f(), 11)
|
||||
self.assertEqual(d.f(3), 4)
|
||||
self.assertEqual(call_f(c), 20)
|
||||
self.assertEqual(call_f(c, 4), 8)
|
||||
self.assertEqual(call_f(d), 11)
|
||||
self.assertEqual(call_f(d, 3), 4)
|
||||
|
||||
# test data members
|
||||
def testValue(value):
|
||||
self.assertEqual(c.value, value)
|
||||
self.assertEqual(d.value, value)
|
||||
self.assertEqual(get_value(c), value)
|
||||
self.assertEqual(get_value(d), value)
|
||||
testValue(1)
|
||||
c.value = 30
|
||||
d.value = 30
|
||||
testValue(30)
|
||||
self.assertEqual(c.const_value, 0)
|
||||
self.assertEqual(d.const_value, 0)
|
||||
def set_const_value():
|
||||
c.const_value = 12
|
||||
self.assertRaises(AttributeError, set_const_value)
|
||||
|
||||
# test static data-members
|
||||
def testStatic(value):
|
||||
self.assertEqual(C.static_value, value)
|
||||
self.assertEqual(c.static_value, value)
|
||||
self.assertEqual(D.static_value, value)
|
||||
self.assertEqual(d.static_value, value)
|
||||
self.assertEqual(get_static(), value)
|
||||
testStatic(3)
|
||||
C.static_value = 10
|
||||
testStatic(10)
|
||||
self.assertEqual(C.const_static_value, 100)
|
||||
def set_const_static():
|
||||
C.const_static_value = 1
|
||||
self.assertRaises(AttributeError, set_const_static)
|
||||
|
||||
# test static function
|
||||
def test_mul(result, *args):
|
||||
self.assertEqual(C.mul(*args), result)
|
||||
self.assertEqual(c.mul(*args), result)
|
||||
test_mul(6)
|
||||
test_mul(3, 1)
|
||||
test_mul(16, 8, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
29
pyste/tests/enums.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef ENUMS_H
|
||||
#define ENUMS_H
|
||||
|
||||
namespace enums {
|
||||
|
||||
enum color { red, blue };
|
||||
|
||||
struct X
|
||||
{
|
||||
enum choices
|
||||
{
|
||||
good = 1,
|
||||
bad = 2
|
||||
};
|
||||
|
||||
int set(choices c)
|
||||
{
|
||||
return (int)c;
|
||||
}
|
||||
};
|
||||
|
||||
enum {
|
||||
x = 0,
|
||||
y = 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
7
pyste/tests/enums.pyste
Normal file
@@ -0,0 +1,7 @@
|
||||
h = AllFromHeader('enums.h')
|
||||
rename(h.color.red, 'Red')
|
||||
rename(h.color.blue, 'Blue')
|
||||
rename(h.X.choices.bad, 'Bad')
|
||||
rename(h.X.choices.good, 'Good')
|
||||
rename(h.X.choices, 'Choices')
|
||||
|
||||
20
pyste/tests/enumsUT.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import unittest
|
||||
from _enums import *
|
||||
|
||||
class EnumsTest(unittest.TestCase):
|
||||
|
||||
def testIt(self):
|
||||
self.assertEqual(int(color.Red), 0)
|
||||
self.assertEqual(int(color.Blue), 1)
|
||||
|
||||
self.assertEqual(int(X.Choices.Good), 1)
|
||||
self.assertEqual(int(X.Choices.Bad), 2)
|
||||
x = X()
|
||||
self.assertEqual(x.set(x.Choices.Good), 1)
|
||||
self.assertEqual(x.set(x.Choices.Bad), 2)
|
||||
self.assertEqual(unnamed.x, 0)
|
||||
self.assertEqual(unnamed.y, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
38
pyste/tests/header_test.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef HEADER_TEST_H
|
||||
#define HEADER_TEST_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace header_test {
|
||||
|
||||
enum choice { red, blue };
|
||||
|
||||
inline std::string choice_str(choice c)
|
||||
{
|
||||
std::map<choice, std::string> choice_map;
|
||||
choice_map[red] = "red";
|
||||
choice_map[blue] = "blue";
|
||||
return choice_map[c];
|
||||
}
|
||||
|
||||
struct C
|
||||
{
|
||||
choice c;
|
||||
|
||||
std::string get()
|
||||
{
|
||||
return choice_str(c);
|
||||
}
|
||||
};
|
||||
|
||||
// test the exclusion of the following
|
||||
|
||||
struct ForwardDeclared; // should be excluded automatically
|
||||
struct A {};
|
||||
void foo();
|
||||
enum bar { value };
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||