From 5d48e36440d6b4ebf4c04a413bd340b214ba8c42 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 2 Oct 2012 16:13:29 +0100 Subject: [PATCH] Use String::compose in a few places. --- src/lib/ab_transcode_job.cc | 4 +--- src/lib/check_hashes_job.cc | 4 +--- src/lib/dcp_video_frame.cc | 12 ++---------- src/lib/examine_content_job.cc | 4 +--- src/lib/film.cc | 10 ++-------- src/lib/j2k_wav_encoder.cc | 24 +++++++++-------------- src/lib/job.cc | 4 +--- src/lib/make_dcp_job.cc | 4 +--- src/lib/scp_dcp_job.cc | 36 +++++++++------------------------- src/lib/server.cc | 8 ++------ src/lib/thumbs_job.cc | 4 +--- src/lib/transcode_job.cc | 9 ++------- src/wx/film_editor.cc | 4 +--- src/wx/job_manager_view.cc | 4 +--- src/wx/job_wrapper.cc | 8 ++------ 15 files changed, 36 insertions(+), 103 deletions(-) diff --git a/src/lib/ab_transcode_job.cc b/src/lib/ab_transcode_job.cc index 1a6104251..d94f56d0a 100644 --- a/src/lib/ab_transcode_job.cc +++ b/src/lib/ab_transcode_job.cc @@ -46,9 +46,7 @@ ABTranscodeJob::ABTranscodeJob (shared_ptr s, shared_ptrname; - return s.str (); + return String::compose ("A/B transcode %1", _fs->name); } void diff --git a/src/lib/check_hashes_job.cc b/src/lib/check_hashes_job.cc index 5a927f752..cf269564a 100644 --- a/src/lib/check_hashes_job.cc +++ b/src/lib/check_hashes_job.cc @@ -41,9 +41,7 @@ CheckHashesJob::CheckHashesJob (shared_ptr s, shared_ptrname; - return s.str (); + return String::compose ("Check hashes of %1", _fs->name); } void diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index da7133c4b..90826a99f 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -262,11 +262,7 @@ DCPVideoFrame::encode_locally () throw EncodeError ("jpeg2000 encoding failed"); } - { - stringstream s; - s << "Finished locally-encoded frame " << _frame; - _log->log (s.str ()); - } + _log->log (String::compose ("Finished locally-encoded frame %1", _frame)); return shared_ptr (new LocallyEncodedData (_cio->buffer, cio_tell (_cio))); } @@ -318,11 +314,7 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv) /* now read the rest */ socket.read_definite_and_consume (e->data(), e->size(), 30); - { - stringstream s; - s << "Finished remotely-encoded frame " << _frame; - _log->log (s.str ()); - } + _log->log (String::compose ("Finished remotely-encoded frame %1", _frame)); return e; } diff --git a/src/lib/examine_content_job.cc b/src/lib/examine_content_job.cc index 6927715bd..d77ede2f9 100644 --- a/src/lib/examine_content_job.cc +++ b/src/lib/examine_content_job.cc @@ -43,9 +43,7 @@ ExamineContentJob::~ExamineContentJob () string ExamineContentJob::name () const { - stringstream s; - s << "Examine content of " << _fs->name; - return s.str (); + return String::compose ("Examine content of %1", _fs->name); } void diff --git a/src/lib/film.cc b/src/lib/film.cc index 583a15e19..90c410546 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -483,18 +483,12 @@ Film::make_dcp (bool transcode, int freq) throw BadSettingError ("name", "cannot contain slashes"); } - { - stringstream s; - s << "DVD-o-matic " << DVDOMATIC_VERSION << " using " << dependency_version_summary (); - log()->log (s.str ()); - } + log()->log (String::compose ("DVD-o-matic %1 using %2", DVDOMATIC_VERSION, dependency_version_summary())); { char buffer[128]; gethostname (buffer, sizeof (buffer)); - stringstream s; - s << "Starting to make a DCP on " << buffer; - log()->log (s.str ()); + log()->log (String::compose ("Starting to make DCP on %1", buffer)); } if (format() == 0) { diff --git a/src/lib/j2k_wav_encoder.cc b/src/lib/j2k_wav_encoder.cc index 73aa1bff2..08c796350 100644 --- a/src/lib/j2k_wav_encoder.cc +++ b/src/lib/j2k_wav_encoder.cc @@ -169,9 +169,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) encoded = vf->encode_remotely (server); if (remote_backoff > 0) { - stringstream s; - s << server->host_name() << " was lost, but now she is found; removing backoff"; - _log->log (s.str ()); + _log->log (String::compose ("%1 was lost, but now she is found; removing backoff", server->host_name ())); } /* This job succeeded, so remove any backoff */ @@ -182,9 +180,11 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) /* back off more */ remote_backoff += 10; } - stringstream s; - s << "Remote encode of " << vf->frame() << " on " << server->host_name() << " failed (" << e.what() << "); thread sleeping for " << remote_backoff << "s."; - _log->log (s.str ()); + _log->log ( + String::compose ( + "Remote encode of %1 on %2 failed (%3); thread sleeping for %4s", + vf->frame(), server->host_name(), e.what(), remote_backoff) + ); } } else { @@ -193,9 +193,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) encoded = vf->encode_locally (); TIMING ("encoder thread %1 finishes local encode of %2", pthread_self(), vf->frame()); } catch (std::exception& e) { - stringstream s; - s << "Local encode failed " << e.what() << "."; - _log->log (s.str ()); + _log->log (String::compose ("Local encode failed (%1)", e.what ())); } } @@ -263,17 +261,13 @@ J2KWAVEncoder::process_end () */ for (list >::iterator i = _queue.begin(); i != _queue.end(); ++i) { - stringstream s; - s << "Encode left-over frame " << (*i)->frame(); - _log->log (s.str ()); + _log->log (String::compose ("Encode left-over frame %1", (*i)->frame ())); try { shared_ptr e = (*i)->encode_locally (); e->write (_opt, (*i)->frame ()); frame_done ((*i)->frame ()); } catch (std::exception& e) { - stringstream s; - s << "Local encode failed " << e.what() << "."; - _log->log (s.str ()); + _log->log (String::compose ("Local encode failed (%1)", e.what ())); } } diff --git a/src/lib/job.cc b/src/lib/job.cc index e78a91315..39ce4173a 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -69,9 +69,7 @@ Job::run_wrapper () set_progress (1); set_state (FINISHED_ERROR); - stringstream s; - s << e.what() << "(" << filesystem::path (e.filename()).leaf() << ")"; - set_error (s.str ()); + set_error (String::compose ("%1 (%2)", e.what(), filesystem::path (e.filename()).leaf())); } catch (std::exception& e) { diff --git a/src/lib/make_dcp_job.cc b/src/lib/make_dcp_job.cc index 8d3547cae..ae4bb4fbe 100644 --- a/src/lib/make_dcp_job.cc +++ b/src/lib/make_dcp_job.cc @@ -52,9 +52,7 @@ MakeDCPJob::MakeDCPJob (shared_ptr s, shared_ptr string MakeDCPJob::name () const { - stringstream s; - s << "Make DCP for " << _fs->name; - return s.str (); + return String::compose ("Make DCP for %1", _fs->name); } string diff --git a/src/lib/scp_dcp_job.cc b/src/lib/scp_dcp_job.cc index f62d2db8d..dac4a602c 100644 --- a/src/lib/scp_dcp_job.cc +++ b/src/lib/scp_dcp_job.cc @@ -78,9 +78,7 @@ public: { scp = ssh_scp_new (s, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, Config::instance()->tms_path().c_str ()); if (!scp) { - stringstream s; - s << "Could not start SCP session (" << ssh_get_error (s) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not start SCP session (%1)", ssh_get_error (s))); } } @@ -103,9 +101,7 @@ SCPDCPJob::SCPDCPJob (shared_ptr s, Log* l) string SCPDCPJob::name () const { - stringstream s; - s << "Copy DCP to TMS"; - return s.str (); + return "Copy DCP to TMS"; } void @@ -124,39 +120,29 @@ SCPDCPJob::run () int r = ss.connect (); if (r != SSH_OK) { - stringstream s; - s << "Could not connect to server " << Config::instance()->tms_ip() << " (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not connect to server %1 (%2)", Config::instance()->tms_ip(), ssh_get_error (ss.session))); } int const state = ssh_is_server_known (ss.session); if (state == SSH_SERVER_ERROR) { - stringstream s; - s << "SSH error (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("SSH error (%1)", ssh_get_error (ss.session))); } r = ssh_userauth_password (ss.session, 0, Config::instance()->tms_password().c_str ()); if (r != SSH_AUTH_SUCCESS) { - stringstream s; - s << "Failed to authenticate with server (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Failed to authenticate with server (%1)", ssh_get_error (ss.session))); } SSHSCP sc (ss.session); r = ssh_scp_init (sc.scp); if (r != SSH_OK) { - stringstream s; - s << "Could not start SCP session (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not start SCP session (%1)", ssh_get_error (ss.session))); } r = ssh_scp_push_directory (sc.scp, _fs->name.c_str(), S_IRWXU); if (r != SSH_OK) { - stringstream s; - s << "Could not create remote directory " << _fs->name << "(" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not create remote directory %1 (%2)", _fs->name, ssh_get_error (ss.session))); } string const dcp_dir = _fs->dir (_fs->name); @@ -186,9 +172,7 @@ SCPDCPJob::run () FILE* f = fopen (filesystem::path (*i).string().c_str(), "rb"); if (f == 0) { - stringstream s; - s << "Could not open " << *i << " to send"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not open %1 to send", *i)); } while (to_do > 0) { @@ -200,9 +184,7 @@ SCPDCPJob::run () r = ssh_scp_write (sc.scp, buffer, t); if (r != SSH_OK) { - stringstream s; - s << "Could not write to remote file (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not write to remote file (%1)", ssh_get_error (ss.session))); } to_do -= t; bytes_transferred += t; diff --git a/src/lib/server.cc b/src/lib/server.cc index f8c4425d9..28236e3e0 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -163,9 +163,7 @@ Server::worker_thread () if (frame >= 0) { struct timeval end; gettimeofday (&end, 0); - stringstream s; - s << "Encoded frame " << frame << " in " << (seconds (end) - seconds (start)); - _log->log (s.str ()); + _log->log (String::compose ("Encoded frame %1 in %2", frame, seconds (end) - seconds (start))); } _worker_condition.notify_all (); @@ -175,9 +173,7 @@ Server::worker_thread () void Server::run (int num_threads) { - stringstream s; - s << "Server starting with " << num_threads << " threads."; - _log->log (s.str ()); + _log->log (String::compose ("Server starting with %1 threads", num_threads)); for (int i = 0; i < num_threads; ++i) { _worker_threads.push_back (new thread (bind (&Server::worker_thread, this))); diff --git a/src/lib/thumbs_job.cc b/src/lib/thumbs_job.cc index 0eb116fd1..f6ed75ff7 100644 --- a/src/lib/thumbs_job.cc +++ b/src/lib/thumbs_job.cc @@ -44,9 +44,7 @@ ThumbsJob::ThumbsJob (shared_ptr s, shared_ptr o string ThumbsJob::name () const { - stringstream s; - s << "Update thumbs for " << _fs->name; - return s.str (); + return String::compose ("Update thumbs for %1", _fs->name); } void diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index 9113593f0..e79be09fe 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -48,9 +48,7 @@ TranscodeJob::TranscodeJob (shared_ptr s, shared_ptrname; - return s.str (); + return String::compose ("Transcode %1", _fs->name); } void @@ -70,12 +68,9 @@ TranscodeJob::run () } catch (std::exception& e) { - stringstream s; set_progress (1); set_state (FINISHED_ERROR); - - s << "Transcode job failed (" << e.what() << ")"; - _log->log (s.str ()); + _log->log (String::compose ("Transcode job failed (%1)", e.what())); throw; } diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 6de3af9e7..9171daa5c 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -289,9 +289,7 @@ FilmEditor::content_changed (wxCommandEvent &) _film->set_content (wx_to_std (_content->GetPath ())); } catch (std::exception& e) { _content->SetPath (std_to_wx (_film->directory ())); - stringstream m; - m << "Could not set content: " << e.what() << "."; - error_dialog (this, m.str ()); + error_dialog (this, String::compose ("Could not set content: %1", e.what ())); } _ignore_changes = Film::NONE; diff --git a/src/wx/job_manager_view.cc b/src/wx/job_manager_view.cc index 1d5c855ea..97da3936f 100644 --- a/src/wx/job_manager_view.cc +++ b/src/wx/job_manager_view.cc @@ -111,9 +111,7 @@ JobManagerView::update () try { (*i)->emit_finished (); } catch (OpenFileError& e) { - stringstream s; - s << "Error: " << e.what(); - error_dialog (this, s.str ()); + error_dialog (this, String::compose ("Error: %1", e.what ())); } _job_records[*i].informed_of_finish = true; diff --git a/src/wx/job_wrapper.cc b/src/wx/job_wrapper.cc index ad83aa271..cc7507547 100644 --- a/src/wx/job_wrapper.cc +++ b/src/wx/job_wrapper.cc @@ -35,12 +35,8 @@ JobWrapper::make_dcp (wxWindow* parent, Film* film, bool transcode) try { film->make_dcp (transcode); } catch (BadSettingError& e) { - stringstream s; - s << "Bad setting for " << e.setting() << "(" << e.what() << ")"; - error_dialog (parent, s.str ()); + error_dialog (parent, String::compose ("Bad setting for %1 (%2)", e.setting(), e.what ())); } catch (std::exception& e) { - stringstream s; - s << "Could not make DCP: " << e.what () << "."; - error_dialog (parent, s.str ()); + error_dialog (parent, String::compose ("Could not make DCP: %1", e.what ())); } } -- 2.30.2