13
0

Replace boost::format with PBD::string_compose

This commit is contained in:
Robin Gareus 2024-10-19 01:34:26 +02:00
parent 609b723650
commit 8eb9263af2
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
12 changed files with 78 additions and 75 deletions

View File

@ -4,7 +4,7 @@
#include <exception> #include <exception>
#include <string> #include <string>
#include <boost/format.hpp> #include "pbd/compose.h"
#include "audiographer/visibility.h" #include "audiographer/visibility.h"
#include "audiographer/debug_utils.h" #include "audiographer/debug_utils.h"
@ -20,20 +20,18 @@ class LIBAUDIOGRAPHER_API Exception : public std::exception
public: public:
template<typename T> template<typename T>
Exception (T const & thrower, std::string const & reason) Exception (T const & thrower, std::string const & reason)
: reason (boost::str (boost::format : explanation(string_compose ("Exception thrown by %1: %2", DebugUtils::demangled_name (thrower), reason))
("Exception thrown by %1%: %2%")
% DebugUtils::demangled_name (thrower) % reason))
{} {}
virtual ~Exception () throw() { } virtual ~Exception () throw() { }
const char* what() const throw() const char* what() const throw()
{ {
return reason.c_str(); return explanation.c_str();
} }
private: private:
std::string const reason; std::string const explanation;
}; };

View File

@ -7,8 +7,6 @@
#include "process_context.h" #include "process_context.h"
#include "types.h" #include "types.h"
#include <boost/format.hpp>
namespace AudioGrapher namespace AudioGrapher
{ {
@ -35,10 +33,11 @@ class LIBAUDIOGRAPHER_API FlagDebuggable : public Debuggable<L>
FlagField unsupported = flags.unsupported_flags_of (context.flags()); FlagField unsupported = flags.unsupported_flags_of (context.flags());
for (FlagField::iterator it = unsupported.begin(); it != unsupported.end(); ++it) { for (FlagField::iterator it = unsupported.begin(); it != unsupported.end(); ++it) {
Debuggable<L>::debug_stream() << boost::str (boost::format Debuggable<L>::debug_stream()
("%1% does not support flag %2%") << DebugUtils::demangled_name (self)
% DebugUtils::demangled_name (self) % DebugUtils::process_context_flag_name (*it) << " does not support flag "
) << std::endl; << DebugUtils::process_context_flag_name (*it)
<< std::endl;
} }
} }

View File

@ -4,7 +4,6 @@
#include <string> #include <string>
#include <glib.h> #include <glib.h>
#include <boost/format.hpp>
#include "audiographer/flag_debuggable.h" #include "audiographer/flag_debuggable.h"
#include "audiographer/sink.h" #include "audiographer/sink.h"
@ -70,8 +69,7 @@ public:
check_flags (*this, c); check_flags (*this, c);
if (_tmp_fd < 0 && (!_proc || !_proc->is_running())) { if (_tmp_fd < 0 && (!_proc || !_proc->is_running())) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, "Target encoder process is not running");
("Target encoder process is not running")));
} }
const size_t bytes_per_sample = sizeof (T); const size_t bytes_per_sample = sizeof (T);
@ -85,8 +83,7 @@ public:
samples_written += written; samples_written += written;
if (throw_level (ThrowProcess) && written != c.samples()) { if (throw_level (ThrowProcess) && written != c.samples()) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, "Could not write data to output file");
("Could not write data to output file")));
} }
if (c.has_flag(ProcessContext<T>::EndOfInput)) { if (c.has_flag(ProcessContext<T>::EndOfInput)) {

View File

@ -8,11 +8,11 @@
#include <glibmm/threadpool.h> #include <glibmm/threadpool.h>
#include <glibmm/timeval.h> #include <glibmm/timeval.h>
#include <sigc++/slot.h> #include <sigc++/slot.h>
#include <boost/format.hpp>
#include <glib.h> #include <glib.h>
#include "pbd/atomic.h" #include "pbd/atomic.h"
#include "pbd/compose.h"
#include "audiographer/visibility.h" #include "audiographer/visibility.h"
#include "audiographer/source.h" #include "audiographer/source.h"
@ -28,10 +28,7 @@ class /*LIBAUDIOGRAPHER_API*/ ThreaderException : public Exception
public: public:
template<typename T> template<typename T>
ThreaderException (T const & thrower, std::exception const & e) ThreaderException (T const & thrower, std::exception const & e)
: Exception (thrower, : Exception (thrower, string_compose ("\n\t- Dynamic type: %1\n\t- what(): %2", DebugUtils::demangled_name (e), e.what()))
boost::str ( boost::format
("\n\t- Dynamic type: %1%\n\t- what(): %2%")
% DebugUtils::demangled_name (e) % e.what() ))
{ } { }
}; };

View File

@ -1,6 +1,8 @@
#ifndef AUDIOGRAPHER_SNDFILE_READER_H #ifndef AUDIOGRAPHER_SNDFILE_READER_H
#define AUDIOGRAPHER_SNDFILE_READER_H #define AUDIOGRAPHER_SNDFILE_READER_H
#include "pbd/compose.h"
#include "audiographer/utils/listed_source.h" #include "audiographer/utils/listed_source.h"
#include "audiographer/process_context.h" #include "audiographer/process_context.h"
#include "audiographer/sndfile/sndfile_base.h" #include "audiographer/sndfile/sndfile_base.h"
@ -32,9 +34,9 @@ class SndfileReader
samplecnt_t read (ProcessContext<T> & context) samplecnt_t read (ProcessContext<T> & context)
{ {
if (throw_level (ThrowStrict) && context.channels() != channels() ) { if (throw_level (ThrowStrict) && context.channels() != channels() ) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("Wrong number of channels given to process(), %1% instead of %2%") ("Wrong number of channels given to process(), %1 instead of %2",
% context.channels() % channels())); context.channels(), channels()));
} }
samplecnt_t const samples_read = SndfileHandle::read (context.data(), context.samples()); samplecnt_t const samples_read = SndfileHandle::read (context.data(), context.samples());

View File

@ -3,14 +3,13 @@
#include <string> #include <string>
#include <boost/format.hpp>
#include "audiographer/flag_debuggable.h" #include "audiographer/flag_debuggable.h"
#include "audiographer/sink.h" #include "audiographer/sink.h"
#include "audiographer/types.h" #include "audiographer/types.h"
#include "audiographer/sndfile/sndfile_base.h" #include "audiographer/sndfile/sndfile_base.h"
#include "audiographer/broadcast_info.h" #include "audiographer/broadcast_info.h"
#include "pbd/compose.h"
#include "pbd/signals.h" #include "pbd/signals.h"
namespace AudioGrapher namespace AudioGrapher
@ -51,18 +50,21 @@ class SndfileWriter
check_flags (*this, c); check_flags (*this, c);
if (throw_level (ThrowStrict) && c.channels() != channels()) { if (throw_level (ThrowStrict) && c.channels() != channels()) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("Wrong number of channels given to process(), %1% instead of %2%") ("Wrong number of channels given to process(), %1 instead of %2",
% c.channels() % channels())); c.channels(), channels()));
} }
samplecnt_t const written = write (c.data(), c.samples()); samplecnt_t const written = write (c.data(), c.samples());
samples_written += written; samples_written += written;
if (throw_level (ThrowProcess) && written != c.samples()) { if (throw_level (ThrowProcess) && written != c.samples()) {
throw Exception (*this, boost::str (boost::format std::stringstream reason;
("Could not write data to output file (%1%)") reason << "Could not write data to output file ("
% strError())); << strError()
<< ")";
throw Exception (*this, reason.str());
} }
if (c.has_flag(ProcessContext<T>::EndOfInput)) { if (c.has_flag(ProcessContext<T>::EndOfInput)) {
@ -85,8 +87,12 @@ class SndfileWriter
virtual void init() virtual void init()
{ {
if (SF_ERR_NO_ERROR != SndfileHandle::error ()) { if (SF_ERR_NO_ERROR != SndfileHandle::error ()) {
throw Exception (*this, boost::str (boost::format std::stringstream reason;
("Could not create output file (%1%)") % path)); reason << "Could not write data to output file ("
<< path
<< ")";
throw Exception (*this, reason.str());
} }
samples_written = 0; samples_written = 0;
add_supported_flag (ProcessContext<T>::EndOfInput); add_supported_flag (ProcessContext<T>::EndOfInput);

View File

@ -6,6 +6,7 @@
#include <glib.h> #include <glib.h>
#include "pbd/compose.h"
#include "pbd/gstdio_compat.h" #include "pbd/gstdio_compat.h"
#include "pbd/pthread_utils.h" #include "pbd/pthread_utils.h"
#include "pbd/ringbuffer.h" #include "pbd/ringbuffer.h"
@ -63,15 +64,16 @@ class TmpFileRt
SndfileWriter<T>::check_flags (*this, c); SndfileWriter<T>::check_flags (*this, c);
if (SndfileWriter<T>::throw_level (ThrowStrict) && c.channels() != SndfileHandle::channels()) { if (SndfileWriter<T>::throw_level (ThrowStrict) && c.channels() != SndfileHandle::channels()) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("Wrong number of channels given to process(), %1% instead of %2%") ("Wrong number of channels given to process(), %1 instead of %2",
% c.channels() % SndfileHandle::channels())); c.channels(), SndfileHandle::channels()));
} }
if (SndfileWriter<T>::throw_level (ThrowProcess) && _rb.write_space() < (size_t) c.samples()) { if (SndfileWriter<T>::throw_level (ThrowProcess) && _rb.write_space() < (size_t) c.samples()) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("Could not write data to ringbuffer/output file (%1%)") ("Could not write data to ringbuffer/output file (%1)",
% SndfileHandle::strError())); SndfileHandle::strError()));
} }
_rb.write (c.data(), c.samples()); _rb.write (c.data(), c.samples());

View File

@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <cassert>
#include "audiographer/general/demo_noise.h" #include "audiographer/general/demo_noise.h"
#include "ardour/dB.h" #include "ardour/dB.h"
@ -67,10 +69,14 @@ DemoNoiseAdder::process (ProcessContext<float> const& ctx)
const samplecnt_t n_samples = ctx.samples_per_channel (); const samplecnt_t n_samples = ctx.samples_per_channel ();
if (throw_level (ThrowStrict) && ctx.channels () != _channels) { 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) { 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) { if (_pos + n_samples > _duration) {

View File

@ -17,6 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <cassert>
#include "audiographer/general/loudness_reader.h" #include "audiographer/general/loudness_reader.h"
#include "pbd/fastlog.h" #include "pbd/fastlog.h"

View File

@ -19,14 +19,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "pbd/compose.h"
#include "audiographer/general/sample_format_converter.h" #include "audiographer/general/sample_format_converter.h"
#include "audiographer/exception.h" #include "audiographer/exception.h"
#include "audiographer/type_utils.h" #include "audiographer/type_utils.h"
#include "private/gdither/gdither.h" #include "private/gdither/gdither.h"
#include <boost/format.hpp>
namespace AudioGrapher namespace AudioGrapher
{ {
@ -72,9 +72,9 @@ void
SampleFormatConverter<int16_t>::init (samplecnt_t max_samples, int type, int data_width) SampleFormatConverter<int16_t>::init (samplecnt_t max_samples, int type, int data_width)
{ {
if (throw_level (ThrowObject) && data_width > 16) { if (throw_level (ThrowObject) && data_width > 16) {
throw Exception (*this, boost::str(boost::format throw Exception (*this, string_compose
("Data width (%1%) too large for int16_t") ("Data width (%1) too large for int16_t",
% data_width)); data_width));
} }
init_common (max_samples); init_common (max_samples);
dither = gdither_new ((GDitherType) type, channels, GDither16bit, data_width); dither = gdither_new ((GDitherType) type, channels, GDither16bit, data_width);
@ -85,9 +85,9 @@ void
SampleFormatConverter<uint8_t>::init (samplecnt_t max_samples, int type, int data_width) SampleFormatConverter<uint8_t>::init (samplecnt_t max_samples, int type, int data_width)
{ {
if (throw_level (ThrowObject) && data_width > 8) { if (throw_level (ThrowObject) && data_width > 8) {
throw Exception (*this, boost::str(boost::format throw Exception (*this, string_compose
("Data width (%1%) too large for uint8_t") ("Data width (%1) too large for uint8_t",
% data_width)); data_width));
} }
init_common (max_samples); init_common (max_samples);
dither = gdither_new ((GDitherType) type, channels, GDither8bit, data_width); dither = gdither_new ((GDitherType) type, channels, GDither8bit, data_width);
@ -197,15 +197,15 @@ void
SampleFormatConverter<TOut>::check_sample_and_channel_count (samplecnt_t samples, ChannelCount channels_) SampleFormatConverter<TOut>::check_sample_and_channel_count (samplecnt_t samples, ChannelCount channels_)
{ {
if (throw_level (ThrowStrict) && channels_ != channels) { if (throw_level (ThrowStrict) && channels_ != channels) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("Wrong channel count given to process(), %1% instead of %2%") ("Wrong channel count given to process(), %1 instead of %2",
% channels_ % channels)); channels_, channels));
} }
if (throw_level (ThrowProcess) && samples > data_out_size) { if (throw_level (ThrowProcess) && samples > data_out_size) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("Too many samples given to process(), %1% instead of %2%") ("Too many samples given to process(), %1 instead of %2",
% samples % data_out_size)); samples, data_out_size));
} }
} }

View File

@ -18,18 +18,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "pbd/compose.h"
#include "audiographer/general/sr_converter.h" #include "audiographer/general/sr_converter.h"
#include "audiographer/exception.h" #include "audiographer/exception.h"
#include "audiographer/type_utils.h" #include "audiographer/type_utils.h"
#include <cmath> #include <cmath>
#include <boost/format.hpp>
namespace AudioGrapher namespace AudioGrapher
{ {
using boost::format;
using boost::str;
SampleRateConverter::SampleRateConverter (uint32_t channels) SampleRateConverter::SampleRateConverter (uint32_t channels)
: active (false) : active (false)
@ -59,9 +58,9 @@ SampleRateConverter::init (samplecnt_t in_rate, samplecnt_t out_rate, int qualit
int err; int err;
src_state = src_new (quality, channels, &err); src_state = src_new (quality, channels, &err);
if (throw_level (ThrowObject) && !src_state) { if (throw_level (ThrowObject) && !src_state) {
throw Exception (*this, str (format throw Exception (*this, string_compose
("Cannot initialize sample rate converter: %1%") ("Cannot initialize sample rate converter: %1",
% src_strerror (err))); src_strerror (err)));
} }
src_data.src_ratio = (double) out_rate / (double) in_rate; src_data.src_ratio = (double) out_rate / (double) in_rate;
@ -113,9 +112,9 @@ SampleRateConverter::process (ProcessContext<float> const & c)
float * in = const_cast<float *> (c.data()); // TODO check if this is safe! float * in = const_cast<float *> (c.data()); // TODO check if this is safe!
if (throw_level (ThrowProcess) && samples > max_samples_in) { if (throw_level (ThrowProcess) && samples > max_samples_in) {
throw Exception (*this, str (format ( throw Exception (*this, string_compose
"process() called with too many samples, %1% instead of %2%") ("process() called with too many samples, %1 instead of %2",
% samples % max_samples_in)); samples, max_samples_in));
} }
int err; int err;
@ -163,9 +162,7 @@ SampleRateConverter::process (ProcessContext<float> const & c)
err = src_process (src_state, &src_data); err = src_process (src_state, &src_data);
if (throw_level (ThrowProcess) && err) { if (throw_level (ThrowProcess) && err) {
throw Exception (*this, str (format throw Exception (*this, string_compose ("An error occurred during sample rate conversion: %1",src_strerror (err)));
("An error occurred during sample rate conversion: %1%")
% src_strerror (err)));
} }
leftover_samples = src_data.input_frames - src_data.input_frames_used; leftover_samples = src_data.input_frames - src_data.input_frames_used;
@ -191,9 +188,9 @@ SampleRateConverter::process (ProcessContext<float> const & c)
} }
if (throw_level (ThrowProcess) && src_data.output_frames_gen == 0 && leftover_samples) { if (throw_level (ThrowProcess) && src_data.output_frames_gen == 0 && leftover_samples) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, string_compose
("No output samples generated with %1% leftover samples") ("No output samples generated with %1 leftover samples",
% leftover_samples)); leftover_samples));
} }
} while (leftover_samples > samples); } while (leftover_samples > samples);

View File

@ -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, 'sndfile', uselib_store='SNDFILE', atleast_version='1.0.18', mandatory=False)
autowaf.check_pkg(conf, 'fftw3f', uselib_store='FFTW3F', mandatory=True) autowaf.check_pkg(conf, 'fftw3f', uselib_store='FFTW3F', mandatory=True)
# Boost headers
autowaf.check_header(conf, 'cxx', 'boost/format.hpp')
def build(bld): def build(bld):
# Headers # Headers