core.commands.command module

Define the base class from which all commands will inherit.

class Command(line: list[str], dat_idx: int, **kwargs)

Bases: Instruction

A generic Command class.

Parameters:
  • idx (dict[str, int]) – Dictionary holding useful indexes. Keys are 'dat_idx' (position in the .dat file) and 'influenced_elements' (position in the .dat file of the elements concerned by current command).

  • line (list[str]) – Line in the .dat file corresponding to current command.

See also

core.list_of_elements.factory.subset_of_pre_existing_list_of_elements(), tracewin_utils.dat_files.dat_filecontent_from_smaller_list_of_elements()

__init__(line: list[str], dat_idx: int, **kwargs) None

Instantiate mandatory attributes.

_abc_impl = <_abc._abc_data object>
_indexes_between_this_command_and(instructions_after_self: Sequence[Instruction], *stop_types: type) slice

Determine the indexes of the instructions affected by an instruction.

We return the indexes of instructions between the first of instructions and the first instruction which type is in stop_types.

Parameters:
  • instructions_after_self (Sequence[Instruction]) – All instructions after self (self not included).

  • stop_types (type) – Type(s) of commands after which self has no influence. If not provided, we set it to the type of self. In other words, a FREQ influences every element up to the following FREQ.

Returns:

All the indexes of the instrutions that will be affected by self.

Return type:

slice

abstract apply(instructions: list[Instruction], **kwargs: float) list[Instruction]

Apply the command.

concerns_one_of(dat_indexes: Iterable[int]) bool

Tell if self concerns an element, which dat_idx is given.

Internally, we convert the self.influenced from a set to a list object and check intersections with dat_indexes.

Parameters:

dat_indexes (list[int]) – Indexes in the .dat file of the sub-list of elements under creation.

increment_dat_position(increment: int = 1) None

Increment dat_index and indexes of elements concerned by command.

set_influenced_elements(instructions: list[Instruction], **kwargs: float) None

Determine the index of the elements concerned by apply().