TemplateProxy.h

Go to the documentation of this file.
00001 // Author: Wim Lavrijsen, Jan 2008
00002 
00003 #ifndef PYROOT_TEMPLATEPROXY_H
00004 #define PYROOT_TEMPLATEPROXY_H
00005 
00006 // ROOT
00007 #include "DllImport.h"
00008 
00009 // Standard
00010 #include <string>
00011 
00012 
00013 namespace PyROOT {
00014 
00015 /** Template proxy object to return functions and methods
00016       @author  WLAV
00017       @date    01/15/2008
00018       @version 1.0
00019  */
00020 
00021    class TemplateProxy {
00022    public:
00023       void Set( const std::string& name, PyObject* pyclass )
00024       {
00025          fPyName  = PyROOT_PyUnicode_FromString( const_cast< char* >( name.c_str() ) );
00026          Py_XINCREF( pyclass );
00027          fPyClass = pyclass;
00028       }
00029 
00030    public:               // public, as the python C-API works with C structs
00031       PyObject_HEAD
00032       PyObject* fPyName;
00033       PyObject* fPyClass;
00034       PyObject* fSelf;
00035 
00036    private:              // private, as the python C-API will handle creation
00037       TemplateProxy() {}
00038    };
00039 
00040 
00041 //- template proxy type and type verification --------------------------------
00042    R__EXTERN PyTypeObject TemplateProxy_Type;
00043 
00044    template< typename T >
00045    inline Bool_t TemplateProxy_Check( T* object )
00046    {
00047       return object && PyObject_TypeCheck( object, &TemplateProxy_Type );
00048    }
00049 
00050    template< typename T >
00051    inline Bool_t TemplateProxy_CheckExact( T* object )
00052    {
00053       return object && Py_TYPE(object) == &TemplateProxy_Type;
00054    }
00055 
00056 //- creation -----------------------------------------------------------------
00057    inline TemplateProxy* TemplateProxy_New( const std::string& name, PyObject* pyclass )
00058    {
00059       TemplateProxy* pytmpl = (TemplateProxy*)TemplateProxy_Type.tp_new( &TemplateProxy_Type, 0, 0 );
00060       pytmpl->Set( name, pyclass );
00061       return pytmpl;
00062    }
00063 
00064 } // namespace PyROOT
00065 
00066 #endif // !PYROOT_TEMPLATEPROXY_H

Generated on Tue Jul 5 14:10:16 2011 for ROOT_528-00b_version by  doxygen 1.5.1