16#include "../../cppyy/CPyCppyy/src/CPyCppyy.h"
17#include "../../cppyy/CPyCppyy/src/CPPInstance.h"
18#include "../../cppyy/CPyCppyy/src/Utility.h"
30std::string GetScopedFinalNameFromPyObject(
const PyObject *pyobj)
45 if (
auto clInfo = cl->GetClassInfo()) {
56 static std::map<ULong64_t, void *> declIDPrinterMap;
61 return PyObject_Repr(self);
67 if (0 == declIDPrinterMap.size()) {
68 std::string printerCode =
"namespace ROOT::Internal::Pythonizations::ValuePrinters"
70 " template<class T, ULong64_t> std::string ValuePrinter(void *obj)"
72 " return cling::printValue((T *)obj);"
78 const std::string className = GetScopedFinalNameFromPyObject(self);
80 std::string printResult;
82 if (
const auto classID =
GetClassID(className.c_str())) {
89 auto &printerFuncrPtr = declIDPrinterMap[classID];
91 if (!printerFuncrPtr) {
92 std::string printFuncName =
"ROOT::Internal::Pythonizations::ValuePrinters::ValuePrinter<" + className +
", " +
93 std::to_string(classID) +
">";
94 printerFuncrPtr = (
void *)
gInterpreter->Calc(printFuncName.c_str());
96 printResult = ((std::string(*)(
void *))printerFuncrPtr)(cppObj);
99 printResult =
gInterpreter->ToString(className.c_str(), cppObj);
102 if (printResult.find(
"@0x") == 0) {
104 return PyObject_Repr(self);
106 return PyUnicode_FromString(printResult.c_str());
121 PyObject *pyclass = PyTuple_GetItem(args, 0);
static ULong64_t GetClassID(const char *clName)
PyObject * ClingPrintValue(PyObject *self, PyObject *)
unsigned long long ULong64_t
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
CPYCPPYY_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
PyObject * AddPrettyPrintingPyz(PyObject *self, PyObject *args)
Add pretty printing pythonization.