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')
KM_prng.cpp
"""
- if bld.env.STATIC_LIBDCP:
+ if bld.env.STATIC:
obj = bld(features = 'cxx cxxstlib')
else:
obj = bld(features = 'cxx cxxshlib')
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')
#include <boost/algorithm/string.hpp>
#include "asset_map.h"
#include "util.h"
+#include "xml.h"
using std::string;
using std::list;
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://";
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>
#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;
/** @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;
/** @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);
#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 ();
}
#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;
{
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 */
{
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;
};
/** @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;
};
/** @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;
};
/** @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;
/** @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;
* 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 */
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 ("");
}
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;
std::string original_file_name;
};
-class PKLFile : public XMLFile
+class PKLFile
{
public:
PKLFile (std::string file);
#include <boost/algorithm/string.hpp>
#include "subtitle_asset.h"
#include "util.h"
+#include "xml.h"
using std::string;
using std::list;
using std::stringstream;
using boost::shared_ptr;
using boost::lexical_cast;
+using boost::optional;
using namespace libdcp;
SubtitleAsset::SubtitleAsset (string directory, string xml_file)
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");
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.
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
)
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
)
);
}
-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)
}
}
-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 ()) {
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> >
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;
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;
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;
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;
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
);
def build(bld):
- if bld.env.STATIC_LIBDCP:
+ if bld.env.STATIC:
obj = bld(features = 'cxx cxxstlib')
else:
obj = bld(features = 'cxx cxxshlib')
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
types.cc
util.cc
version.cc
- xml.cc
"""
headers = """
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')
+++ /dev/null
-#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;
-}
-#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
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')
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:
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
}
""",
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'