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