Пример #1
0
 def next(self):
     if self.node:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(self.node)
         obj = typed_ptr(p,datatype)
         self.node = py2shmobj.shmlist_next(self.list, self.node)
         return obj
     else:
         raise StopIteration
Пример #2
0
 def remove(self, item):
     SHMOBJ.protect(self)
     np = py2shmobj.shmlist_first(self.addr)
     while np:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
         obj = typed_ptr(p,datatype)
         if obj == item:
             py2shmobj.shmlist_remove(self.addr, np)
             return None
         np = py2shmobj.shmlist_next(self.addr,np)
Пример #3
0
 def count(self, arg):
     SHMOBJ.protect(self)
     count = 0
     np = py2shmobj.shmlist_first(self.addr)
     while np:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
         obj = typed_ptr(p,datatype)
         if obj == arg:
             count += 1
         np = py2shmobj.shmlist_next(self.addr,np)
     return count
Пример #4
0
 def index(self, item, begIdx=0, endIdx=sys.maxint):
     SHMOBJ.protect(self)
     idx = 0
     np = py2shmobj.shmlist_getnode(self.addr, begIdx)
     while np and idx < endIdx:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
         obj = typed_ptr(p,datatype)
         if obj == item:
             return idx
         np = py2shmobj.shmlist_next(self.addr,np)
         idx += 1
     raise ValueError
Пример #5
0
 def delete(self, shallow=False):
     SHMOBJ.protect(self)
     np = py2shmobj.shmlist_first(self.addr)
     while np:
         if not shallow:
             (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
             if p:
                 val = typed_ptr(p,datatype)
                 if type(val) in [SHMLST, SHMDCT]:
                     val.delete(shallow=shallow)
                 elif isinstance(val, SHMOBJ):
                     val.delete()
         next = py2shmobj.shmlist_next(self.addr,np)
         py2shmobj.shmlist_remove(self.addr, np)
         py2shmobj.shmobj_del(np)
         np = next
     SHMOBJ.delete(self)
Пример #6
0
    def __getslice__(self,idx_a,idx_b):
        SHMOBJ.protect(self)
        slice = []

        if idx_b == sys.maxint:
            idx_b = len(self)

        if idx_a < 0:
            idx_a += len(self)
            if idx_a < 0:
                idx_a = 0
        if idx_a > len(self):
            idx_a = len(self)

        if idx_b < 0:
            idx_b += len(self)
            if idx_b < 0:
                idx_b = 0
        if idx_b > len(self):
            idx_b = len(self)

        if idx_b <= idx_a: 
            return slice

        if idx_a < 0 or idx_b < 0 or idx_a > len(self) or idx_b > len(self):
            raise IndexError

        i = idx_a
        np = py2shmobj.shmlist_getnode(self.addr, idx_a)
        while np and i < idx_b:
            (ep,datatype,datalen) = py2shmobj.shmlnode_get(np)
            slice.append(typed_ptr(ep,datatype))
            np = py2shmobj.shmlist_next(self.addr,np)
            i += 1
        if i < idx_b:
            raise IndexError
        return slice