Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / share / swig / 1.3.26 / python / std_multimap.i
CommitLineData
920dae64
AT
1/*
2 Multimaps
3*/
4%include <std_map.i>
5
6%fragment("StdMultimapTraits","header",fragment="StdSequenceTraits")
7{
8 namespace swig {
9 template <class PySeq, class K, class T >
10 inline void
11 assign(const PySeq& pyseq, std::multimap<K,T > *multimap) {
12 typedef typename std::map<K,T>::value_type value_type;
13 typename PySeq::const_iterator it = pyseq.begin();
14 for (;it != pyseq.end(); ++it) {
15 multimap->insert(value_type(it->first, it->second));
16 }
17 }
18
19 template <class K, class T>
20 struct traits_asptr<std::multimap<K,T> > {
21 static int asptr(PyObject *obj, std::multimap<K,T> **val) {
22 if (PyDict_Check(obj)) {
23 PyObject_var items = PyMapping_Items(obj);
24 return traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >
25 ::asptr(items, val);
26 }
27 if (val) {
28 PyErr_SetString(PyExc_TypeError, "a dictionary is expected");
29 }
30 return 0;
31 }
32 };
33
34 template <class K, class T >
35 struct traits_from<std::multimap<K,T> > {
36 typedef std::multimap<K,T> multimap_type;
37 typedef typename multimap_type::const_iterator const_iterator;
38 typedef typename multimap_type::size_type size_type;
39
40 static PyObject *from(const multimap_type& multimap) {
41 size_type size = multimap.size();
42 int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
43 if (pysize < 0) {
44 PyErr_SetString(PyExc_OverflowError,
45 "multimap size not valid in python");
46 return NULL;
47 }
48 PyObject *obj = PyDict_New();
49 for (const_iterator i= multimap.begin(); i!= multimap.end(); ++i) {
50 PyDict_SetItem(obj,
51 swig::from(i->first),
52 swig::from(i->second));
53 }
54 return obj;
55 }
56 };
57 }
58}
59
60#define %swig_multimap_methods(Type...) %swig_map_methods(Type)
61
62%include <std/std_multimap.i>
63