gnome.utilities.orderedcollection

Classes

OrderedCollection

Generalized Container for a set of objects of a particular type which

Module Contents

class gnome.utilities.orderedcollection.OrderedCollection(elems=None, dtype=None)

Bases: object

Generalized Container for a set of objects of a particular type which preserves the order of insertion and supports replacement of not only an object in the list, but the key/id that references it. (a normal OrderedDict can’t do this) - The order of insertion is preserved. - Objects are accessed by id, as if in a dictionary. - Objects can be replaced in order. The objects will be referenced by a new id, and still be in the correct order.

callbacks = []
remake()

remove None elements from self._elems and renumber the indices in self._d_index

get(ident)

can get the object either by ‘id’ or by index in the order in which it was added

add(elem)

Add an object to the collection

append(elem)
remove(ident)

Remove an object from the collection: 1) can remove by index (similar to a list) 2) can remove by id of object (similar to a dict)

replace(ident, new_elem)

replace an object in the collection: 1) replace by index (similar to a list) 2) replace by id of object (similar to a dict)

raise exception if ‘id’ is not found.

index(elem)

acts like index method in a list. It returns the index associated with self._elems[index] = elem It can also take the ‘id’ as input and returns the index of the object in the list

update(cstruct, refs=None)

cstruct is meant to be a list of COMPLETE object serializations, or GnomeID appstructs (refs to existing objects).

to_dict()

Method takes the instance of ordered collection and outputs a list of dicts, each with two fields:

{obj_type: object type <module.class>,
id: IDs of each object}
register_callback(callback, events=('add', 'replace', 'remove'))

callbacks registered for following events: - add: item is added - replace: - remove: callback invoked after removing the item

fire_event(event, obj_)
clear()

clear all elements from collection

values()

return list of items contained in collection