Salome HOME
refs# 1917 + protection against null shapes wires in GetMiddlePoint()
[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;