mailr22671 - /trunk/specific_analyses/parameter_object.py


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

Header


Content

Posted by edward on April 09, 2014 - 18:42:
Author: bugman
Date: Wed Apr  9 18:42:44 2014
New Revision: 22671

URL: http://svn.gna.org/viewcvs/relax?rev=22671&view=rev
Log:
The parameter list objects in the specific analysis API are now singletons.

This has no immediate benefit as these classes are only instantiated once.  
But it will allow for
efficient reuse of these objects in the future and for expansions of the 
specific analysis API.


Modified:
    trunk/specific_analyses/parameter_object.py

Modified: trunk/specific_analyses/parameter_object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/parameter_object.py?rev=22671&r1=22670&r2=22671&view=diff
==============================================================================
--- trunk/specific_analyses/parameter_object.py (original)
+++ trunk/specific_analyses/parameter_object.py Wed Apr  9 18:42:44 2014
@@ -64,6 +64,18 @@
         if self.spin_data:
             self.add('select', scope='spin', desc='The spin selection flag', 
py_type=bool, sim=True)
             self.add('fixed', scope='spin', desc='The fixed flag', 
py_type=bool)
+
+
+    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 add(self, name, scope=None, string=None, default=None, units=None, 
desc=None, py_type=None, set='generic', conv_factor=None, grace_string=None, 
err=False, sim=False):




Related Messages


Powered by MHonArc, Updated Thu Apr 10 12:20:02 2014