fork download
  1. class SharedPointerPrinter:
  2. "Print a shared_ptr or weak_ptr"
  3.  
  4. class _iterator:
  5. def __init__(self, sharedPointer):
  6. self.sharedPointer = sharedPointer
  7. self.managedValue = sharedPointer.val['_M_ptr']
  8. self.count = 0
  9.  
  10. def __iter__(self):
  11. return self
  12.  
  13. def next(self):
  14. if self.managedValue == 0:
  15. raise StopIteration
  16. self.count = self.count + 1
  17. if (self.count == 1):
  18. return ('Managed value', self.managedValue.cast(self.managedValue.dynamic_type).dereference())
  19.  
  20. else:
  21. raise StopIteration
  22.  
  23. def __init__ (self, typename, val):
  24. self.typename = typename
  25. self.val = val
  26.  
  27. def children (self):
  28. return self._iterator(self)
  29.  
  30. def to_string (self):
  31. state = 'empty'
  32. refcounts = self.val['_M_refcount']['_M_pi']
  33. if refcounts != 0:
  34. usecount = refcounts['_M_use_count']
  35. weakcount = refcounts['_M_weak_count']
  36. if usecount == 0:
  37. state = 'expired, weakcount %d' % weakcount
  38. else:
  39. state = 'usecount %d, weakcount %d' % (usecount, weakcount - 1)
  40. return '%s (%s) to %s' % (self.typename, state, self.val['_M_ptr'])
Success #stdin #stdout 0.08s 8832KB
stdin
Standard input is empty
stdout
Standard output is empty