MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / MockBufferModel

Class MockBufferModel

src/host/ui/buffer_model.h:92–131  ·  view source on GitHub ↗

Deterministic, IPC-free BufferModel: holds a fixed vector supplied at construction (typically via make_default_mock_model()), so chrome development and tests never depend on randomness or live IPC. Storage is vector > rather than vector so each BufferRecord has a stable heap address: erase() must not move surviving records, because each oid::Sta

Source from the content-addressed store, hash-verified

90// moving that record on erase would dangle every other Stage's span. This
91// makes MockBufferModel move-only, which is fine: nothing copies it.
92class MockBufferModel : public BufferModel {
93 public:
94 explicit MockBufferModel(std::vector<std::unique_ptr<BufferRecord>> records)
95 : storage_(std::move(records)) {}
96
97 std::size_t size() const override {
98 return storage_.size();
99 }
100
101 const BufferRecord& at(std::size_t i) const override {
102 return *storage_.at(i);
103 }
104
105 const std::string& variable_name_of(std::size_t i) const override {
106 return storage_.at(i)->variable_name;
107 }
108
109 // MockBufferModel's records never re-plot, so every slot's revision is
110 // permanently 0: StageManager's sync() will never see it change and so
111 // will never call Stage::buffer_update() for a mock buffer.
112 std::uint64_t revision_of(std::size_t /*i*/) const override {
113 return 0;
114 }
115
116 // Bounds-guarded erase: no-op if `i >= size()`. Erasing storage_[i]
117 // (a unique_ptr) never touches the addresses of surviving BufferRecords,
118 // so any Stage still holding a span into a surviving record's bytes
119 // stays valid. Callers that also own per-index Stage state must drop
120 // the Stage referencing the erased record *before* calling this, since
121 // the Stage's span becomes dangling once the record is destroyed.
122 void erase(std::size_t i) {
123 if (i >= storage_.size()) {
124 return;
125 }
126 storage_.erase(storage_.begin() + static_cast<std::ptrdiff_t>(i));
127 }
128
129 private:
130 std::vector<std::unique_ptr<BufferRecord>> storage_;
131};
132
133// Human-readable type+channel label used by the buffer-list panel, e.g.
134// "uint8x3", "float32x1".

Callers 1

make_default_mock_modelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected