pyapple2disk/src/apple2disk/container.py
kris f3bde766bf Add a container.Container() type that carries a list of Anomaly()
objects associated to the container, and builds a tree of child
containers with support for depth-first recursion

Convert all of the disk container classes to use Container() and
register themselves with this tree.  This constructs a hierarchy of
container objects rooted in Disk that describe the structures found on
the disk image.

Convert most of the print statements and some of the assertions to
register Anomaly records instead

Fix/improve some of the __str__ representations
2017-04-20 23:04:24 +01:00

21 lines
592 B
Python

class Container(object):
"""Generic container type, every structure on the disk extends from this."""
def __init__(self):
self.anomalies = []
self.parent = None
self.children = []
def AddChild(self, child):
assert child.parent is None, "%s already has parent %s" % (child, child.parent)
self.children.append(child)
child.parent = self
def Recurse(self, callback):
"""Depth-first recursive traversal of children."""
for child in self.children:
callback(child)
child.Recurse(callback)