-// Copyright (C) 2006-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#ifdef OMNIORB
#include <omniORB4/CORBA.h>
-//--- from omniORBpy.h (not present on Debian Sarge packages)
-struct omniORBPYAPI
-{
- PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
- CORBA::Boolean hold_lock);
- // Convert a C++ object reference to a Python object reference.
- // If <hold_lock> is true, caller holds the Python interpreter lock.
-
- CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
- CORBA::Boolean hold_lock);
- // Convert a Python object reference to a C++ object reference.
- // Raises BAD_PARAM if the Python object is not an object reference.
- // If <hold_lock> is true, caller holds the Python interpreter lock.
-
- PyObject* (*handleCxxSystemException)(const CORBA::SystemException& ex);
- // Sets the Python exception state to reflect the given C++ system
- // exception. Always returns NULL. The caller must hold the Python
- // interpreter lock.
-};
-
-omniORBPYAPI* api;
+#include <omniORBpy.h>
+omniORBpyAPI* api=0;
#define OMNIPY_CATCH_AND_HANDLE_SYSTEM_EXCEPTIONS \
catch (const CORBA::SystemException& ex) { \
$result = PyList_New($1.size());
for (i=0, iL=$1.begin(); iL!=$1.end(); i++, iL++)
- PyList_SetItem($result,i,PyString_FromString((*iL).c_str()));
+ PyList_SetItem($result,i,PyUnicode_FromString((*iL).c_str()));
}
%typemap(in) std::list<std::string>
for (i = 0; i < size; i++)
{
PyObject *o = PyList_GetItem($input,i);
- if (PyString_Check(o))
- $1.push_back(std::string(PyString_AsString(PyList_GetItem($input,i))));
+ if (PyUnicode_Check(o))
+ $1.push_back(std::string(PyUnicode_AsUTF8(PyList_GetItem($input,i))));
else
{
PyErr_SetString(PyExc_TypeError,"list must contain strings");
void *ptr;
if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0) == 0)
$1 = 1;
- else if (PyInt_Check($input))
+ else if (PyLong_Check($input))
$1 = 1;
else if(PyFloat_Check($input))
$1 = 1;
- else if (PyString_Check($input))
+ else if (PyUnicode_Check($input))
+ $1 = 1;
+ else if (PyBytes_Check($input))
$1 = 1;
else
$1 = 0;
// It is an Any : it is converted by SWIG_ConvertPtr $input -> $1
is_new_object=0;
}
- else if (PyInt_Check($input))
+ else if (PyLong_Check($input))
{
// It is an Int
- $1=YACS::ENGINE::AtomAny::New((int)PyInt_AsLong($input));
+ $1=YACS::ENGINE::AtomAny::New((int)PyLong_AsLong($input));
is_new_object=1;
}
else if(PyFloat_Check($input))
$1=YACS::ENGINE::AtomAny::New(PyFloat_AsDouble($input));
is_new_object=1;
}
- else if(PyString_Check($input))
+ else if(PyUnicode_Check($input))
{
- // It is a Float
- $1=YACS::ENGINE::AtomAny::New(PyString_AsString($input));
+ // It is a Unicode
+ $1=YACS::ENGINE::AtomAny::New(PyUnicode_AsUTF8($input));
+ is_new_object=1;
+ }
+ else if(PyBytes_Check($input))
+ {
+ // It is a Bytes
+ $1=YACS::ENGINE::AtomAny::New(PyBytes_AsString($input));
is_new_object=1;
}
else
else if (PyInt_Check($1))
{
// It is an Int
- $result=YACS::ENGINE::AtomAny::New((int)PyInt_AsLong($1));
+ $result=YACS::ENGINE::AtomAny::New((int)PyLong_AsLong($1));
}
else if(PyFloat_Check($1))
{
// It is a Float
$result=YACS::ENGINE::AtomAny::New(PyFloat_AsDouble($1));
}
- else if(PyString_Check($1))
+ else if(PyUnicode_Check($1))
{
- // It is a String
- $result=YACS::ENGINE::AtomAny::New(PyString_AsString($1));
+ // It is a Unicode
+ $result=YACS::ENGINE::AtomAny::New(PyUnicode_AsUTF8($1));
+ }
+ else if(PyBytes_Check($1))
+ {
+ // It is a Bytes
+ $result=YACS::ENGINE::AtomAny::New(PyBytes_AsString($1));
}
else
{
To overload standard SWIG wrapping we define a full specialization of std::map
with %extend for 4 basic methods : getitem, setitem, delitem and keys.
Then we complete the interface by deriving the shadow wrapper from
- the python mixin class (UserDict.DictMixin).
+ the python mixin class (UserDict.DictMixin / collections.MutableMapping with Python 3).
Do not forget to declare the new shadow class to SWIG with tname_swigregister(tname).
Objects returned by __getitem__ are declared new (%newobject) so that when destroyed they
call decrRef (see feature("unref") for RefCounter).
*/
+
+%include "exception.i"
+%exception Iterator::next {
+ try
+ {
+ $action // calls %extend function next() below
+ }
+ catch (StopIterator)
+ {
+ PyErr_SetString(PyExc_StopIteration, "End of iterator");
+ return NULL;
+ }
+}
+
+%extend Iterator
+{
+ std::map<std::string,U*>& next()
+ {
+ if ($self->cur != $self->end)
+ {
+ // dereference the iterator and return reference to the object,
+ // after that it increments the iterator
+ return *$self->cur++;
+ }
+ throw StopIterator();
+ }
+}
+
template<>
class std::map<std::string,T*>
{
PyObject* keyList = PyList_New(pysize);
std::map<std::string, T* >::const_iterator i = self->begin();
for (int j = 0; j < pysize; ++i, ++j) {
- PyList_SET_ITEM(keyList, j, PyString_FromString(i->first.c_str()));
+ PyList_SET_ITEM(keyList, j, PyUnicode_FromString(i->first.c_str()));
}
return keyList;
}
+ Iterator<T> __iter__()
+ {
+ // return a constructed Iterator object
+ return typename Iterator($self->begin(), $self->end());
+ }
+
+ int __len__()
+ {
+ int pysize = self->size();
+ return pysize;
+ }
}
};
-
+%rename(__next__) Iterator::next;
%newobject std::map<std::string,T* >::__getitem__;
+%newobject std::map<std::string,T* >::__iter__;
%template() std::pair<std::string, T* >;
%template(tname) std::map<std::string, T* >;
%pythoncode{
-from UserDict import DictMixin
-class tname(tname,DictMixin):pass
+from collections import MutableMapping
+class tname(tname,MutableMapping):pass
tname##_swigregister(tname)
}
%enddef