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
8namespace CPyCppyy {
9
10struct Parameter;
11struct CallContext;
12
13class CPYCPPYY_CLASS_EXPORT Converter {
14public:
15 virtual ~Converter();
16
17public:
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)
25CPYCPPYY_EXPORT Converter* CreateConverter(const std::string& fullType, dims_t dims = nullptr);
26CPYCPPYY_EXPORT void DestroyConverter(Converter* p);
27typedef Converter* (*cf_t)(dims_t d);
28CPYCPPYY_EXPORT bool RegisterConverter(const std::string& name, cf_t fac);
29CPYCPPYY_EXPORT bool UnregisterConverter(const std::string& name);
30
31
32// converters for special cases (only here b/c of external use of StrictInstancePtrConverter)
34public:
35 VoidArrayConverter(bool keepControl = true) { fKeepControl = keepControl; }
36
37public:
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
43protected:
44 virtual bool GetAddressSpecialCase(PyObject* pyobject, void*& address);
45 bool KeepControl() { return fKeepControl; }
46
47private:
49};
50
52public:
53 InstancePtrConverter(Cppyy::TCppType_t klass, bool keepControl = false) :
54 VoidArrayConverter(keepControl), fClass(klass) {}
55
56public:
57 virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr);
58 virtual PyObject* FromMemory(void* address);
59 virtual bool ToMemory(PyObject* value, void* address);
60
61protected:
63};
64
66public:
68
69protected:
70 virtual bool GetAddressSpecialCase(PyObject*, void*&) { return false; }
71};
72
73} // namespace CPyCppyy
74
75#endif // !CPYCPPYY_CONVERTERS_H
dim_t * dims_t
Definition: CPyCppyy.h:65
_object PyObject
Definition: PyResult.h:13
#define d(i)
Definition: RSha256.hxx:102
char name[80]
Definition: TGX11.cxx:109
#define CPYCPPYY_CLASS_EXPORT
Definition: CommonDefs.h:27
#define CPYCPPYY_EXPORT
Definition: CommonDefs.h:25
virtual PyObject * FromMemory(void *address)
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)=0
virtual bool ToMemory(PyObject *value, void *address)
virtual bool HasState()
Definition: Converters.h:21
InstancePtrConverter(Cppyy::TCppType_t klass, bool keepControl=false)
Definition: Converters.h:53
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)
virtual PyObject * FromMemory(void *address)
virtual bool ToMemory(PyObject *value, void *address)
Cppyy::TCppType_t fClass
Definition: Converters.h:62
virtual bool GetAddressSpecialCase(PyObject *, void *&)
Definition: Converters.h:70
VoidArrayConverter(bool keepControl=true)
Definition: Converters.h:35
virtual bool ToMemory(PyObject *value, void *address)
virtual bool GetAddressSpecialCase(PyObject *pyobject, void *&address)
virtual PyObject * FromMemory(void *address)
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)
CPYCPPYY_EXTERN bool RegisterConverter(const std::string &name, ConverterFactory_t)
Converter *(* cf_t)(dims_t d)
Definition: Converters.h:27
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, Py_ssize_t *dims=nullptr)
CPYCPPYY_EXTERN void DestroyConverter(Converter *p)
CPYCPPYY_EXTERN bool UnregisterConverter(const std::string &name)
TCppScope_t TCppType_t
Definition: cpp_cppyy.h:19