From 8eb9263af2a7404ce2408e0b7a92245d0f64d611 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 19 Oct 2024 01:34:26 +0200 Subject: [PATCH] Replace boost::format with PBD::string_compose --- libs/audiographer/audiographer/exception.h | 10 +++---- .../audiographer/flag_debuggable.h | 11 ++++---- .../audiographer/general/cmdpipe_writer.h | 7 ++--- .../audiographer/general/threader.h | 7 ++--- .../audiographer/sndfile/sndfile_reader.h | 8 ++++-- .../audiographer/sndfile/sndfile_writer.h | 26 ++++++++++------- .../audiographer/sndfile/tmp_file_rt.h | 14 ++++++---- libs/audiographer/src/general/demo_noise.cc | 10 +++++-- .../src/general/loudness_reader.cc | 2 ++ .../src/general/sample_format_converter.cc | 28 +++++++++---------- libs/audiographer/src/general/sr_converter.cc | 27 ++++++++---------- libs/audiographer/wscript | 3 -- 12 files changed, 78 insertions(+), 75 deletions(-) diff --git a/libs/audiographer/audiographer/exception.h b/libs/audiographer/audiographer/exception.h index b5141cb4c2..3c2fdb2749 100644 --- a/libs/audiographer/audiographer/exception.h +++ b/libs/audiographer/audiographer/exception.h @@ -4,7 +4,7 @@ #include #include -#include +#include "pbd/compose.h" #include "audiographer/visibility.h" #include "audiographer/debug_utils.h" @@ -20,20 +20,18 @@ class LIBAUDIOGRAPHER_API Exception : public std::exception public: template Exception (T const & thrower, std::string const & reason) - : reason (boost::str (boost::format - ("Exception thrown by %1%: %2%") - % DebugUtils::demangled_name (thrower) % reason)) + : explanation(string_compose ("Exception thrown by %1: %2", DebugUtils::demangled_name (thrower), reason)) {} virtual ~Exception () throw() { } const char* what() const throw() { - return reason.c_str(); + return explanation.c_str(); } private: - std::string const reason; + std::string const explanation; }; diff --git a/libs/audiographer/audiographer/flag_debuggable.h b/libs/audiographer/audiographer/flag_debuggable.h index 5816fe8243..266e4355b2 100644 --- a/libs/audiographer/audiographer/flag_debuggable.h +++ b/libs/audiographer/audiographer/flag_debuggable.h @@ -7,8 +7,6 @@ #include "process_context.h" #include "types.h" -#include - namespace AudioGrapher { @@ -35,10 +33,11 @@ class LIBAUDIOGRAPHER_API FlagDebuggable : public Debuggable FlagField unsupported = flags.unsupported_flags_of (context.flags()); for (FlagField::iterator it = unsupported.begin(); it != unsupported.end(); ++it) { - Debuggable::debug_stream() << boost::str (boost::format - ("%1% does not support flag %2%") - % DebugUtils::demangled_name (self) % DebugUtils::process_context_flag_name (*it) - ) << std::endl; + Debuggable::debug_stream() + << DebugUtils::demangled_name (self) + << " does not support flag " + << DebugUtils::process_context_flag_name (*it) + << std::endl; } } diff --git a/libs/audiographer/audiographer/general/cmdpipe_writer.h b/libs/audiographer/audiographer/general/cmdpipe_writer.h index 648e4a3e03..c79c1b96f8 100644 --- a/libs/audiographer/audiographer/general/cmdpipe_writer.h +++ b/libs/audiographer/audiographer/general/cmdpipe_writer.h @@ -4,7 +4,6 @@ #include #include -#include #include "audiographer/flag_debuggable.h" #include "audiographer/sink.h" @@ -70,8 +69,7 @@ public: check_flags (*this, c); if (_tmp_fd < 0 && (!_proc || !_proc->is_running())) { - throw Exception (*this, boost::str (boost::format - ("Target encoder process is not running"))); + throw Exception (*this, "Target encoder process is not running"); } const size_t bytes_per_sample = sizeof (T); @@ -85,8 +83,7 @@ public: samples_written += written; if (throw_level (ThrowProcess) && written != c.samples()) { - throw Exception (*this, boost::str (boost::format - ("Could not write data to output file"))); + throw Exception (*this, "Could not write data to output file"); } if (c.has_flag(ProcessContext::EndOfInput)) { diff --git a/libs/audiographer/audiographer/general/threader.h b/libs/audiographer/audiographer/general/threader.h index d0f871585e..828643def0 100644 --- a/libs/audiographer/audiographer/general/threader.h +++ b/libs/audiographer/audiographer/general/threader.h @@ -8,11 +8,11 @@ #include #include #include -#include #include #include "pbd/atomic.h" +#include "pbd/compose.h" #include "audiographer/visibility.h" #include "audiographer/source.h" @@ -28,10 +28,7 @@ class /*LIBAUDIOGRAPHER_API*/ ThreaderException : public Exception public: template ThreaderException (T const & thrower, std::exception const & e) - : Exception (thrower, - boost::str ( boost::format - ("\n\t- Dynamic type: %1%\n\t- what(): %2%") - % DebugUtils::demangled_name (e) % e.what() )) + : Exception (thrower, string_compose ("\n\t- Dynamic type: %1\n\t- what(): %2", DebugUtils::demangled_name (e), e.what())) { } }; diff --git a/libs/audiographer/audiographer/sndfile/sndfile_reader.h b/libs/audiographer/audiographer/sndfile/sndfile_reader.h index b3e84ac40a..01f5a6475e 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_reader.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_reader.h @@ -1,6 +1,8 @@ #ifndef AUDIOGRAPHER_SNDFILE_READER_H #define AUDIOGRAPHER_SNDFILE_READER_H +#include "pbd/compose.h" + #include "audiographer/utils/listed_source.h" #include "audiographer/process_context.h" #include "audiographer/sndfile/sndfile_base.h" @@ -32,9 +34,9 @@ class SndfileReader samplecnt_t read (ProcessContext & context) { if (throw_level (ThrowStrict) && context.channels() != channels() ) { - throw Exception (*this, boost::str (boost::format - ("Wrong number of channels given to process(), %1% instead of %2%") - % context.channels() % channels())); + throw Exception (*this, string_compose + ("Wrong number of channels given to process(), %1 instead of %2", + context.channels(), channels())); } samplecnt_t const samples_read = SndfileHandle::read (context.data(), context.samples()); diff --git a/libs/audiographer/audiographer/sndfile/sndfile_writer.h b/libs/audiographer/audiographer/sndfile/sndfile_writer.h index f88eed2267..9f468a92db 100644 --- a/libs/audiographer/audiographer/sndfile/sndfile_writer.h +++ b/libs/audiographer/audiographer/sndfile/sndfile_writer.h @@ -3,14 +3,13 @@ #include -#include - #include "audiographer/flag_debuggable.h" #include "audiographer/sink.h" #include "audiographer/types.h" #include "audiographer/sndfile/sndfile_base.h" #include "audiographer/broadcast_info.h" +#include "pbd/compose.h" #include "pbd/signals.h" namespace AudioGrapher @@ -51,18 +50,21 @@ class SndfileWriter check_flags (*this, c); if (throw_level (ThrowStrict) && c.channels() != channels()) { - throw Exception (*this, boost::str (boost::format - ("Wrong number of channels given to process(), %1% instead of %2%") - % c.channels() % channels())); + throw Exception (*this, string_compose + ("Wrong number of channels given to process(), %1 instead of %2", + c.channels(), channels())); } samplecnt_t const written = write (c.data(), c.samples()); samples_written += written; if (throw_level (ThrowProcess) && written != c.samples()) { - throw Exception (*this, boost::str (boost::format - ("Could not write data to output file (%1%)") - % strError())); + std::stringstream reason; + reason << "Could not write data to output file (" + << strError() + << ")"; + + throw Exception (*this, reason.str()); } if (c.has_flag(ProcessContext::EndOfInput)) { @@ -85,8 +87,12 @@ class SndfileWriter virtual void init() { if (SF_ERR_NO_ERROR != SndfileHandle::error ()) { - throw Exception (*this, boost::str (boost::format - ("Could not create output file (%1%)") % path)); + std::stringstream reason; + reason << "Could not write data to output file (" + << path + << ")"; + + throw Exception (*this, reason.str()); } samples_written = 0; add_supported_flag (ProcessContext::EndOfInput); diff --git a/libs/audiographer/audiographer/sndfile/tmp_file_rt.h b/libs/audiographer/audiographer/sndfile/tmp_file_rt.h index 4b9f321b4e..62f52080de 100644 --- a/libs/audiographer/audiographer/sndfile/tmp_file_rt.h +++ b/libs/audiographer/audiographer/sndfile/tmp_file_rt.h @@ -6,6 +6,7 @@ #include +#include "pbd/compose.h" #include "pbd/gstdio_compat.h" #include "pbd/pthread_utils.h" #include "pbd/ringbuffer.h" @@ -63,15 +64,16 @@ class TmpFileRt SndfileWriter::check_flags (*this, c); if (SndfileWriter::throw_level (ThrowStrict) && c.channels() != SndfileHandle::channels()) { - throw Exception (*this, boost::str (boost::format - ("Wrong number of channels given to process(), %1% instead of %2%") - % c.channels() % SndfileHandle::channels())); + throw Exception (*this, string_compose + ("Wrong number of channels given to process(), %1 instead of %2", + c.channels(), SndfileHandle::channels())); } if (SndfileWriter::throw_level (ThrowProcess) && _rb.write_space() < (size_t) c.samples()) { - throw Exception (*this, boost::str (boost::format - ("Could not write data to ringbuffer/output file (%1%)") - % SndfileHandle::strError())); + throw Exception (*this, string_compose + ("Could not write data to ringbuffer/output file (%1)", + SndfileHandle::strError())); + } _rb.write (c.data(), c.samples()); diff --git a/libs/audiographer/src/general/demo_noise.cc b/libs/audiographer/src/general/demo_noise.cc index 4bbe1e0729..c99a4c4352 100644 --- a/libs/audiographer/src/general/demo_noise.cc +++ b/libs/audiographer/src/general/demo_noise.cc @@ -16,6 +16,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + #include "audiographer/general/demo_noise.h" #include "ardour/dB.h" @@ -67,10 +69,14 @@ DemoNoiseAdder::process (ProcessContext const& ctx) const samplecnt_t n_samples = ctx.samples_per_channel (); if (throw_level (ThrowStrict) && ctx.channels () != _channels) { - throw Exception (*this, boost::str (boost::format ("Wrong channel count given to process(), %1% instead of %2%") % ctx.channels () % _channels)); + throw Exception (*this, string_compose + ("Wrong channel count given to process(), %1 instead of %2", + ctx.channels () % _channels)); } if (throw_level (ThrowProcess) && ctx.samples () > _data_out_size) { - throw Exception (*this, boost::str (boost::format ("Too many samples given to process(), %1% instead of %2%") % ctx.samples () % _data_out_size)); + throw Exception (*this, string_compose + ("Too many samples given to process(), %1 instead of %2", + ctx.samples (), _data_out_size)); } if (_pos + n_samples > _duration) { diff --git a/libs/audiographer/src/general/loudness_reader.cc b/libs/audiographer/src/general/loudness_reader.cc index fa53f0bd96..4fe5f88414 100644 --- a/libs/audiographer/src/general/loudness_reader.cc +++ b/libs/audiographer/src/general/loudness_reader.cc @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + #include "audiographer/general/loudness_reader.h" #include "pbd/fastlog.h" diff --git a/libs/audiographer/src/general/sample_format_converter.cc b/libs/audiographer/src/general/sample_format_converter.cc index 1cf22e5dd6..2d8150aec4 100644 --- a/libs/audiographer/src/general/sample_format_converter.cc +++ b/libs/audiographer/src/general/sample_format_converter.cc @@ -19,14 +19,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "pbd/compose.h" + #include "audiographer/general/sample_format_converter.h" #include "audiographer/exception.h" #include "audiographer/type_utils.h" #include "private/gdither/gdither.h" -#include - namespace AudioGrapher { @@ -72,9 +72,9 @@ void SampleFormatConverter::init (samplecnt_t max_samples, int type, int data_width) { if (throw_level (ThrowObject) && data_width > 16) { - throw Exception (*this, boost::str(boost::format - ("Data width (%1%) too large for int16_t") - % data_width)); + throw Exception (*this, string_compose + ("Data width (%1) too large for int16_t", + data_width)); } init_common (max_samples); dither = gdither_new ((GDitherType) type, channels, GDither16bit, data_width); @@ -85,9 +85,9 @@ void SampleFormatConverter::init (samplecnt_t max_samples, int type, int data_width) { if (throw_level (ThrowObject) && data_width > 8) { - throw Exception (*this, boost::str(boost::format - ("Data width (%1%) too large for uint8_t") - % data_width)); + throw Exception (*this, string_compose + ("Data width (%1) too large for uint8_t", + data_width)); } init_common (max_samples); dither = gdither_new ((GDitherType) type, channels, GDither8bit, data_width); @@ -197,15 +197,15 @@ void SampleFormatConverter::check_sample_and_channel_count (samplecnt_t samples, ChannelCount channels_) { if (throw_level (ThrowStrict) && channels_ != channels) { - throw Exception (*this, boost::str (boost::format - ("Wrong channel count given to process(), %1% instead of %2%") - % channels_ % channels)); + throw Exception (*this, string_compose + ("Wrong channel count given to process(), %1 instead of %2", + channels_, channels)); } if (throw_level (ThrowProcess) && samples > data_out_size) { - throw Exception (*this, boost::str (boost::format - ("Too many samples given to process(), %1% instead of %2%") - % samples % data_out_size)); + throw Exception (*this, string_compose + ("Too many samples given to process(), %1 instead of %2", + samples, data_out_size)); } } diff --git a/libs/audiographer/src/general/sr_converter.cc b/libs/audiographer/src/general/sr_converter.cc index 49004d3884..0e39a460ce 100644 --- a/libs/audiographer/src/general/sr_converter.cc +++ b/libs/audiographer/src/general/sr_converter.cc @@ -18,18 +18,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "pbd/compose.h" + #include "audiographer/general/sr_converter.h" #include "audiographer/exception.h" #include "audiographer/type_utils.h" #include -#include namespace AudioGrapher { -using boost::format; -using boost::str; SampleRateConverter::SampleRateConverter (uint32_t channels) : active (false) @@ -59,9 +58,9 @@ SampleRateConverter::init (samplecnt_t in_rate, samplecnt_t out_rate, int qualit int err; src_state = src_new (quality, channels, &err); if (throw_level (ThrowObject) && !src_state) { - throw Exception (*this, str (format - ("Cannot initialize sample rate converter: %1%") - % src_strerror (err))); + throw Exception (*this, string_compose + ("Cannot initialize sample rate converter: %1", + src_strerror (err))); } src_data.src_ratio = (double) out_rate / (double) in_rate; @@ -113,9 +112,9 @@ SampleRateConverter::process (ProcessContext const & c) float * in = const_cast (c.data()); // TODO check if this is safe! if (throw_level (ThrowProcess) && samples > max_samples_in) { - throw Exception (*this, str (format ( - "process() called with too many samples, %1% instead of %2%") - % samples % max_samples_in)); + throw Exception (*this, string_compose + ("process() called with too many samples, %1 instead of %2", + samples, max_samples_in)); } int err; @@ -163,9 +162,7 @@ SampleRateConverter::process (ProcessContext const & c) err = src_process (src_state, &src_data); if (throw_level (ThrowProcess) && err) { - throw Exception (*this, str (format - ("An error occurred during sample rate conversion: %1%") - % src_strerror (err))); + throw Exception (*this, string_compose ("An error occurred during sample rate conversion: %1",src_strerror (err))); } leftover_samples = src_data.input_frames - src_data.input_frames_used; @@ -191,9 +188,9 @@ SampleRateConverter::process (ProcessContext const & c) } if (throw_level (ThrowProcess) && src_data.output_frames_gen == 0 && leftover_samples) { - throw Exception (*this, boost::str (boost::format - ("No output samples generated with %1% leftover samples") - % leftover_samples)); + throw Exception (*this, string_compose + ("No output samples generated with %1 leftover samples", + leftover_samples)); } } while (leftover_samples > samples); diff --git a/libs/audiographer/wscript b/libs/audiographer/wscript index 5d726d4d04..633bd239b7 100644 --- a/libs/audiographer/wscript +++ b/libs/audiographer/wscript @@ -27,9 +27,6 @@ def configure(conf): autowaf.check_pkg(conf, 'sndfile', uselib_store='SNDFILE', atleast_version='1.0.18', mandatory=False) autowaf.check_pkg(conf, 'fftw3f', uselib_store='FFTW3F', mandatory=True) - # Boost headers - autowaf.check_header(conf, 'cxx', 'boost/format.hpp') - def build(bld): # Headers