diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-05-13 14:20:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-05-13 14:20:36 +0100 |
| commit | 797916ae28d976f3c5be62d37b45864219af6098 (patch) | |
| tree | a9bf9231987085c0eb9b6c3ce7427e1489929ec8 /src | |
| parent | d77d0d1bd972f6343752ca45a3d5e0a0924e2d50 (diff) | |
Use libcxml. Lump all static configuration flags into one.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_map.cc | 36 | ||||
| -rw-r--r-- | src/asset_map.h | 12 | ||||
| -rw-r--r-- | src/cpl_file.cc | 147 | ||||
| -rw-r--r-- | src/cpl_file.h | 35 | ||||
| -rw-r--r-- | src/pkl_file.cc | 30 | ||||
| -rw-r--r-- | src/pkl_file.h | 6 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 88 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 22 | ||||
| -rw-r--r-- | src/wscript | 8 | ||||
| -rw-r--r-- | src/xml.cc | 263 | ||||
| -rw-r--r-- | src/xml.h | 156 |
11 files changed, 265 insertions, 538 deletions
diff --git a/src/asset_map.cc b/src/asset_map.cc index 8fcc515f..fb42f363 100644 --- a/src/asset_map.cc +++ b/src/asset_map.cc @@ -24,6 +24,7 @@ #include <boost/algorithm/string.hpp> #include "asset_map.h" #include "util.h" +#include "xml.h" using std::string; using std::list; @@ -31,28 +32,27 @@ using boost::shared_ptr; using namespace libdcp; AssetMap::AssetMap (string file) - : XMLFile (file, "AssetMap") { - 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"); + cxml::File f (file, "AssetMap"); + + id = f.string_child ("Id"); + creator = f.string_child ("Creator"); + volume_count = f.number_child<int64_t> ("VolumeCount"); + issue_date = f.string_child ("IssueDate"); + issuer = f.string_child ("Issuer"); + assets = type_grand_children<AssetMapAsset> (f, "AssetList", "Asset"); } -AssetMapAsset::AssetMapAsset (xmlpp::Node const * node) - : XMLNode (node) +AssetMapAsset::AssetMapAsset (shared_ptr<const cxml::Node> node) { - id = string_child ("Id"); - packing_list = optional_string_child ("PackingList"); - chunks = type_grand_children<Chunk> ("ChunkList", "Chunk"); + id = node->string_child ("Id"); + packing_list = node->optional_string_child ("PackingList").get_value_or (""); + chunks = type_grand_children<Chunk> (node, "ChunkList", "Chunk"); } -Chunk::Chunk (xmlpp::Node const * node) - : XMLNode (node) +Chunk::Chunk (shared_ptr<const cxml::Node> node) { - path = string_child ("Path"); + path = node->string_child ("Path"); string const prefix = "file://"; @@ -60,9 +60,9 @@ Chunk::Chunk (xmlpp::Node const * node) path = path.substr (prefix.length()); } - volume_index = optional_int64_child ("VolumeIndex"); - offset = optional_int64_child ("Offset"); - length = optional_int64_child ("Length"); + volume_index = node->optional_number_child<int64_t> ("VolumeIndex").get_value_or (0); + offset = node->optional_number_child<int64_t> ("Offset").get_value_or (0); + length = node->optional_number_child<int64_t> ("Length").get_value_or (0); } shared_ptr<AssetMapAsset> diff --git a/src/asset_map.h b/src/asset_map.h index 8cf89b4b..e7ba6978 100644 --- a/src/asset_map.h +++ b/src/asset_map.h @@ -23,18 +23,18 @@ #include <stdint.h> #include <boost/shared_ptr.hpp> -#include "xml.h" +#include <libcxml/cxml.h> namespace libdcp { /** @class Chunk * @brief A simple parser for and representation of a \<Chunk\> node within an asset map. */ -class Chunk : public XMLNode +class Chunk { public: Chunk (); - Chunk (xmlpp::Node const * node); + Chunk (boost::shared_ptr<const cxml::Node> node); std::string path; int64_t volume_index; @@ -45,11 +45,11 @@ public: /** @class AssetMapAsset * @brief A simple parser for and representation of an \<AssetMap\> node within an asset map. */ -class AssetMapAsset : public XMLNode +class AssetMapAsset { public: AssetMapAsset (); - AssetMapAsset (xmlpp::Node const * node); + AssetMapAsset (boost::shared_ptr<const cxml::Node> node); std::string id; std::string packing_list; @@ -59,7 +59,7 @@ public: /** @class AssetMap * @brief A simple parser for and representation of an asset map file. */ -class AssetMap : public XMLFile +class AssetMap { public: AssetMap (std::string file); diff --git a/src/cpl_file.cc b/src/cpl_file.cc index 6a17d721..3126b99c 100644 --- a/src/cpl_file.cc +++ b/src/cpl_file.cc @@ -23,126 +23,125 @@ #include <iostream> #include "cpl_file.h" +#include "xml.h" +#include "util.h" -using namespace std; +using std::string; +using std::bad_cast; +using boost::shared_ptr; using namespace libdcp; CPLFile::CPLFile (string file) - : XMLFile (file, "CompositionPlaylist") { - 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 (); + cxml::File f (file, "CompositionPlaylist"); + + id = f.string_child ("Id"); + annotation_text = f.optional_string_child ("AnnotationText").get_value_or (""); + issue_date = f.string_child ("IssueDate"); + creator = f.optional_string_child ("Creator").get_value_or (""); + content_title_text = f.string_child ("ContentTitleText"); + content_kind = content_kind_from_string (f.string_child ("ContentKind")); + content_version = optional_type_child<ContentVersion> (f, "ContentVersion"); + f.ignore_child ("RatingList"); + reels = type_grand_children<CPLReel> (f, "ReelList", "Reel"); + + f.ignore_child ("Issuer"); + f.ignore_child ("Signer"); + f.ignore_child ("Signature"); + + f.done (); } -ContentVersion::ContentVersion (xmlpp::Node const * node) - : XMLNode (node) +ContentVersion::ContentVersion (shared_ptr<const cxml::Node> node) { - id = optional_string_child ("Id"); - label_text = string_child ("LabelText"); - done (); + id = node->optional_string_child ("Id").get_value_or (""); + label_text = node->string_child ("LabelText"); + node->done (); } -CPLReel::CPLReel (xmlpp::Node const * node) - : XMLNode (node) +CPLReel::CPLReel (shared_ptr<const cxml::Node> node) { - id = string_child ("Id"); - asset_list = type_child<CPLAssetList> ("AssetList"); + id = node->string_child ("Id"); + asset_list = type_child<CPLAssetList> (node, "AssetList"); - ignore_child ("AnnotationText"); - done (); + node->ignore_child ("AnnotationText"); + node->done (); } -CPLAssetList::CPLAssetList (xmlpp::Node const * node) - : XMLNode (node) +CPLAssetList::CPLAssetList (shared_ptr<const cxml::Node> node) { - 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"); + main_picture = optional_type_child<MainPicture> (node, "MainPicture"); + main_stereoscopic_picture = optional_type_child<MainStereoscopicPicture> (node, "MainStereoscopicPicture"); + main_sound = optional_type_child<MainSound> (node, "MainSound"); + main_subtitle = optional_type_child<MainSubtitle> (node, "MainSubtitle"); - done (); + node->done (); } -MainPicture::MainPicture (xmlpp::Node const * node) +MainPicture::MainPicture (shared_ptr<const cxml::Node> node) : Picture (node) { } -MainStereoscopicPicture::MainStereoscopicPicture (xmlpp::Node const * node) +MainStereoscopicPicture::MainStereoscopicPicture (shared_ptr<const cxml::Node> node) : Picture (node) { } -Picture::Picture (xmlpp::Node const * node) - : XMLNode (node) +Picture::Picture (shared_ptr<const cxml::Node> node) { - 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"); + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + edit_rate = Fraction (node->string_child ("EditRate")); + intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration"); + entry_point = node->number_child<int64_t> ("EntryPoint"); + duration = node->number_child<int64_t> ("Duration"); + frame_rate = Fraction (node->string_child ("FrameRate")); try { - screen_aspect_ratio = fraction_child ("ScreenAspectRatio"); + screen_aspect_ratio = Fraction (node->string_child ("ScreenAspectRatio")); } catch (XMLError& e) { /* Maybe it's not a fraction */ } try { - float f = float_child ("ScreenAspectRatio"); + float f = node->number_child<float> ("ScreenAspectRatio"); screen_aspect_ratio = Fraction (f * 1000, 1000); } catch (bad_cast& e) { } - ignore_child ("Hash"); + node->ignore_child ("Hash"); - done (); + node->done (); } -MainSound::MainSound (xmlpp::Node const * node) - : XMLNode (node) +MainSound::MainSound (shared_ptr<const cxml::Node> node) { - 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"); + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + edit_rate = Fraction (node->string_child ("EditRate")); + intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration"); + entry_point = node->number_child<int64_t> ("EntryPoint"); + duration = node->number_child<int64_t> ("Duration"); + + node->ignore_child ("Hash"); + node->ignore_child ("Language"); - done (); + node->done (); } -MainSubtitle::MainSubtitle (xmlpp::Node const * node) - : XMLNode (node) +MainSubtitle::MainSubtitle (shared_ptr<const cxml::Node> node) { - 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"); + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + edit_rate = Fraction (node->string_child ("EditRate")); + intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration"); + entry_point = node->number_child<int64_t> ("EntryPoint"); + duration = node->number_child<int64_t> ("Duration"); + + node->ignore_child ("Hash"); + node->ignore_child ("Language"); - done (); + node->done (); } diff --git a/src/cpl_file.h b/src/cpl_file.h index 44115401..b17f47cd 100644 --- a/src/cpl_file.h +++ b/src/cpl_file.h @@ -23,16 +23,17 @@ #include <stdint.h> #include <boost/shared_ptr.hpp> -#include "xml.h" +#include <libcxml/cxml.h> +#include "types.h" namespace libdcp { -/** @brief A simple parser for and representation of a CPL \<Picture\> node */ -class Picture : public XMLNode +/** @brief A simple representation of a CPL \<Picture\> node */ +class Picture { public: Picture () {} - Picture (xmlpp::Node const * node); + Picture (boost::shared_ptr<const cxml::Node> node); std::string id; std::string annotation_text; @@ -53,7 +54,7 @@ class MainPicture : public Picture { public: MainPicture () {} - MainPicture (xmlpp::Node const * node); + MainPicture (boost::shared_ptr<const cxml::Node> node); }; /** @brief A simple parser for and representation of a CPL \<MainStereoscopicPicture\> node */ @@ -61,15 +62,15 @@ class MainStereoscopicPicture : public Picture { public: MainStereoscopicPicture () {} - MainStereoscopicPicture (xmlpp::Node const * node); + MainStereoscopicPicture (boost::shared_ptr<const cxml::Node> node); }; /** @brief A simple parser for and representation of a CPL \<MainSound\> node */ -class MainSound : public XMLNode +class MainSound { public: MainSound () {} - MainSound (xmlpp::Node const * node); + MainSound (boost::shared_ptr<const cxml::Node> node); std::string id; std::string annotation_text; @@ -80,11 +81,11 @@ public: }; /** @brief A simple parser for and representation of a CPL \<MainSubtitle\> node */ -class MainSubtitle : public XMLNode +class MainSubtitle { public: MainSubtitle () {} - MainSubtitle (xmlpp::Node const * node); + MainSubtitle (boost::shared_ptr<const cxml::Node> node); std::string id; std::string annotation_text; @@ -95,11 +96,11 @@ public: }; /** @brief A simple parser for and representation of a CPL \<AssetList\> node */ -class CPLAssetList : public XMLNode +class CPLAssetList { public: CPLAssetList () {} - CPLAssetList (xmlpp::Node const * node); + CPLAssetList (boost::shared_ptr<const cxml::Node> node); boost::shared_ptr<MainPicture> main_picture; boost::shared_ptr<MainStereoscopicPicture> main_stereoscopic_picture; @@ -108,11 +109,11 @@ public: }; /** @brief A simple parser for and representation of a CPL \<Reel\> node */ -class CPLReel : public XMLNode +class CPLReel { public: CPLReel () {} - CPLReel (xmlpp::Node const * node); + CPLReel (boost::shared_ptr<const cxml::Node> node); std::string id; boost::shared_ptr<CPLAssetList> asset_list; @@ -120,11 +121,11 @@ public: /** @brief A simple parser for and representation of a CPL \<ContentVersion\> node */ -class ContentVersion : public XMLNode +class ContentVersion { public: ContentVersion () {} - ContentVersion (xmlpp::Node const * node); + ContentVersion (boost::shared_ptr<const cxml::Node> node); std::string id; std::string label_text; @@ -136,7 +137,7 @@ public: * This class is used to parse XML CPL files. It is rarely necessary * for the caller to use it outside libdcp. */ -class CPLFile : public XMLFile +class CPLFile { public: /** Parse a CPL XML file into our member variables */ diff --git a/src/pkl_file.cc b/src/pkl_file.cc index 6dfb627c..9119d883 100644 --- a/src/pkl_file.cc +++ b/src/pkl_file.cc @@ -29,23 +29,23 @@ using namespace boost; using namespace libdcp; PKLFile::PKLFile (string file) - : XMLFile (file, "PackingList") { - id = string_child ("Id"); - annotation_text = optional_string_child ("AnnotationText"); - issue_date = string_child ("IssueDate"); - issuer = string_child ("Issuer"); - creator = string_child ("Creator"); - assets = type_grand_children<PKLAsset> ("AssetList", "Asset"); + cxml::File f (file, "PackingList"); + + id = f.string_child ("Id"); + annotation_text = f.optional_string_child ("AnnotationText").get_value_or (""); + issue_date = f.string_child ("IssueDate"); + issuer = f.string_child ("Issuer"); + creator = f.string_child ("Creator"); + assets = type_grand_children<PKLAsset> (f, "AssetList", "Asset"); } -PKLAsset::PKLAsset (xmlpp::Node const * node) - : XMLNode (node) +PKLAsset::PKLAsset (boost::shared_ptr<const cxml::Node> node) { - 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"); + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + hash = node->string_child ("Hash"); + size = node->number_child<int64_t> ("Size"); + type = node->string_child ("Type"); + original_file_name = node->optional_string_child ("OriginalFileName").get_value_or (""); } diff --git a/src/pkl_file.h b/src/pkl_file.h index b64da5da..77b83fca 100644 --- a/src/pkl_file.h +++ b/src/pkl_file.h @@ -26,11 +26,11 @@ namespace libdcp { -class PKLAsset : public XMLNode +class PKLAsset { public: PKLAsset () {} - PKLAsset (xmlpp::Node const * node); + PKLAsset (boost::shared_ptr<const cxml::Node>); std::string id; std::string annotation_text; @@ -40,7 +40,7 @@ public: std::string original_file_name; }; -class PKLFile : public XMLFile +class PKLFile { public: PKLFile (std::string file); diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index ba91cf90..1eae1fcc 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -22,6 +22,7 @@ #include <boost/algorithm/string.hpp> #include "subtitle_asset.h" #include "util.h" +#include "xml.h" using std::string; using std::list; @@ -30,6 +31,7 @@ using std::ofstream; using std::stringstream; using boost::shared_ptr; using boost::lexical_cast; +using boost::optional; using namespace libdcp; SubtitleAsset::SubtitleAsset (string directory, string xml_file) @@ -52,7 +54,7 @@ SubtitleAsset::SubtitleAsset (string directory, string movie_title, string langu void SubtitleAsset::read_xml (string xml_file) { - shared_ptr<XMLFile> xml (new XMLFile (xml_file, "DCSubtitle")); + shared_ptr<cxml::File> xml (new cxml::File (xml_file, "DCSubtitle")); _uuid = xml->string_child ("SubtitleID"); _movie_title = xml->string_child ("MovieTitle"); @@ -61,8 +63,8 @@ SubtitleAsset::read_xml (string xml_file) xml->ignore_child ("LoadFont"); - list<shared_ptr<FontNode> > font_nodes = xml->type_children<FontNode> ("Font"); - _load_font_nodes = xml->type_children<LoadFontNode> ("LoadFont"); + list<shared_ptr<FontNode> > font_nodes = type_children<FontNode> (xml, "Font"); + _load_font_nodes = type_children<LoadFontNode> (xml, "LoadFont"); /* Now make Subtitle objects to represent the raw XML nodes in a sane way. @@ -74,7 +76,7 @@ SubtitleAsset::read_xml (string xml_file) void SubtitleAsset::examine_font_nodes ( - shared_ptr<XMLFile> xml, + shared_ptr<const cxml::Node> xml, list<shared_ptr<FontNode> > const & font_nodes, ParseState& parse_state ) @@ -100,7 +102,7 @@ SubtitleAsset::examine_font_nodes ( void SubtitleAsset::examine_text_nodes ( - shared_ptr<XMLFile> xml, + shared_ptr<const cxml::Node> xml, list<shared_ptr<TextNode> > const & text_nodes, ParseState& parse_state ) @@ -152,23 +154,28 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state) ); } -FontNode::FontNode (xmlpp::Node const * node) - : XMLNode (node) +FontNode::FontNode (shared_ptr<const cxml::Node> node) { - text = content (); + text = node->content (); - id = optional_string_attribute ("Id"); - size = optional_int64_attribute ("Size"); - italic = optional_bool_attribute ("Italic"); - color = optional_color_attribute ("Color"); - string const e = optional_string_attribute ("Effect"); - if (!e.empty ()) { - effect = string_to_effect (e); + id = node->optional_string_attribute ("Id").get_value_or (""); + size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0); + italic = node->optional_bool_attribute ("Italic").get_value_or (false); + optional<string> c = node->optional_string_attribute ("Color"); + if (c) { + color = Color (c.get ()); } - effect_color = optional_color_attribute ("EffectColor"); - subtitle_nodes = type_children<SubtitleNode> ("Subtitle"); - font_nodes = type_children<FontNode> ("Font"); - text_nodes = type_children<TextNode> ("Text"); + optional<string> const e = node->optional_string_attribute ("Effect"); + if (e) { + effect = string_to_effect (e.get ()); + } + c = node->optional_string_attribute ( "EffectColor"); + if (c) { + effect_color = Color (c.get ()); + } + subtitle_nodes = type_children<SubtitleNode> (node, "Subtitle"); + font_nodes = type_children<FontNode> (node, "Font"); + text_nodes = type_children<TextNode> (node, "Text"); } FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes) @@ -199,29 +206,27 @@ FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes) } } -LoadFontNode::LoadFontNode (xmlpp::Node const * node) - : XMLNode (node) +LoadFontNode::LoadFontNode (shared_ptr<const cxml::Node> node) { - id = string_attribute ("Id"); - uri = string_attribute ("URI"); + id = node->string_attribute ("Id"); + uri = node->string_attribute ("URI"); } -SubtitleNode::SubtitleNode (xmlpp::Node const * node) - : XMLNode (node) +SubtitleNode::SubtitleNode (shared_ptr<const cxml::Node> node) { - in = time_attribute ("TimeIn"); - out = time_attribute ("TimeOut"); - font_nodes = type_children<FontNode> ("Font"); - text_nodes = type_children<TextNode> ("Text"); - fade_up_time = fade_time ("FadeUpTime"); - fade_down_time = fade_time ("FadeDownTime"); + in = Time (node->string_attribute ("TimeIn")); + out = Time (node->string_attribute ("TimeOut")); + font_nodes = type_children<FontNode> (node, "Font"); + text_nodes = type_children<TextNode> (node, "Text"); + fade_up_time = fade_time (node, "FadeUpTime"); + fade_down_time = fade_time (node, "FadeDownTime"); } Time -SubtitleNode::fade_time (string name) +SubtitleNode::fade_time (shared_ptr<const cxml::Node> node, string name) { - string const u = optional_string_attribute (name); + string const u = node->optional_string_attribute (name).get_value_or (""); Time t; if (u.empty ()) { @@ -239,18 +244,17 @@ SubtitleNode::fade_time (string name) return t; } -TextNode::TextNode (xmlpp::Node const * node) - : XMLNode (node) - , v_align (CENTER) +TextNode::TextNode (shared_ptr<const cxml::Node> node) + : v_align (CENTER) { - text = content (); - v_position = float_attribute ("VPosition"); - string const v = optional_string_attribute ("VAlign"); - if (!v.empty ()) { - v_align = string_to_valign (v); + text = node->content (); + v_position = node->number_attribute<float> ("VPosition"); + optional<string> v = node->optional_string_attribute ("VAlign"); + if (v) { + v_align = string_to_valign (v.get ()); } - font_nodes = type_children<FontNode> ("Font"); + font_nodes = type_children<FontNode> (node, "Font"); } list<shared_ptr<Subtitle> > diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 1e31df2b..591985d1 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -26,11 +26,11 @@ namespace libdcp class FontNode; -class TextNode : public XMLNode +class TextNode { public: TextNode () {} - TextNode (xmlpp::Node const * node); + TextNode (boost::shared_ptr<const cxml::Node> node); float v_position; VAlign v_align; @@ -38,11 +38,11 @@ public: std::list<boost::shared_ptr<FontNode> > font_nodes; }; -class SubtitleNode : public XMLNode +class SubtitleNode { public: SubtitleNode () {} - SubtitleNode (xmlpp::Node const * node); + SubtitleNode (boost::shared_ptr<const cxml::Node> node); Time in; Time out; @@ -52,14 +52,14 @@ public: std::list<boost::shared_ptr<TextNode> > text_nodes; private: - Time fade_time (std::string name); + Time fade_time (boost::shared_ptr<const cxml::Node>, std::string name); }; -class FontNode : public XMLNode +class FontNode { public: FontNode () {} - FontNode (xmlpp::Node const * node); + FontNode (boost::shared_ptr<const cxml::Node> node); FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes); std::string text; @@ -75,11 +75,11 @@ public: std::list<boost::shared_ptr<TextNode> > text_nodes; }; -class LoadFontNode : public XMLNode +class LoadFontNode { public: LoadFontNode () {} - LoadFontNode (xmlpp::Node const * node); + LoadFontNode (boost::shared_ptr<const cxml::Node> node); std::string id; std::string uri; @@ -218,13 +218,13 @@ private: void maybe_add_subtitle (std::string text, ParseState const & parse_state); void examine_font_nodes ( - boost::shared_ptr<XMLFile> xml, + boost::shared_ptr<const cxml::Node> xml, std::list<boost::shared_ptr<FontNode> > const & font_nodes, ParseState& parse_state ); void examine_text_nodes ( - boost::shared_ptr<XMLFile> xml, + boost::shared_ptr<const cxml::Node> xml, std::list<boost::shared_ptr<TextNode> > const & text_nodes, ParseState& parse_state ); diff --git a/src/wscript b/src/wscript index 81c39926..fb8f688e 100644 --- a/src/wscript +++ b/src/wscript @@ -1,5 +1,5 @@ def build(bld): - if bld.env.STATIC_LIBDCP: + if bld.env.STATIC: obj = bld(features = 'cxx cxxstlib') else: obj = bld(features = 'cxx cxxshlib') @@ -7,7 +7,7 @@ def build(bld): obj.name = 'libdcp' obj.target = 'dcp' obj.export_includes = ['.'] - obj.uselib = 'BOOST_FILESYSTEM BOOST_SIGNALS2 OPENSSL SIGC++ LIBXML++ OPENJPEG' + obj.uselib = 'BOOST_FILESYSTEM BOOST_SIGNALS2 OPENSSL SIGC++ LIBXML++ OPENJPEG CXML' obj.use = 'libkumu-libdcp libasdcp-libdcp' obj.source = """ asset.cc @@ -30,7 +30,6 @@ def build(bld): types.cc util.cc version.cc - xml.cc """ headers = """ @@ -51,9 +50,8 @@ def build(bld): types.h util.h version.h - xml.h """ bld.install_files('${PREFIX}/include/libdcp', headers) - if bld.env.STATIC_LIBDCP: + if bld.env.STATIC: bld.install_files('${PREFIX}/lib', 'libdcp.a') diff --git a/src/xml.cc b/src/xml.cc deleted file mode 100644 index 508790ab..00000000 --- a/src/xml.cc +++ /dev/null @@ -1,263 +0,0 @@ -#include <sstream> -#include <iostream> -#include <boost/lexical_cast.hpp> -#include <boost/filesystem.hpp> -#include <boost/algorithm/string.hpp> -#include <libxml++/libxml++.h> -#include "xml.h" -#include "exceptions.h" -#include "util.h" - -using namespace std; -using namespace boost; -using namespace libdcp; - -XMLNode::XMLNode () - : _node (0) -{ - -} - -XMLNode::XMLNode (xmlpp::Node const * node) - : _node (node) -{ - -} - -xmlpp::Node * -XMLNode::node_child (string name) -{ - list<xmlpp::Node*> n = node_children (name); - if (n.size() > 1) { - boost::throw_exception (XMLError ("duplicate XML tag " + name)); - } else if (n.empty ()) { - boost::throw_exception (XMLError ("missing XML tag " + name + " in " + _node->get_name())); - } - - return n.front (); -} - -list<xmlpp::Node*> -XMLNode::node_children (string name) -{ - /* XXX: using find / get_path should work here, but I can't follow - how get_path works. - */ - - xmlpp::Node::NodeList c = _node->get_children (); - - list<xmlpp::Node*> n; - for (xmlpp::Node::NodeList::iterator i = c.begin (); i != c.end(); ++i) { - if ((*i)->get_name() == name) { - n.push_back (*i); - } - } - - _taken.push_back (name); - return n; -} - -string -XMLNode::string_child (string name) -{ - return XMLNode (node_child (name)).content (); -} - -string -XMLNode::optional_string_child (string name) -{ - list<xmlpp::Node*> nodes = node_children (name); - if (nodes.size() > 2) { - boost::throw_exception (XMLError ("duplicate XML tag " + name)); - } - - if (nodes.empty ()) { - return ""; - } - - return string_child (name); -} - -ContentKind -XMLNode::kind_child (string name) -{ - return content_kind_from_string (string_child (name)); -} - -Fraction -XMLNode::fraction_child (string name) -{ - return Fraction (string_child (name)); -} - -int64_t -XMLNode::int64_child (string name) -{ - string s = string_child (name); - erase_all (s, " "); - return lexical_cast<int64_t> (s); -} - -int64_t -XMLNode::optional_int64_child (string name) -{ - list<xmlpp::Node*> nodes = node_children (name); - if (nodes.size() > 2) { - boost::throw_exception (XMLError ("duplicate XML tag " + name)); - } - - if (nodes.empty ()) { - return 0; - } - - return int64_child (name); -} - -float -XMLNode::float_child (string name) -{ - return lexical_cast<float> (string_child (name)); -} - -void -XMLNode::ignore_child (string name) -{ - _taken.push_back (name); -} - -Time -XMLNode::time_attribute (string name) -{ - return Time (string_attribute (name)); -} - -string -XMLNode::string_attribute (string name) -{ - xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node); - if (!e) { - boost::throw_exception (XMLError ("missing attribute")); - } - - xmlpp::Attribute* a = e->get_attribute (name); - if (!a) { - boost::throw_exception (XMLError ("missing attribute")); - } - - return a->get_value (); -} - -string -XMLNode::optional_string_attribute (string name) -{ - xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node); - if (!e) { - return ""; - } - - xmlpp::Attribute* a = e->get_attribute (name); - if (!a) { - return ""; - } - - return a->get_value (); -} - -float -XMLNode::float_attribute (string name) -{ - return lexical_cast<float> (string_attribute (name)); -} - -int64_t -XMLNode::int64_attribute (string name) -{ - return lexical_cast<int64_t> (string_attribute (name)); -} - -int64_t -XMLNode::optional_int64_attribute (string name) -{ - string const s = optional_string_attribute (name); - if (s.empty ()) { - return 0; - } - - return lexical_cast<int64_t> (s); -} - -optional<bool> -XMLNode::optional_bool_attribute (string name) -{ - string const s = optional_string_attribute (name); - if (s.empty ()) { - return optional<bool> (); - } - - if (s == "1" || s == "yes") { - return optional<bool> (true); - } - - return optional<bool> (false); -} - -optional<Color> -XMLNode::optional_color_attribute (string name) -{ - string const s = optional_string_attribute (name); - if (s.empty ()) { - return optional<Color> (); - } - - return optional<Color> (Color (s)); -} - -void -XMLNode::done () -{ - xmlpp::Node::NodeList c = _node->get_children (); - for (xmlpp::Node::NodeList::iterator i = c.begin(); i != c.end(); ++i) { - if (dynamic_cast<xmlpp::Element *> (*i) && find (_taken.begin(), _taken.end(), (*i)->get_name()) == _taken.end ()) { - boost::throw_exception (XMLError ("unexpected XML node " + (*i)->get_name())); - } - } -} - -string -XMLNode::content () -{ - string content; - - xmlpp::Node::NodeList c = _node->get_children (); - for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) { - xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (*i); - if (v) { - content += v->get_content (); - } - } - - return content; -} - -XMLFile::XMLFile (string file, string root_name) -{ - if (!filesystem::exists (file)) { - boost::throw_exception (FileError ("XML file does not exist", file)); - } - - _parser = new xmlpp::DomParser; - _parser->parse_file (file); - if (!_parser) { - boost::throw_exception (XMLError ("could not parse XML")); - } - - _node = _parser->get_document()->get_root_node (); - if (_node->get_name() != root_name) { - boost::throw_exception (XMLError ("unrecognised root node")); - } -} - -XMLFile::~XMLFile () -{ - delete _parser; -} @@ -1,103 +1,91 @@ -#ifndef LIBDCP_XML_H -#define LIBDCP_XML_H +/* + Copyright (C) 2013 Carl Hetherington <cth@carlh.net> -#include <string> -#include <list> -#include <stdint.h> -#include <glibmm.h> -#include <boost/shared_ptr.hpp> -#include <boost/optional.hpp> -#include "types.h" -#include "exceptions.h" -#include "dcp_time.h" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -namespace xmlpp { - class Node; - class DomParser; -} + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -namespace libdcp { + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -/** @brief A helper class for XML nodes */ -class XMLNode -{ -public: - XMLNode (); - XMLNode (xmlpp::Node const * node); +*/ - 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 (); +#ifndef LIBDCP_XML_H +#define LIBDCP_XML_H - Time time_attribute (std::string); - float float_attribute (std::string); - std::string string_attribute (std::string); - std::string optional_string_attribute (std::string); - int64_t int64_attribute (std::string); - int64_t optional_int64_attribute (std::string); - boost::optional<bool> optional_bool_attribute (std::string); - boost::optional<Color> optional_color_attribute (std::string); +#include <libcxml/cxml.h> +#include "exceptions.h" - std::string content (); +namespace libdcp +{ - template <class T> - 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_type_child (cxml::Node const & node, std::string name) +{ + std::list<boost::shared_ptr<cxml::Node> > n = node.node_children (name); + if (n.size() > 1) { + throw XMLError ("duplicate XML tag"); + } else if (n.empty ()) { + return boost::shared_ptr<T> (); } - template <class T> - 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 ()) { - return boost::shared_ptr<T> (); - } - - return boost::shared_ptr<T> (new T (n.front ())); - } + return boost::shared_ptr<T> (new T (n.front ())); +} + +template <class T> +boost::shared_ptr<T> type_child (boost::shared_ptr<const cxml::Node> node, std::string name) { + return boost::shared_ptr<T> (new T (node->node_child (name))); +} - template <class T> - 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))); - } - return r; - } +template <class T> +boost::shared_ptr<T> +optional_type_child (boost::shared_ptr<const cxml::Node> node, std::string name) +{ + return optional_type_child<T> (*node.get(), name); +} - template <class T> - 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); +template <class T> +std::list<boost::shared_ptr<T> > +type_children (cxml::Node const & node, std::string name) +{ + std::list<boost::shared_ptr<cxml::Node> > n = node.node_children (name); + std::list<boost::shared_ptr<T> > r; + for (typename std::list<boost::shared_ptr<cxml::Node> >::iterator i = n.begin(); i != n.end(); ++i) { + r.push_back (boost::shared_ptr<T> (new T (*i))); } + return r; +} - xmlpp::Node const * _node; - -private: - xmlpp::Node* node_child (std::string); - std::list<xmlpp::Node*> node_children (std::string); - std::list<Glib::ustring> _taken; -}; - -/** @brief A helper class for XML files */ -class XMLFile : public XMLNode +template <class T> +std::list<boost::shared_ptr<T> > +type_children (boost::shared_ptr<const cxml::Node> node, std::string name) { -public: - XMLFile (std::string file, std::string root_name); - virtual ~XMLFile (); - -private: - xmlpp::DomParser* _parser; -}; + return type_children<T> (*node.get(), name); +} + +template <class T> +std::list<boost::shared_ptr<T> > +type_grand_children (cxml::Node const & node, std::string name, std::string sub) +{ + boost::shared_ptr<const cxml::Node> p = node.node_child (name); + return type_children<T> (p, sub); +} +template <class T> +std::list<boost::shared_ptr<T> > +type_grand_children (boost::shared_ptr<const cxml::Node> node, std::string name, std::string sub) +{ + return type_grand_children<T> (*node.get(), name, sub); +} + } #endif |
