gnome.utilities.orderedcollection ================================= .. py:module:: gnome.utilities.orderedcollection Classes ------- .. autoapisummary:: gnome.utilities.orderedcollection.OrderedCollection Module Contents --------------- .. py:class:: OrderedCollection(elems=None, dtype=None) Bases: :py:obj:`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. .. py:attribute:: callbacks :value: [] .. py:method:: remake() remove None elements from self._elems and renumber the indices in self._d_index .. py:method:: get(ident) can get the object either by 'id' or by index in the order in which it was added .. py:method:: add(elem) Add an object to the collection .. py:method:: append(elem) .. py:method:: 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) .. py:method:: 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. .. py:method:: 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 .. py:method:: update(cstruct, refs=None) cstruct is meant to be a list of COMPLETE object serializations, or GnomeID appstructs (refs to existing objects). .. py:method:: to_dict() Method takes the instance of ordered collection and outputs a list of dicts, each with two fields:: {obj_type: object type , id: IDs of each object} .. py:method:: register_callback(callback, events=('add', 'replace', 'remove')) callbacks registered for following events: - add: item is added - replace: - remove: callback invoked after removing the item .. py:method:: fire_event(event, obj_) .. py:method:: clear() clear all elements from collection .. py:method:: values() return list of items contained in collection