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