diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-09-18 23:32:44 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-09-18 23:32:44 +0100 |
| commit | c23087acc887289f04f927bf7ede352324f4081b (patch) | |
| tree | a54446dae4b875fa01dcfeadf9de7c26182e8a69 /src | |
| parent | 075cb794fbb5871d1a361995f5e55ca220316a02 (diff) | |
Some renaming of XML-related methods.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_map.cc | 26 | ||||
| -rw-r--r-- | src/cpl_file.cc | 100 | ||||
| -rw-r--r-- | src/pkl_file.cc | 24 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 26 | ||||
| -rw-r--r-- | src/xml.cc | 41 | ||||
| -rw-r--r-- | src/xml.h | 38 |
6 files changed, 128 insertions, 127 deletions
diff --git a/src/asset_map.cc b/src/asset_map.cc index 35f96c45..4d6b1870 100644 --- a/src/asset_map.cc +++ b/src/asset_map.cc @@ -31,26 +31,26 @@ using namespace libdcp; AssetMap::AssetMap (string file) : XMLFile (file, "AssetMap") { - id = string_node ("Id"); - creator = string_node ("Creator"); - volume_count = int64_node ("VolumeCount"); - issue_date = string_node ("IssueDate"); - issuer = string_node ("Issuer"); - assets = sub_nodes<AssetMapAsset> ("AssetList", "Asset"); + id = string_child ("Id"); + creator = string_child ("Creator"); + volume_count = int64_child ("VolumeCount"); + issue_date = string_child ("IssueDate"); + issuer = string_child ("Issuer"); + assets = type_grand_children<AssetMapAsset> ("AssetList", "Asset"); } AssetMapAsset::AssetMapAsset (xmlpp::Node const * node) : XMLNode (node) { - id = string_node ("Id"); - packing_list = optional_string_node ("PackingList"); - chunks = sub_nodes<Chunk> ("ChunkList", "Chunk"); + id = string_child ("Id"); + packing_list = optional_string_child ("PackingList"); + chunks = type_grand_children<Chunk> ("ChunkList", "Chunk"); } Chunk::Chunk (xmlpp::Node const * node) : XMLNode (node) { - path = string_node ("Path"); + path = string_child ("Path"); string const prefix = "file://"; @@ -58,9 +58,9 @@ Chunk::Chunk (xmlpp::Node const * node) path = path.substr (prefix.length()); } - volume_index = optional_int64_node ("VolumeIndex"); - offset = optional_int64_node ("Offset"); - length = optional_int64_node ("Length"); + volume_index = optional_int64_child ("VolumeIndex"); + offset = optional_int64_child ("Offset"); + length = optional_int64_child ("Length"); } shared_ptr<AssetMapAsset> diff --git a/src/cpl_file.cc b/src/cpl_file.cc index 0160ce2a..6a17d721 100644 --- a/src/cpl_file.cc +++ b/src/cpl_file.cc @@ -30,19 +30,19 @@ using namespace libdcp; CPLFile::CPLFile (string file) : XMLFile (file, "CompositionPlaylist") { - id = string_node ("Id"); - annotation_text = optional_string_node ("AnnotationText"); - issue_date = string_node ("IssueDate"); - creator = optional_string_node ("Creator"); - content_title_text = string_node ("ContentTitleText"); - content_kind = kind_node ("ContentKind"); - content_version = optional_sub_node<ContentVersion> ("ContentVersion"); - ignore_node ("RatingList"); - reels = sub_nodes<CPLReel> ("ReelList", "Reel"); - - ignore_node ("Issuer"); - ignore_node ("Signer"); - ignore_node ("Signature"); + id = string_child ("Id"); + annotation_text = optional_string_child ("AnnotationText"); + issue_date = string_child ("IssueDate"); + creator = optional_string_child ("Creator"); + content_title_text = string_child ("ContentTitleText"); + content_kind = kind_child ("ContentKind"); + content_version = optional_type_child<ContentVersion> ("ContentVersion"); + ignore_child ("RatingList"); + reels = type_grand_children<CPLReel> ("ReelList", "Reel"); + + ignore_child ("Issuer"); + ignore_child ("Signer"); + ignore_child ("Signature"); done (); } @@ -50,28 +50,28 @@ CPLFile::CPLFile (string file) ContentVersion::ContentVersion (xmlpp::Node const * node) : XMLNode (node) { - id = optional_string_node ("Id"); - label_text = string_node ("LabelText"); + id = optional_string_child ("Id"); + label_text = string_child ("LabelText"); done (); } CPLReel::CPLReel (xmlpp::Node const * node) : XMLNode (node) { - id = string_node ("Id"); - asset_list = sub_node<CPLAssetList> ("AssetList"); + id = string_child ("Id"); + asset_list = type_child<CPLAssetList> ("AssetList"); - ignore_node ("AnnotationText"); + ignore_child ("AnnotationText"); done (); } CPLAssetList::CPLAssetList (xmlpp::Node const * node) : XMLNode (node) { - main_picture = optional_sub_node<MainPicture> ("MainPicture"); - main_stereoscopic_picture = optional_sub_node<MainStereoscopicPicture> ("MainStereoscopicPicture"); - main_sound = optional_sub_node<MainSound> ("MainSound"); - main_subtitle = optional_sub_node<MainSubtitle> ("MainSubtitle"); + main_picture = optional_type_child<MainPicture> ("MainPicture"); + main_stereoscopic_picture = optional_type_child<MainStereoscopicPicture> ("MainStereoscopicPicture"); + main_sound = optional_type_child<MainSound> ("MainSound"); + main_subtitle = optional_type_child<MainSubtitle> ("MainSubtitle"); done (); } @@ -91,26 +91,26 @@ MainStereoscopicPicture::MainStereoscopicPicture (xmlpp::Node const * node) Picture::Picture (xmlpp::Node const * node) : XMLNode (node) { - id = string_node ("Id"); - annotation_text = optional_string_node ("AnnotationText"); - edit_rate = fraction_node ("EditRate"); - intrinsic_duration = int64_node ("IntrinsicDuration"); - entry_point = int64_node ("EntryPoint"); - duration = int64_node ("Duration"); - frame_rate = fraction_node ("FrameRate"); + id = string_child ("Id"); + annotation_text = optional_string_child ("AnnotationText"); + edit_rate = fraction_child ("EditRate"); + intrinsic_duration = int64_child ("IntrinsicDuration"); + entry_point = int64_child ("EntryPoint"); + duration = int64_child ("Duration"); + frame_rate = fraction_child ("FrameRate"); try { - screen_aspect_ratio = fraction_node ("ScreenAspectRatio"); + screen_aspect_ratio = fraction_child ("ScreenAspectRatio"); } catch (XMLError& e) { /* Maybe it's not a fraction */ } try { - float f = float_node ("ScreenAspectRatio"); + float f = float_child ("ScreenAspectRatio"); screen_aspect_ratio = Fraction (f * 1000, 1000); } catch (bad_cast& e) { } - ignore_node ("Hash"); + ignore_child ("Hash"); done (); } @@ -118,15 +118,15 @@ Picture::Picture (xmlpp::Node const * node) MainSound::MainSound (xmlpp::Node const * node) : XMLNode (node) { - id = string_node ("Id"); - annotation_text = optional_string_node ("AnnotationText"); - edit_rate = fraction_node ("EditRate"); - intrinsic_duration = int64_node ("IntrinsicDuration"); - entry_point = int64_node ("EntryPoint"); - duration = int64_node ("Duration"); - - ignore_node ("Hash"); - ignore_node ("Language"); + id = string_child ("Id"); + annotation_text = optional_string_child ("AnnotationText"); + edit_rate = fraction_child ("EditRate"); + intrinsic_duration = int64_child ("IntrinsicDuration"); + entry_point = int64_child ("EntryPoint"); + duration = int64_child ("Duration"); + + ignore_child ("Hash"); + ignore_child ("Language"); done (); } @@ -134,15 +134,15 @@ MainSound::MainSound (xmlpp::Node const * node) MainSubtitle::MainSubtitle (xmlpp::Node const * node) : XMLNode (node) { - id = string_node ("Id"); - annotation_text = optional_string_node ("AnnotationText"); - edit_rate = fraction_node ("EditRate"); - intrinsic_duration = int64_node ("IntrinsicDuration"); - entry_point = int64_node ("EntryPoint"); - duration = int64_node ("Duration"); - - ignore_node ("Hash"); - ignore_node ("Language"); + id = string_child ("Id"); + annotation_text = optional_string_child ("AnnotationText"); + edit_rate = fraction_child ("EditRate"); + intrinsic_duration = int64_child ("IntrinsicDuration"); + entry_point = int64_child ("EntryPoint"); + duration = int64_child ("Duration"); + + ignore_child ("Hash"); + ignore_child ("Language"); done (); } diff --git a/src/pkl_file.cc b/src/pkl_file.cc index d823e585..21763f27 100644 --- a/src/pkl_file.cc +++ b/src/pkl_file.cc @@ -31,21 +31,21 @@ using namespace libdcp; PKLFile::PKLFile (string file) : XMLFile (file, "PackingList") { - id = string_node ("Id"); - annotation_text = string_node ("AnnotationText"); - issue_date = string_node ("IssueDate"); - issuer = string_node ("Issuer"); - creator = string_node ("Creator"); - assets = sub_nodes<PKLAsset> ("AssetList", "Asset"); + id = string_child ("Id"); + annotation_text = string_child ("AnnotationText"); + issue_date = string_child ("IssueDate"); + issuer = string_child ("Issuer"); + creator = string_child ("Creator"); + assets = type_grand_children<PKLAsset> ("AssetList", "Asset"); } PKLAsset::PKLAsset (xmlpp::Node const * node) : XMLNode (node) { - id = string_node ("Id"); - annotation_text = optional_string_node ("AnnotationText"); - hash = string_node ("Hash"); - size = int64_node ("Size"); - type = string_node ("Type"); - original_file_name = optional_string_node ("OriginalFileName"); + id = string_child ("Id"); + annotation_text = optional_string_child ("AnnotationText"); + hash = string_child ("Hash"); + size = int64_child ("Size"); + type = string_child ("Type"); + original_file_name = optional_string_child ("OriginalFileName"); } diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index b7586207..0d89546e 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -29,15 +29,15 @@ SubtitleAsset::SubtitleAsset (string directory, string xml) : Asset (directory, xml) , XMLFile (path().string(), "DCSubtitle") { - _subtitle_id = string_node ("SubtitleID"); - _movie_title = string_node ("MovieTitle"); - _reel_number = int64_node ("ReelNumber"); - _language = string_node ("Language"); + _subtitle_id = string_child ("SubtitleID"); + _movie_title = string_child ("MovieTitle"); + _reel_number = int64_child ("ReelNumber"); + _language = string_child ("Language"); - ignore_node ("LoadFont"); + ignore_child ("LoadFont"); - list<shared_ptr<FontNode> > font_nodes = sub_nodes<FontNode> ("Font"); - _load_font_nodes = sub_nodes<LoadFontNode> ("LoadFont"); + list<shared_ptr<FontNode> > font_nodes = type_children<FontNode> ("Font"); + _load_font_nodes = type_children<LoadFontNode> ("LoadFont"); /* Now make Subtitle objects to represent the raw XML nodes in a sane way. @@ -145,9 +145,9 @@ FontNode::FontNode (xmlpp::Node const * node) throw DCPReadError ("unknown subtitle effect type"); } effect_color = optional_color_attribute ("EffectColor"); - subtitle_nodes = sub_nodes<SubtitleNode> ("Subtitle"); - font_nodes = sub_nodes<FontNode> ("Font"); - text_nodes = sub_nodes<TextNode> ("Text"); + subtitle_nodes = type_children<SubtitleNode> ("Subtitle"); + font_nodes = type_children<FontNode> ("Font"); + text_nodes = type_children<TextNode> ("Text"); } FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes) @@ -191,8 +191,8 @@ SubtitleNode::SubtitleNode (xmlpp::Node const * node) { in = time_attribute ("TimeIn"); out = time_attribute ("TimeOut"); - font_nodes = sub_nodes<FontNode> ("Font"); - text_nodes = sub_nodes<TextNode> ("Text"); + font_nodes = type_children<FontNode> ("Font"); + text_nodes = type_children<TextNode> ("Text"); fade_up_time = fade_time ("FadeUpTime"); fade_down_time = fade_time ("FadeDownTime"); } @@ -233,7 +233,7 @@ TextNode::TextNode (xmlpp::Node const * node) v_align = BOTTOM; } - font_nodes = sub_nodes<FontNode> ("Font"); + font_nodes = type_children<FontNode> ("Font"); } list<shared_ptr<Subtitle> > @@ -25,9 +25,9 @@ XMLNode::XMLNode (xmlpp::Node const * node) } xmlpp::Node * -XMLNode::xml_node (string name) +XMLNode::node_child (string name) { - list<xmlpp::Node*> n = xml_nodes (name); + list<xmlpp::Node*> n = node_children (name); if (n.size() > 1) { throw XMLError ("duplicate XML tag " + name); } else if (n.empty ()) { @@ -38,7 +38,7 @@ XMLNode::xml_node (string name) } list<xmlpp::Node*> -XMLNode::xml_nodes (string name) +XMLNode::node_children (string name) { /* XXX: using find / get_path should work here, but I can't follow how get_path works. @@ -58,15 +58,15 @@ XMLNode::xml_nodes (string name) } string -XMLNode::string_node (string name) +XMLNode::string_child (string name) { - return XMLNode (xml_node (name)).content (); + return XMLNode (node_child (name)).content (); } string -XMLNode::optional_string_node (string name) +XMLNode::optional_string_child (string name) { - list<xmlpp::Node*> nodes = xml_nodes (name); + list<xmlpp::Node*> nodes = node_children (name); if (nodes.size() > 2) { throw XMLError ("duplicate XML tag " + name); } @@ -75,33 +75,33 @@ XMLNode::optional_string_node (string name) return ""; } - return string_node (name); + return string_child (name); } ContentKind -XMLNode::kind_node (string name) +XMLNode::kind_child (string name) { - return content_kind_from_string (string_node (name)); + return content_kind_from_string (string_child (name)); } Fraction -XMLNode::fraction_node (string name) +XMLNode::fraction_child (string name) { - return Fraction (string_node (name)); + return Fraction (string_child (name)); } int64_t -XMLNode::int64_node (string name) +XMLNode::int64_child (string name) { - string s = string_node (name); + string s = string_child (name); erase_all (s, " "); return lexical_cast<int64_t> (s); } int64_t -XMLNode::optional_int64_node (string name) +XMLNode::optional_int64_child (string name) { - list<xmlpp::Node*> nodes = xml_nodes (name); + list<xmlpp::Node*> nodes = node_children (name); if (nodes.size() > 2) { throw XMLError ("duplicate XML tag " + name); } @@ -110,17 +110,18 @@ XMLNode::optional_int64_node (string name) return 0; } - return int64_node (name); + return int64_child (name); } float -XMLNode::float_node (string name) +XMLNode::float_child (string name) { - return lexical_cast<float> (string_node (name)); + cout << "float node of " << string_child(name) << " for " << name << "\n"; + return lexical_cast<float> (string_child (name)); } void -XMLNode::ignore_node (string name) +XMLNode::ignore_child (string name) { _taken.push_back (name); } @@ -25,14 +25,14 @@ public: XMLNode (xmlpp::Node const * node); protected: - std::string string_node (std::string); - std::string optional_string_node (std::string); - ContentKind kind_node (std::string); - Fraction fraction_node (std::string); - int64_t int64_node (std::string); - int64_t optional_int64_node (std::string); - float float_node (std::string); - void ignore_node (std::string); + std::string string_child (std::string); + std::string optional_string_child (std::string); + ContentKind kind_child (std::string); + Fraction fraction_child (std::string); + int64_t int64_child (std::string); + int64_t optional_int64_child (std::string); + float float_child (std::string); + void ignore_child (std::string); void done (); Time time_attribute (std::string); @@ -47,13 +47,13 @@ protected: std::string content (); template <class T> - boost::shared_ptr<T> sub_node (std::string name) { - return boost::shared_ptr<T> (new T (xml_node (name))); + boost::shared_ptr<T> type_child (std::string name) { + return boost::shared_ptr<T> (new T (node_child (name))); } template <class T> - boost::shared_ptr<T> optional_sub_node (std::string name) { - std::list<xmlpp::Node*> n = xml_nodes (name); + boost::shared_ptr<T> optional_type_child (std::string name) { + std::list<xmlpp::Node*> n = node_children (name); if (n.size() > 1) { throw XMLError ("duplicate XML tag"); } else if (n.empty ()) { @@ -64,8 +64,8 @@ protected: } template <class T> - std::list<boost::shared_ptr<T> > sub_nodes (std::string name) { - std::list<xmlpp::Node*> n = xml_nodes (name); + std::list<boost::shared_ptr<T> > type_children (std::string name) { + std::list<xmlpp::Node*> n = node_children (name); std::list<boost::shared_ptr<T> > r; for (typename std::list<xmlpp::Node*>::iterator i = n.begin(); i != n.end(); ++i) { r.push_back (boost::shared_ptr<T> (new T (*i))); @@ -74,16 +74,16 @@ protected: } template <class T> - std::list<boost::shared_ptr<T> > sub_nodes (std::string name, std::string sub) { - XMLNode p (xml_node (name)); - return p.sub_nodes<T> (sub); + std::list<boost::shared_ptr<T> > type_grand_children (std::string name, std::string sub) { + XMLNode p (node_child (name)); + return p.type_children<T> (sub); } xmlpp::Node const * _node; private: - xmlpp::Node* xml_node (std::string); - std::list<xmlpp::Node*> xml_nodes (std::string); + xmlpp::Node* node_child (std::string); + std::list<xmlpp::Node*> node_children (std::string); std::list<Glib::ustring> _taken; }; |
