Browse Source

added SerialNum and printListEnum, put Functor, Stack, Queue, SerialNum in __builtin__

Darren Ranalli 19 years ago
parent
commit
733be2ee64
1 changed files with 26 additions and 0 deletions
  1. 26 0
      direct/src/showbase/PythonUtil.py

+ 26 - 0
direct/src/showbase/PythonUtil.py

@@ -1713,6 +1713,16 @@ def randUint32(rng=random.random):
     rng must return float in [0..1]"""
     return long(rng() * 0xFFFFFFFFL)
 
+class SerialNum:
+    """generates serial numbers"""
+    def __init__(self, start=None):
+        if start is None:
+            start = 0
+        self.__counter = start-1
+    def next(self):
+        self.__counter += 1
+        return self.__counter
+
 def beginExports(modname):
     """The beginExports/endExports construct is used to bracket
     a set of top-level python declarations.  The effect is to
@@ -1884,3 +1894,19 @@ class Singleton(type):
 class SingletonError(ValueError):
     """ Used to indicate an inappropriate value for a Singleton."""
 
+def printListEnum(l):
+    # log each individual item with a number in front of it
+    digits = 0
+    n = len(l)
+    while n > 0:
+        digits += 1
+        n /= 10
+    format = '%0' + '%s' % digits + 'i:%s'
+    for i in range(len(l)):
+        print format % (i, l[i])
+
+import __builtin__
+__builtin__.Functor = Functor
+__builtin__.Stack = Stack
+__builtin__.Queue = Queue
+__builtin__.SerialNum = SerialNum