Author: bugman Date: Wed Mar 7 09:36:19 2007 New Revision: 3089 URL: http://svn.gna.org/viewcvs/relax?rev=3089&view=rev Log: Converted the Data() class from the 'data' directory into a singleton. For more infomation about this usage of the singleton design pattern, see my post at https://mail.gna.org/public/relax-devel/2007-03/msg00012.html (Message-id: <7f080ed10703070006s309a1e1do38e621f48d8f6d9e@xxxxxxxxxxxxxx>). Modified: 1.3/data/main.py Modified: 1.3/data/main.py URL: http://svn.gna.org/viewcvs/relax/1.3/data/main.py?rev=3089&r1=3088&r2=3089&view=diff ============================================================================== --- 1.3/data/main.py (original) +++ 1.3/data/main.py Wed Mar 7 09:36:19 2007 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003, 2004, 2006 Edward d'Auvergne # +# Copyright (C) 2003-2004, 2006-2007 Edward d'Auvergne # # # # This file is part of the program relax. # # # @@ -33,7 +33,9 @@ # Global data. ############## -class Data: +class Data(object): + __instance = None + def __init__(self): """Class containing all the program data.""" @@ -70,6 +72,22 @@ self.warning = {} + def __new__(self, *args, **kargs): + """Method for implementing the singleton design pattern. + + If no other class instance currently exists, create a new instance of this class. Otherwise + return the class instance. See http://en.wikipedia.org/wiki/Singleton_pattern for a + description of this design pattern. + """ + + # Create a new instance if none exists. + if self.__instance is None: + self.__instance = object.__new__(self, *args, **kargs) + + # Return the class instance. + return self.__instance + + def __repr__(self): text = "The data class containing all permanent program data.\n" text = text + "The class contains the following objects:\n"