From 4de8f0118e1baf31cf4c859881dfbf39014b566f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 11 May 2014 23:59:19 +0100 Subject: Use raw_convert instead of boost::lexical_cast as it seems that lexical_cast will sometimes use a thousands separator (i.e. it will convert 1234 to a string 1,234). It appears not to be possible safely to turn this off (you have to set the global locale). Instead, raw_convert uses a stringstream which you can imbue() with std::locale::classic() to turn off the locale-specific behaviour. --- src/asset.cc | 7 +++---- src/cpl.cc | 7 ++++--- src/dcp.cc | 6 ++---- src/dcp_time.cc | 10 +++++----- src/mono_picture_asset.cc | 2 +- src/mono_picture_asset_writer.cc | 1 - src/mxf_asset.cc | 11 +++++------ src/parse/subtitle.cc | 5 +++-- src/picture_asset.cc | 7 ++++--- src/sound_asset.cc | 2 +- src/subtitle_asset.cc | 15 +++++++-------- src/types.cc | 24 ++++++++++++++++++++++-- 12 files changed, 57 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/asset.cc b/src/asset.cc index 4ad29dde..00ad67bc 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include #include "AS_DCP.h" @@ -32,10 +31,10 @@ #include "util.h" #include "metadata.h" #include "compose.hpp" +#include "raw_convert.h" using std::string; using boost::shared_ptr; -using boost::lexical_cast; using namespace libdcp; Asset::Asset (boost::filesystem::path directory, boost::filesystem::path file_name) @@ -59,7 +58,7 @@ Asset::write_to_pkl (xmlpp::Node* node, bool interop) const asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); asset->add_child("AnnotationText")->add_child_text (_file_name.string ()); asset->add_child("Hash")->add_child_text (digest ()); - asset->add_child("Size")->add_child_text (lexical_cast (boost::filesystem::file_size(path()))); + asset->add_child("Size")->add_child_text (raw_convert (boost::filesystem::file_size(path()))); if (interop) { asset->add_child("Type")->add_child_text (String::compose ("application/x-smpte-mxf;asdcpKind=%1", asdcp_kind ())); } else { @@ -77,7 +76,7 @@ Asset::write_to_assetmap (xmlpp::Node* node) const chunk->add_child("Path")->add_child_text (_file_name.string ()); chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text ("0"); - chunk->add_child("Length")->add_child_text (lexical_cast (boost::filesystem::file_size(path()))); + chunk->add_child("Length")->add_child_text (raw_convert (boost::filesystem::file_size(path()))); } boost::filesystem::path diff --git a/src/cpl.cc b/src/cpl.cc index e333df0d..5079b4f6 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2013 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington 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 @@ -31,6 +31,7 @@ #include "signer.h" #include "exceptions.h" #include "compose.hpp" +#include "raw_convert.h" using std::string; using std::stringstream; @@ -248,7 +249,7 @@ CPL::write_to_pkl (xmlpp::Node* node, bool interop) const xmlpp::Node* asset = node->add_child ("Asset"); asset->add_child("Id")->add_child_text ("urn:uuid:" + _id); asset->add_child("Hash")->add_child_text (_digest); - asset->add_child("Size")->add_child_text (lexical_cast (_length)); + asset->add_child("Size")->add_child_text (raw_convert (_length)); if (interop) { asset->add_child("Type")->add_child_text ("text/xml;asdcpKind=CPL"); } else { @@ -285,7 +286,7 @@ CPL::write_to_assetmap (xmlpp::Node* node) const chunk->add_child("Path")->add_child_text (_id + "_cpl.xml"); chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text("0"); - chunk->add_child("Length")->add_child_text(lexical_cast (_length)); + chunk->add_child("Length")->add_child_text (raw_convert (_length)); } diff --git a/src/dcp.cc b/src/dcp.cc index 7748a97f..7cce30fe 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -26,9 +26,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -46,6 +44,7 @@ #include "cpl.h" #include "signer.h" #include "kdm.h" +#include "raw_convert.h" using std::string; using std::list; @@ -55,7 +54,6 @@ using std::copy; using std::back_inserter; using std::make_pair; using boost::shared_ptr; -using boost::lexical_cast; using namespace libdcp; DCP::DCP (boost::filesystem::path directory) @@ -191,7 +189,7 @@ DCP::write_assetmap (string pkl_uuid, int pkl_length, bool interop, XMLMetadata chunk->add_child("Path")->add_child_text (pkl_uuid + "_pkl.xml"); chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text ("0"); - chunk->add_child("Length")->add_child_text (lexical_cast (pkl_length)); + chunk->add_child("Length")->add_child_text (raw_convert (pkl_length)); for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { (*i)->write_to_assetmap (asset_list); diff --git a/src/dcp_time.cc b/src/dcp_time.cc index 14155fdb..d597e3dc 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -24,10 +24,10 @@ #include #include #include -#include #include #include "dcp_time.h" #include "exceptions.h" +#include "raw_convert.h" using namespace std; using namespace boost; @@ -78,10 +78,10 @@ Time::Time (string time) boost::throw_exception (DCPReadError ("unrecognised time specification")); } - h = lexical_cast (b[0]); - m = lexical_cast (b[1]); - s = lexical_cast (b[2]); - t = lexical_cast (b[3]); + h = raw_convert (b[0]); + m = raw_convert (b[1]); + s = raw_convert (b[2]); + t = raw_convert (b[3]); } bool diff --git a/src/mono_picture_asset.cc b/src/mono_picture_asset.cc index 0ac48d37..f70db2b4 100644 --- a/src/mono_picture_asset.cc +++ b/src/mono_picture_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2013 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington 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 diff --git a/src/mono_picture_asset_writer.cc b/src/mono_picture_asset_writer.cc index 6f0ba973..ebf3ec00 100644 --- a/src/mono_picture_asset_writer.cc +++ b/src/mono_picture_asset_writer.cc @@ -29,7 +29,6 @@ using std::istream; using std::ostream; using std::string; using boost::shared_ptr; -using boost::lexical_cast; using namespace libdcp; struct MonoPictureAssetWriter::ASDCPState : public ASDCPStateBase diff --git a/src/mxf_asset.cc b/src/mxf_asset.cc index c2428a3c..f16fd35b 100644 --- a/src/mxf_asset.cc +++ b/src/mxf_asset.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include "AS_DCP.h" #include "KM_prng.h" @@ -33,12 +32,12 @@ #include "metadata.h" #include "exceptions.h" #include "kdm.h" +#include "raw_convert.h" using std::string; using std::list; using std::pair; using boost::shared_ptr; -using boost::lexical_cast; using boost::dynamic_pointer_cast; using namespace libdcp; @@ -117,10 +116,10 @@ MXFAsset::write_to_cpl (xmlpp::Element* node) const } a->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); a->add_child ("AnnotationText")->add_child_text (_file_name.string ()); - a->add_child ("EditRate")->add_child_text (lexical_cast (_edit_rate) + " 1"); - a->add_child ("IntrinsicDuration")->add_child_text (lexical_cast (_intrinsic_duration)); - a->add_child ("EntryPoint")->add_child_text (lexical_cast (_entry_point)); - a->add_child ("Duration")->add_child_text (lexical_cast (_duration)); + a->add_child ("EditRate")->add_child_text (raw_convert (_edit_rate) + " 1"); + a->add_child ("IntrinsicDuration")->add_child_text (raw_convert (_intrinsic_duration)); + a->add_child ("EntryPoint")->add_child_text (raw_convert (_entry_point)); + a->add_child ("Duration")->add_child_text (raw_convert (_duration)); if (!_key_id.empty ()) { a->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id); } diff --git a/src/parse/subtitle.cc b/src/parse/subtitle.cc index 914be677..a4b0410a 100644 --- a/src/parse/subtitle.cc +++ b/src/parse/subtitle.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2013 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington 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 @@ -20,6 +20,7 @@ #include #include #include "subtitle.h" +#include "../raw_convert.h" #include "../types.h" using std::string; @@ -114,7 +115,7 @@ Subtitle::fade_time (shared_ptr node, string name) } else if (u.find (":") != string::npos) { t = Time (u); } else { - t = Time (0, 0, 0, lexical_cast (u)); + t = Time (0, 0, 0, raw_convert (u)); } if (t > Time (0, 0, 8, 0)) { diff --git a/src/picture_asset.cc b/src/picture_asset.cc index b2eecee5..8d3b0347 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington 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 @@ -36,6 +36,7 @@ #include "exceptions.h" #include "xyz_frame.h" #include "picture_asset_writer.h" +#include "raw_convert.h" using std::string; using std::ostream; @@ -71,13 +72,13 @@ PictureAsset::write_to_cpl (xmlpp::Element* node) const assert (i != c.end ()); - (*i)->add_child ("FrameRate")->add_child_text (lexical_cast (_edit_rate * edit_rate_factor ()) + " 1"); + (*i)->add_child ("FrameRate")->add_child_text (raw_convert (_edit_rate * edit_rate_factor ()) + " 1"); if (_interop) { stringstream s; s << std::fixed << std::setprecision (2) << (float (_size.width) / _size.height); (*i)->add_child ("ScreenAspectRatio")->add_child_text (s.str ()); } else { - (*i)->add_child ("ScreenAspectRatio")->add_child_text (lexical_cast (_size.width) + " " + lexical_cast (_size.height)); + (*i)->add_child ("ScreenAspectRatio")->add_child_text (raw_convert (_size.width) + " " + raw_convert (_size.height)); } } diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 95244b90..54fbdb88 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington 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 diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 4eb1a9cd..89269fb0 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include #include "AS_DCP.h" @@ -28,6 +27,7 @@ #include "parse/subtitle.h" #include "util.h" #include "xml.h" +#include "raw_convert.h" using std::string; using std::list; @@ -36,7 +36,6 @@ using std::ofstream; using std::stringstream; using std::cout; using boost::shared_ptr; -using boost::lexical_cast; using boost::optional; using namespace libdcp; @@ -378,7 +377,7 @@ SubtitleAsset::xml_as_string () const if (_movie_title) { root->add_child("MovieTitle")->add_child_text (_movie_title.get ()); } - root->add_child("ReelNumber")->add_child_text (lexical_cast (_reel_number)); + root->add_child("ReelNumber")->add_child_text (raw_convert (_reel_number)); root->add_child("Language")->add_child_text (_language); if (_load_font_nodes.size() > 1) { @@ -446,7 +445,7 @@ SubtitleAsset::xml_as_string () const font->set_attribute ("Id", id); font->set_attribute ("Italic", italic ? "yes" : "no"); font->set_attribute ("Color", color.to_argb_string()); - font->set_attribute ("Size", lexical_cast (size)); + font->set_attribute ("Size", raw_convert (size)); font->set_attribute ("Effect", effect_to_string (effect)); font->set_attribute ("EffectColor", effect_color.to_argb_string()); font->set_attribute ("Script", "normal"); @@ -462,11 +461,11 @@ SubtitleAsset::xml_as_string () const )) { subtitle = font->add_child ("Subtitle"); - subtitle->set_attribute ("SpotNumber", lexical_cast (spot_number++)); + subtitle->set_attribute ("SpotNumber", raw_convert (spot_number++)); subtitle->set_attribute ("TimeIn", (*i)->in().to_string()); subtitle->set_attribute ("TimeOut", (*i)->out().to_string()); - subtitle->set_attribute ("FadeUpTime", lexical_cast ((*i)->fade_up_time().to_ticks())); - subtitle->set_attribute ("FadeDownTime", lexical_cast ((*i)->fade_down_time().to_ticks())); + subtitle->set_attribute ("FadeUpTime", raw_convert ((*i)->fade_up_time().to_ticks())); + subtitle->set_attribute ("FadeDownTime", raw_convert ((*i)->fade_down_time().to_ticks())); last_in = (*i)->in (); last_out = (*i)->out (); @@ -476,7 +475,7 @@ SubtitleAsset::xml_as_string () const xmlpp::Element* text = subtitle->add_child ("Text"); text->set_attribute ("VAlign", valign_to_string ((*i)->v_align())); - text->set_attribute ("VPosition", lexical_cast ((*i)->v_position())); + text->set_attribute ("VPosition", raw_convert ((*i)->v_position())); text->add_child_text ((*i)->text()); } diff --git a/src/types.cc b/src/types.cc index 693b9ab2..f45e3345 100644 --- a/src/types.cc +++ b/src/types.cc @@ -1,3 +1,22 @@ +/* + Copyright (C) 2012-2014 Carl Hetherington + + 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. + + 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. + + 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. + +*/ + #include #include #include @@ -5,6 +24,7 @@ #include #include "types.h" #include "exceptions.h" +#include "raw_convert.h" using namespace std; using namespace libdcp; @@ -17,8 +37,8 @@ Fraction::Fraction (string s) if (b.size() != 2) { boost::throw_exception (XMLError ("malformed fraction " + s + " in XML node")); } - numerator = lexical_cast (b[0]); - denominator = lexical_cast (b[1]); + numerator = raw_convert (b[0]); + denominator = raw_convert (b[1]); } bool -- cgit v1.2.3 From 470ca64f19d38ef377ec08f03f5ad3b88b370003 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 12 May 2014 00:03:22 +0100 Subject: Missing file. --- src/raw_convert.h | 39 +++++++++++++++++++++++++++++++++++++++ src/wscript | 1 + 2 files changed, 40 insertions(+) create mode 100644 src/raw_convert.h (limited to 'src') diff --git a/src/raw_convert.h b/src/raw_convert.h new file mode 100644 index 00000000..507af152 --- /dev/null +++ b/src/raw_convert.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2014 Carl Hetherington + + 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. + + 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. + + 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. + +*/ + +#include + +namespace libdcp { + +/** A sort-of version of boost::lexical_cast that does uses the "C" + * locale (i.e. no thousands separators and a . for the decimal separator). + */ +template +P +raw_convert (Q v) +{ + std::stringstream s; + s.imbue (std::locale::classic ()); + s << v; + P r; + s >> r; + return r; +} + +}; diff --git a/src/wscript b/src/wscript index cdf3c062..8923455f 100644 --- a/src/wscript +++ b/src/wscript @@ -73,6 +73,7 @@ def build(bld): mxf_asset.h picture_asset.h picture_asset_writer.h + raw_convert.h rgb_xyz.h rec709_linearised_gamma_lut.h reel.h -- cgit v1.2.3 From 110dc70856bd0f6ae5ec1931f51a4817c5e38f42 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 12 May 2014 00:35:48 +0100 Subject: Bump libcxml again. --- cscript | 2 +- src/parse/subtitle.cc | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/cscript b/cscript index 12d39ba1..1bb7a35f 100644 --- a/cscript +++ b/cscript @@ -1,7 +1,7 @@ import os def dependencies(target): - return (('libcxml', 'df3b86a'), ('openjpeg-cdist', '13b69c2')) + return (('libcxml', '7b4ecc3'), ('openjpeg-cdist', '13b69c2')) def build(target, options): cmd = './waf configure --prefix=%s' % target.work_dir_cscript() diff --git a/src/parse/subtitle.cc b/src/parse/subtitle.cc index a4b0410a..831fef59 100644 --- a/src/parse/subtitle.cc +++ b/src/parse/subtitle.cc @@ -27,7 +27,6 @@ using std::string; using std::list; using boost::shared_ptr; using boost::optional; -using boost::lexical_cast; using namespace libdcp; using namespace libdcp::parse; -- cgit v1.2.3