Boost logo

Boost :

From: Ivan A. Vigasin (vig_at_[hidden])
Date: 2001-11-13 19:39:23


On Tue, 13 Nov 2001, David Abrahams wrote:

Dave,

Many thanks for your answer !

> The best workaround I can think of is to derive A from an extension class.
> You could just wrap a boring empty struct.
A is not mine. I tried to subclass from extension class and threading.Thread at the same time.
class MyClass(ExtClass, Thread):
...

Of course, it's possible to derive from ExtClass only and create threads separately as
m=MyClass()
t=Thread(None,m.run)
...

But it's not good, and situation is worse in case of other foreign classes (from standard library, for example).

One of solutions is to wrap each extension class with real python class.
Possibly like folowing:

class ExtWrapper(ExtClass):
  def __init__(self,real):
    ExtClass.__init__(self)
    self.real = real
  def EachMethod(self, *args):
    self.real.EachMethod(*args)

class RealClass:
  def __init__(self):
    self.extclass = ExtWrapper(self)
  def EachMethod(self, args):
    pass

Can you offer more elegant solution?

Regards, Ivan <vig_at_[hidden]>
ICQ: 22181170


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk