Commits

Andrew Peterson committed 6cd26dc

Add documentation for utils module.

  • Participants
  • Parent commits b219106
  • Branches comments

Comments (0)

Files changed (1)

File djlib/utils.py

-
+""" Misc DJLib Utils Module
+
+Provides miscellaneous utilities that don't quite fit in any other modules.
+
+Overview:
+    enum - Create class mimicking enumeration capabilities of C++
+    IAllocator - Interface for creating classes that allocates arbitrary data.
+    IdAllocator - Allocator of globally unique integer values.
+    IManager - Interface for selecting global system Managers.
+    IPersistent - Interface for selecting classes that support persistence.
+    IGame - Interface for selecting a global Game Singleton.
+"""
 from zope.interface import implements, Interface
 
 
 def enum(*sequential, **named):
+    """ Create class mimicking enumeration capabilities of C++. """
     enums = dict(zip(sequential, range(len(sequential))), **named)
     enums["debug"] = sequential
     return type('Enum', (), enums)
     implements(IAllocator)
 
     def __init__(self, start_id = 0, end_id = None):
+        """ 
+        Args:
+            start_id(int, Optional) - Starting Value of allocation pool
+            end_id(int, Optional) - Ending Value of allocation pool
+        """
         if end_id:
             assert start_id < end_id
         self.start = start_id
         self.curr = start_id
 
     def allocate(self, reserve = None):
+        """ Return global unique identifier.
+
+        Returns `None` if allocation pool is empty.
+        """
         if self.end and self.curr > self.end:
             return None #Generator is empty
             
         return reserve
 
     def deallocate(self, value):
+        """ Add previously allocated ID back into allocation pool. """
         #deallocate does nothing for a basic allocator
         pass
 #end IdAllocator
 
 class IManager(Interface):
     """A global system Manager"""
+#end IManager
 
 class IPersistent(Interface):
 
 
     def save(stream):
         """Save Manager state to any data stream."""
-        
 #end IPersistent
 
 class IGame(Interface):
     """The Game Singleton"""
+#end IGame