Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Converters.h
Go to the documentation of this file.
1#ifndef CPYRT_CONVERTERS_H
2#define CPYRT_CONVERTERS_H
3
4// Bindings
5#include "Dimensions.h"
6
7// Standard
8#include <string>
9
10namespace cppjit::cpyrt {
11
12struct Parameter;
13struct CallContext;
14
15class CPYRT_CLASS_EXPORT Converter {
16public:
17 virtual ~Converter();
18
19 Converter() = default;
20
21 Converter(Converter const& other) = delete;
22 Converter(Converter&& other) = delete;
23 Converter& operator=(Converter const& other) = delete;
24 Converter& operator=(Converter&& other) = delete;
25
26public:
27 virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr) = 0;
28 virtual PyObject* FromMemory(void* address);
29 virtual bool ToMemory(PyObject* value, void* address,
30 PyObject* ctxt = nullptr);
31 virtual bool HasState() { return false; }
32 virtual std::string GetFailureMsg() { return "[Converter]"; }
33};
34
35// create/destroy converter from fully qualified type (public API)
36CPYRT_EXPORT Converter* CreateConverter(const std::string& fullType,
37 cdims_t dims = 0);
39 cdims_t dims = 0);
40CPYRT_EXPORT void DestroyConverter(Converter* p);
41typedef Converter* (*cf_t)(cdims_t d);
42CPYRT_EXPORT bool RegisterConverter(const std::string& name, cf_t fac);
43CPYRT_EXPORT bool RegisterConverterAlias(const std::string& name,
44 const std::string& target);
45CPYRT_EXPORT bool UnregisterConverter(const std::string& name);
46
47// converters for special cases (only here b/c of external use of
48// StrictInstancePtrConverter)
50public:
51 VoidArrayConverter(bool keepControl = true,
52 const std::string& failureMsg = std::string())
53 : fFailureMsg(failureMsg) {
54 fKeepControl = keepControl;
55 }
56
57public:
58 bool SetArg(PyObject*, Parameter&, CallContext* = nullptr) override;
59 PyObject* FromMemory(void* address) override;
60 bool ToMemory(PyObject* value, void* address,
61 PyObject* ctxt = nullptr) override;
62 bool HasState() override { return true; }
63 std::string GetFailureMsg() override {
64 return "[VoidArrayConverter] " + fFailureMsg;
65 }
66
67protected:
68 virtual bool GetAddressSpecialCase(PyObject* pyobject, void*& address);
69 bool KeepControl() { return fKeepControl; }
70 const std::string fFailureMsg;
71
72private:
74};
75
76template <bool ISCONST> class InstancePtrConverter : public VoidArrayConverter {
77public:
78 InstancePtrConverter(interop::TCppScope_t klass, bool keepControl = false,
79 const std::string& failureMsg = std::string())
80 : VoidArrayConverter(keepControl, failureMsg),
81 fClass(interop::GetUnderlyingScope(klass)) {}
82
83public:
84 bool SetArg(PyObject*, Parameter&, CallContext* = nullptr) override;
85 PyObject* FromMemory(void* address) override;
86 bool ToMemory(PyObject* value, void* address,
87 PyObject* ctxt = nullptr) override;
88
89protected:
91};
92
94public:
96
97protected:
98 bool GetAddressSpecialCase(PyObject*, void*&) override { return false; }
99};
100
101} // namespace cppjit::cpyrt
102
103#endif // !CPYRT_CONVERTERS_H
_object PyObject
#define d(i)
Definition RSha256.hxx:102
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
#define CPYRT_CLASS_EXPORT
Definition CommonDefs.h:27
#define CPYRT_EXPORT
Definition CommonDefs.h:25
virtual std::string GetFailureMsg()
Definition Converters.h:32
virtual bool HasState()
Definition Converters.h:31
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)=0
Converter & operator=(Converter const &other)=delete
virtual bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr)
Converter & operator=(Converter &&other)=delete
Converter(Converter const &other)=delete
Converter(Converter &&other)=delete
virtual PyObject * FromMemory(void *address)
bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr) override
PyObject * FromMemory(void *address) override
bool SetArg(PyObject *, Parameter &, CallContext *=nullptr) override
InstancePtrConverter(interop::TCppScope_t klass, bool keepControl=false, const std::string &failureMsg=std::string())
Definition Converters.h:78
bool GetAddressSpecialCase(PyObject *, void *&) override
Definition Converters.h:98
bool SetArg(PyObject *, Parameter &, CallContext *=nullptr) override
bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr) override
PyObject * FromMemory(void *address) override
virtual bool GetAddressSpecialCase(PyObject *pyobject, void *&address)
std::string GetFailureMsg() override
Definition Converters.h:63
VoidArrayConverter(bool keepControl=true, const std::string &failureMsg=std::string())
Definition Converters.h:51
CPYRT_EXTERN Converter * CreateConverter(const std::string &name, cdims_t=0)
CPYRT_EXTERN bool RegisterConverter(const std::string &name, ConverterFactory_t)
CPYRT_EXTERN void DestroyConverter(Converter *p)
CPYRT_EXTERN bool UnregisterConverter(const std::string &name)
const dims_t & cdims_t
Definition API.h:114
Converter *(* cf_t)(cdims_t d)
Definition Converters.h:41
CPYRT_EXTERN bool RegisterConverterAlias(const std::string &name, const std::string &target)
Cpp::TypeRef TCppType_t
Definition API.h:42
Cpp::DeclRef TCppScope_t
Definition API.h:41