| 298 | } |
| 299 | |
| 300 | void writeH5Attributes(h5::Group sub, const AnyMap& meta) |
| 301 | { |
| 302 | for (auto& [name, item] : meta) { |
| 303 | if (sub.hasAttribute(name)) { |
| 304 | throw NotImplementedError("writeH5Attributes", |
| 305 | "Unable to overwrite existing Attribute '{}'", name); |
| 306 | } |
| 307 | if (item.is<long int>()) { |
| 308 | int value = item.asInt(); |
| 309 | h5::Attribute attr = sub.createAttribute<long int>( |
| 310 | name, h5::DataSpace::From(value)); |
| 311 | attr.write(value); |
| 312 | } else if (item.is<double>()) { |
| 313 | double value = item.asDouble(); |
| 314 | h5::Attribute attr = sub.createAttribute<double>( |
| 315 | name, h5::DataSpace::From(value)); |
| 316 | attr.write(value); |
| 317 | } else if (item.is<string>()) { |
| 318 | string value = item.asString(); |
| 319 | h5::Attribute attr = sub.createAttribute<string>( |
| 320 | name, h5::DataSpace::From(value)); |
| 321 | attr.write(value); |
| 322 | } else if (item.is<bool>()) { |
| 323 | bool bValue = item.asBool(); |
| 324 | H5Boolean value = bValue ? |
| 325 | H5Boolean::HighFiveTrue : H5Boolean::HighFiveFalse; |
| 326 | h5::Attribute attr = sub.createAttribute<H5Boolean>( |
| 327 | name, h5::DataSpace::From(value)); |
| 328 | attr.write(value); |
| 329 | } else if (item.is<vector<long int>>()) { |
| 330 | auto values = item.as<vector<long int>>(); |
| 331 | h5::Attribute attr = sub.createAttribute<long int>( |
| 332 | name, h5::DataSpace::From(values)); |
| 333 | attr.write(values); |
| 334 | } else if (item.is<vector<double>>()) { |
| 335 | auto values = item.as<vector<double>>(); |
| 336 | h5::Attribute attr = sub.createAttribute<double>( |
| 337 | name, h5::DataSpace::From(values)); |
| 338 | attr.write(values); |
| 339 | } else if (item.is<vector<string>>()) { |
| 340 | auto values = item.as<vector<string>>(); |
| 341 | h5::Attribute attr = sub.createAttribute<string>( |
| 342 | name, h5::DataSpace::From(values)); |
| 343 | attr.write(values); |
| 344 | } else if (item.is<vector<bool>>()) { |
| 345 | auto bValue = item.as<vector<bool>>(); |
| 346 | vector<H5Boolean> values; |
| 347 | for (auto b : bValue) { |
| 348 | values.push_back(b ? |
| 349 | H5Boolean::HighFiveTrue : H5Boolean::HighFiveFalse); |
| 350 | } |
| 351 | h5::Attribute attr = sub.createAttribute<H5Boolean>( |
| 352 | name, h5::DataSpace::From(values)); |
| 353 | attr.write(values); |
| 354 | } else if (item.is<AnyMap>()) { |
| 355 | // step into recursion |
| 356 | auto value = item.as<AnyMap>(); |
| 357 | auto grp = sub.createGroup(name); |
no test coverage detected