peng3dnet.registry - Smart Registry Class

class peng3dnet.registry.BaseRegistry(objtype=None)[source]

Basic registry class.

Supports smart conversions between the integer, string and generic object representation of a registered entity.

Optionally allows for automatic and threadsafe integer ID generation.

Requires bidict to be installed and available.

objtype may be used to override the class attribute of the same name per instance.

Instances of this class also support dictionary-style access to their data, e.g. reg[val] will always return the object representation of the value, see getObj() for details.

deleteObj(obj)[source]

Removes an object from the internal registry.

obj may be any of the three representations of an object.

getAll(obj)[source]

Returns a three-tuple of form (getObj(obj),getID(obj),getName(obj)).

getID(obj)[source]

Converts the given value to its integer representation.

This method accepts either strings, integers or objects of type objtype.

getInt() may be used as an alias to this method.

getName(obj)[source]

Converts the given value to its string representation.

This method accepts either strings, integers or objects of type objtype.

getStr() may be used as an alias to this method.

getNewID()[source]

Generates a new ID.

Currently, all IDs are increasing from a fixed starting point, by default 64.

getObj(obj)[source]

Converts the given value to its object representation.

This method accepts either strings, integers or objects of type objtype.

objtype

alias of builtins.object

register(obj, name, n=None)[source]

Registers a relation between an object, its string representation and its integer representation.

If n is not given, getNewID() will be used to generate it.

Trying to register an already registered object may cause various kinds of corruptions on internal storages.

Trying to register an object that is not of the type specified in objtype will result in an TypeError.

registerObject(obj, n=None)[source]

Same as register(), but extracts the string representation from the object’s name attribute.

class peng3dnet.registry.PacketRegistry(objtype=None)[source]

Subclass of BaseRegistry customized for storing Packet instances and instances of subclasses.

objtype

alias of peng3dnet.packet.Packet