[C++-sig] Simple rvalue_from_python_data usage example availabe?

Stefan Franke franke at ableton.com
Sat Jun 14 03:21:59 CEST 2003


I'm currently trying to implement a bidirectional conversion
from Python unicode strings to our library's own unicode string
type, called 'TString'.

The 'TString -> Python Unicode Object' part was easy. Just had to
register a to_python_converter as shown in the manual examples.

Unfortunately, being a BPL newbie, I'm unable to figure out the
'Python Unicode Object -> TString' part. At least I have spotted
the rvalue_from_python_data mechanism which I believe is the right
one for the job.

But I'm clueless how to set it up for correct usage. I've checked
the reference to the "scitbx" in the FAQ, but there it's done in a
totally generic way, from which I'm too stupid to derive my special
case.

Dear SIG, can you help me? This is what I have so far:


struct TStringToPythonUnicode
{
  static PyObject* convert(const TString& s)
  {
    return PyUnicode_FromWideChar(s.FirstChar(), s.Length());
  }
};


struct PythonUnicodeToTString
{
  static TString extract(PyObject* o)
  {
    // Test string without any actual PyUnicode_Type instance access
    return ToString("extracted");
  }
};


BOOST_PYTHON_MODULE(TStringModule)
{
  to_python_converter<TString, TStringToPythonUnicode>();

  rvalue_from_python_data<PythonUnicodeToTString>( ??? );
  //                         What to place here? ^^^^^^^
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030614/9935579e/attachment.htm>


More information about the Cplusplus-sig mailing list