summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-11 23:59:19 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-11 23:59:19 +0100
commit4de8f0118e1baf31cf4c859881dfbf39014b566f (patch)
tree91be88947914d05ff942cbefff6c71eab187cc3c /src
parent3390da35584709ea0626ec1fefd3bf5d797bcc00 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc7
-rw-r--r--src/cpl.cc7
-rw-r--r--src/dcp.cc6
-rw-r--r--src/dcp_time.cc10
-rw-r--r--src/mono_picture_asset.cc2
-rw-r--r--src/mono_picture_asset_writer.cc1
-rw-r--r--src/mxf_asset.cc11
-rw-r--r--src/parse/subtitle.cc5
-rw-r--r--src/picture_asset.cc7
-rw-r--r--src/sound_asset.cc2
-rw-r--r--src/subtitle_asset.cc15
-rw-r--r--src/types.cc24
12 files changed, 57 insertions, 40 deletions
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 <iostream>
#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
#include <boost/function.hpp>
#include <libxml++/nodes/element.h>
#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<string> (boost::filesystem::file_size(path())));
+ asset->add_child("Size")->add_child_text (raw_convert<string> (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<string> (boost::filesystem::file_size(path())));
+ chunk->add_child("Length")->add_child_text (raw_convert<string> (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 <cth@carlh.net>
+ Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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<string> (_length));
+ asset->add_child("Size")->add_child_text (raw_convert<string> (_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<string> (_length));
+ chunk->add_child("Length")->add_child_text (raw_convert<string> (_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 <cassert>
#include <iostream>
#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
#include <libxml++/libxml++.h>
#include <xmlsec/xmldsig.h>
#include <xmlsec/app.h>
@@ -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<string> (pkl_length));
+ chunk->add_child("Length")->add_child_text (raw_convert<string> (pkl_length));
for (list<shared_ptr<CPL> >::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 <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
#include <cmath>
#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<int> (b[0]);
- m = lexical_cast<int> (b[1]);
- s = lexical_cast<int> (b[2]);
- t = lexical_cast<int> (b[3]);
+ h = raw_convert<int> (b[0]);
+ m = raw_convert<int> (b[1]);
+ s = raw_convert<int> (b[2]);
+ t = raw_convert<int> (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 <cth@carlh.net>
+ Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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 <iostream>
#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
#include <libxml++/nodes/element.h>
#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<string> (_edit_rate) + " 1");
- a->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration));
- a->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point));
- a->add_child ("Duration")->add_child_text (lexical_cast<string> (_duration));
+ a->add_child ("EditRate")->add_child_text (raw_convert<string> (_edit_rate) + " 1");
+ a->add_child ("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration));
+ a->add_child ("EntryPoint")->add_child_text (raw_convert<string> (_entry_point));
+ a->add_child ("Duration")->add_child_text (raw_convert<string> (_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 <cth@carlh.net>
+ Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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 <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include "subtitle.h"
+#include "../raw_convert.h"
#include "../types.h"
using std::string;
@@ -114,7 +115,7 @@ Subtitle::fade_time (shared_ptr<const cxml::Node> node, string name)
} else if (u.find (":") != string::npos) {
t = Time (u);
} else {
- t = Time (0, 0, 0, lexical_cast<int> (u));
+ t = Time (0, 0, 0, raw_convert<int> (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 <cth@carlh.net>
+ Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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<string> (_edit_rate * edit_rate_factor ()) + " 1");
+ (*i)->add_child ("FrameRate")->add_child_text (raw_convert<string> (_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<string> (_size.width) + " " + lexical_cast<string> (_size.height));
+ (*i)->add_child ("ScreenAspectRatio")->add_child_text (raw_convert<string> (_size.width) + " " + raw_convert<string> (_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 <cth@carlh.net>
+ Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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 <fstream>
#include <cerrno>
-#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <libxml++/nodes/element.h>
#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<string> (_reel_number));
+ root->add_child("ReelNumber")->add_child_text (raw_convert<string> (_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<string> (size));
+ font->set_attribute ("Size", raw_convert<string> (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<string> (spot_number++));
+ subtitle->set_attribute ("SpotNumber", raw_convert<string> (spot_number++));
subtitle->set_attribute ("TimeIn", (*i)->in().to_string());
subtitle->set_attribute ("TimeOut", (*i)->out().to_string());
- subtitle->set_attribute ("FadeUpTime", lexical_cast<string> ((*i)->fade_up_time().to_ticks()));
- subtitle->set_attribute ("FadeDownTime", lexical_cast<string> ((*i)->fade_down_time().to_ticks()));
+ subtitle->set_attribute ("FadeUpTime", raw_convert<string> ((*i)->fade_up_time().to_ticks()));
+ subtitle->set_attribute ("FadeDownTime", raw_convert<string> ((*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<string> ((*i)->v_position()));
+ text->set_attribute ("VPosition", raw_convert<string> ((*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 <cth@carlh.net>
+
+ 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 <vector>
#include <cstdio>
#include <iomanip>
@@ -5,6 +24,7 @@
#include <boost/algorithm/string.hpp>
#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<int> (b[0]);
- denominator = lexical_cast<int> (b[1]);
+ numerator = raw_convert<int> (b[0]);
+ denominator = raw_convert<int> (b[1]);
}
bool