Spaces:
Build error
Build error
File size: 673 Bytes
67a8158 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import copy
def singleton(class_):
instances = {}
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]
return getinstance
##############
# cfg_holder #
##############
@singleton
class cfg_unique_holder(object):
def __init__(self):
self.cfg = None
# this is use to track the main codes.
self.code = set()
def save_cfg(self, cfg):
self.cfg = copy.deepcopy(cfg)
def add_code(self, code):
"""
A new main code is reached and
its name is added.
"""
self.code.add(code)
|