Core: the idl parser now properly insert the flags in the ast.
[fail.git] / python / genericpointer.h
blobb43f2775ab7c07ef7f9127fd52a58094f60cd396
1 #ifndef AWFUL_PYTHON_GENERICPOINTER_H
2 #define AWFUL_PYTHON_GENERICPOINTER_H
4 #include <map>
6 namespace awful { namespace PythonImpl
8 template<> struct TypeConverter< NormalType, GenericPointer >
9 {
10 static bool CheckType_nothrow( PyObject* pPyObj_ )
12 if( pPyObj_ == Py_None )
13 return true;
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 )
23 Dest_.clear();
24 else
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_ )
43 if( !Ptr_ )
44 Py_RETURN_NONE;
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_ );
55 #endif