:py:mod:`gnome.utilities.orderedcollection` =========================================== .. py:module:: gnome.utilities.orderedcollection Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: gnome.utilities.orderedcollection.OrderedCollection .. 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:method:: _s_id(elem) return the id of the object as a string .. 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:: __len__() .. py:method:: __iter__() .. py:method:: __contains__(elem) .. py:method:: _slice_attr(ident) support for slice operations like a list .. py:method:: __getitem__(ident) slicing works just like it does for lists .. py:method:: __setitem__(ident, new_elem) does not yet support slice assignment. There is no need but is easy to add if required .. py:method:: __delitem__(ident) does not yet support slice assignment. There is no need but is easy to add if required .. py:method:: __iadd__(rop) .. py:method:: __str__() for __str__, don't show the keys .. py:method:: __repr__() Return repr(self). .. py:method:: __eq__(other) Equality of two ordered collections .. py:method:: __ne__(other) Return self!=value. .. 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