I am trying to wrap Python PyObject*in a class Object. In Python, anyway PyObject*. A list is that PyObject*, and each item in the list is itself PyObject*. This could be another list. and etc.
I am trying to resolve style syntax fooList[42] = barObjusing a proxy template ( here ).
Now that I’m working, I want to expand it so that I fooList[42]can use it as Object. In particular, I want to be able to handle ...
fooList[42].myObjMethod()
fooList[42].myObjMember = ...
Objecthas many methods, and is currently fooList[42].myObjMethod()going to first resolve fooList[42]to an instance Proxy, say tmpProxy, and then try tmpProxy.myObjMethod().
That means I would have to do
void Proxy::myObjMethod(){ return wrapped_ob.myObjMethod(); }
. Object Proxy, .
(. ), :
fooList[42]->myObjMethod()
... , , → ( ., ).
operator->.
, - ( pObj), ++ pObj->whatever.
. , " Object".
Object
const Object operator[] (const Object& key) const {
return Object{ PyObject_GetItem( p, key.p ) };
}
, 'const Object &' " Object".
class Proxy {
private:
const Object& container;
const Object& key;
public:
Proxy( const Object& c, const Object& k ) : container{c}, key{k}
{ }
operator Object() const {
return container[key];
}
const Proxy& operator= (const Object& rhs_ob) {
PyObject_SetItem( container.p, key.p, rhs_ob.p );
return *this;
}
const Object* operator->() const { return &container[key]; }
};
, myList[5]->someMemberObj = ....
myList[5] Proxy, Object ( myList). myItem.
, someProxy->fooFunc() someProxy->fooProperty myItem.fooFunc() myItem.fooProperty .
" Object".