pyanatomist 6.0.0
sipconverthelpers.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL license version 2 under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL license version 2 as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL license version 2 and that you accept its terms.
32 */
33
34#ifndef PYANATOMIST_SIPCONVERTHELPERS_H
35#define PYANATOMIST_SIPCONVERTHELPERS_H
36
37#include <sip.h>
38
39namespace anatomist
40{
41 class AObject;
42 class AWindow;
43 class Referential;
44 class Transformation;
45
46
47 template <typename T> inline
49 sipTypeDef *siptype,
50 PyObject *sipTransferObj,
51 int *&sipIsErr, T **&sipCppPtr )
52 {
53 if (!sipIsErr)
54 {
55 // check type
56 if( sipCanConvertToType( sipPy, siptype,
57 SIP_NOT_NONE | SIP_NO_CONVERTORS ) )
58 return 1;
59 if( PyObject_HasAttrString( sipPy, "internalRep" ) )
60 {
61 PyObject *internalRep = PyObject_GetAttrString( sipPy, "internalRep" );
62 if( internalRep )
63 {
64 bool x = sipCanConvertToType( internalRep, siptype,
65 SIP_NOT_NONE | SIP_NO_CONVERTORS );
66 Py_DECREF( internalRep );
67 return x;
68 }
69 }
70 return 0;
71 }
72
73 if( sipPy == Py_None )
74 {
75 *sipCppPtr = 0;
76 return 0;
77 }
78
79 int state = 0;
80
81 T * obj = 0;
82 if( sipCanConvertToType( sipPy, siptype, SIP_NO_CONVERTORS ) )
83 obj = (T *)
84 sipConvertToType( sipPy, siptype, sipTransferObj,
85 SIP_NO_CONVERTORS, &state, sipIsErr );
86 if( !obj && PyObject_HasAttrString( sipPy, "internalRep" ) )
87 {
88 PyObject *internalRep = PyObject_GetAttrString( sipPy, "internalRep" );
89 if( internalRep )
90 {
91 obj = (T *)
92 sipConvertToType( internalRep, siptype, sipTransferObj,
93 SIP_NO_CONVERTORS, &state, sipIsErr );
94 Py_DECREF( internalRep );
95 }
96 }
97 if( *sipIsErr && obj )
98 {
99 sipReleaseType( obj, sipType_anatomist_Referential, state );
100 obj = 0;
101 }
102 else if( obj )
103 {
104 *sipCppPtr = obj;
105 return 0; // in any case it's an existing instance, not a temporary
106 }
107
108 *sipIsErr = 1;
109 return 0;
110 }
111
112}
113
114
115#endif
116
117
118
int sipConvertToTypeCodeFromInternalRep(PyObject *sipPy, sipTypeDef *siptype, PyObject *sipTransferObj, int *&sipIsErr, T **&sipCppPtr)