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, seegetObj()
for details.-
deleteObj
(obj)[source]¶ Removes an object from the internal registry.
obj
may be any of the three representations of an object.
-
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 anTypeError
.
-
registerObject
(obj, n=None)[source]¶ Same as
register()
, but extracts the string representation from the object’sname
attribute.
-
-
class
peng3dnet.registry.
PacketRegistry
(objtype=None)[source]¶ Subclass of
BaseRegistry
customized for storingPacket
instances and instances of subclasses.-
objtype
¶ alias of
peng3dnet.packet.Packet
-