~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Lib/python/std_map.i

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2009-11-15 14:00:28 UTC
  • mfrom: (1.2.9 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091115140028-me7amr2rie8zz1xn
Tags: 1.3.40-2ubuntu1
* Merge from Debian testing (LP: #356529), remaining changes:
  - Drop libchicken-dev from the build-depends (it's in universe)
  - Remove Pike from package description and from configure flags
  - drop "--without-mzscheme", we don't have it in our build-depends
  - use php-config5
  - Clean Runtime/ as well.
  - debian/rules (clean): Remove Lib/ocaml/swigp4.ml.
* debian/rules: Remove hardcoded python version.
* Remove upper limit for python from Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
%fragment("StdMapTraits","header",fragment="StdSequenceTraits")
6
6
{
7
7
  namespace swig {
8
 
    template <class PySeq, class K, class T >
 
8
    template <class SwigPySeq, class K, class T >
9
9
    inline void
10
 
    assign(const PySeq& pyseq, std::map<K,T > *map) {
 
10
    assign(const SwigPySeq& swigpyseq, std::map<K,T > *map) {
11
11
      typedef typename std::map<K,T>::value_type value_type;
12
 
      typename PySeq::const_iterator it = pyseq.begin();
13
 
      for (;it != pyseq.end(); ++it) {
 
12
      typename SwigPySeq::const_iterator it = swigpyseq.begin();
 
13
      for (;it != swigpyseq.end(); ++it) {
14
14
        map->insert(value_type(it->first, it->second));
15
15
      }
16
16
    }
20
20
      typedef std::map<K,T> map_type;
21
21
      static int asptr(PyObject *obj, map_type **val) {
22
22
        int res = SWIG_ERROR;
 
23
        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
23
24
        if (PyDict_Check(obj)) {
24
 
          PyObject_var items = PyObject_CallMethod(obj,(char *)"items",NULL);
 
25
          SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
 
26
%#if PY_VERSION_HEX >= 0x03000000
 
27
          /* In Python 3.x the ".items()" method returns a dict_items object */
 
28
          items = PySequence_Fast(items, ".items() didn't return a sequence!");
 
29
%#endif
25
30
          res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
26
31
        } else {
27
32
          map_type *p;
28
33
          res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
29
34
          if (SWIG_IsOK(res) && val)  *val = p;
30
35
        }
 
36
        SWIG_PYTHON_THREAD_END_BLOCK;
31
37
        return res;
32
38
      }      
33
39
    };
43
49
        if (desc && desc->clientdata) {
44
50
          return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
45
51
        } else {
 
52
          SWIG_PYTHON_THREAD_BEGIN_BLOCK;
46
53
          size_type size = map.size();
47
54
          int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
48
55
          if (pysize < 0) {
49
 
            SWIG_PYTHON_THREAD_BEGIN_BLOCK;
50
56
            PyErr_SetString(PyExc_OverflowError,
51
57
                            "map size not valid in python");
52
58
            SWIG_PYTHON_THREAD_END_BLOCK;
54
60
          }
55
61
          PyObject *obj = PyDict_New();
56
62
          for (const_iterator i= map.begin(); i!= map.end(); ++i) {
57
 
            swig::PyObject_var key = swig::from(i->first);
58
 
            swig::PyObject_var val = swig::from(i->second);
 
63
            swig::SwigVar_PyObject key = swig::from(i->first);
 
64
            swig::SwigVar_PyObject val = swig::from(i->second);
59
65
            PyDict_SetItem(obj, key, val);
60
66
          }
 
67
          SWIG_PYTHON_THREAD_END_BLOCK;
61
68
          return obj;
62
69
        }
63
70
      }
86
93
    };
87
94
 
88
95
    template<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type>
89
 
    struct PyMapIterator_T : PySwigIteratorClosed_T<OutIterator, ValueType, FromOper>
 
96
    struct SwigPyMapIterator_T : SwigPyIteratorClosed_T<OutIterator, ValueType, FromOper>
90
97
    {
91
 
      PyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
92
 
        : PySwigIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
 
98
      SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
 
99
        : SwigPyIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
93
100
      {
94
101
      }
95
102
    };
97
104
 
98
105
    template<class OutIterator,
99
106
             class FromOper = from_key_oper<typename OutIterator::value_type> >
100
 
    struct PyMapKeyIterator_T : PyMapIterator_T<OutIterator, FromOper>
 
107
    struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T<OutIterator, FromOper>
101
108
    {
102
 
      PyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
103
 
        : PyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
 
109
      SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
 
110
        : SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
104
111
      {
105
112
      }
106
113
    };
107
114
 
108
115
    template<typename OutIter>
109
 
    inline PySwigIterator*
 
116
    inline SwigPyIterator*
110
117
    make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
111
118
    {
112
 
      return new PyMapKeyIterator_T<OutIter>(current, begin, end, seq);
 
119
      return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq);
113
120
    }
114
121
 
115
122
    template<class OutIterator,
116
123
             class FromOper = from_value_oper<typename OutIterator::value_type> >
117
 
    struct PyMapValueIterator_T : PyMapIterator_T<OutIterator, FromOper>
 
124
    struct SwigPyMapValueITerator_T : SwigPyMapIterator_T<OutIterator, FromOper>
118
125
    {
119
 
      PyMapValueIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
120
 
        : PyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
 
126
      SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq)
 
127
        : SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
121
128
      {
122
129
      }
123
130
    };
124
131
    
125
132
 
126
133
    template<typename OutIter>
127
 
    inline PySwigIterator*
 
134
    inline SwigPyIterator*
128
135
    make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0)
129
136
    {
130
 
      return new PyMapValueIterator_T<OutIter>(current, begin, end, seq);
 
137
      return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq);
131
138
    }
132
139
  }
133
140
}
161
168
    PyObject* keys() {
162
169
      Map::size_type size = self->size();
163
170
      int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
 
171
      SWIG_PYTHON_THREAD_BEGIN_BLOCK;
164
172
      if (pysize < 0) {
165
 
        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
166
173
        PyErr_SetString(PyExc_OverflowError,
167
174
                        "map size not valid in python");
168
175
        SWIG_PYTHON_THREAD_END_BLOCK;
173
180
      for (int j = 0; j < pysize; ++i, ++j) {
174
181
        PyList_SET_ITEM(keyList, j, swig::from(i->first));
175
182
      }
 
183
      SWIG_PYTHON_THREAD_END_BLOCK;
176
184
      return keyList;
177
185
    }
178
186
    
179
187
    PyObject* values() {
180
188
      Map::size_type size = self->size();
181
189
      int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
 
190
      SWIG_PYTHON_THREAD_BEGIN_BLOCK;
182
191
      if (pysize < 0) {
183
 
        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
184
192
        PyErr_SetString(PyExc_OverflowError,
185
193
                        "map size not valid in python");
186
194
        SWIG_PYTHON_THREAD_END_BLOCK;
191
199
      for (int j = 0; j < pysize; ++i, ++j) {
192
200
        PyList_SET_ITEM(valList, j, swig::from(i->second));
193
201
      }
 
202
      SWIG_PYTHON_THREAD_END_BLOCK;
194
203
      return valList;
195
204
    }
196
205
    
197
206
    PyObject* items() {
198
207
      Map::size_type size = self->size();
199
208
      int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
 
209
      SWIG_PYTHON_THREAD_BEGIN_BLOCK;
200
210
      if (pysize < 0) {
201
 
        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
202
211
        PyErr_SetString(PyExc_OverflowError,
203
212
                        "map size not valid in python");
204
213
        SWIG_PYTHON_THREAD_END_BLOCK;
209
218
      for (int j = 0; j < pysize; ++i, ++j) {
210
219
        PyList_SET_ITEM(itemList, j, swig::from(*i));
211
220
      }
 
221
      SWIG_PYTHON_THREAD_END_BLOCK;
212
222
      return itemList;
213
223
    }
214
224
    
218
228
    }
219
229
 
220
230
    %newobject key_iterator(PyObject **PYTHON_SELF);
221
 
    swig::PySwigIterator* key_iterator(PyObject **PYTHON_SELF) {
 
231
    swig::SwigPyIterator* key_iterator(PyObject **PYTHON_SELF) {
222
232
      return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
223
233
    }
224
234
 
225
235
    %newobject value_iterator(PyObject **PYTHON_SELF);
226
 
    swig::PySwigIterator* value_iterator(PyObject **PYTHON_SELF) {
 
236
    swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
227
237
      return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
228
238
    }
229
239