slice page working. added temporarily core and util classes from manifold core
[myslice.git] / manifold / util / singleton.py
diff --git a/manifold/util/singleton.py b/manifold/util/singleton.py
new file mode 100644 (file)
index 0000000..b622c13
--- /dev/null
@@ -0,0 +1,19 @@
+#-------------------------------------------------------------------------
+# Class Singleton
+#
+# Classes that inherit from Singleton can be instanciated only once 
+#-------------------------------------------------------------------------
+
+class Singleton(type):
+    def __init__(cls, name, bases, dic):
+        super(Singleton,cls).__init__(name,bases,dic)
+        cls.instance=None
+
+    def __call__(cls, *args, **kw):
+        if cls.instance is None:
+            cls.instance=super(Singleton,cls).__call__(*args,**kw)
+        return cls.instance
+
+
+# See also
+# http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python