diff sat_frontends/tools/misc.py @ 2615:b4ecbcc2fd08

tools (misc): do not remove flags while using them anymore, instead added "all_used" and "unused" properties in FlagsHandler
author Goffi <goffi@goffi.org>
date Thu, 21 Jun 2018 01:21:44 +0200
parents 26edcf3a30eb
children 56f94936df1e
line wrap: on
line diff
--- a/sat_frontends/tools/misc.py	Thu Jun 21 01:21:44 2018 +0200
+++ b/sat_frontends/tools/misc.py	Thu Jun 21 01:21:44 2018 +0200
@@ -67,24 +67,29 @@
 
     the instance is initialized with an iterable
     then attribute return True if flag is set, False else.
-    WARNING: If a flag is checked, it is removed (i.e. unset)
-        this is done to use bool(flags_handler) to check if all flags
-        have been used
     """
 
     def __init__(self, flags):
         self.flags = set(flags or [])
+        self._used_flags = set()
 
     def __getattr__(self, flag):
-        try:
-            self.flags.remove(flag)
-        except KeyError:
-            return False
-        else:
-            return True
+        self._used_flags.add(flag)
+        return flag in self.flags
 
     def __len__(self):
         return len(self.flags)
 
     def __iter__(self):
         return self.flags.__iter__()
+
+    @property
+    def all_used(self):
+        """Return True if all flags have been used"""
+        return self._used_flags.issuperset(self.flags)
+
+    @property
+    def unused(self):
+        """Return flags which has not been used yet"""
+        return self.flags.difference(self._used_flags)
+