diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-04-16 23:10:28 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-04-16 23:10:28 +0100 |
| commit | 769c71b5c3e050ccfc1c13771d24328fbf76a495 (patch) | |
| tree | f75d5c5c953884395b2e59358e2c7faff5d5ba4b /src/lib | |
| parent | 91bd51ff82e99113860570b519459303802bd98f (diff) | |
Add our own raw_convert that uses SafeStringStream.
Diffstat (limited to 'src/lib')
29 files changed, 90 insertions, 81 deletions
diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 9909e3a08..53160fdb0 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -25,8 +25,8 @@ #include "config.h" #include "frame_rate_change.h" #include "audio_processor.h" +#include "raw_convert.h" #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include "i18n.h" @@ -38,7 +38,6 @@ using std::fixed; using std::setprecision; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; int const AudioContentProperty::AUDIO_CHANNELS = 200; int const AudioContentProperty::AUDIO_LENGTH = 201; diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 35e4c036c..4e5a8afa2 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -20,8 +20,8 @@ #include "audio_mapping.h" #include "util.h" #include "md5_digester.h" +#include "raw_convert.h" #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include <libxml++/libxml++.h> using std::list; @@ -33,7 +33,6 @@ using std::min; using std::vector; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; AudioMapping::AudioMapping () : _content_channels (0) diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index eea6f77cf..4bf84281d 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -21,8 +21,8 @@ #include "colour_conversion.h" #include "util.h" #include "md5_digester.h" +#include "raw_convert.h" #include <dcp/colour_matrix.h> -#include <dcp/raw_convert.h> #include <dcp/gamma_transfer_function.h> #include <dcp/modified_gamma_transfer_function.h> #include <libcxml/cxml.h> @@ -37,7 +37,6 @@ using std::vector; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; -using dcp::raw_convert; ColourConversion::ColourConversion () : dcp::ColourConversion (dcp::ColourConversion::srgb_to_xyz ()) diff --git a/src/lib/config.cc b/src/lib/config.cc index cc0edd4a5..c75eaa0f5 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -27,8 +27,8 @@ #include "cinema.h" #include "util.h" #include "cross.h" +#include "raw_convert.h" #include <dcp/colour_matrix.h> -#include <dcp/raw_convert.h> #include <dcp/signer.h> #include <dcp/certificate_chain.h> #include <libcxml/cxml.h> @@ -52,7 +52,6 @@ using std::cerr; using boost::shared_ptr; using boost::optional; using boost::algorithm::trim; -using dcp::raw_convert; Config* Config::_instance = 0; diff --git a/src/lib/content.cc b/src/lib/content.cc index 550a8cd05..fcc658717 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -29,8 +29,8 @@ #include "film.h" #include "safe_stringstream.h" #include "job.h" +#include "raw_convert.h" #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include <libxml++/libxml++.h> #include <boost/thread/mutex.hpp> @@ -42,7 +42,6 @@ using std::cout; using std::vector; using std::max; using boost::shared_ptr; -using dcp::raw_convert; int const ContentProperty::PATH = 400; int const ContentProperty::POSITION = 401; @@ -145,7 +144,7 @@ Content::examine (shared_ptr<Job> job) digest here: a MD5 of the first and last 1e6 bytes with the size of the first file tacked on the end as a string. */ - string const d = md5_digest_head_tail (p, 1000000) + dcp::raw_convert<string> (boost::filesystem::file_size (p.front ())); + string const d = md5_digest_head_tail (p, 1000000) + raw_convert<string> (boost::filesystem::file_size (p.front ())); lm.lock (); _digest = d; diff --git a/src/lib/dcp_subtitle_content.cc b/src/lib/dcp_subtitle_content.cc index 9f2ff61c5..f3198c58d 100644 --- a/src/lib/dcp_subtitle_content.cc +++ b/src/lib/dcp_subtitle_content.cc @@ -19,17 +19,16 @@ #include "font.h" #include "dcp_subtitle_content.h" +#include "raw_convert.h" #include <dcp/interop_subtitle_content.h> #include <dcp/smpte_subtitle_content.h> #include <dcp/interop_load_font.h> -#include <dcp/raw_convert.h> #include "i18n.h" using std::string; using std::list; using boost::shared_ptr; -using dcp::raw_convert; DCPSubtitleContent::DCPSubtitleContent (shared_ptr<const Film> film, boost::filesystem::path path) : Content (film, path) diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc index a2668c4a7..f2d765f7d 100644 --- a/src/lib/dcp_video.cc +++ b/src/lib/dcp_video.cc @@ -37,12 +37,12 @@ #include "log.h" #include "cross.h" #include "player_video.h" +#include "raw_convert.h" #include "encoded_data.h" #include <libcxml/cxml.h> #include <dcp/xyz_image.h> #include <dcp/rgb_xyz.h> #include <dcp/colour_matrix.h> -#include <dcp/raw_convert.h> #include <boost/array.hpp> #include <boost/asio.hpp> #include <boost/filesystem.hpp> @@ -67,7 +67,6 @@ using std::cout; using boost::shared_ptr; using boost::lexical_cast; using dcp::Size; -using dcp::raw_convert; #define DCI_COEFFICENT (48.0 / 52.37) diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index c39ad8aab..08349fba4 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -22,20 +22,19 @@ extern "C" { #include <libavformat/avformat.h> #include <libswscale/swscale.h> } -#include <dcp/raw_convert.h> #include "ffmpeg.h" #include "ffmpeg_content.h" #include "ffmpeg_audio_stream.h" #include "ffmpeg_subtitle_stream.h" #include "exceptions.h" #include "util.h" +#include "raw_convert.h" #include "i18n.h" using std::string; using std::cout; using boost::shared_ptr; -using dcp::raw_convert; boost::mutex FFmpeg::_mutex; diff --git a/src/lib/ffmpeg_audio_stream.cc b/src/lib/ffmpeg_audio_stream.cc index d8666e89e..6300958e0 100644 --- a/src/lib/ffmpeg_audio_stream.cc +++ b/src/lib/ffmpeg_audio_stream.cc @@ -17,13 +17,12 @@ */ +#include "ffmpeg_audio_stream.h" +#include "raw_convert.h" #include <libxml++/libxml++.h> #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> -#include "ffmpeg_audio_stream.h" using std::string; -using dcp::raw_convert; FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version) : FFmpegStream (node) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 9e9473935..3a42b169f 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -17,11 +17,6 @@ */ -extern "C" { -#include <libavformat/avformat.h> -} -#include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include "ffmpeg_content.h" #include "ffmpeg_examiner.h" #include "ffmpeg_subtitle_stream.h" @@ -35,6 +30,11 @@ extern "C" { #include "exceptions.h" #include "frame_rate_change.h" #include "safe_stringstream.h" +#include "raw_convert.h" +#include <libcxml/cxml.h> +extern "C" { +#include <libavformat/avformat.h> +} #include "i18n.h" @@ -47,7 +47,6 @@ using std::cout; using std::pair; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; int const FFmpegContentProperty::SUBTITLE_STREAMS = 100; int const FFmpegContentProperty::SUBTITLE_STREAM = 101; diff --git a/src/lib/ffmpeg_stream.cc b/src/lib/ffmpeg_stream.cc index f28a2f14e..dfd6f718c 100644 --- a/src/lib/ffmpeg_stream.cc +++ b/src/lib/ffmpeg_stream.cc @@ -19,14 +19,13 @@ #include "ffmpeg_stream.h" #include "dcpomatic_assert.h" -#include <dcp/raw_convert.h> +#include "raw_convert.h" #include <libxml++/libxml++.h> extern "C" { #include <libavformat/avformat.h> } using std::string; -using dcp::raw_convert; FFmpegStream::FFmpegStream (cxml::ConstNodePtr node) : name (node->string_child ("Name")) diff --git a/src/lib/film.cc b/src/lib/film.cc index 297193f83..a7be8aea7 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -41,12 +41,12 @@ #include "cinema.h" #include "safe_stringstream.h" #include "environment_info.h" +#include "raw_convert.h" #include <libcxml/cxml.h> #include <dcp/cpl.h> #include <dcp/signer.h> #include <dcp/util.h> #include <dcp/local_time.h> -#include <dcp/raw_convert.h> #include <dcp/decrypted_kdm.h> #include <libxml++/libxml++.h> #include <boost/filesystem.hpp> @@ -86,8 +86,6 @@ using boost::optional; using boost::is_any_of; using dcp::Size; using dcp::Signer; -using dcp::raw_convert; -using dcp::raw_convert; #define LOG_GENERAL(...) log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL); #define LOG_GENERAL_NC(...) log()->log (__VA_ARGS__, Log::TYPE_GENERAL); diff --git a/src/lib/image_filename_sorter.cc b/src/lib/image_filename_sorter.cc index 7bb1b4c37..805c469b0 100644 --- a/src/lib/image_filename_sorter.cc +++ b/src/lib/image_filename_sorter.cc @@ -17,10 +17,10 @@ */ -#include <iostream> +#include "raw_convert.h" #include <boost/filesystem.hpp> #include <boost/optional.hpp> -#include <dcp/raw_convert.h> +#include <iostream> class ImageFilenameSorter { @@ -57,6 +57,6 @@ private: return boost::optional<int> (); } - return dcp::raw_convert<int> (number); + return raw_convert<int> (number); } }; diff --git a/src/lib/image_proxy.cc b/src/lib/image_proxy.cc index f72a6c3e4..c803e6bd0 100644 --- a/src/lib/image_proxy.cc +++ b/src/lib/image_proxy.cc @@ -25,7 +25,6 @@ #include "exceptions.h" #include "cross.h" #include <dcp/util.h> -#include <dcp/raw_convert.h> #include <libcxml/cxml.h> #include "i18n.h" diff --git a/src/lib/isdcf_metadata.cc b/src/lib/isdcf_metadata.cc index e9d2e313e..a9d7d939e 100644 --- a/src/lib/isdcf_metadata.cc +++ b/src/lib/isdcf_metadata.cc @@ -17,16 +17,15 @@ */ -#include <iostream> -#include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include "isdcf_metadata.h" +#include "raw_convert.h" +#include <libcxml/cxml.h> +#include <iostream> #include "i18n.h" using std::string; using boost::shared_ptr; -using dcp::raw_convert; ISDCFMetadata::ISDCFMetadata (cxml::ConstNodePtr node) : content_version (node->number_child<int> ("ContentVersion")) diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index 99e4dddab..16b886169 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -21,7 +21,7 @@ #include "dcpomatic_socket.h" #include "image.h" #include "encoded_data.h" -#include <dcp/raw_convert.h> +#include "raw_convert.h" #include <dcp/mono_picture_frame.h> #include <dcp/stereo_picture_frame.h> #include <dcp/colour_conversion.h> @@ -94,14 +94,14 @@ void J2KImageProxy::add_metadata (xmlpp::Node* node) const { node->add_child("Type")->add_child_text (N_("J2K")); - node->add_child("Width")->add_child_text (dcp::raw_convert<string> (_size.width)); - node->add_child("Height")->add_child_text (dcp::raw_convert<string> (_size.height)); + node->add_child("Width")->add_child_text (raw_convert<string> (_size.width)); + node->add_child("Height")->add_child_text (raw_convert<string> (_size.height)); if (_stereo) { - node->add_child("Eye")->add_child_text (dcp::raw_convert<string> (_eye.get ())); - node->add_child("LeftSize")->add_child_text (dcp::raw_convert<string> (_stereo->left_j2k_size ())); - node->add_child("RightSize")->add_child_text (dcp::raw_convert<string> (_stereo->right_j2k_size ())); + node->add_child("Eye")->add_child_text (raw_convert<string> (_eye.get ())); + node->add_child("LeftSize")->add_child_text (raw_convert<string> (_stereo->left_j2k_size ())); + node->add_child("RightSize")->add_child_text (raw_convert<string> (_stereo->right_j2k_size ())); } else { - node->add_child("Size")->add_child_text (dcp::raw_convert<string> (_mono->j2k_size ())); + node->add_child("Size")->add_child_text (raw_convert<string> (_mono->j2k_size ())); } } diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index f9f06f63a..aad75889f 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -17,16 +17,15 @@ */ -#include <dcp/raw_convert.h> #include "player_video.h" #include "image.h" #include "image_proxy.h" #include "j2k_image_proxy.h" #include "film.h" +#include "raw_convert.h" using std::string; using std::cout; -using dcp::raw_convert; using boost::shared_ptr; using boost::dynamic_pointer_cast; using boost::optional; diff --git a/src/lib/raw_convert.h b/src/lib/raw_convert.h new file mode 100644 index 000000000..2e5d1373c --- /dev/null +++ b/src/lib/raw_convert.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2014-2015 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 <iomanip> +#include "safe_stringstream.h" + +/** 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 <typename P, typename Q> +P +raw_convert (Q v, int precision = 16) +{ + SafeStringStream s; + s.imbue (std::locale::classic ()); + s << std::setprecision (precision); + s << v; + P r; + s >> r; + return r; +} diff --git a/src/lib/raw_image_proxy.cc b/src/lib/raw_image_proxy.cc index 8f05f5455..e73a1543d 100644 --- a/src/lib/raw_image_proxy.cc +++ b/src/lib/raw_image_proxy.cc @@ -17,14 +17,14 @@ */ +#include "raw_image_proxy.h" +#include "image.h" +#include "raw_convert.h" +#include <dcp/util.h> extern "C" { #include <libavutil/pixfmt.h> } #include <libcxml/cxml.h> -#include <dcp/util.h> -#include <dcp/raw_convert.h> -#include "raw_image_proxy.h" -#include "image.h" #include "i18n.h" @@ -58,9 +58,9 @@ void RawImageProxy::add_metadata (xmlpp::Node* node) const { node->add_child("Type")->add_child_text (N_("Raw")); - node->add_child("Width")->add_child_text (dcp::raw_convert<string> (_image->size().width)); - node->add_child("Height")->add_child_text (dcp::raw_convert<string> (_image->size().height)); - node->add_child("PixelFormat")->add_child_text (dcp::raw_convert<string> (_image->pixel_format ())); + node->add_child("Width")->add_child_text (raw_convert<string> (_image->size().width)); + node->add_child("Height")->add_child_text (raw_convert<string> (_image->size().height)); + node->add_child("PixelFormat")->add_child_text (raw_convert<string> (_image->pixel_format ())); } void diff --git a/src/lib/server.cc b/src/lib/server.cc index ba8580732..9b3b3808b 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -31,7 +31,7 @@ #include "player_video.h" #include "encoded_data.h" #include "safe_stringstream.h" -#include <dcp/raw_convert.h> +#include "raw_convert.h" #include <libcxml/cxml.h> #include <boost/algorithm/string.hpp> #include <boost/scoped_array.hpp> @@ -62,7 +62,6 @@ using boost::bind; using boost::scoped_array; using boost::optional; using dcp::Size; -using dcp::raw_convert; Server::Server (shared_ptr<Log> log, bool verbose) : _terminate (false) diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index d62531d9f..979046dab 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -24,8 +24,8 @@ #include "cross.h" #include "ui_signaller.h" #include "dcpomatic_socket.h" +#include "raw_convert.h" #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include <boost/lambda/lambda.hpp> #include "i18n.h" @@ -37,7 +37,6 @@ using std::cout; using boost::shared_ptr; using boost::scoped_array; using boost::weak_ptr; -using dcp::raw_convert; ServerFinder* ServerFinder::_instance = 0; diff --git a/src/lib/single_stream_audio_content.cc b/src/lib/single_stream_audio_content.cc index 521597606..4547ae600 100644 --- a/src/lib/single_stream_audio_content.cc +++ b/src/lib/single_stream_audio_content.cc @@ -17,15 +17,14 @@ */ -#include <dcp/raw_convert.h> #include "single_stream_audio_content.h" #include "audio_examiner.h" #include "film.h" +#include "raw_convert.h" using std::string; using std::cout; using boost::shared_ptr; -using dcp::raw_convert; SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> f) : Content (f) diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc index e757c77c5..9f9ea351e 100644 --- a/src/lib/sndfile_content.cc +++ b/src/lib/sndfile_content.cc @@ -18,7 +18,6 @@ */ #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include "sndfile_content.h" #include "sndfile_decoder.h" #include "film.h" @@ -32,7 +31,6 @@ using std::string; using std::cout; using boost::shared_ptr; -using dcp::raw_convert; SndfileContent::SndfileContent (shared_ptr<const Film> f, boost::filesystem::path p) : Content (f, p) diff --git a/src/lib/subrip_content.cc b/src/lib/subrip_content.cc index fc0637bfd..f9d184b9d 100644 --- a/src/lib/subrip_content.cc +++ b/src/lib/subrip_content.cc @@ -22,13 +22,12 @@ #include "subrip.h" #include "film.h" #include "font.h" -#include <dcp/raw_convert.h> +#include "raw_convert.h" #include "i18n.h" using std::string; using std::cout; -using dcp::raw_convert; using boost::shared_ptr; using boost::lexical_cast; diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index 2bed5413c..f42f3db37 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -17,13 +17,13 @@ */ -#include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include "subtitle_content.h" #include "util.h" #include "exceptions.h" #include "safe_stringstream.h" #include "font.h" +#include "raw_convert.h" +#include <libcxml/cxml.h> #include "i18n.h" @@ -33,7 +33,6 @@ using std::cout; using std::list; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; int const SubtitleContentProperty::SUBTITLE_X_OFFSET = 500; int const SubtitleContentProperty::SUBTITLE_Y_OFFSET = 501; diff --git a/src/lib/types.cc b/src/lib/types.cc index 54a8cb492..6ab4d56f2 100644 --- a/src/lib/types.cc +++ b/src/lib/types.cc @@ -17,16 +17,15 @@ */ +#include "types.h" +#include "raw_convert.h" #include <libxml++/libxml++.h> #include <libcxml/cxml.h> -#include <dcp/raw_convert.h> -#include "types.h" using std::max; using std::min; using std::string; using boost::shared_ptr; -using dcp::raw_convert; bool operator== (Crop const & a, Crop const & b) { diff --git a/src/lib/update.cc b/src/lib/update.cc index b41d8bb66..a05df8ef3 100644 --- a/src/lib/update.cc +++ b/src/lib/update.cc @@ -17,17 +17,17 @@ */ -#include <string> -#include <boost/algorithm/string.hpp> -#include <curl/curl.h> -#include <libcxml/cxml.h> -#include <dcp/raw_convert.h> #include "update.h" #include "version.h" #include "ui_signaller.h" #include "safe_stringstream.h" #include "config.h" #include "util.h" +#include "raw_convert.h" +#include <libcxml/cxml.h> +#include <curl/curl.h> +#include <boost/algorithm/string.hpp> +#include <string> #define BUFFER_SIZE 1024 @@ -35,7 +35,6 @@ using std::cout; using std::min; using std::string; using std::vector; -using dcp::raw_convert; using boost::is_any_of; using boost::ends_with; diff --git a/src/lib/util.cc b/src/lib/util.cc index 6ebdc85d4..ab991e76b 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -37,7 +37,6 @@ #include "safe_stringstream.h" #include <dcp/util.h> #include <dcp/signer.h> -#include <dcp/raw_convert.h> #include <glib.h> #include <pangomm/init.h> #include <boost/algorithm/string.hpp> @@ -81,7 +80,6 @@ using boost::shared_ptr; using boost::thread; using boost::optional; using dcp::Size; -using dcp::raw_convert; /** Path to our executable, required by the stacktrace stuff and filled * in during App::onInit(). diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 64c51be99..bfbcef9bf 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -29,9 +29,9 @@ #include "frame_rate_change.h" #include "log.h" #include "safe_stringstream.h" +#include "raw_convert.h" #include <libcxml/cxml.h> #include <dcp/colour_matrix.h> -#include <dcp/raw_convert.h> #include <iomanip> #include "i18n.h" @@ -59,7 +59,6 @@ using std::setprecision; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; -using dcp::raw_convert; VideoContent::VideoContent (shared_ptr<const Film> f) : Content (f) |
