Skip to content

Commit

Permalink
add __cpp_reflex__ to CPPScope to check properties
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Jun 11, 2022
1 parent 6303351 commit aa68005
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/CPyCppyy/Reflex.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ namespace Cppyy {
namespace Reflex {

typedef int RequestId_t;
const RequestId_t OFFSET = 1;
const RequestId_t RETURN_TYPE = 2;
const RequestId_t TYPE = 3;

const RequestId_t IS_NAMESPACE = 1;

const RequestId_t OFFSET = 2;
const RequestId_t RETURN_TYPE = 3;
const RequestId_t TYPE = 4;

typedef int FormatId_t;
const FormatId_t OPTIMAL = 1;
Expand Down
21 changes: 21 additions & 0 deletions src/CPPScope.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,25 @@ static int meta_setattro(PyObject* pyclass, PyObject* pyname, PyObject* pyval)
}


//----------------------------------------------------------------------------
static PyObject* meta_reflex(CPPScope* klass, PyObject* args)
{
// Provide the requested reflection information.
Cppyy::Reflex::RequestId_t request = -1;
Cppyy::Reflex::FormatId_t format = Cppyy::Reflex::OPTIMAL;
if (!PyArg_ParseTuple(args, const_cast<char*>("i|i:__cpp_reflex__"), &request, &format))
return nullptr;

if (request == Cppyy::Reflex::IS_NAMESPACE) {
if (klass->fFlags & CPPScope::kIsNamespace)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}

PyErr_Format(PyExc_ValueError, "unsupported reflex request %d or format %d", request, format);
return nullptr;
}

//----------------------------------------------------------------------------
// p2.7 does not have a __dir__ in object, and object.__dir__ in p3 does not
// quite what I'd expected of it, so the following pulls in the internal code
Expand Down Expand Up @@ -597,6 +616,8 @@ static PyObject* meta_dir(CPPScope* klass)

//-----------------------------------------------------------------------------
static PyMethodDef meta_methods[] = {
{(char*)"__cpp_reflex__", (PyCFunction)meta_reflex, METH_VARARGS,
(char*)"C++ datamember reflection information" },
{(char*)"__dir__", (PyCFunction)meta_dir, METH_NOARGS, nullptr},
{(char*)nullptr, nullptr, 0, nullptr}
};
Expand Down

0 comments on commit aa68005

Please sign in to comment.