forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wacky_ints.sip
146 lines (116 loc) · 3.51 KB
/
wacky_ints.sip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//--------------------------------------------------------------------------
// Name: wacky_ints.sip
//
// Purpose: Implements a %MappedType for size_t and others in order to
// deal with different sizeof's on different platforms. They're
// 32bit on some, 64bit on others.
//
// Author: Robin Dunn
//
// Created: 4-March-2016
// Copyright: (c) 2016-2017 by Total Control Software
// Licence: wxWindows license
//--------------------------------------------------------------------------
// size_t will either be equivalent to an unsigned long, or to an
// unsigned long long. wxWidgets' configure script has already figured out
// which it is, so we can make it conditional on those results.
%MappedType size_t {
%TypeHeaderCode
#include <wxpy_api.h>
%End
%ConvertToTypeCode
// Allow conversions from any number type
if (!sipIsErr) {
if (PyNumber_Check(sipPy))
return TRUE;
return FALSE;
}
// Do the conversion
*sipCppPtr = new size_t(wxPyInt_AsSize_t(sipPy));
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
return wxPyInt_FromSize_t(*sipCpp);
%End
};
// This type is a signed integer value that is large enough to hold a
// pointer. Again we'll use the results of wxWidgets configuration.
%MappedType wxIntPtr {
%TypeHeaderCode
#include <wx/setup.h>
#include <wxpy_api.h>
%End
%ConvertToTypeCode
// Allow conversions from any number type
if (!sipIsErr) {
if (PyNumber_Check(sipPy))
return TRUE;
return FALSE;
}
// Do the conversion
#if SIZEOF_LONG >= SIZEOF_VOID_P
*sipCppPtr = new wxIntPtr(wxPyInt_AsLong(sipPy));
#else
*sipCppPtr = new wxIntPtr(wxPyInt_AsSsize_t(sipPy));
#endif
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
#if SIZEOF_LONG >= SIZEOF_VOID_P
return wxPyInt_FromLong(*sipCpp);
#else
return wxPyInt_FromSsize_t(*sipCpp);
#endif
%End
};
// This type is an unsigned integer value that is large enough to hold a
// pointer. Again we'll use the results of wxWidgets configuration.
%MappedType wxUIntPtr {
%TypeHeaderCode
#include <wx/setup.h>
#include <wxpy_api.h>
%End
%ConvertToTypeCode
// Allow conversions from any number type
if (!sipIsErr) {
if (PyNumber_Check(sipPy))
return TRUE;
return FALSE;
}
// Do the conversion
#if SIZEOF_LONG >= SIZEOF_VOID_P
*sipCppPtr = new wxUIntPtr(wxPyInt_AsUnsignedLong(sipPy));
#else
*sipCppPtr = new wxUIntPtr(wxPyInt_AsSize_t(sipPy));
#endif
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
#if SIZEOF_LONG >= SIZEOF_VOID_P
return wxPyInt_FromUnsignedLong(*sipCpp);
#else
return wxPyInt_FromSize_t(*sipCpp);
#endif
%End
};
// Used just for testing the MappedTypes
%ModuleCode
size_t testSizetTypemap(size_t value)
{
size_t local = value;
return local;
}
wxIntPtr testIntPtrTypemap(wxIntPtr value)
{
wxIntPtr local = value;
return local;
}
wxUIntPtr testUIntPtrTypemap(wxUIntPtr value)
{
wxUIntPtr local = value;
return local;
}
%End
size_t testSizetTypemap(size_t value);
wxIntPtr testIntPtrTypemap(wxIntPtr value);
wxUIntPtr testUIntPtrTypemap(wxUIntPtr value);