1 #ifndef AWFUL_PYTHON_GENERICPOINTER_H
2 #define AWFUL_PYTHON_GENERICPOINTER_H
6 namespace awful
{ namespace PythonImpl
8 template<> struct TypeConverter
< NormalType
, GenericPointer
>
10 static bool CheckType_nothrow( PyObject
* pPyObj_
)
12 if( pPyObj_
== Py_None
)
15 GenericPointerTable::conv_frompython_map::const_iterator it
=
16 GenericPointerTable::PointerFromPythonConverters
.find( pPyObj_
->ob_type
);
17 return it
!= GenericPointerTable::PointerFromPythonConverters
.end();
20 static void ConvertFromPython_nocheck( PyObject
* pPyObj_
, GenericPointer
& Dest_
)
22 if( pPyObj_
== Py_None
)
26 // TODO: this should be cached from the previous call to CheckType_nothrow, if any.
27 // I will need move away from using static methods in the python typeconverter class though.
28 GenericPointerTable::conv_frompython_map::const_iterator it
=
29 GenericPointerTable::PointerFromPythonConverters
.find( pPyObj_
->ob_type
);
30 it
->second
->ConvertFromPython_nocheck( pPyObj_
, Dest_
);
34 static void ConvertFromPython( PyObject
* pPyObj_
, GenericPointer
& Dest_
)
36 if( !CheckType_nothrow( pPyObj_
) )
37 throw Error::TypeMismatch();
38 ConvertFromPython_nocheck( pPyObj_
, Dest_
);
41 static PyObject
* ConvertToPython( const GenericPointer
& Ptr_
)
46 // TODO: what if the GenericPointer somehow points to a type that is not registered
47 // in the conversion map? We should throw a specific diagnostic message.
48 GenericPointerTable::conv_topython_map::const_iterator it
=
49 GenericPointerTable::PointerToPythonConverters
.find( *Ptr_
.getDynamicType() );
50 return it
->second
->ConvertToPython( Ptr_
);