Use libcxml. Lump all static configuration flags into one.
authorCarl Hetherington <cth@carlh.net>
Mon, 13 May 2013 13:20:36 +0000 (14:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 May 2013 13:20:36 +0000 (14:20 +0100)
13 files changed:
asdcplib/src/wscript
src/asset_map.cc
src/asset_map.h
src/cpl_file.cc
src/cpl_file.h
src/pkl_file.cc
src/pkl_file.h
src/subtitle_asset.cc
src/subtitle_asset.h
src/wscript
src/xml.cc [deleted file]
src/xml.h
wscript

index 6f9e1f44c07c0f8d5f2792cacacffaa903bb5205..661971ac20189d7c1155c86da889755e33850873 100644 (file)
@@ -8,7 +8,7 @@ def configure(conf):
         conf.env.append_value('CXXFLAGS', '-DASDCP_PLATFORM="linux"')
 
 def build(bld):
-    if bld.env.STATIC_LIBDCP:
+    if bld.env.STATIC:
         obj = bld(features = 'cxx cxxstlib')
     else:
         obj = bld(features = 'cxx cxxshlib')
@@ -27,7 +27,7 @@ def build(bld):
                  KM_prng.cpp
                  """
 
-    if bld.env.STATIC_LIBDCP:
+    if bld.env.STATIC:
         obj = bld(features = 'cxx cxxstlib')
     else:
         obj = bld(features = 'cxx cxxshlib')
@@ -66,6 +66,6 @@ def build(bld):
                  MDD.cpp
                  """
 
-    if bld.env.STATIC_LIBDCP:
+    if bld.env.STATIC:
         bld.install_files('${PREFIX}/lib', 'libkumu-libdcp.a')
         bld.install_files('${PREFIX}/lib', 'libasdcp-libdcp.a')
index 8fcc515f037241d7e8d30b45c508e04877fcb960..fb42f363a8247307160c034868de70fb1459740c 100644 (file)
@@ -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>
index 8cf89b4b72f4f2b4df7c0224c617dc3aef1147aa..e7ba6978182d3a0d9882d363266ebd127a605fbf 100644 (file)
 
 #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);
index 6a17d7212957d0a1bab60991117f0c9558556c1f..3126b99c3a3cdcc55c540e0ef8f718287d152ddc 100644 (file)
 
 #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 ();
 }
index 44115401fa3169ada14329f92cf28c35892469db..b17f47cd188210e271c677df451ca51da24d6c8c 100644 (file)
 
 #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 */
index 6dfb627cb3bb369fc428a23403db744cc8fc1058..9119d88333199257d892690fe1d80edf5f30b271 100644 (file)
@@ -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 ("");
 }
index b64da5dab0b63b38791170e9aa04bbd3dfc0a466..77b83fcae44206e49fd4024af5914a1b566b9fd7 100644 (file)
 
 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);
index ba91cf9028932117953a9137099434ff36821fa5..1eae1fcc07c0a4ec53ef28091cd34ffca9bb2015 100644 (file)
@@ -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> >
index 1e31df2b1f8775419215bf1a0ae4482f11e34adb..591985d17fd7cd2cb5d0e3034c849ac99feb417a 100644 (file)
@@ -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
                );
index 81c3992668ea54945957e479be196d799506e1d6..fb8f688e6944b7a68caab16e22b8e35a1c2d4816 100644 (file)
@@ -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 (file)
index 508790a..0000000
+++ /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;
-}
index 6fc0d0fa6e3acfa93dd5f3c376c6f776b885c7a3..5978ff7ec10d7346a941d5ebbb71297c3fc5b33c 100644 (file)
--- a/src/xml.h
+++ b/src/xml.h
-#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
diff --git a/wscript b/wscript
index e8de8385dd01e7641f016542471331bf8cbc4783..5414f13d2b115b3a972d7270502d37977603fa14 100644 (file)
--- a/wscript
+++ b/wscript
@@ -8,8 +8,7 @@ def options(opt):
     opt.load('compiler_cxx')
     opt.add_option('--target-windows', action='store_true', default = False, help = 'set up to do a cross-compile to Windows')
     opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation')
-    opt.add_option('--static-openjpeg', action='store_true', default = False, help = 'link statically to openjpeg')
-    opt.add_option('--static-libdcp', action='store_true', default = False, help = 'build libdcp and in-tree dependencies statically')
+    opt.add_option('--static', action='store_true', default = False, help = 'build libdcp and in-tree dependencies statically, and link statically to openjpeg and cxml')
 
 def configure(conf):
     conf.load('compiler_cxx')
@@ -17,8 +16,7 @@ def configure(conf):
     conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
 
     conf.env.TARGET_WINDOWS = conf.options.target_windows
-    conf.env.STATIC_OPENJPEG = conf.options.static_openjpeg
-    conf.env.STATIC_LIBDCP = conf.options.static_libdcp
+    conf.env.STATIC = conf.options.static
     conf.env.ENABLE_DEBUG = conf.options.enable_debug
 
     if conf.options.target_windows:
@@ -28,8 +26,7 @@ def configure(conf):
 
     conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
     conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
-    if conf.options.static_openjpeg:
-
+    if conf.options.static:
         conf.check_cc(fragment = """
                        #include <stdio.h>\n
                        #include <openjpeg.h>\n
@@ -39,8 +36,12 @@ def configure(conf):
                        }
                        """,
                        msg = 'Checking for library openjpeg', stlib = 'openjpeg', uselib_store = 'OPENJPEG', mandatory = True)
+        
+        conf.env.HAVE_CXML = 1
+        conf.env.STLIB_CXML = ['cxml']
     else:
         conf.check_cfg(package = 'libopenjpeg', args = '--cflags --libs', uselib_store = 'OPENJPEG', mandatory = True)
+        conf.check_cfg(package = 'libcxml', args = '--cflags --libs', uselib_store = 'CXML', mandatory = True)
 
     if conf.options.target_windows:
         boost_lib_suffix = '-mt'