mailr22575 - /trunk/specific_analyses/api_base.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on March 28, 2014 - 10:16:
Author: bugman
Date: Fri Mar 28 10:16:53 2014
New Revision: 22575

URL: http://svn.gna.org/viewcvs/relax?rev=22575&view=rev
Log:
The specific analysis API classes are now all singletons.

This change will reduce the amount of memory used, as these classes are 
initialised multiple times
throughout relax, especially in the test suite.  The API objects are not used 
for local storage so
the multiple instance verses singleton design change will make no difference. 
 The singleton design
pattern code has been added to the base class 
specific_analyses.api_base.Api_base so that all
classes inherit the __new__() method which implements the singleton.


Modified:
    trunk/specific_analyses/api_base.py

Modified: trunk/specific_analyses/api_base.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/api_base.py?rev=22575&r1=22574&r2=22575&view=diff
==============================================================================
--- trunk/specific_analyses/api_base.py (original)
+++ trunk/specific_analyses/api_base.py Fri Mar 28 10:16:53 2014
@@ -33,11 +33,26 @@
     All the methods here are prototype methods.  To identify that the method 
is not available for certain analysis types, if called a RelaxImplementError 
is raised if called.
     """
 
+    # Class variable for storing the class instance (for the singleton 
design pattern).
+    instance = None
+
     def __init__(self):
         """Set up the specific objects."""
 
         # Class variables.
         self.PARAMS = Param_list()
+
+
+    def __new__(self, *args, **kargs):
+        """Replacement function for implementing the singleton design 
pattern."""
+
+        # First initialisation.
+        if self.instance is None:
+            # Create a new instance.
+            self.instance = object.__new__(self, *args, **kargs)
+
+        # Already initialised, so return the instance.
+        return self.instance
 
 
     def back_calc_ri(self, spin_index=None, ri_id=None, ri_type=None, 
frq=None):




Related Messages


Powered by MHonArc, Updated Fri Mar 28 10:40:02 2014