PLearn 0.1
Static Public Member Functions
PLearn::ConvertFromPyObject< string > Struct Template Reference

#include <PythonObjectWrapper.h>

List of all members.

Static Public Member Functions

static string convert (PyObject *, bool print_traceback)

Detailed Description

template<>
struct PLearn::ConvertFromPyObject< string >

Definition at line 314 of file PythonObjectWrapper.h.


Member Function Documentation

string PLearn::ConvertFromPyObject< string >::convert ( PyObject *  pyobj,
bool  print_traceback 
) [static]

Definition at line 152 of file PythonObjectWrapper.cc.

References PLASSERT, PLERROR, and PLearn::PLPythonConversionError().

{
    PLASSERT(pyobj);

    // if unicode, encode into a string (utf8) then return
    if(PyUnicode_Check(pyobj))
    {
        PyObject* pystr= PyUnicode_AsUTF8String(pyobj);
        if(!pystr)
        {
            if(PyErr_Occurred()) PyErr_Print();
            Py_DECREF(pystr);
            PLERROR("in ConvertFromPyObject<string>::convert : "
                    "Unicode to string conversion failed.");
        }
        string str= PyString_AsString(pystr);
        Py_DECREF(pystr);
        return str;
    }
    
    // otherwise, should already be a string
    if(!PyString_Check(pyobj))
        PLPythonConversionError("ConvertFromPyObject<string>", pyobj,
                                print_traceback);
    return PyString_AsString(pyobj);
}

Here is the call graph for this function:


The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines