The Backdoor Initializer in Python

In Object Oriented languages there is no _wrapObj method exposed to the user. Instead, the same functionality is achieved simply by calling ``new'' on the Impl class.

However, writing the Python backdoor constructor is a little trickier than Java or C++. This is because there is no overloading in Python, so multiple constructors were a problem. Instead, the class implementor needs to determine if the object is being constructed directly by the user, or through the normal Babel process. This can be achieved with an if statement. If the argument IORself == None, then the user has called the backdoor constructor, if IORself != None, it is a normal Babel construction.

Here is an excerpt from the class definition for wrapper.Data_Impl.Data:

class Data:
  def __init__(self, IORself = None):
    if (IORself == None):
      self.__IORself = wrapper.Data.Data(impl = self)
    else:
      self.__IORself = IORself
    # DO-NOT-DELETE splicer.begin(__init__)
    if(IORself == None):
      self.d_string = "placeholder value"
      self.d_ctortest = "ctor was run"
      self.d_int = 0
    # DO-NOT-DELETE splicer.end(__init__)

  def setString(self, s):
    # DO-NOT-DELETE splicer.begin(setString)
    self.d_string = s
    # DO-NOT-DELETE splicer.end(setString)

  def setInt(self, i):
    # DO-NOT-DELETE splicer.begin(setInt)
    self.d_int = i
    # DO-NOT-DELETE splicer.end(setInt)

Here is the client code from WrapTest.java:

import wrapper.User
import wrapper.Data
import wrapper.Data_Impl

if __name__ == '__main__':
  user = wrapper.User.User()
  data = wrapper.Data_Impl.Data()

  print data.d_ctortest
  user.accept(data._getStub())
  print data.d_string + " " + d_int
0





babel-1.4.0
users_guide Last Modified 2008-10-16

http://www.llnl.gov/CASC/components
components@llnl.gov