MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / FromXml

Method FromXml

lib/mdflib/mdflib/src/mdnumber.cpp:192–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192void MdNumber::FromXml(const IXmlNode& number_node) {
193 const auto attr_list = number_node.GetAttributeList();
194 for (const auto& [key, value] : attr_list) {
195 if (key == "ci" && !value.empty()) {
196 try {
197 ci_ = std::stoll(value);
198 } catch (const std::exception_ptr&) {
199 ci_ = 0;
200 }
201 } else if (key == "xml:lang") {
202 lang_ = value;
203 } else if (key == "byte_count") {
204 try {
205 byte_count_ = std::stoull(value);
206 } catch (const std::exception&) {
207 byte_count_.reset();
208 }
209 } else if (key == "bit_mask") {
210 try {
211 if (value.size() > 2 && value.substr(0, 2) == "0x") {
212 // HEX decode
213 const auto hex_value = value.substr(2);
214 bit_mask_ = std::stoull(hex_value, nullptr, 16);
215 } else if (!value.empty()) {
216 bit_mask_ = std::stoull(value);
217 }
218 } catch (const std::exception&) {
219 bit_mask_.reset();
220 }
221 } else if (key == "byte_order") {
222 if (value == "BE") {
223 byte_order_ = MdByteOrder::BigEndian;
224 }
225 } else if (key == "min") {
226 try {
227 min_ = std::stod(value);
228 } catch (const std::exception&) {
229 min_.reset();
230 }
231 } else if (key == "max") {
232 try {
233 max_ = std::stod(value);
234 } catch (const std::exception&) {
235 max_.reset();
236 }
237 } else if (key == "average") {
238 try {
239 average_ = std::stod(value);
240 } catch (const std::exception&) {
241 average_.reset();
242 }
243 } else if (key == "unit") {
244 unit_ = value;
245 } else if (key == "unit_ref") {
246 unit_ref_ = value;
247 } else if (key == "triggered") {
248 triggered_ = number_node.Attribute(key, false);
249 } else {

Callers

nothing calls this directly

Calls 5

GetAttributeListMethod · 0.80
emptyMethod · 0.80
AttributeMethod · 0.80
resetMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected