Identity

Reference for the ID types StructureId, MaterialId, AssignmentId, SurfaceId, AntennaId and PrimitiveId, and the new_*_id and reserve_*_id allocators.

The identity types and allocators live in witwin.core.identity and are exported from witwin.core. For when to use which, see Identity and versions.

from witwin.core import StructureId, new_structure_id, reserve_structure_id

ID types#

StructureId = NewType("StructureId", int)
MaterialId = NewType("MaterialId", int)
AssignmentId = NewType("AssignmentId", int)
SurfaceId = NewType("SurfaceId", int)
AntennaId = NewType("AntennaId", int)
PrimitiveId = NewType("PrimitiveId", int)

Each is an int at run time. The names only help type checkers and readers.

Allocators#

KindAllocateReserve
Structurenew_structure_id() -> StructureIdreserve_structure_id(value: int) -> StructureId
Materialnew_material_id() -> MaterialIdreserve_material_id(value: int) -> MaterialId
Assignmentnew_assignment_id() -> AssignmentIdreserve_assignment_id(value: int) -> AssignmentId
Surfacenew_surface_id() -> SurfaceIdreserve_surface_id(value: int) -> SurfaceId
Antennanew_antenna_id() -> AntennaIdreserve_antenna_id(value: int) -> AntennaId

There is no allocator for PrimitiveId; see Structure.primitive_id.

new_*_id#

Returns the next value of a process-global counter, starting at 0, and increments it. Thread-safe. The values are unique within the process but depend on construction order.

reserve_*_id#

reserve_structure_id(value: int) -> StructureId

Returns value as an ID and moves the counter to at least value + 1, so later new_*_id() calls never return it. Raises ValueError if value is negative.

Constructors call these for you: passing structure_id=10 to Structure calls reserve_structure_id(10), and omitting it calls new_structure_id().

from witwin.core import new_structure_id, reserve_structure_id
 
print(reserve_structure_id(100), new_structure_id())
100 101

The second number assumes no structure with an ID above 100 was created earlier in the process.