Logo ROOT  
Reference Guide
Converters.h
Go to the documentation of this file.
1 #ifndef CPYCPPYY_CONVERTERS_H
2 #define CPYCPPYY_CONVERTERS_H
3 
4 // Standard
5 #include <string>
6 
7 
8 namespace CPyCppyy {
9 
10 struct Parameter;
11 struct CallContext;
12 
13 class CPYCPPYY_CLASS_EXPORT Converter {
14 public:
15  virtual ~Converter();
16 
17 public:
18  virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr) = 0;
19  virtual PyObject* FromMemory(void* address);
20  virtual bool ToMemory(PyObject* value, void* address);
21  virtual bool HasState() { return false; }
22 };
23 
24 // create/destroy converter from fully qualified type (public API)
25 CPYCPPYY_EXPORT Converter* CreateConverter(const std::string& fullType, dims_t dims = nullptr);
26 CPYCPPYY_EXPORT void DestroyConverter(Converter* p);
27 typedef Converter* (*cf_t)(dims_t d);
28 CPYCPPYY_EXPORT bool RegisterConverter(const std::string& name, cf_t fac);
29 CPYCPPYY_EXPORT bool UnregisterConverter(const std::string& name);
30 
31 
32 // converters for special cases (only here b/c of external use of StrictInstancePtrConverter)
33 class VoidArrayConverter : public Converter {
34 public:
35  VoidArrayConverter(bool keepControl = true) { fKeepControl = keepControl; }
36 
37 public:
38  virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr);
39  virtual PyObject* FromMemory(void* address);
40  virtual bool ToMemory(PyObject* value, void* address);
41  virtual bool HasState() { return true; }
42 
43 protected:
44  virtual bool GetAddressSpecialCase(PyObject* pyobject, void*& address);
45  bool KeepControl() { return fKeepControl; }
46 
47 private:
49 };
50 
52 public:
53  InstancePtrConverter(Cppyy::TCppType_t klass, bool keepControl = false) :
54  VoidArrayConverter(keepControl), fClass(klass) {}
55 
56 public:
57  virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr);
58  virtual PyObject* FromMemory(void* address);
59  virtual bool ToMemory(PyObject* value, void* address);
60 
61 protected:
63 };
64 
66 public:
68 
69 protected:
70  virtual bool GetAddressSpecialCase(PyObject*, void*&) { return false; }
71 };
72 
73 } // namespace CPyCppyy
74 
75 #endif // !CPYCPPYY_CONVERTERS_H
CPyCppyy
Set of helper functions that are invoked from the pythonizors, on the Python side.
Definition: TPyClassGenerator.cxx:31
CPyCppyy::VoidArrayConverter
Definition: Converters.h:33
CPyCppyy::CallContext
Definition: CallContext.h:45
PyObject
_object PyObject
Definition: PyMethodBase.h:42
CPyCppyy::VoidArrayConverter::HasState
virtual bool HasState()
Definition: Converters.h:41
CPyCppyy::InstancePtrConverter::SetArg
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)
Definition: Converters.cxx:1744
CPyCppyy::cf_t
Converter *(* cf_t)(dims_t d)
Definition: Converters.h:27
CPyCppyy::InstancePtrConverter::FromMemory
virtual PyObject * FromMemory(void *address)
Definition: Converters.cxx:1780
CPyCppyy::StrictInstancePtrConverter::GetAddressSpecialCase
virtual bool GetAddressSpecialCase(PyObject *, void *&)
Definition: Converters.h:70
CPyCppyy::UnregisterConverter
CPYCPPYY_EXTERN bool UnregisterConverter(const std::string &name)
Definition: Converters.cxx:2858
CPyCppyy::VoidArrayConverter::GetAddressSpecialCase
virtual bool GetAddressSpecialCase(PyObject *pyobject, void *&address)
Definition: Converters.cxx:1341
CPyCppyy::VoidArrayConverter::VoidArrayConverter
VoidArrayConverter(bool keepControl=true)
Definition: Converters.h:35
CPyCppyy::VoidArrayConverter::fKeepControl
bool fKeepControl
Definition: Converters.h:48
CPyCppyy::InstancePtrConverter
Definition: Converters.h:51
dims_t
dim_t * dims_t
Definition: CPyCppyy.h:65
CPyCppyy::RegisterConverter
CPYCPPYY_EXTERN bool RegisterConverter(const std::string &name, ConverterFactory_t)
CPyCppyy::CreateConverter
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, Py_ssize_t *dims=nullptr)
CPyCppyy::StrictInstancePtrConverter
Definition: Converters.h:65
CPyCppyy::InstancePtrConverter::ToMemory
virtual bool ToMemory(PyObject *value, void *address)
Definition: Converters.cxx:1787
CPyCppyy::VoidArrayConverter::ToMemory
virtual bool ToMemory(PyObject *value, void *address)
Definition: Converters.cxx:1436
CPyCppyy::VoidArrayConverter::KeepControl
bool KeepControl()
Definition: Converters.h:45
Cppyy::TCppType_t
TCppScope_t TCppType_t
Definition: cpp_cppyy.h:19
CPyCppyy::VoidArrayConverter::SetArg
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)
Definition: Converters.cxx:1370
CPyCppyy::Converter
Definition: API.h:91
name
char name[80]
Definition: TGX11.cxx:110
CPyCppyy::DestroyConverter
CPYCPPYY_EXTERN void DestroyConverter(Converter *p)
Definition: Converters.cxx:2837
d
#define d(i)
Definition: RSha256.hxx:120
CPyCppyy::VoidArrayConverter::FromMemory
virtual PyObject * FromMemory(void *address)
Definition: Converters.cxx:1425
CPyCppyy::Converter::HasState
virtual bool HasState()
Definition: Converters.h:21
CPYCPPYY_CLASS_EXPORT
#define CPYCPPYY_CLASS_EXPORT
Definition: CommonDefs.h:27
CPYCPPYY_EXPORT
#define CPYCPPYY_EXPORT
Definition: CommonDefs.h:25
CPyCppyy::InstancePtrConverter::InstancePtrConverter
InstancePtrConverter(Cppyy::TCppType_t klass, bool keepControl=false)
Definition: Converters.h:53
CPyCppyy::Parameter
Definition: callcontext.h:13
CPyCppyy::InstancePtrConverter::fClass
Cppyy::TCppType_t fClass
Definition: Converters.h:62
int