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_idID 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#
| Kind | Allocate | Reserve |
|---|---|---|
| Structure | new_structure_id() -> StructureId | reserve_structure_id(value: int) -> StructureId |
| Material | new_material_id() -> MaterialId | reserve_material_id(value: int) -> MaterialId |
| Assignment | new_assignment_id() -> AssignmentId | reserve_assignment_id(value: int) -> AssignmentId |
| Surface | new_surface_id() -> SurfaceId | reserve_surface_id(value: int) -> SurfaceId |
| Antenna | new_antenna_id() -> AntennaId | reserve_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) -> StructureIdReturns 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 101The second number assumes no structure with an ID above 100 was created earlier in the process.