| 182 | } |
| 183 | |
| 184 | void HdComment::FromXml(const std::string& xml_snippet) { |
| 185 | if (xml_snippet.empty()) { |
| 186 | return; |
| 187 | } |
| 188 | try { |
| 189 | auto xml_file = CreateXmlFile("Expat"); |
| 190 | if (!xml_file) { |
| 191 | throw std::runtime_error("Failed to create EXPAT parser object"); |
| 192 | } |
| 193 | const bool parse = xml_file->ParseString(xml_snippet); |
| 194 | if (!parse) { |
| 195 | throw std::runtime_error("Failed to parse the XML string."); |
| 196 | } |
| 197 | const auto* root_node = xml_file->RootNode(); |
| 198 | if (root_node == nullptr) { |
| 199 | throw std::runtime_error("There is no root node in the XML string"); |
| 200 | } |
| 201 | MdComment::FromXml(*root_node); |
| 202 | |
| 203 | IXmlNode::ChildList node_list; |
| 204 | xml_file->GetChildList(node_list); |
| 205 | for (const IXmlNode* node : node_list) { |
| 206 | if (node == nullptr) { |
| 207 | continue; |
| 208 | } |
| 209 | if (node->IsTagName("time_source") ) { |
| 210 | time_source_.FromXml(*node); |
| 211 | } else if (node->IsTagName("constants")) { |
| 212 | IXmlNode::ChildList const_list; |
| 213 | node->GetChildList(const_list); |
| 214 | for (const auto* const_node : const_list) { |
| 215 | if (const_node == nullptr || !const_node->IsTagName("const")) { |
| 216 | continue; |
| 217 | } |
| 218 | std::string expression = const_node->Value<std::string>(); |
| 219 | std::string name = const_node->Attribute<std::string>("name", ""); |
| 220 | MdString temp; |
| 221 | temp.FromXml(*const_node); |
| 222 | temp.Text(name); |
| 223 | AddConstant(temp, expression); |
| 224 | } |
| 225 | } else if (node->IsTagName("UNIT-SPEC")) { |
| 226 | unit_spec_.FromXml(*node); |
| 227 | } |
| 228 | } |
| 229 | } catch (const std::exception& err) { |
| 230 | MDF_ERROR() << "Failed to parse the HD comment. Error: " << err.what(); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | |
| 235 | } // namespace mdf |
nothing calls this directly
no test coverage detected