From b81241ce69a689629307832f802ac4faa6ed885f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 12 Aug 2016 09:10:08 +0100 Subject: [PATCH] Move locale_convert into libdcp. --- src/lib/audio_content.cc | 1 - src/lib/colour_conversion.cc | 2 +- src/lib/config.cc | 2 +- src/lib/content.cc | 3 +- src/lib/ffmpeg_content.cc | 9 +-- src/lib/film.cc | 2 +- src/lib/j2k_image_proxy.cc | 2 +- src/lib/locale_convert.cc | 122 ----------------------------- src/lib/locale_convert.h | 81 ------------------- src/lib/player_video.cc | 4 +- src/lib/raw_image_proxy.cc | 2 +- src/lib/subtitle_content.cc | 8 +- src/lib/user_property.h | 4 +- src/lib/util.cc | 3 +- src/lib/video_content.cc | 1 - src/lib/wscript | 1 - src/wx/audio_mapping_view.cc | 3 +- src/wx/colour_conversion_editor.cc | 3 +- src/wx/config_dialog.cc | 3 +- src/wx/dcp_panel.cc | 3 +- src/wx/image_sequence_dialog.cc | 4 +- src/wx/playhead_to_frame_dialog.cc | 4 +- src/wx/time_picker.cc | 3 +- src/wx/timing_panel.cc | 3 +- src/wx/video_waveform_plot.cc | 3 +- src/wx/wx_util.cc | 3 +- 26 files changed, 43 insertions(+), 236 deletions(-) delete mode 100644 src/lib/locale_convert.cc delete mode 100644 src/lib/locale_convert.h diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 25a7ef8a5..e66b8b998 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -24,7 +24,6 @@ #include "config.h" #include "frame_rate_change.h" #include "compose.hpp" -#include "locale_convert.h" #include #include #include diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index e4659a5d9..aa6b61fed 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -152,7 +152,7 @@ ColourConversion::as_xml (xmlpp::Node* node) const in_node->add_child("B")->add_child_text (raw_convert (tf->B ())); } - node->add_child("YUVToRGB")->add_child_text (raw_convert (_yuv_to_rgb)); + node->add_child("YUVToRGB")->add_child_text (raw_convert (static_cast (_yuv_to_rgb))); node->add_child("RedX")->add_child_text (raw_convert (_red.x)); node->add_child("RedY")->add_child_text (raw_convert (_red.y)); node->add_child("GreenX")->add_child_text (raw_convert (_green.x)); diff --git a/src/lib/config.cc b/src/lib/config.cc index 7f457439d..b5e4b4d00 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -380,7 +380,7 @@ Config::write_config_xml () const } root->add_child("OnlyServersEncode")->add_child_text (_only_servers_encode ? "1" : "0"); - root->add_child("TMSProtocol")->add_child_text (raw_convert (_tms_protocol)); + root->add_child("TMSProtocol")->add_child_text (raw_convert (static_cast (_tms_protocol))); root->add_child("TMSIP")->add_child_text (_tms_ip); root->add_child("TMSPath")->add_child_text (_tms_path); root->add_child("TMSUser")->add_child_text (_tms_user); diff --git a/src/lib/content.cc b/src/lib/content.cc index 536036ff7..9083635f2 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -27,9 +27,9 @@ #include "content_factory.h" #include "exceptions.h" #include "film.h" -#include "locale_convert.h" #include "job.h" #include "compose.hpp" +#include #include #include #include @@ -46,6 +46,7 @@ using std::max; using std::pair; using boost::shared_ptr; using dcp::raw_convert; +using dcp::locale_convert; int const ContentProperty::PATH = 400; int const ContentProperty::POSITION = 401; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 71cda084c..b5c5ce0a8 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -33,7 +33,6 @@ #include "exceptions.h" #include "frame_rate_change.h" #include "subtitle_content.h" -#include "locale_convert.h" #include #include extern "C" { @@ -223,10 +222,10 @@ FFmpegContent::as_xml (xmlpp::Node* node) const node->add_child("FirstVideo")->add_child_text (raw_convert (_first_video.get().get())); } - node->add_child("ColorRange")->add_child_text (raw_convert (_color_range)); - node->add_child("ColorPrimaries")->add_child_text (raw_convert (_color_primaries)); - node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert (_color_trc)); - node->add_child("Colorspace")->add_child_text (raw_convert (_colorspace)); + node->add_child("ColorRange")->add_child_text (raw_convert (static_cast (_color_range))); + node->add_child("ColorPrimaries")->add_child_text (raw_convert (static_cast (_color_primaries))); + node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert (static_cast (_color_trc))); + node->add_child("Colorspace")->add_child_text (raw_convert (static_cast (_colorspace))); if (_bits_per_pixel) { node->add_child("BitsPerPixel")->add_child_text (raw_convert (_bits_per_pixel.get ())); } diff --git a/src/lib/film.cc b/src/lib/film.cc index 58c272eb1..a41ab3c95 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -361,7 +361,7 @@ Film::metadata () const if (_audio_processor) { root->add_child("AudioProcessor")->add_child_text (_audio_processor->id ()); } - root->add_child("ReelType")->add_child_text (raw_convert (_reel_type)); + root->add_child("ReelType")->add_child_text (raw_convert (static_cast (_reel_type))); root->add_child("ReelLength")->add_child_text (raw_convert (_reel_length)); root->add_child("UploadAfterMakeDCP")->add_child_text (_upload_after_make_dcp ? "1" : "0"); _playlist->as_xml (root->add_child ("Playlist")); diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index 707a088e9..fb38c9e99 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -143,7 +143,7 @@ J2KImageProxy::add_metadata (xmlpp::Node* node) const node->add_child("Width")->add_child_text (raw_convert (_size.width)); node->add_child("Height")->add_child_text (raw_convert (_size.height)); if (_eye) { - node->add_child("Eye")->add_child_text (raw_convert (_eye.get ())); + node->add_child("Eye")->add_child_text (raw_convert (static_cast (_eye.get ()))); } node->add_child("Size")->add_child_text (raw_convert (_data.size ())); } diff --git a/src/lib/locale_convert.cc b/src/lib/locale_convert.cc deleted file mode 100644 index 6358c0f8c..000000000 --- a/src/lib/locale_convert.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - Copyright (C) 2012-2016 Carl Hetherington - - This file is part of DCP-o-matic. - - DCP-o-matic 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. - - DCP-o-matic 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 DCP-o-matic. If not, see . - -*/ - -#include "locale_convert.h" -#include -#include - -using std::string; - -template<> -string -locale_convert (int x, int) -{ - char buffer[64]; - snprintf (buffer, sizeof(buffer), "%d", x); - return buffer; -} - -template<> -string -locale_convert (int64_t x, int) -{ - char buffer[64]; - snprintf (buffer, sizeof(buffer), "%" PRId64, x); - return buffer; -} - -template<> -string -locale_convert (float x, int precision) -{ - char format[64]; - snprintf (format, sizeof(format), "%%.%df", precision); - char buffer[64]; - snprintf (buffer, sizeof(buffer), format, x); - return buffer; -} - -template<> -string -locale_convert (double x, int precision) -{ - char format[64]; - snprintf (format, sizeof(format), "%%.%df", precision); - char buffer[64]; - snprintf (buffer, sizeof(buffer), format, x); - return buffer; -} - -template<> -string -locale_convert (string x, int) -{ - return x; -} - -template<> -string -locale_convert (char* x, int) -{ - return x; -} - -template<> -string -locale_convert (char const * x, int) -{ - return x; -} - -template<> -int -locale_convert (string x, int) -{ - int y = 0; - sscanf (x.c_str(), "%d", &y); - return y; -} - -template<> -int64_t -locale_convert (string x, int) -{ - int64_t y = 0; - sscanf (x.c_str(), "%" PRId64, &y); - return y; -} - -template<> -float -locale_convert (string x, int) -{ - float y = 0; - sscanf (x.c_str(), "%f", &y); - return y; -} - -template<> -double -locale_convert (string x, int) -{ - double y = 0; - sscanf (x.c_str(), "%lf", &y); - return y; -} diff --git a/src/lib/locale_convert.h b/src/lib/locale_convert.h deleted file mode 100644 index b5c38caae..000000000 --- a/src/lib/locale_convert.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - Copyright (C) 2012-2016 Carl Hetherington - - This file is part of DCP-o-matic. - - DCP-o-matic 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. - - DCP-o-matic 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 DCP-o-matic. If not, see . - -*/ - -#ifndef DCPOMATIC_LOCALE_CONVERT_H -#define DCPOMATIC_LOCALE_CONVERT_H - -#include -#include - -template -P -locale_convert (Q x, int precision = 16) -{ - /* We can't write a generic version of locale_convert; all required - versions must be specialised. - */ - BOOST_STATIC_ASSERT (sizeof (Q) == 0); -} - -template <> -std::string -locale_convert (int x, int); - -template <> -std::string -locale_convert (int64_t x, int); - -template <> -std::string -locale_convert (float x, int precision); - -template <> -std::string -locale_convert (double x, int precision); - -template <> -std::string -locale_convert (std::string x, int); - -template <> -std::string -locale_convert (char* x, int); - -template <> -std::string -locale_convert (char const * x, int); - -template <> -int -locale_convert (std::string x, int); - -template <> -int64_t -locale_convert (std::string x, int); - -template <> -float -locale_convert (std::string x, int); - -template <> -double -locale_convert (std::string x, int); - -#endif diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index a86ff1451..17d3dc522 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -159,8 +159,8 @@ PlayerVideo::add_metadata (xmlpp::Node* node) const node->add_child("InterHeight")->add_child_text (raw_convert (_inter_size.height)); node->add_child("OutWidth")->add_child_text (raw_convert (_out_size.width)); node->add_child("OutHeight")->add_child_text (raw_convert (_out_size.height)); - node->add_child("Eyes")->add_child_text (raw_convert (_eyes)); - node->add_child("Part")->add_child_text (raw_convert (_part)); + node->add_child("Eyes")->add_child_text (raw_convert (static_cast (_eyes))); + node->add_child("Part")->add_child_text (raw_convert (static_cast (_part))); if (_colour_conversion) { _colour_conversion.get().as_xml (node); } diff --git a/src/lib/raw_image_proxy.cc b/src/lib/raw_image_proxy.cc index e182c0e5d..6ebcee60c 100644 --- a/src/lib/raw_image_proxy.cc +++ b/src/lib/raw_image_proxy.cc @@ -64,7 +64,7 @@ RawImageProxy::add_metadata (xmlpp::Node* node) const node->add_child("Type")->add_child_text (N_("Raw")); node->add_child("Width")->add_child_text (raw_convert (_image->size().width)); node->add_child("Height")->add_child_text (raw_convert (_image->size().height)); - node->add_child("PixelFormat")->add_child_text (raw_convert (_image->pixel_format ())); + node->add_child("PixelFormat")->add_child_text (raw_convert (static_cast (_image->pixel_format ()))); } void diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index d6bf54aef..21bfd8a2d 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -224,8 +224,8 @@ SubtitleContent::as_xml (xmlpp::Node* root) const { boost::mutex::scoped_lock lm (_mutex); - root->add_child("UseSubtitles")->add_child_text (raw_convert (_use)); - root->add_child("BurnSubtitles")->add_child_text (raw_convert (_burn)); + root->add_child("UseSubtitles")->add_child_text (_use ? "1" : "0"); + root->add_child("BurnSubtitles")->add_child_text (_burn ? "1" : "0"); root->add_child("SubtitleXOffset")->add_child_text (raw_convert (_x_offset)); root->add_child("SubtitleYOffset")->add_child_text (raw_convert (_y_offset)); root->add_child("SubtitleXScale")->add_child_text (raw_convert (_x_scale)); @@ -234,8 +234,8 @@ SubtitleContent::as_xml (xmlpp::Node* root) const root->add_child("Red")->add_child_text (raw_convert (_colour.r)); root->add_child("Green")->add_child_text (raw_convert (_colour.g)); root->add_child("Blue")->add_child_text (raw_convert (_colour.b)); - root->add_child("Outline")->add_child_text (raw_convert (_outline)); - root->add_child("Shadow")->add_child_text (raw_convert (_shadow)); + root->add_child("Outline")->add_child_text (_outline ? "1" : "0"); + root->add_child("Shadow")->add_child_text (_shadow ? "1" : "0"); root->add_child("EffectRed")->add_child_text (raw_convert (_effect_colour.r)); root->add_child("EffectGreen")->add_child_text (raw_convert (_effect_colour.g)); root->add_child("EffectBlue")->add_child_text (raw_convert (_effect_colour.b)); diff --git a/src/lib/user_property.h b/src/lib/user_property.h index 8b69b7687..ffbb99a5f 100644 --- a/src/lib/user_property.h +++ b/src/lib/user_property.h @@ -21,7 +21,7 @@ #ifndef DCPOMATIC_USER_PROPERTY_H #define DCPOMATIC_USER_PROPERTY_H -#include "locale_convert.h" +#include class UserProperty { @@ -37,7 +37,7 @@ public: UserProperty (Category category_, std::string key_, T value_, std::string unit_ = "") : category (category_) , key (key_) - , value (locale_convert (value_)) + , value (dcp::locale_convert (value_)) , unit (unit_) {} diff --git a/src/lib/util.cc b/src/lib/util.cc index eedc7ddb5..d20fd7dc7 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -36,7 +36,7 @@ #include "digester.h" #include "audio_processor.h" #include "compose.hpp" -#include "locale_convert.h" +#include #include #include #include @@ -94,6 +94,7 @@ using boost::lexical_cast; using boost::bad_lexical_cast; using dcp::Size; using dcp::raw_convert; +using dcp::locale_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 ac038678c..4f1b08016 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -30,7 +30,6 @@ #include "exceptions.h" #include "frame_rate_change.h" #include "log.h" -#include "locale_convert.h" #include #include #include diff --git a/src/lib/wscript b/src/lib/wscript index 074c12ad4..911ee0af4 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -94,7 +94,6 @@ sources = """ job.cc job_manager.cc json_server.cc - locale_convert.cc log.cc log_entry.cc magick_image_proxy.cc diff --git a/src/wx/audio_mapping_view.cc b/src/wx/audio_mapping_view.cc index 866156336..0833eadde 100644 --- a/src/wx/audio_mapping_view.cc +++ b/src/wx/audio_mapping_view.cc @@ -27,7 +27,7 @@ #include "audio_gain_dialog.h" #include "lib/audio_mapping.h" #include "lib/util.h" -#include "lib/locale_convert.h" +#include #include #include #include @@ -45,6 +45,7 @@ using std::vector; using std::pair; using std::make_pair; using boost::shared_ptr; +using dcp::locale_convert; #define INDICATOR_SIZE 16 #define LEFT_WIDTH 48 diff --git a/src/wx/colour_conversion_editor.cc b/src/wx/colour_conversion_editor.cc index e56f30baf..d21d45fd2 100644 --- a/src/wx/colour_conversion_editor.cc +++ b/src/wx/colour_conversion_editor.cc @@ -21,7 +21,7 @@ #include "wx_util.h" #include "colour_conversion_editor.h" #include "lib/colour_conversion.h" -#include "lib/locale_convert.h" +#include #include #include #include @@ -32,6 +32,7 @@ using std::string; using std::cout; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using dcp::locale_convert; ColourConversionEditor::ColourConversionEditor (wxWindow* parent, bool yuv) : wxPanel (parent, wxID_ANY) diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index 6006ba782..cb9f4669b 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -41,7 +41,7 @@ #include "lib/util.h" #include "lib/cross.h" #include "lib/exceptions.h" -#include "lib/locale_convert.h" +#include #include #include #include @@ -63,6 +63,7 @@ using boost::bind; using boost::shared_ptr; using boost::function; using boost::optional; +using dcp::locale_convert; class Page { diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index 8cbd1dbb6..ea1315246 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -34,7 +34,7 @@ #include "lib/subtitle_content.h" #include "lib/dcp_content.h" #include "lib/audio_content.h" -#include "lib/locale_convert.h" +#include #include #include #include @@ -53,6 +53,7 @@ using std::max; using std::make_pair; using boost::lexical_cast; using boost::shared_ptr; +using dcp::locale_convert; DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr film) : _audio_dialog (0) diff --git a/src/wx/image_sequence_dialog.cc b/src/wx/image_sequence_dialog.cc index a207338a1..0484b900e 100644 --- a/src/wx/image_sequence_dialog.cc +++ b/src/wx/image_sequence_dialog.cc @@ -20,7 +20,9 @@ #include "wx_util.h" #include "image_sequence_dialog.h" -#include "lib/locale_convert.h" +#include + +using dcp::locale_convert; ImageSequenceDialog::ImageSequenceDialog (wxWindow* parent) : TableDialog (parent, _("Add image sequence"), 2, 1, true) diff --git a/src/wx/playhead_to_frame_dialog.cc b/src/wx/playhead_to_frame_dialog.cc index 3f1d06d2a..137be60ae 100644 --- a/src/wx/playhead_to_frame_dialog.cc +++ b/src/wx/playhead_to_frame_dialog.cc @@ -19,7 +19,9 @@ */ #include "playhead_to_frame_dialog.h" -#include "lib/locale_convert.h" +#include + +using dcp::locale_convert; PlayheadToFrameDialog::PlayheadToFrameDialog (wxWindow* parent, int fps) : TableDialog (parent, _("Go to frame"), 2, 1, true) diff --git a/src/wx/time_picker.cc b/src/wx/time_picker.cc index bddf615d0..309e5c713 100644 --- a/src/wx/time_picker.cc +++ b/src/wx/time_picker.cc @@ -20,7 +20,7 @@ #include "time_picker.h" #include "wx_util.h" -#include "lib/locale_convert.h" +#include #include #include #include @@ -32,6 +32,7 @@ using std::max; using std::string; using std::cout; using boost::bind; +using dcp::locale_convert; TimePicker::TimePicker (wxWindow* parent, wxDateTime time) : wxPanel (parent) diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 25cf2b524..d9777834f 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -30,8 +30,8 @@ #include "lib/dcp_subtitle_content.h" #include "lib/audio_content.h" #include "lib/text_subtitle_content.h" -#include "lib/locale_convert.h" #include "lib/video_content.h" +#include #include #include #include @@ -42,6 +42,7 @@ using std::set; using boost::shared_ptr; using boost::dynamic_pointer_cast; using boost::optional; +using dcp::locale_convert; TimingPanel::TimingPanel (ContentPanel* p, FilmViewer* viewer) /* horrid hack for apparent lack of context support with wxWidgets i18n code */ diff --git a/src/wx/video_waveform_plot.cc b/src/wx/video_waveform_plot.cc index 096d340e8..794922bff 100644 --- a/src/wx/video_waveform_plot.cc +++ b/src/wx/video_waveform_plot.cc @@ -23,7 +23,7 @@ #include "wx_util.h" #include "lib/image.h" #include "lib/dcp_video.h" -#include "lib/locale_convert.h" +#include #include #include #include @@ -35,6 +35,7 @@ using std::min; using std::string; using boost::weak_ptr; using boost::shared_ptr; +using dcp::locale_convert; int const VideoWaveformPlot::_vertical_margin = 8; diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index cb9f72a42..05f2db121 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -26,12 +26,13 @@ #include "file_picker_ctrl.h" #include "lib/config.h" #include "lib/util.h" -#include "lib/locale_convert.h" +#include #include #include using namespace std; using namespace boost; +using dcp::locale_convert; /** Add a wxStaticText to a wxSizer, aligning it at vertical centre. * @param s Sizer to add to. -- 2.30.2