From 8f1f5db2b193fe1db7eeabda2a7b3eee03dde886 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 9 Feb 2024 00:29:00 +0100 Subject: [PATCH] Replace xmlpp::Node::add_child with cxml::add_child. --- cscript | 6 +- src/asset_map.cc | 40 ++++----- src/certificate_chain.cc | 49 +++++----- src/cpl.cc | 106 +++++++++++----------- src/dcp.cc | 2 +- src/encrypted_kdm.cc | 110 +++++++++++------------ src/interop_subtitle_asset.cc | 10 +-- src/pkl.cc | 26 +++--- src/rating.cc | 4 +- src/reel.cc | 6 +- src/reel_asset.cc | 18 ++-- src/reel_asset.h | 2 +- src/reel_atmos_asset.cc | 6 +- src/reel_atmos_asset.h | 2 +- src/reel_file_asset.cc | 10 +-- src/reel_file_asset.h | 2 +- src/reel_interop_closed_caption_asset.cc | 6 +- src/reel_interop_closed_caption_asset.h | 2 +- src/reel_markers_asset.cc | 12 +-- src/reel_markers_asset.h | 2 +- src/reel_picture_asset.cc | 14 +-- src/reel_picture_asset.h | 2 +- src/reel_smpte_closed_caption_asset.cc | 6 +- src/reel_smpte_closed_caption_asset.h | 2 +- src/reel_subtitle_asset.cc | 6 +- src/reel_subtitle_asset.h | 2 +- src/smpte_subtitle_asset.cc | 22 ++--- src/subtitle_asset_internal.cc | 16 ++-- src/types.cc | 8 +- test/shared_subtitle_test.cc | 12 +-- 30 files changed, 259 insertions(+), 252 deletions(-) diff --git a/cscript b/cscript index 5cfa5834..413f62c2 100644 --- a/cscript +++ b/cscript @@ -35,7 +35,11 @@ import os import shutil def dependencies(target, options): - return (('libcxml', 'v0.17.6'), ('openjpeg', 'ad8edaacd54a862940d0a77c41ecda5858b54d6e'), ('asdcplib', '8a4a2f25cac0c58aac1d4267facab20e5ec3b57f')) + return ( + ('libcxml', 'v0.17.8', options), + ('openjpeg', 'ad8edaacd54a862940d0a77c41ecda5858b54d6e'), + ('asdcplib', '8a4a2f25cac0c58aac1d4267facab20e5ec3b57f') + ) def build(target, options): cmd = './waf configure --disable-examples --disable-dumpimage --disable-benchmarks --prefix=%s' % target.directory diff --git a/src/asset_map.cc b/src/asset_map.cc index 281f27c3..0ee4b486 100644 --- a/src/asset_map.cc +++ b/src/asset_map.cc @@ -165,29 +165,29 @@ AssetMap::write_xml(boost::filesystem::path file) const DCP_ASSERT (false); } - root->add_child("Id")->add_child_text("urn:uuid:" + _id); + cxml::add_text_child(root, "Id", "urn:uuid:" + _id); if (_annotation_text) { - root->add_child("AnnotationText")->add_child_text(*_annotation_text); + cxml::add_text_child(root, "AnnotationText", *_annotation_text); } switch (_standard) { case Standard::INTEROP: - root->add_child("VolumeCount")->add_child_text("1"); - root->add_child("IssueDate")->add_child_text(_issue_date); - root->add_child("Issuer")->add_child_text(_issuer); - root->add_child("Creator")->add_child_text(_creator); + cxml::add_text_child(root, "VolumeCount", "1"); + cxml::add_text_child(root, "IssueDate", _issue_date); + cxml::add_text_child(root, "Issuer", _issuer); + cxml::add_text_child(root, "Creator", _creator); break; case Standard::SMPTE: - root->add_child("Creator")->add_child_text(_creator); - root->add_child("VolumeCount")->add_child_text("1"); - root->add_child("IssueDate")->add_child_text(_issue_date); - root->add_child("Issuer")->add_child_text(_issuer); + cxml::add_text_child(root, "Creator", _creator); + cxml::add_text_child(root, "VolumeCount", "1"); + cxml::add_text_child(root, "IssueDate", _issue_date); + cxml::add_text_child(root, "Issuer", _issuer); break; default: DCP_ASSERT (false); } - auto asset_list = root->add_child("AssetList"); + auto asset_list = cxml::add_child(root, "AssetList"); for (auto const& asset: _assets) { asset.write_xml(asset_list, file.parent_path()); } @@ -200,20 +200,20 @@ AssetMap::write_xml(boost::filesystem::path file) const void AssetMap::Asset::write_xml(xmlpp::Element* asset_list, boost::filesystem::path dcp_root_directory) const { - auto node = asset_list->add_child("Asset"); - node->add_child("Id")->add_child_text("urn:uuid:" + _id); + auto node = cxml::add_child(asset_list, "Asset"); + cxml::add_text_child(node, "Id", "urn:uuid:" + _id); if (_pkl) { - node->add_child("PackingList")->add_child_text("true"); + cxml::add_text_child(node, "PackingList", "true"); } - auto chunk_list = node->add_child("ChunkList"); - auto chunk = chunk_list->add_child("Chunk"); + auto chunk_list = cxml::add_child(node, "ChunkList"); + auto chunk = cxml::add_child(chunk_list, "Chunk"); auto relative_path = relative_to_root(filesystem::canonical(dcp_root_directory), filesystem::canonical(_path)); DCP_ASSERT(relative_path); - chunk->add_child("Path")->add_child_text(relative_path->generic_string()); - chunk->add_child("VolumeIndex")->add_child_text("1"); - chunk->add_child("Offset")->add_child_text("0"); - chunk->add_child("Length")->add_child_text(raw_convert(filesystem::file_size(_path))); + cxml::add_text_child(chunk, "Path", relative_path->generic_string()); + cxml::add_text_child(chunk, "VolumeIndex", "1"); + cxml::add_text_child(chunk, "Offset", "0"); + cxml::add_text_child(chunk, "Length", raw_convert(filesystem::file_size(_path))); } diff --git a/src/certificate_chain.cc b/src/certificate_chain.cc index c4e3a9b0..2bbddc7f 100644 --- a/src/certificate_chain.cc +++ b/src/certificate_chain.cc @@ -606,47 +606,47 @@ CertificateChain::sign (xmlpp::Element* parent, Standard standard) const /* */ parent->add_child_text(" "); - auto signer = parent->add_child("Signer"); + auto signer = cxml::add_child(parent, "Signer"); signer->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "dsig"); - auto data = signer->add_child("X509Data", "dsig"); - auto serial_element = data->add_child("X509IssuerSerial", "dsig"); - serial_element->add_child("X509IssuerName", "dsig")->add_child_text (leaf().issuer()); - serial_element->add_child("X509SerialNumber", "dsig")->add_child_text (leaf().serial()); - data->add_child("X509SubjectName", "dsig")->add_child_text (leaf().subject()); + auto data = cxml::add_child(signer, "X509Data", string("dsig")); + auto serial_element = cxml::add_child(data, "X509IssuerSerial", string("dsig")); + cxml::add_child(serial_element, "X509IssuerName", string("dsig"))->add_child_text(leaf().issuer()); + cxml::add_child(serial_element, "X509SerialNumber", string("dsig"))->add_child_text(leaf().serial()); + cxml::add_child(data, "X509SubjectName", string("dsig"))->add_child_text(leaf().subject()); indent (signer, 2); /* */ parent->add_child_text("\n "); - auto signature = parent->add_child("Signature"); + auto signature = cxml::add_child(parent, "Signature"); signature->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "dsig"); signature->set_namespace ("dsig"); parent->add_child_text("\n"); - auto signed_info = signature->add_child ("SignedInfo", "dsig"); - signed_info->add_child("CanonicalizationMethod", "dsig")->set_attribute ("Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"); + auto signed_info = cxml::add_child(signature, "SignedInfo", string("dsig")); + cxml::add_child(signed_info, "CanonicalizationMethod", string("dsig"))->set_attribute("Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"); if (standard == Standard::INTEROP) { - signed_info->add_child("SignatureMethod", "dsig")->set_attribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); + cxml::add_child(signed_info, "SignatureMethod", string("dsig"))->set_attribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); } else { - signed_info->add_child("SignatureMethod", "dsig")->set_attribute("Algorithm", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); + cxml::add_child(signed_info, "SignatureMethod", string("dsig"))->set_attribute("Algorithm", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); } - auto reference = signed_info->add_child("Reference", "dsig"); + auto reference = cxml::add_child(signed_info, "Reference", string("dsig")); reference->set_attribute ("URI", ""); - auto transforms = reference->add_child("Transforms", "dsig"); - transforms->add_child("Transform", "dsig")->set_attribute ( + auto transforms = cxml::add_child(reference, "Transforms", string("dsig")); + cxml::add_child(transforms, "Transform", string("dsig"))->set_attribute( "Algorithm", "http://www.w3.org/2000/09/xmldsig#enveloped-signature" ); - reference->add_child("DigestMethod", "dsig")->set_attribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1"); + cxml::add_child(reference, "DigestMethod", string("dsig"))->set_attribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1"); /* This will be filled in by the signing later */ - reference->add_child("DigestValue", "dsig"); + cxml::add_child(reference, "DigestValue", string("dsig")); - signature->add_child("SignatureValue", "dsig"); - signature->add_child("KeyInfo", "dsig"); + cxml::add_child(signature, "SignatureValue", string("dsig")); + cxml::add_child(signature, "KeyInfo", string("dsig")); add_signature_value (signature, "dsig", true); } @@ -655,19 +655,20 @@ void CertificateChain::add_signature_value (xmlpp::Element* parent, string ns, bool add_indentation) const { cxml::Node cp (parent); - auto key_info = cp.node_child("KeyInfo")->node(); + auto key_info = dynamic_cast(cp.node_child("KeyInfo")->node()); + DCP_ASSERT(key_info); /* Add the certificate chain to the KeyInfo child node of parent */ for (auto const& i: leaf_to_root()) { - auto data = key_info->add_child("X509Data", ns); + auto data = cxml::add_child(key_info, "X509Data", ns); { - auto serial = data->add_child("X509IssuerSerial", ns); - serial->add_child("X509IssuerName", ns)->add_child_text (i.issuer ()); - serial->add_child("X509SerialNumber", ns)->add_child_text (i.serial ()); + auto serial = cxml::add_child(data, "X509IssuerSerial", ns); + cxml::add_child(serial, "X509IssuerName", ns)->add_child_text(i.issuer()); + cxml::add_child(serial, "X509SerialNumber", ns)->add_child_text(i.serial()); } - data->add_child("X509Certificate", ns)->add_child_text (i.certificate()); + cxml::add_child(data, "X509Certificate", ns)->add_child_text(i.certificate()); } auto signature_context = xmlSecDSigCtxCreate (0); diff --git a/src/cpl.cc b/src/cpl.cc index 5467fef3..6a9a46b5 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -194,15 +194,15 @@ CPL::write_xml(boost::filesystem::path file, shared_ptr root = doc.create_root_node ("CompositionPlaylist", cpl_smpte_ns); } - root->add_child("Id")->add_child_text ("urn:uuid:" + _id); + cxml::add_text_child(root, "Id", "urn:uuid:" + _id); if (_annotation_text) { - root->add_child("AnnotationText")->add_child_text (*_annotation_text); + cxml::add_text_child(root, "AnnotationText", *_annotation_text); } - root->add_child("IssueDate")->add_child_text (_issue_date); - root->add_child("Issuer")->add_child_text (_issuer); - root->add_child("Creator")->add_child_text (_creator); - root->add_child("ContentTitleText")->add_child_text (_content_title_text); - auto content_kind = root->add_child("ContentKind"); + cxml::add_text_child(root, "IssueDate", _issue_date); + cxml::add_text_child(root, "Issuer", _issuer); + cxml::add_text_child(root, "Creator", _creator); + cxml::add_text_child(root, "ContentTitleText", _content_title_text); + auto content_kind = cxml::add_child(root, "ContentKind"); content_kind->add_child_text(_content_kind.name()); if (_content_kind.scope()) { content_kind->set_attribute("scope", *_content_kind.scope()); @@ -214,12 +214,12 @@ CPL::write_xml(boost::filesystem::path file, shared_ptr _content_versions[0].as_xml (root); } - auto rating_list = root->add_child("RatingList"); + auto rating_list = cxml::add_child(root, "RatingList"); for (auto i: _ratings) { - i.as_xml (rating_list->add_child("Rating")); + i.as_xml(cxml::add_child(rating_list, "Rating")); } - auto reel_list = root->add_child ("ReelList"); + auto reel_list = cxml::add_child(root, "ReelList"); if (_reels.empty()) { throw NoReelsError (); @@ -373,27 +373,27 @@ CPL::write_mca_subdescriptors(xmlpp::Element* parent, shared_ptr(&soundfield) ); if (KM_SUCCESS(r)) { - auto mca_subs = parent->add_child("mca:MCASubDescriptors"); + auto mca_subs = cxml::add_child(parent, "mca:MCASubDescriptors"); mca_subs->set_namespace_declaration (mca_sub_descriptors_ns, "mca"); mca_subs->set_namespace_declaration (smpte_395_ns, "r0"); mca_subs->set_namespace_declaration (smpte_335_ns, "r1"); - auto sf = mca_subs->add_child("SoundfieldGroupLabelSubDescriptor", "r0"); + auto sf = cxml::add_child(mca_subs, "SoundfieldGroupLabelSubDescriptor", string("r0")); char buffer[64]; soundfield->InstanceUID.EncodeString(buffer, sizeof(buffer)); - sf->add_child("InstanceID", "r1")->add_child_text("urn:uuid:" + string(buffer)); + cxml::add_child(sf, "InstanceID", string("r1"))->add_child_text("urn:uuid:" + string(buffer)); soundfield->MCALabelDictionaryID.EncodeString(buffer, sizeof(buffer)); - sf->add_child("MCALabelDictionaryID", "r1")->add_child_text("urn:smpte:ul:" + string(buffer)); + cxml::add_child(sf, "MCALabelDictionaryID", string("r1"))->add_child_text("urn:smpte:ul:" + string(buffer)); soundfield->MCALinkID.EncodeString(buffer, sizeof(buffer)); - sf->add_child("MCALinkID", "r1")->add_child_text("urn:uuid:" + string(buffer)); + cxml::add_child(sf, "MCALinkID", string("r1"))->add_child_text("urn:uuid:" + string(buffer)); soundfield->MCATagSymbol.EncodeString(buffer, sizeof(buffer)); - sf->add_child("MCATagSymbol", "r1")->add_child_text(buffer); + cxml::add_child(sf, "MCATagSymbol", string("r1"))->add_child_text(buffer); if (!soundfield->MCATagName.empty()) { soundfield->MCATagName.get().EncodeString(buffer, sizeof(buffer)); - sf->add_child("MCATagName", "r1")->add_child_text(buffer); + cxml::add_child(sf, "MCATagName", string("r1"))->add_child_text(buffer); } if (!soundfield->RFC5646SpokenLanguage.empty()) { soundfield->RFC5646SpokenLanguage.get().EncodeString(buffer, sizeof(buffer)); - sf->add_child("RFC5646SpokenLanguage", "r1")->add_child_text(buffer); + cxml::add_child(sf, "RFC5646SpokenLanguage", string("r1"))->add_child_text(buffer); } /* Find the MCA subdescriptors in the MXF so that we can also write them here */ @@ -405,29 +405,29 @@ CPL::write_mca_subdescriptors(xmlpp::Element* parent, shared_ptr(i); - auto ch = mca_subs->add_child("AudioChannelLabelSubDescriptor", "r0"); + auto ch = cxml::add_child(mca_subs, "AudioChannelLabelSubDescriptor", string("r0")); channel->InstanceUID.EncodeString(buffer, sizeof(buffer)); - ch->add_child("InstanceID", "r1")->add_child_text("urn:uuid:" + string(buffer)); + cxml::add_child(ch, "InstanceID", string("r1"))->add_child_text("urn:uuid:" + string(buffer)); channel->MCALabelDictionaryID.EncodeString(buffer, sizeof(buffer)); - ch->add_child("MCALabelDictionaryID", "r1")->add_child_text("urn:smpte:ul:" + string(buffer)); + cxml::add_child(ch, "MCALabelDictionaryID", string("r1"))->add_child_text("urn:smpte:ul:" + string(buffer)); channel->MCALinkID.EncodeString(buffer, sizeof(buffer)); - ch->add_child("MCALinkID", "r1")->add_child_text("urn:uuid:" + string(buffer)); + cxml::add_child(ch, "MCALinkID", string("r1"))->add_child_text("urn:uuid:" + string(buffer)); channel->MCATagSymbol.EncodeString(buffer, sizeof(buffer)); - ch->add_child("MCATagSymbol", "r1")->add_child_text(buffer); + cxml::add_child(ch, "MCATagSymbol", string("r1"))->add_child_text(buffer); if (!channel->MCATagName.empty()) { channel->MCATagName.get().EncodeString(buffer, sizeof(buffer)); - ch->add_child("MCATagName", "r1")->add_child_text(buffer); + cxml::add_child(ch, "MCATagName", string("r1"))->add_child_text(buffer); } if (!channel->MCAChannelID.empty()) { - ch->add_child("MCAChannelID", "r1")->add_child_text(raw_convert(channel->MCAChannelID.get())); + cxml::add_child(ch, "MCAChannelID", string("r1"))->add_child_text(raw_convert(channel->MCAChannelID.get())); } if (!channel->RFC5646SpokenLanguage.empty()) { channel->RFC5646SpokenLanguage.get().EncodeString(buffer, sizeof(buffer)); - ch->add_child("RFC5646SpokenLanguage", "r1")->add_child_text(buffer); + cxml::add_child(ch, "RFC5646SpokenLanguage", string("r1"))->add_child_text(buffer); } if (!channel->SoundfieldGroupLinkID.empty()) { channel->SoundfieldGroupLinkID.get().EncodeString(buffer, sizeof(buffer)); - ch->add_child("SoundfieldGroupLinkID", "r1")->add_child_text("urn:uuid:" + string(buffer)); + cxml::add_child(ch, "SoundfieldGroupLinkID", string("r1"))->add_child_text("urn:uuid:" + string(buffer)); } } } @@ -451,16 +451,16 @@ CPL::maybe_write_composition_metadata_asset(xmlpp::Element* node, bool include_m return; } - auto meta = node->add_child("meta:CompositionMetadataAsset"); + auto meta = cxml::add_child(node, "meta:CompositionMetadataAsset"); meta->set_namespace_declaration (cpl_metadata_ns, "meta"); - meta->add_child("Id")->add_child_text("urn:uuid:" + _cpl_metadata_id); + cxml::add_text_child(meta, "Id", "urn:uuid:" + _cpl_metadata_id); auto mp = _reels.front()->main_picture(); - meta->add_child("EditRate")->add_child_text(mp->edit_rate().as_string()); - meta->add_child("IntrinsicDuration")->add_child_text(raw_convert(mp->intrinsic_duration())); + cxml::add_text_child(meta, "EditRate", mp->edit_rate().as_string()); + cxml::add_text_child(meta, "IntrinsicDuration", raw_convert(mp->intrinsic_duration())); - auto fctt = meta->add_child("FullContentTitleText", "meta"); + auto fctt = cxml::add_child(meta, "FullContentTitleText", string("meta")); if (_full_content_title_text && !_full_content_title_text->empty()) { fctt->add_child_text (*_full_content_title_text); } @@ -469,11 +469,11 @@ CPL::maybe_write_composition_metadata_asset(xmlpp::Element* node, bool include_m } if (_release_territory) { - meta->add_child("ReleaseTerritory", "meta")->add_child_text(*_release_territory); + cxml::add_child(meta, "ReleaseTerritory", string("meta"))->add_child_text(*_release_territory); } if (_version_number) { - xmlpp::Element* vn = meta->add_child("VersionNumber", "meta"); + auto vn = cxml::add_child(meta, "VersionNumber", string("meta")); vn->add_child_text(raw_convert(*_version_number)); if (_status) { vn->set_attribute("status", status_to_string(*_status)); @@ -481,19 +481,19 @@ CPL::maybe_write_composition_metadata_asset(xmlpp::Element* node, bool include_m } if (_chain) { - meta->add_child("Chain", "meta")->add_child_text(*_chain); + cxml::add_child(meta, "Chain", string("meta"))->add_child_text(*_chain); } if (_distributor) { - meta->add_child("Distributor", "meta")->add_child_text(*_distributor); + cxml::add_child(meta, "Distributor", string("meta"))->add_child_text(*_distributor); } if (_facility) { - meta->add_child("Facility", "meta")->add_child_text(*_facility); + cxml::add_child(meta, "Facility", string("meta"))->add_child_text(*_facility); } if (_content_versions.size() > 1) { - xmlpp::Element* vc = meta->add_child("AlternateContentVersionList", "meta"); + auto vc = cxml::add_child(meta, "AlternateContentVersionList", string("meta")); for (size_t i = 1; i < _content_versions.size(); ++i) { _content_versions[i].as_xml (vc); } @@ -504,17 +504,17 @@ CPL::maybe_write_composition_metadata_asset(xmlpp::Element* node, bool include_m } if (_main_sound_configuration) { - meta->add_child("MainSoundConfiguration", "meta")->add_child_text(_main_sound_configuration->to_string()); + cxml::add_child(meta, "MainSoundConfiguration", string("meta"))->add_child_text(_main_sound_configuration->to_string()); } - meta->add_child("MainSoundSampleRate", "meta")->add_child_text(raw_convert(*_main_sound_sample_rate) + " 1"); + cxml::add_child(meta, "MainSoundSampleRate", string("meta"))->add_child_text(raw_convert(*_main_sound_sample_rate) + " 1"); - auto stored = meta->add_child("MainPictureStoredArea", "meta"); - stored->add_child("Width", "meta")->add_child_text(raw_convert(_main_picture_stored_area->width)); - stored->add_child("Height", "meta")->add_child_text(raw_convert(_main_picture_stored_area->height)); + auto stored = cxml::add_child(meta, "MainPictureStoredArea", string("meta")); + cxml::add_child(stored, "Width", string("meta"))->add_child_text(raw_convert(_main_picture_stored_area->width)); + cxml::add_child(stored, "Height", string("meta"))->add_child_text(raw_convert(_main_picture_stored_area->height)); - auto active = meta->add_child("MainPictureActiveArea", "meta"); - active->add_child("Width", "meta")->add_child_text(raw_convert(_main_picture_active_area->width)); - active->add_child("Height", "meta")->add_child_text(raw_convert(_main_picture_active_area->height)); + auto active = cxml::add_child(meta, "MainPictureActiveArea", string("meta")); + cxml::add_child(active, "Width", string("meta"))->add_child_text(raw_convert(_main_picture_active_area->width)); + cxml::add_child(active, "Height", string("meta"))->add_child_text(raw_convert(_main_picture_active_area->height)); optional first_subtitle_language; for (auto i: _reels) { @@ -537,18 +537,18 @@ CPL::maybe_write_composition_metadata_asset(xmlpp::Element* node, bool include_m } lang += i; } - meta->add_child("MainSubtitleLanguageList", "meta")->add_child_text(lang); + cxml::add_child(meta, "MainSubtitleLanguageList", string("meta"))->add_child_text(lang); } - auto metadata_list = meta->add_child("ExtensionMetadataList", "meta"); + auto metadata_list = cxml::add_child(meta, "ExtensionMetadataList", string("meta")); auto add_extension_metadata = [metadata_list](string scope, string name, string property_name, string property_value) { - auto extension = metadata_list->add_child("ExtensionMetadata", "meta"); + auto extension = cxml::add_child(metadata_list, "ExtensionMetadata", string("meta")); extension->set_attribute("scope", scope); - extension->add_child("Name", "meta")->add_child_text(name); - auto property = extension->add_child("PropertyList", "meta")->add_child("Property", "meta"); - property->add_child("Name", "meta")->add_child_text(property_name); - property->add_child("Value", "meta")->add_child_text(property_value); + cxml::add_child(extension, "Name", string("meta"))->add_child_text(name); + auto property = cxml::add_child(cxml::add_child(extension, "PropertyList", string("meta")), "Property", string("meta")); + cxml::add_child(property, "Name", string("meta"))->add_child_text(property_name); + cxml::add_child(property, "Value", string("meta"))->add_child_text(property_value); }; /* SMPTE Bv2.1 8.6.3 */ diff --git a/src/dcp.cc b/src/dcp.cc index d603cfae..2906d575 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -441,7 +441,7 @@ DCP::write_volindex (Standard standard) const DCP_ASSERT (false); } - root->add_child("Index")->add_child_text ("1"); + cxml::add_text_child(root, "Index", "1"); doc.write_to_file_formatted(dcp::filesystem::fix_long_path(p).string(), "UTF-8"); } diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index 465a657d..5b33e3f6 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -85,8 +85,8 @@ public: void as_xml (xmlpp::Element* node) const { - node->add_child("X509IssuerName", "ds")->add_child_text (x509_issuer_name); - node->add_child("X509SerialNumber", "ds")->add_child_text (x509_serial_number); + cxml::add_child(node, "X509IssuerName", string("ds"))->add_child_text(x509_issuer_name); + cxml::add_child(node, "X509SerialNumber", string("ds"))->add_child_text(x509_serial_number); } string x509_issuer_name; @@ -108,8 +108,8 @@ public: void as_xml (xmlpp::Element* node) const { - x509_issuer_serial.as_xml (node->add_child ("X509IssuerSerial", "ds")); - node->add_child("X509Certificate", "ds")->add_child_text (x509_certificate); + x509_issuer_serial.as_xml(cxml::add_child(node, "X509IssuerSerial", string("ds"))); + cxml::add_child(node, "X509Certificate", string("ds"))->add_child_text(x509_certificate); } Signer x509_issuer_serial; @@ -136,8 +136,8 @@ public: void as_xml (xmlpp::Element* node) const { node->set_attribute ("URI", uri); - node->add_child("DigestMethod", "ds")->set_attribute ("Algorithm", "http://www.w3.org/2001/04/xmlenc#sha256"); - node->add_child("DigestValue", "ds")->add_child_text (digest_value); + cxml::add_child(node, "DigestMethod", string("ds"))->set_attribute("Algorithm", "http://www.w3.org/2001/04/xmlenc#sha256"); + cxml::add_child(node, "DigestValue", string("ds"))->add_child_text(digest_value); } string uri; @@ -168,16 +168,16 @@ public: void as_xml (xmlpp::Element* node) const { - node->add_child ("CanonicalizationMethod", "ds")->set_attribute ( + cxml::add_child(node, "CanonicalizationMethod", string("ds"))->set_attribute( "Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" ); - node->add_child ("SignatureMethod", "ds")->set_attribute ( + cxml::add_child(node, "SignatureMethod", string("ds"))->set_attribute( "Algorithm", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" ); - authenticated_public.as_xml (node->add_child ("Reference", "ds")); - authenticated_private.as_xml (node->add_child ("Reference", "ds")); + authenticated_public.as_xml(cxml::add_child(node, "Reference", string("ds"))); + authenticated_private.as_xml(cxml::add_child(node, "Reference", string("ds"))); } private: @@ -200,14 +200,14 @@ public: } } - void as_xml (xmlpp::Node* node) const + void as_xml(xmlpp::Element* element) const { - signed_info.as_xml (node->add_child ("SignedInfo", "ds")); - node->add_child("SignatureValue", "ds")->add_child_text (signature_value); + signed_info.as_xml(cxml::add_child(element, "SignedInfo", string("ds"))); + cxml::add_child(element, "SignatureValue", string("ds"))->add_child_text(signature_value); - auto key_info_node = node->add_child("KeyInfo", "ds"); + auto key_info_node = cxml::add_child(element, "KeyInfo", string("ds")); for (auto i: x509_data) { - i.as_xml (key_info_node->add_child("X509Data", "ds")); + i.as_xml(cxml::add_child(key_info_node, "X509Data", string("ds"))); } } @@ -234,17 +234,17 @@ public: references["ID_AuthenticatedPrivate"] = node->set_attribute ("Id", "ID_AuthenticatedPrivate"); for (auto i: encrypted_key) { - auto encrypted_key = node->add_child ("EncryptedKey", "enc"); + auto encrypted_key = cxml::add_child(node, "EncryptedKey", string("enc")); /* XXX: hack for testing with Dolby */ encrypted_key->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc"); - auto encryption_method = encrypted_key->add_child("EncryptionMethod", "enc"); + auto encryption_method = cxml::add_child(encrypted_key, "EncryptionMethod", string("enc")); encryption_method->set_attribute ("Algorithm", "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"); - auto digest_method = encryption_method->add_child ("DigestMethod", "ds"); + auto digest_method = cxml::add_child(encryption_method, "DigestMethod", string("ds")); /* XXX: hack for testing with Dolby */ digest_method->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds"); digest_method->set_attribute ("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1"); - auto cipher_data = encrypted_key->add_child("CipherData", "enc"); - cipher_data->add_child("CipherValue", "enc")->add_child_text (i); + auto cipher_data = cxml::add_child(encrypted_key, "CipherData", string("enc")); + cxml::add_child(cipher_data, "CipherValue", string("enc"))->add_child_text(i); } } @@ -271,9 +271,9 @@ public: void as_xml (xmlpp::Element* node) const { - auto type = node->add_child("KeyType"); + auto type = cxml::add_child(node, "KeyType"); type->add_child_text (key_type); - node->add_child("KeyId")->add_child_text ("urn:uuid:" + key_id); + cxml::add_text_child(node, "KeyId", "urn:uuid:" + key_id); /* XXX: this feels like a bit of a hack */ if (key_type == "MDEK") { type->set_attribute ("scope", "http://www.dolby.com/cp850/2012/KDM#kdm-key-type"); @@ -302,7 +302,7 @@ public: void as_xml (xmlpp::Element* node) const { for (auto const& i: typed_key_id) { - i.as_xml (node->add_child("TypedKeyId")); + i.as_xml(cxml::add_child(node, ("TypedKeyId"))); } } @@ -326,13 +326,13 @@ public: void as_xml (xmlpp::Element* node) const { - node->add_child ("DeviceListIdentifier")->add_child_text ("urn:uuid:" + device_list_identifier); + cxml::add_text_child(node, "DeviceListIdentifier", "urn:uuid:" + device_list_identifier); if (device_list_description) { - node->add_child ("DeviceListDescription")->add_child_text (device_list_description.get()); + cxml::add_text_child(node, "DeviceListDescription", device_list_description.get()); } - auto device_list = node->add_child ("DeviceList"); + auto device_list = cxml::add_child(node, "DeviceList"); for (auto i: certificate_thumbprints) { - device_list->add_child("CertificateThumbprint")->add_child_text (i); + cxml::add_text_child(device_list, "CertificateThumbprint", i); } } @@ -357,8 +357,8 @@ public: void as_xml (xmlpp::Element* node) const { - node->add_child("X509IssuerName", "ds")->add_child_text (x509_issuer_name); - node->add_child("X509SerialNumber", "ds")->add_child_text (x509_serial_number); + cxml::add_child(node, "X509IssuerName", string("ds"))->add_child_text(x509_issuer_name); + cxml::add_child(node, "X509SerialNumber", string("ds"))->add_child_text(x509_serial_number); } string x509_issuer_name; @@ -380,8 +380,8 @@ public: void as_xml (xmlpp::Element* node) const { - x509_issuer_serial.as_xml (node->add_child ("X509IssuerSerial")); - node->add_child("X509SubjectName")->add_child_text (x509_subject_name); + x509_issuer_serial.as_xml(cxml::add_child(node, "X509IssuerSerial")); + cxml::add_text_child(node, "X509SubjectName", x509_subject_name); } X509IssuerSerial x509_issuer_serial; @@ -428,30 +428,30 @@ public: { node->set_attribute ("xmlns", "http://www.smpte-ra.org/schemas/430-1/2006/KDM"); - recipient.as_xml (node->add_child ("Recipient")); - node->add_child("CompositionPlaylistId")->add_child_text ("urn:uuid:" + composition_playlist_id); - node->add_child("ContentTitleText")->add_child_text (content_title_text); + recipient.as_xml(cxml::add_child(node, "Recipient")); + cxml::add_text_child(node, "CompositionPlaylistId", "urn:uuid:" + composition_playlist_id); + cxml::add_text_child(node, "ContentTitleText", content_title_text); if (content_authenticator) { - node->add_child("ContentAuthenticator")->add_child_text (content_authenticator.get ()); + cxml::add_text_child(node, "ContentAuthenticator", content_authenticator.get()); } - node->add_child("ContentKeysNotValidBefore")->add_child_text (not_valid_before.as_string ()); - node->add_child("ContentKeysNotValidAfter")->add_child_text (not_valid_after.as_string ()); + cxml::add_text_child(node, "ContentKeysNotValidBefore", not_valid_before.as_string()); + cxml::add_text_child(node, "ContentKeysNotValidAfter", not_valid_after.as_string()); if (authorized_device_info) { - authorized_device_info->as_xml (node->add_child ("AuthorizedDeviceInfo")); + authorized_device_info->as_xml(cxml::add_child(node, "AuthorizedDeviceInfo")); } - key_id_list.as_xml (node->add_child ("KeyIdList")); + key_id_list.as_xml(cxml::add_child(node, "KeyIdList")); if (disable_forensic_marking_picture || disable_forensic_marking_audio) { - auto forensic_mark_flag_list = node->add_child ("ForensicMarkFlagList"); + auto forensic_mark_flag_list = cxml::add_child(node, "ForensicMarkFlagList"); if (disable_forensic_marking_picture) { - forensic_mark_flag_list->add_child("ForensicMarkFlag")->add_child_text(picture_disable); + cxml::add_text_child(forensic_mark_flag_list, "ForensicMarkFlag", picture_disable); } if (disable_forensic_marking_audio) { auto mrkflg = audio_disable; if (*disable_forensic_marking_audio > 0) { mrkflg += String::compose ("-above-channel-%1", *disable_forensic_marking_audio); } - forensic_mark_flag_list->add_child("ForensicMarkFlag")->add_child_text (mrkflg); + cxml::add_text_child(forensic_mark_flag_list, "ForensicMarkFlag", mrkflg); } } } @@ -490,7 +490,7 @@ public: void as_xml (xmlpp::Element* node) const { - kdm_required_extensions.as_xml (node->add_child ("KDMRequiredExtensions")); + kdm_required_extensions.as_xml(cxml::add_child(node, "KDMRequiredExtensions")); } KDMRequiredExtensions kdm_required_extensions; @@ -521,17 +521,17 @@ public: { references["ID_AuthenticatedPublic"] = node->set_attribute ("Id", "ID_AuthenticatedPublic"); - node->add_child("MessageId")->add_child_text ("urn:uuid:" + message_id); - node->add_child("MessageType")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type"); + cxml::add_text_child(node, "MessageId", "urn:uuid:" + message_id); + cxml::add_text_child(node, "MessageType", "http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type"); if (annotation_text) { - node->add_child("AnnotationText")->add_child_text (annotation_text.get ()); + cxml::add_text_child(node, "AnnotationText", annotation_text.get()); } - node->add_child("IssueDate")->add_child_text (issue_date); + cxml::add_text_child(node, "IssueDate", issue_date); - signer.as_xml (node->add_child ("Signer")); - required_extensions.as_xml (node->add_child ("RequiredExtensions")); + signer.as_xml(cxml::add_child(node, "Signer")); + required_extensions.as_xml(cxml::add_child(node, "RequiredExtensions")); - node->add_child ("NonCriticalExtensions"); + cxml::add_child(node, "NonCriticalExtensions"); } string message_id; @@ -563,14 +563,14 @@ public: shared_ptr as_xml () const { - shared_ptr document (new xmlpp::Document ()); - xmlpp::Element* root = document->create_root_node ("DCinemaSecurityMessage", "http://www.smpte-ra.org/schemas/430-3/2006/ETM"); + auto document = make_shared(); + auto root = document->create_root_node("DCinemaSecurityMessage", "http://www.smpte-ra.org/schemas/430-3/2006/ETM"); root->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds"); root->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc"); map references; - authenticated_public.as_xml (root->add_child ("AuthenticatedPublic"), references); - authenticated_private.as_xml (root->add_child ("AuthenticatedPrivate"), references); - signature.as_xml (root->add_child ("Signature", "ds")); + authenticated_public.as_xml(cxml::add_child(root, "AuthenticatedPublic"), references); + authenticated_private.as_xml(cxml::add_child(root, "AuthenticatedPrivate"), references); + signature.as_xml(cxml::add_child(root, "Signature", string("ds"))); for (auto i: references) { xmlAddID (0, document->cobj(), (const xmlChar *) i.first.c_str(), i.second->cobj()); diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 32c3f66a..a4594207 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -115,13 +115,13 @@ InteropSubtitleAsset::xml_as_string () const auto root = doc.create_root_node ("DCSubtitle"); root->set_attribute ("Version", "1.0"); - root->add_child("SubtitleID")->add_child_text (_id); - root->add_child("MovieTitle")->add_child_text (_movie_title); - root->add_child("ReelNumber")->add_child_text (raw_convert (_reel_number)); - root->add_child("Language")->add_child_text (_language); + cxml::add_text_child(root, "SubtitleID", _id); + cxml::add_text_child(root, "MovieTitle", _movie_title); + cxml::add_text_child(root, "ReelNumber", raw_convert (_reel_number)); + cxml::add_text_child(root, "Language", _language); for (auto i: _load_font_nodes) { - auto load_font = root->add_child("LoadFont"); + auto load_font = cxml::add_child(root, "LoadFont"); load_font->set_attribute ("Id", i->id); load_font->set_attribute ("URI", i->uri); } diff --git a/src/pkl.cc b/src/pkl.cc index 57eda9da..463d046a 100644 --- a/src/pkl.cc +++ b/src/pkl.cc @@ -105,26 +105,26 @@ PKL::write_xml (boost::filesystem::path file, shared_ptr pkl = doc.create_root_node("PackingList", pkl_smpte_ns); } - pkl->add_child("Id")->add_child_text ("urn:uuid:" + _id); + cxml::add_text_child(pkl, "Id", "urn:uuid:" + _id); if (_annotation_text) { - pkl->add_child("AnnotationText")->add_child_text (*_annotation_text); + cxml::add_text_child(pkl, "AnnotationText", *_annotation_text); } - pkl->add_child("IssueDate")->add_child_text (_issue_date); - pkl->add_child("Issuer")->add_child_text (_issuer); - pkl->add_child("Creator")->add_child_text (_creator); + cxml::add_text_child(pkl, "IssueDate", _issue_date); + cxml::add_text_child(pkl, "Issuer", _issuer); + cxml::add_text_child(pkl, "Creator", _creator); - auto asset_list = pkl->add_child("AssetList"); + auto asset_list = cxml::add_child(pkl, "AssetList"); for (auto i: _assets) { - auto asset = asset_list->add_child("Asset"); - asset->add_child("Id")->add_child_text ("urn:uuid:" + i->id()); + auto asset = cxml::add_child(asset_list, "Asset"); + cxml::add_text_child(asset, "Id", "urn:uuid:" + i->id()); if (i->annotation_text()) { - asset->add_child("AnnotationText")->add_child_text (*i->annotation_text()); + cxml::add_text_child(asset, "AnnotationText", *i->annotation_text()); } - asset->add_child("Hash")->add_child_text (i->hash()); - asset->add_child("Size")->add_child_text (raw_convert(i->size())); - asset->add_child("Type")->add_child_text (i->type()); + cxml::add_text_child(asset, "Hash", i->hash()); + cxml::add_text_child(asset, "Size", raw_convert(i->size())); + cxml::add_text_child(asset, "Type", i->type()); if (auto filename = i->original_filename()) { - asset->add_child("OriginalFileName")->add_child_text(*filename); + cxml::add_text_child(asset, "OriginalFileName", *filename); } } diff --git a/src/rating.cc b/src/rating.cc index 21960365..156d5ad0 100644 --- a/src/rating.cc +++ b/src/rating.cc @@ -61,8 +61,8 @@ Rating::Rating (cxml::ConstNodePtr node) void Rating::as_xml (xmlpp::Element* parent) const { - parent->add_child("Agency")->add_child_text(agency); - parent->add_child("Label")->add_child_text(label); + cxml::add_text_child(parent, "Agency", agency); + cxml::add_text_child(parent, "Label", label); } diff --git a/src/reel.cc b/src/reel.cc index a8481d59..def3a4ae 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -141,9 +141,9 @@ Reel::Reel (std::shared_ptr node, dcp::Standard standard) xmlpp::Element * Reel::write_to_cpl (xmlpp::Element* node, Standard standard) const { - auto reel = node->add_child ("Reel"); - reel->add_child("Id")->add_child_text("urn:uuid:" + _id); - xmlpp::Element* asset_list = reel->add_child ("AssetList"); + auto reel = cxml::add_child(node, "Reel"); + cxml::add_text_child(reel, "Id", "urn:uuid:" + _id); + auto asset_list = cxml::add_child(reel, "AssetList"); if (_main_markers) { _main_markers->write_to_cpl (asset_list, standard); diff --git a/src/reel_asset.cc b/src/reel_asset.cc index 3a3ae731..c782cf2b 100644 --- a/src/reel_asset.cc +++ b/src/reel_asset.cc @@ -84,10 +84,10 @@ ReelAsset::ReelAsset (shared_ptr node) } -xmlpp::Node* -ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element* +ReelAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { - auto a = node->add_child (cpl_node_name (standard)); + auto a = cxml::add_child(node, cpl_node_name(standard)); auto const attr = cpl_node_attribute (standard); if (!attr.first.empty ()) { a->set_attribute (attr.first, attr.second); @@ -96,18 +96,18 @@ ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const if (!ns.first.empty()) { a->set_namespace_declaration (ns.first, ns.second); } - a->add_child("Id")->add_child_text ("urn:uuid:" + _id); + cxml::add_text_child(a, "Id", "urn:uuid:" + _id); /* Empty tags cause refusal to play on some Sony SRX320 / LMT3000 systems (DoM bug #2124) */ if (_annotation_text && !_annotation_text->empty()) { - a->add_child("AnnotationText")->add_child_text(*_annotation_text); + cxml::add_text_child(a, "AnnotationText", *_annotation_text); } - a->add_child("EditRate")->add_child_text (_edit_rate.as_string()); - a->add_child("IntrinsicDuration")->add_child_text (raw_convert (_intrinsic_duration)); + cxml::add_text_child(a, "EditRate", _edit_rate.as_string()); + cxml::add_text_child(a, "IntrinsicDuration", raw_convert(_intrinsic_duration)); if (_entry_point) { - a->add_child("EntryPoint")->add_child_text(raw_convert(*_entry_point)); + cxml::add_text_child(a, "EntryPoint", raw_convert(*_entry_point)); } if (_duration) { - a->add_child("Duration")->add_child_text(raw_convert(*_duration)); + cxml::add_text_child(a, "Duration", raw_convert(*_duration)); } return a; } diff --git a/src/reel_asset.h b/src/reel_asset.h index e928cb18..8dad739e 100644 --- a/src/reel_asset.h +++ b/src/reel_asset.h @@ -83,7 +83,7 @@ public: explicit ReelAsset (std::shared_ptr); - virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const; + virtual xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const; virtual bool encryptable () const { return false; diff --git a/src/reel_atmos_asset.cc b/src/reel_atmos_asset.cc index ef39a4eb..c2cdb7f3 100644 --- a/src/reel_atmos_asset.cc +++ b/src/reel_atmos_asset.cc @@ -82,11 +82,11 @@ ReelAtmosAsset::cpl_node_namespace () const } -xmlpp::Node * -ReelAtmosAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element* +ReelAtmosAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { auto asset = ReelFileAsset::write_to_cpl (node, standard); - asset->add_child("axd:DataType")->add_child_text("urn:smpte:ul:060e2b34.04010105.0e090604.00000000"); + cxml::add_text_child(asset, "axd:DataType", "urn:smpte:ul:060e2b34.04010105.0e090604.00000000"); return asset; } diff --git a/src/reel_atmos_asset.h b/src/reel_atmos_asset.h index 298cbbfd..c3de76a8 100644 --- a/src/reel_atmos_asset.h +++ b/src/reel_atmos_asset.h @@ -68,7 +68,7 @@ public: return asset_of_type(); } - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; bool equals(std::shared_ptr, EqualityOptions const&, NoteHandler) const; private: diff --git a/src/reel_file_asset.cc b/src/reel_file_asset.cc index 5fefda27..8fed8012 100644 --- a/src/reel_file_asset.cc +++ b/src/reel_file_asset.cc @@ -94,15 +94,15 @@ ReelFileAsset::file_asset_equals(shared_ptr other, Equality } -xmlpp::Node * -ReelFileAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element* +ReelFileAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { - auto asset = ReelAsset::write_to_cpl (node, standard); + auto asset = ReelAsset::write_to_cpl(node, standard); if (_key_id) { - asset->add_child("KeyId")->add_child_text("urn:uuid:" + *_key_id); + cxml::add_text_child(asset, "KeyId", "urn:uuid:" + *_key_id); } if (_hash) { - asset->add_child("Hash")->add_child_text(*_hash); + cxml::add_text_child(asset, "Hash", *_hash); } return asset; } diff --git a/src/reel_file_asset.h b/src/reel_file_asset.h index 687e0d3e..48fdf215 100644 --- a/src/reel_file_asset.h +++ b/src/reel_file_asset.h @@ -56,7 +56,7 @@ public: ReelFileAsset (std::shared_ptr asset, boost::optional key_id, std::string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point); explicit ReelFileAsset (std::shared_ptr node); - virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + virtual xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; /** @return a Ref to our actual asset */ Ref const & asset_ref () const { diff --git a/src/reel_interop_closed_caption_asset.cc b/src/reel_interop_closed_caption_asset.cc index be968068..c4539fd7 100644 --- a/src/reel_interop_closed_caption_asset.cc +++ b/src/reel_interop_closed_caption_asset.cc @@ -75,12 +75,12 @@ ReelInteropClosedCaptionAsset::cpl_node_namespace () const } -xmlpp::Node * -ReelInteropClosedCaptionAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element* +ReelInteropClosedCaptionAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { auto asset = ReelClosedCaptionAsset::write_to_cpl (node, standard); if (_language) { - asset->add_child("Language")->add_child_text(*_language); + cxml::add_text_child(asset, "Language", *_language); } return asset; } diff --git a/src/reel_interop_closed_caption_asset.h b/src/reel_interop_closed_caption_asset.h index 5e8f7c1e..5a074357 100644 --- a/src/reel_interop_closed_caption_asset.h +++ b/src/reel_interop_closed_caption_asset.h @@ -62,7 +62,7 @@ public: return asset_of_type(); } - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; private: std::string cpl_node_name (Standard) const override; diff --git a/src/reel_markers_asset.cc b/src/reel_markers_asset.cc index d71a22ec..4b1b3472 100644 --- a/src/reel_markers_asset.cc +++ b/src/reel_markers_asset.cc @@ -104,16 +104,16 @@ ReelMarkersAsset::get (Marker m) const } -xmlpp::Node* -ReelMarkersAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element* +ReelMarkersAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { int const tcr = edit_rate().numerator / edit_rate().denominator; auto asset = ReelAsset::write_to_cpl (node, standard); - auto ml = asset->add_child("MarkerList"); + auto ml = cxml::add_child(asset, "MarkerList"); for (auto const& i: _markers) { - auto m = ml->add_child("Marker"); - m->add_child("Label")->add_child_text(marker_to_string(i.first)); - m->add_child("Offset")->add_child_text(raw_convert(i.second.as_editable_units_ceil(tcr))); + auto m = cxml::add_child(ml, "Marker"); + cxml::add_text_child(m, "Label", marker_to_string(i.first)); + cxml::add_text_child(m, "Offset", raw_convert(i.second.as_editable_units_ceil(tcr))); } return asset; diff --git a/src/reel_markers_asset.h b/src/reel_markers_asset.h index 2a1480a2..1e87957a 100644 --- a/src/reel_markers_asset.h +++ b/src/reel_markers_asset.h @@ -51,7 +51,7 @@ public: ReelMarkersAsset (Fraction edit_rate, int64_t intrinsic_duration); explicit ReelMarkersAsset (std::shared_ptr); - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; bool equals(std::shared_ptr, EqualityOptions const&, NoteHandler) const; void set (Marker, Time); diff --git a/src/reel_picture_asset.cc b/src/reel_picture_asset.cc index eb87d039..7ee5fa38 100644 --- a/src/reel_picture_asset.cc +++ b/src/reel_picture_asset.cc @@ -86,12 +86,12 @@ ReelPictureAsset::ReelPictureAsset (shared_ptr node) } -xmlpp::Node* -ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element* +ReelPictureAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { auto asset = ReelFileAsset::write_to_cpl (node, standard); - asset->add_child("FrameRate")->add_child_text(String::compose("%1 %2", _frame_rate.numerator, _frame_rate.denominator)); + cxml::add_text_child(asset, "FrameRate", String::compose("%1 %2", _frame_rate.numerator, _frame_rate.denominator)); if (standard == Standard::INTEROP) { @@ -113,10 +113,12 @@ ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const } } - asset->add_child("ScreenAspectRatio")->add_child_text(raw_convert(closest.get(), 2, true)); + cxml::add_text_child(asset, "ScreenAspectRatio", raw_convert(closest.get(), 2, true)); } else { - asset->add_child("ScreenAspectRatio")->add_child_text( - String::compose ("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator) + cxml::add_text_child( + asset, + "ScreenAspectRatio", + String::compose("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator) ); } diff --git a/src/reel_picture_asset.h b/src/reel_picture_asset.h index bf7d40aa..ebfef744 100644 --- a/src/reel_picture_asset.h +++ b/src/reel_picture_asset.h @@ -67,7 +67,7 @@ public: return asset_of_type(); } - virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + virtual xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; bool equals(std::shared_ptr, EqualityOptions const&, NoteHandler) const; /** @return picture frame rate */ diff --git a/src/reel_smpte_closed_caption_asset.cc b/src/reel_smpte_closed_caption_asset.cc index a2a68202..70e5eb36 100644 --- a/src/reel_smpte_closed_caption_asset.cc +++ b/src/reel_smpte_closed_caption_asset.cc @@ -65,12 +65,12 @@ ReelSMPTEClosedCaptionAsset::ReelSMPTEClosedCaptionAsset (shared_ptradd_child("Language", "tt")->add_child_text(*_language); + cxml::add_child(asset, "Language", string("tt"))->add_child_text(*_language); } return asset; } diff --git a/src/reel_smpte_closed_caption_asset.h b/src/reel_smpte_closed_caption_asset.h index 32a79efd..e7a26f65 100644 --- a/src/reel_smpte_closed_caption_asset.h +++ b/src/reel_smpte_closed_caption_asset.h @@ -63,7 +63,7 @@ public: return asset_of_type(); } - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; private: diff --git a/src/reel_subtitle_asset.cc b/src/reel_subtitle_asset.cc index d856a05e..436aa69f 100644 --- a/src/reel_subtitle_asset.cc +++ b/src/reel_subtitle_asset.cc @@ -103,12 +103,12 @@ ReelSubtitleAsset::equals(shared_ptr other, EqualityOpt } -xmlpp::Node * -ReelSubtitleAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +xmlpp::Element * +ReelSubtitleAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const { auto asset = ReelFileAsset::write_to_cpl (node, standard); if (_language) { - asset->add_child("Language")->add_child_text(*_language); + cxml::add_text_child(asset, "Language", *_language); } return asset; } diff --git a/src/reel_subtitle_asset.h b/src/reel_subtitle_asset.h index 8b694fd6..c619c752 100644 --- a/src/reel_subtitle_asset.h +++ b/src/reel_subtitle_asset.h @@ -73,7 +73,7 @@ public: return asset_of_type(); } - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override; bool equals(std::shared_ptr, EqualityOptions const&, NoteHandler) const; diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 0ff1d7ef..06c91c0b 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -369,31 +369,31 @@ SMPTESubtitleAsset::xml_as_string () const auto root = doc.create_root_node ("SubtitleReel"); DCP_ASSERT (_xml_id); - root->add_child("Id")->add_child_text("urn:uuid:" + *_xml_id); - root->add_child("ContentTitleText")->add_child_text(_content_title_text); + cxml::add_text_child(root, "Id", "urn:uuid:" + *_xml_id); + cxml::add_text_child(root, "ContentTitleText", _content_title_text); if (_annotation_text) { - root->add_child("AnnotationText")->add_child_text(_annotation_text.get()); + cxml::add_text_child(root, "AnnotationText", _annotation_text.get()); } - root->add_child("IssueDate")->add_child_text(_issue_date.as_string(false, false)); + cxml::add_text_child(root, "IssueDate", _issue_date.as_string(false, false)); if (_reel_number) { - root->add_child("ReelNumber")->add_child_text(raw_convert(_reel_number.get())); + cxml::add_text_child(root, "ReelNumber", raw_convert(_reel_number.get())); } if (_language) { - root->add_child("Language")->add_child_text(_language.get()); + cxml::add_text_child(root, "Language", _language.get()); } - root->add_child("EditRate")->add_child_text(_edit_rate.as_string()); - root->add_child("TimeCodeRate")->add_child_text(raw_convert(_time_code_rate)); + cxml::add_text_child(root, "EditRate", _edit_rate.as_string()); + cxml::add_text_child(root, "TimeCodeRate", raw_convert(_time_code_rate)); if (_start_time) { - root->add_child("StartTime")->add_child_text(_start_time.get().as_string(Standard::SMPTE)); + cxml::add_text_child(root, "StartTime", _start_time.get().as_string(Standard::SMPTE)); } for (auto i: _load_font_nodes) { - auto load_font = root->add_child("LoadFont"); + auto load_font = cxml::add_child(root, "LoadFont"); load_font->add_child_text ("urn:uuid:" + i->urn); load_font->set_attribute ("ID", i->id); } - subtitles_as_xml (root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE); + subtitles_as_xml(cxml::add_child(root, "SubtitleList"), _time_code_rate, Standard::SMPTE); return format_xml(doc, std::make_pair(string{}, schema_namespace())); } diff --git a/src/subtitle_asset_internal.cc b/src/subtitle_asset_internal.cc index 99d8411b..39f68624 100644 --- a/src/subtitle_asset_internal.cc +++ b/src/subtitle_asset_internal.cc @@ -77,7 +77,7 @@ order::Font::Font (shared_ptr s, Standard standard) xmlpp::Element* order::Font::as_xml (xmlpp::Element* parent, Context&) const { - auto e = parent->add_child("Font"); + auto e = cxml::add_child(parent, "Font"); for (const auto& i: _values) { e->set_attribute (i.first, i.second); } @@ -137,7 +137,7 @@ xmlpp::Element* order::String::as_xml (xmlpp::Element* parent, Context& context) const { if (fabs(_space_before) > SPACE_BEFORE_EPSILON) { - auto space = parent->add_child("Space"); + auto space = cxml::add_child(parent, "Space"); auto size = raw_convert(_space_before, 2); if (context.standard == Standard::INTEROP) { size += "em"; @@ -212,7 +212,7 @@ position_align (xmlpp::Element* e, order::Context& context, HAlign h_align, floa xmlpp::Element* order::Text::as_xml (xmlpp::Element* parent, Context& context) const { - auto e = parent->add_child ("Text"); + auto e = cxml::add_child(parent, "Text"); position_align(e, context, _h_align, _h_position, _v_align, _v_position, _z_position); @@ -224,9 +224,9 @@ order::Text::as_xml (xmlpp::Element* parent, Context& context) const } for (auto const& ruby: _rubies) { - auto xml = e->add_child("Ruby"); - xml->add_child("Rb")->add_child_text(ruby.base); - auto rt = xml->add_child("Rt"); + auto xml = cxml::add_child(e, "Ruby"); + cxml::add_child(xml, "Rb")->add_child_text(ruby.base); + auto rt = cxml::add_child(xml, "Rt"); rt->add_child_text(ruby.annotation); rt->set_attribute("Size", dcp::raw_convert(ruby.size, 6)); rt->set_attribute("Position", ruby.position == RubyPosition::BEFORE ? "before" : "after"); @@ -242,7 +242,7 @@ order::Text::as_xml (xmlpp::Element* parent, Context& context) const xmlpp::Element* order::Subtitle::as_xml (xmlpp::Element* parent, Context& context) const { - auto e = parent->add_child ("Subtitle"); + auto e = cxml::add_child(parent, "Subtitle"); e->set_attribute ("SpotNumber", raw_convert (context.spot_number++)); e->set_attribute ("TimeIn", _in.rebase(context.time_code_rate).as_string(context.standard)); e->set_attribute ("TimeOut", _out.rebase(context.time_code_rate).as_string(context.standard)); @@ -274,7 +274,7 @@ order::Font::clear () xmlpp::Element * order::Image::as_xml (xmlpp::Element* parent, Context& context) const { - auto e = parent->add_child ("Image"); + auto e = cxml::add_child(parent, "Image"); position_align(e, context, _h_align, _h_position, _v_align, _v_position, _z_position); if (context.standard == Standard::SMPTE) { diff --git a/src/types.cc b/src/types.cc index f4bf8db0..c4ba8886 100644 --- a/src/types.cc +++ b/src/types.cc @@ -310,9 +310,9 @@ ContentVersion::ContentVersion (string label_text_) void ContentVersion::as_xml (xmlpp::Element* parent) const { - auto cv = parent->add_child("ContentVersion"); - cv->add_child("Id")->add_child_text(id); - cv->add_child("LabelText")->add_child_text(label_text); + auto cv = cxml::add_child(parent, "ContentVersion"); + cxml::add_text_child(cv, "Id", id); + cxml::add_text_child(cv, "LabelText", label_text); } @@ -345,7 +345,7 @@ Luminance::set_value (float v) void Luminance::as_xml (xmlpp::Element* parent, string ns) const { - auto lum = parent->add_child("Luminance", ns); + auto lum = cxml::add_child(parent, "Luminance", ns); lum->set_attribute("units", unit_to_string(_unit)); lum->add_child_text(raw_convert(_value, 3)); } diff --git a/test/shared_subtitle_test.cc b/test/shared_subtitle_test.cc index 7ac20e10..22ee7177 100644 --- a/test/shared_subtitle_test.cc +++ b/test/shared_subtitle_test.cc @@ -175,13 +175,13 @@ BOOST_AUTO_TEST_CASE (format_xml_test1) { xmlpp::Document doc; auto root = doc.create_root_node("Foo"); - root->add_child("Empty"); - root->add_child("Text")->add_child_text("Hello world"); - root->add_child("Font")->add_child("Text")->add_child_text("Say what"); - auto fred = root->add_child("Text")->add_child("Font"); + cxml::add_child(root, "Empty"); + cxml::add_text_child(root, "Text", "Hello world"); + cxml::add_text_child(cxml::add_child(root, "Font"), "Text", "Say what"); + auto fred = cxml::add_child(cxml::add_child(root, "Text"), "Font"); fred->set_attribute("bob", "job"); fred->add_child_text("Fred"); - fred->add_child("Text")->add_child_text("Jim"); + cxml::add_text_child(fred, "Text", "Jim"); fred->add_child_text("Sheila"); BOOST_REQUIRE_EQUAL (dcp::SubtitleAsset::format_xml(doc, make_pair(string{}, string{"fred"})), "\n" @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE (format_xml_entities_test) { xmlpp::Document doc; auto root = doc.create_root_node("Foo"); - root->add_child("Bar")->add_child_text("Don't panic & xml \"is\" 'great' & < > —"); + cxml::add_text_child(root, "Bar", "Don't panic & xml \"is\" 'great' & < > —"); BOOST_REQUIRE_EQUAL(dcp::SubtitleAsset::format_xml(doc, {}), "\n" "\n" -- 2.30.2