Skip to content

Add const-correctness to read-only APIs across state, control, network, and sync modules - #6

Merged
eskfro merged 2 commits into
mainfrom
copilot/fix-add-const-to-functions
Aug 31, 2026
Merged

eskfro merged 2 commits into
mainfrom
copilot/fix-add-const-to-functions

Conversation

Copilot AI commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

This addresses missing const qualifiers on functions and values that are semantically read-only, with emphasis on getters and pure decision helpers. The update improves const-correctness without changing behavior.

  • Elevator state + node getters

    • Marked read-only ElevatorState accessors as const (Id, Floor, Active, Obstruction, Fault, DoorOpen, Stopped, MotorDir, MovingState, Version, Requests, Inertia, Usable).
    • Marked ElevatorNode::Id() and ElevatorNode::Running() as const.
    • Updated CopyFrom/OnUpdate signatures to use const-safe parameters (const ElevatorState*, const ElevatorState&).
  • Control/request table decision surface

    • Marked RequestTable readers as const (Value, Table, IsRequestAbove/Below/Here).
    • Marked read-only controller methods as const (Requests, ShouldStop, ShouldClearImmediately, ChooseDirection, ClearCurrentFloor).
  • Order sync + packet accessors

    • Marked Order getters as const; made ObservedBy and OnUpdate const-correct.
    • Added const overload for OrderTable::Order(...) and made ToBoolTable/Join const-correct.
    • Marked NetworkPacket::Id() as const and added const overloads for Orders(), State(), CabButtonOrders().
  • Peers read-only methods + local const usage

    • Marked Peers::ObservedByAll, CalculateElevatorCosts, and NumElevs as const.
    • Tightened call-site locals to const where values are not mutated (e.g., selected booleans and copied orders).
// Before
int ElevatorState::Id();
void Order::OnUpdate(Order rcv);
ordersync::Order* OrderTable::Order(int floor, int btn);

// After
int ElevatorState::Id() const;
void Order::OnUpdate(const Order& rcv);
const ordersync::Order* OrderTable::Order(int floor, int btn) const;

Copilot AI linked an issue Aug 31, 2026 that may be closed by this pull request
Co-authored-by: eskfro <106732002+eskfro@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix: add const to functions and variables Add const-correctness to read-only APIs across state, control, network, and sync modules Aug 31, 2026
Copilot AI requested a review from eskfro August 31, 2026 12:33
@eskfro
eskfro marked this pull request as ready for review August 31, 2026 12:34

@eskfro eskfro left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine.

@eskfro
eskfro merged commit 3d3584e into main Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: add const to functions

2 participants