[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Interfacing to C++ standard library
From:       "Paul F. Kunz" <Paul_Kunz () SLAC ! Stanford ! EDU>
Date:       2002-12-21 19:30:57
[Download RAW message or body]

>>>>> On Wed, 11 Dec 2002 22:23:38 +0100, Torsten Marek <shlomme@gmx.net> said:


> It should just need string being replaced by std::string and
> sipForceConvertTo_string(...) renamed to
> sipForceConvertTo_std_string(...), but I'm not really sure about the
> naming scheme, so please try yourself, before I post incorrect code.

   Thanks for your tips.   The following works for me with gcc 2.95.3...

%MappedType std::string
{
%HeaderCode
#include <string>
%End

%ConvertFromTypeCode
     const char *s = sipCpp->c_str();
     return PyString_FromString(s);
%End

%ConvertToTypeCode
         // Allow a Python string whenever a string is expected.
         if (sipIsErr == NULL)
             return PyString_Check(sipPy);
         if (sipPy == Py_None) {
             *sipCppPtr = NULL;
             return 0;
         }
         if (PyString_Check(sipPy)) {
             *sipCppPtr = new string(PyString_AS_STRING(sipPy));
             return 0;
         }
         *sipCppPtr = (string *)sipForceConvertTo_std_string(sipPy,sipIsErr);
         return 1;
%End

};

I eventually need to port to Windows where string is in namespace std,
so needed the std::string stuff.

Thanks again for this code.

_______________________________________________
PyKDE mailing list    PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic