>> Is it possible to customize "virtual protected functions" and
>> "pure virtual protected functions" as above to have control of the GIL?
>> It seems that those templates are ignored in case of
>> protected methods or I'm maybe missing something...

> Can you show the use case?

Sure :)
Let's suppose that we have two classes in C++:
JobsManager (a "Singleton" class) and an interface class of a Job.

class JobsManager : public Singleton<JobsManager>
{
// ...

public:
   void addJob(boost::shared_ptr<Job> j)
   {
      m_jobs.push_back(j);
   }

   void runJobs()
   {
      for(Jobs::const_iterator i = m_jobs.begin(); i != m_jobs.end(); (*i)->run(), ++i);
   }
};

class Job
{
// ...

public:
   void run()
   {
      onInit();
      onRun();
   }

protected:
   virtual void onInit()
   {
      // ...
   }

   virtual void onRun() = 0;
};

The "C++ framework" will load at startup all the python scripts where we
can implement and register our custom jobs, something like:

class MyJob(Job):
   def onInit(self):
      # ...
      Job.onInit(self)

   def onRun(self):
      # ...

JobsManager.instance().addJob( myJobInstance )

The last step in C++ is to call JobsManager::instance().runJobs() (after loading all the python
scripts), but this function call will be from C++ to Python (not from Python to C++ as "usual"),
so we need to restore the correct PyThreadState where MyJob has been created: that's why I need
a custom "base wrapper class" (where I save the PyThreadState in the constructor).

Since I'm not a Python expert (this is my first experience with Python :) ), can you please
help me, as suggested, in customizing the mem_fun_protected_v_wrapper_t and
mem_fun_protected_pv_wrapper_t so that they will "share" the virtual_mem_fun/pure_virtual_mem_fun
templates like in public virtual functions? Isn't possible to write something like:

mem_fun_protected_v_wrapper_t.create_virtual_body = mem_fun_public_v_wrapper_t.create_virtual_body
mem_fun_protected_pv_wrapper_t.create_virtual_body = mem_fun_public_vp_wrapper_t.create_virtual_body

I just need to share the same code (in this way I don't have to deal with Py++ internals).
What about adding two more templates for protected functions instead?

Bye




Scatta, Scarica, Modifica... Condividi le tue foto con Windows Live!