Author: bugman Date: Thu May 22 16:55:25 2008 New Revision: 6254 URL: http://svn.gna.org/viewcvs/relax?rev=6254&view=rev Log: Changed the design of the relax data store singleton. The singleton saving and loading problem is discussed in the thread starting at: https://mail.gna.org/public/relax-devel/2007-11/msg00021.html (Message-id: <7f080ed10711201001s59a00533pf3c0ee3f88a79edb@xxxxxxxxxxxxxx>). For more history, see the thread starting at https://mail.gna.org/public/relax-devel/2007-03/msg00046.html (Message-id: <7f080ed10703140609p70d35295ye10ee5939da494a2@xxxxxxxxxxxxxx>) and the original singleton idea at https://mail.gna.org/public/relax-devel/2007-03/msg00012.html (Message-id: <7f080ed10703070006s309a1e1do38e621f48d8f6d9e@xxxxxxxxxxxxxx>). This reverts to the original singleton behaviour in the last link. Note that this will be reverted to the current singleton design once a good solution to the pickling issues can be found. Modified: branches/singleton_fixing/data/__init__.py Modified: branches/singleton_fixing/data/__init__.py URL: http://svn.gna.org/viewcvs/relax/branches/singleton_fixing/data/__init__.py?rev=6254&r1=6253&r2=6254&view=diff ============================================================================== --- branches/singleton_fixing/data/__init__.py (original) +++ branches/singleton_fixing/data/__init__.py Thu May 22 16:55:25 2008 @@ -38,12 +38,26 @@ 'main' ] -class Data2(dict): +class Relax_data_store(dict): """The relax data storage object.""" # The current data pipe. current_pipe = None + # Class variable for storing the class instance. + instance = None + + def __new__(self, *args, **kargs): + """Replacement function for implementing the singleton design pattern.""" + + # First initialisation. + if self.instance is None: + self.instance = dict.__new__(self, *args, **kargs) + + # Already initialised, so return the instance. + return self.instance + + def __repr__(self): """The string representation of the object. @@ -128,7 +142,3 @@ # Change the current data pipe. self.current_pipe = pipe_name - -# Rebind the name Data with an instance to prevent accidental creation -# of multiple instances of the Data class -Data = Data2()