Dynamic, IPC-fed BufferModel: buffers are added/replaced/removed at runtime as IpcClient observes them arrive, get re-plotted, or leave. Unlike MockBufferModel's fixed set, this model mutates in place via upsert()/remove(). Storage is vector >, mirroring MockBufferModel, so each live BufferRecord keeps a stable heap address: a Stage holds a std::span into a BufferRecord::b
| 53 | // revision_of(i) let a consumer detect "something changed" and "which slot |
| 54 | // changed" cheaply, without diffing bytes. |
| 55 | class IpcBufferModel final : public BufferModel { |
| 56 | public: |
| 57 | std::size_t size() const override; |
| 58 | const BufferRecord& at(std::size_t i) const override; |
| 59 | |
| 60 | // Inserts a new buffer, or replaces an existing one matched by |
| 61 | // `record.variable_name`. On replace, the matching slot's unique_ptr is |
| 62 | // swapped for a fresh one built from `record` (the old BufferRecord is |
| 63 | // destroyed), and that slot's per-slot revision advances so consumers |
| 64 | // can tell a re-plot from an untouched buffer. On insert, the record is |
| 65 | // appended. Either way, the model-wide revision() advances. |
| 66 | void upsert(BufferRecord record); |
| 67 | |
| 68 | // Removes the buffer matched by `variable_name`, if any. No-op (and |
| 69 | // does not bump revision()) if no buffer with that name is present. |
| 70 | void remove(std::string_view variable_name); |
| 71 | |
| 72 | // Monotonic counter bumped on every upsert/remove, for cheap |
| 73 | // model-wide change detection. |
| 74 | [[nodiscard]] std::uint64_t revision() const { |
| 75 | return revision_; |
| 76 | } |
| 77 | |
| 78 | // Per-slot revision, bumped only when that slot's BufferRecord is |
| 79 | // replaced (insert or re-plot), so a consumer can tell a re-plot of |
| 80 | // buffer i from an unrelated change elsewhere in the model. |
| 81 | [[nodiscard]] std::uint64_t revision_of(std::size_t i) const override; |
| 82 | |
| 83 | [[nodiscard]] const std::string& |
| 84 | variable_name_of(std::size_t i) const override; |
| 85 | |
| 86 | private: |
| 87 | std::vector<std::unique_ptr<BufferRecord>> storage_; |
| 88 | std::vector<std::uint64_t> slot_revision_; // parallel to storage_ |
| 89 | std::uint64_t revision_{0}; |
| 90 | std::uint64_t next_slot_rev_{1}; |
| 91 | }; |
| 92 | |
| 93 | } // namespace oid::host |
| 94 |
nothing calls this directly
no outgoing calls
no test coverage detected