CMS 3D CMS Logo

Classes | Functions

python::iterators Namespace Reference

Classes

class  TestIterators

Functions

def _findIterators
def addIterator
def emptyIterator
def iteratorForBeginEnd
def iteratorForSizedObjects

Function Documentation

def python::iterators::_findIterators (   obj) [private]

Definition at line 46 of file iterators.py.

00047                        :
00048     objDict = obj.__dict__
00049     _beginNames = [name for name in objDict.keys() if "begin" in 
00050 name.lower()]
00051     _endNames = [name for name in objDict.keys() if "end" in name.lower()]
00052     if len(_beginNames)==1 and len(_endNames)== 1 and _beginNames[0].lower().replace("begin","") == _endNames[0].lower().replace("end",""):  
00053         return objDict[_beginNames[0]], objDict[_endNames[0]]
00054     else:
00055         return False
00056         
00057         
        
def python::iterators::addIterator (   obj)
function for adding iterators to objects

Definition at line 6 of file iterators.py.

00007                     :
00008     """function for adding iterators to objects""" 
00009     if not hasattr(obj, "__iter__"):
00010         if hasattr(obj, "size"):
00011             obj.__iter__ = iteratorForSizedObjects
00012         else:
00013             try:
00014               begin, end = _findIterators(obj)
00015             except:
00016               return obj  
00017             if not hasattr(obj, "_begin") and hasattr(obj, "_end"):
00018                 obj._begin = begin
00019                 obj._end = end
00020                 obj.__iter__ = iteratorForBeginEnd
00021         #else:
00022         #    obj.__iter__ = EmptyIterator
00023     return obj
00024 

def python::iterators::emptyIterator (   self)
empty iterator

Definition at line 40 of file iterators.py.

00041                        :
00042     """empty iterator"""
00043     raise cmserror("Automatic iterator search failed for %s. Either it is no iterable or it has multiple iterator possibilites. Please use loop(begin, end) instead." %obj )
00044 
00045 
# automatic detection of iterators.      
def python::iterators::iteratorForBeginEnd (   self)
dynamically added iterator

Definition at line 32 of file iterators.py.

00033                              :
00034     """dynamically added iterator"""
00035     it = self._begin
00036     while (it != self.end):
00037         yield begin.__deref__()  #*b
00038         begin.__preinc__()       #++b
00039 

def python::iterators::iteratorForSizedObjects (   self)
dynamically added iterator

Definition at line 25 of file iterators.py.

00026                                  :
00027     """dynamically added iterator"""
00028     entries = container.size()
00029     for entry in xrange(entries):
00030         yield obj[entry]
00031