]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROPy/HYDROData_SequenceOfObjects.sip
Salome HOME
[fix] Corrections for version value
[modules/hydro.git] / src / HYDROPy / HYDROData_SequenceOfObjects.sip
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 %ExportedHeaderCode
20 #include <NCollection_Sequence.hxx>
21 %End
22
23 %MappedType NCollection_Sequence<opencascade::handle<HYDROData_Entity>>
24 {
25 %TypeHeaderCode
26 #include <NCollection_Sequence.hxx>
27 %End
28
29 %ConvertFromTypeCode
30     // Create the list.
31     PyObject *l;
32
33     if ((l = PyList_New(sipCpp->Length())) == NULL)
34         return NULL;
35
36     // Set the list elements.
37     for (int i = 1; i <= sipCpp->Length(); ++i)
38     {
39        HYDROData_Entity* aPntr = createPointer(sipCpp->Value(i));
40      
41         PyObject *tobj;
42         
43         if ((tobj = sipConvertFromNewType(aPntr, sipFindType( aPntr->DynamicType()->Name() ), sipTransferObj)) == NULL)
44         {
45             Py_DECREF(l);
46             {
47               Handle(HYDROData_Entity) anEnt( aPntr );
48             }
49
50             return NULL;
51         }
52
53         PyList_SET_ITEM(l, i - 1, tobj);
54     }
55
56     return l;
57 %End
58
59 %ConvertToTypeCode
60     SIP_SSIZE_T len;
61
62     // Check the type if that is all that is required.
63     if (sipIsErr == NULL)
64     {
65         if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0)
66             return 0;
67
68         for (SIP_SSIZE_T i = 0; i < len; ++i)
69         {
70             PyObject *itm = PySequence_ITEM(sipPy, i);
71             bool ok = (itm && sipCanConvertToType(itm, sipType_HYDROData_Entity, SIP_NOT_NONE));
72
73             Py_XDECREF(itm);
74
75             if (!ok)
76                 return 0;
77         }
78
79         return 1;
80     }
81
82     NCollection_Sequence<Handle(HYDROData_Entity)> *aSeq = 
83       new NCollection_Sequence<Handle(HYDROData_Entity)>;
84     len = PySequence_Size(sipPy);
85  
86     for (SIP_SSIZE_T i = 0; i < len; ++i)
87     {
88         PyObject *itm = PySequence_ITEM(sipPy, i);
89         int state;
90         HYDROData_Entity *t = 
91           reinterpret_cast<HYDROData_Entity *>(sipConvertToType(itm, sipType_HYDROData_Entity, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
92
93         Py_DECREF(itm);
94  
95         if (*sipIsErr)
96         {
97             sipReleaseType(t, sipType_HYDROData_Entity, state);
98
99             delete aSeq;
100             return 0;
101         }
102
103         Handle(HYDROData_Entity) anEnt( t );
104         aSeq->Append( anEnt );
105
106         //sipReleaseType(t, sipType_HYDROData_Entity, state);
107     }
108  
109     *sipCppPtr = aSeq;
110  
111     return sipGetState(sipTransferObj);
112 %End
113 };
114
115 typedef NCollection_Sequence<opencascade::handle<HYDROData_Entity>> HYDROData_SequenceOfObjects;
116
117 %MappedType NCollection_Sequence<opencascade::handle<HYDROData_PolylineXY>>
118 {
119 %TypeHeaderCode
120 #include <NCollection_Sequence.hxx>
121 %End
122
123 %ConvertFromTypeCode
124     // Create the list.
125     PyObject *l;
126
127     if ((l = PyList_New(sipCpp->Length())) == NULL)
128         return NULL;
129
130     // Set the list elements.
131     for (int i = 1; i <= sipCpp->Length(); ++i)
132     {
133        HYDROData_PolylineXY* aPntr = (HYDROData_PolylineXY*)createPointer(sipCpp->Value(i));
134
135         PyObject *tobj;
136
137         if ((tobj = sipConvertFromNewType(aPntr, sipFindType( aPntr->DynamicType()->Name() ), sipTransferObj)) == NULL)
138         {
139             Py_DECREF(l);
140             {
141               Handle(HYDROData_PolylineXY) anEnt( aPntr );
142             }
143
144             return NULL;
145         }
146
147         PyList_SET_ITEM(l, i - 1, tobj);
148     }
149
150     return l;
151 %End
152
153 %ConvertToTypeCode
154     SIP_SSIZE_T len;
155
156     // Check the type if that is all that is required.
157     if (sipIsErr == NULL)
158     {
159         if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0)
160             return 0;
161
162         for (SIP_SSIZE_T i = 0; i < len; ++i)
163         {
164             PyObject *itm = PySequence_ITEM(sipPy, i);
165             bool ok = (itm && sipCanConvertToType(itm, sipType_HYDROData_PolylineXY, SIP_NOT_NONE));
166
167             Py_XDECREF(itm);
168
169             if (!ok)
170                 return 0;
171         }
172
173         return 1;
174     }
175
176     NCollection_Sequence<Handle(HYDROData_PolylineXY)> *aSeq =
177       new NCollection_Sequence<Handle(HYDROData_PolylineXY)>;
178     len = PySequence_Size(sipPy);
179
180     for (SIP_SSIZE_T i = 0; i < len; ++i)
181     {
182         PyObject *itm = PySequence_ITEM(sipPy, i);
183         int state;
184         HYDROData_PolylineXY *t =
185           reinterpret_cast<HYDROData_PolylineXY *>(sipConvertToType(itm, sipType_HYDROData_PolylineXY, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
186
187         Py_DECREF(itm);
188
189         if (*sipIsErr)
190         {
191             sipReleaseType(t, sipType_HYDROData_PolylineXY, state);
192
193             delete aSeq;
194             return 0;
195         }
196
197         Handle(HYDROData_PolylineXY) anEnt( t );
198         aSeq->Append( anEnt );
199
200         //sipReleaseType(t, sipType_HYDROData_PolylineXY, state);
201     }
202
203     *sipCppPtr = aSeq;
204
205     return sipGetState(sipTransferObj);
206 %End
207 };