MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / writeVarvalue

Function writeVarvalue

pj_datastore/src/derived_engine.cpp:126–201  ·  view source on GitHub ↗

Write a VarValue to a DataWriter row at (topic, col), coercing to out_kind.

Source from the content-addressed store, hash-verified

124
125// Write a VarValue to a DataWriter row at (topic, col), coercing to out_kind.
126static void writeVarvalue(
127 DataWriter& writer, PJ::TopicId tid, std::size_t col, const VarValue& val, StorageKind out_kind) {
128 if (out_kind == StorageKind::kString) {
129 if (const auto* s = std::get_if<std::string>(&val)) {
130 writer.set(tid, col, std::string_view(*s));
131 }
132 return;
133 }
134
135 // Integer→integer fast paths: avoid the lossy double round-trip.
136 if (out_kind == StorageKind::kUint64) {
137 if (const auto* u = std::get_if<uint64_t>(&val)) {
138 writer.set(tid, col, *u);
139 return;
140 }
141 if (const auto* i = std::get_if<int64_t>(&val)) {
142 writer.set(tid, col, static_cast<uint64_t>(*i));
143 return;
144 }
145 }
146 if (out_kind == StorageKind::kInt64) {
147 if (const auto* i = std::get_if<int64_t>(&val)) {
148 writer.set(tid, col, *i);
149 return;
150 }
151 if (const auto* u = std::get_if<uint64_t>(&val)) {
152 writer.set(tid, col, static_cast<int64_t>(*u));
153 return;
154 }
155 }
156 if (out_kind == StorageKind::kInt32) {
157 if (const auto* i = std::get_if<int64_t>(&val)) {
158 writer.set(tid, col, static_cast<int32_t>(*i));
159 return;
160 }
161 if (const auto* u = std::get_if<uint64_t>(&val)) {
162 writer.set(tid, col, static_cast<int32_t>(*u));
163 return;
164 }
165 }
166
167 // Fallback: extract as double then coerce to the target type.
168 double dval = std::visit(
169 [](const auto& v) -> double {
170 using T = std::decay_t<decltype(v)>;
171 if constexpr (std::is_same_v<T, std::string>) {
172 return 0.0;
173 } else {
174 return static_cast<double>(v);
175 }
176 },
177 val);
178
179 switch (out_kind) {
180 case StorageKind::kFloat32:
181 writer.set(tid, col, static_cast<float>(dval));
182 break;
183 case StorageKind::kFloat64:

Callers 2

runSisoIncrementalFunction · 0.85
runMimoIncrementalFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected