1.1 --- a/simplify/simplified/data.py Sun Jun 17 22:05:04 2007 +0200
1.2 +++ b/simplify/simplified/data.py Mon Jun 18 00:35:46 2007 +0200
1.3 @@ -28,7 +28,10 @@
1.4
1.5 class _Class(Structure, WithName):
1.6
1.7 - "A Python class."
1.8 + """
1.9 + The basis of a Python class. Classes with specific instantiation behaviour
1.10 + should inherit from this class.
1.11 + """
1.12
1.13 def __init__(self, *args, **kw):
1.14 Structure.__init__(self, *args, **kw)
1.15 @@ -37,6 +40,8 @@
1.16 def full_name(self):
1.17 return "class %s" % self._full_name
1.18
1.19 + # Utility methods.
1.20 +
1.21 def get_instance_attribute_names(self):
1.22
1.23 "Return all attribute names used by the instances of this class."
1.24 @@ -63,9 +68,32 @@
1.25 names.sort()
1.26 return d, names
1.27
1.28 + def get_distinct_instances(self):
1.29 +
1.30 + """
1.31 + Return a list of instances whose instance attribute types are distinct.
1.32 + """
1.33 +
1.34 + instances = []
1.35 + names_found = []
1.36 +
1.37 + # Rather than use the instances directly, get them in name order in
1.38 + # order to favour those earlier according to the sorting.
1.39 +
1.40 + names_to_instances, instance_names = self.get_names_to_instances()
1.41 +
1.42 + for instance_name in instance_names:
1.43 + instance = names_to_instances[instance_name]
1.44 + names = instance.namespace.names
1.45 + if not names in names_found:
1.46 + instances.append(instance)
1.47 + names_found.append(names)
1.48 +
1.49 + return instances
1.50 +
1.51 class SingleInstanceClass(_Class):
1.52
1.53 - "A Python class."
1.54 + "A Python class producing only one instance."
1.55
1.56 def __init__(self, *args, **kw):
1.57 _Class.__init__(self, *args, **kw)
1.58 @@ -90,7 +118,7 @@
1.59
1.60 class MultipleInstanceClass(_Class):
1.61
1.62 - "A Python class."
1.63 + "A Python class producing many instances."
1.64
1.65 def __init__(self, *args, **kw):
1.66 _Class.__init__(self, *args, **kw)