MySlice independant from Manifold package
[myslice.git] / myslice / util / singleton.py
1 #-------------------------------------------------------------------------
2 # Class Singleton
3 #
4 # Classes that inherit from Singleton can be instanciated only once 
5 #-------------------------------------------------------------------------
6
7 class Singleton(type):
8     def __init__(cls, name, bases, dic):
9         super(Singleton,cls).__init__(name,bases,dic)
10         cls.instance=None
11
12     def __call__(cls, *args, **kw):
13         if cls.instance is None:
14             cls.instance=super(Singleton,cls).__call__(*args,**kw)
15         return cls.instance
16
17
18 # See also
19 # http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python