summaryrefslogtreecommitdiff
path: root/src/CheckAudioFormat.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-11-10 11:45:17 +0100
committerMax Kellermann <max@musicpd.org>2016-11-10 12:55:08 +0100
commitcfd51db2292aa9ff0b33d2a7ac50a78cafec6015 (patch)
tree4026d81758898f259622d5cce49f8b052237eaff /src/CheckAudioFormat.cxx
parent12f11c97ae9e5b1b6367e4a5c49713fdd4984b89 (diff)
CheckAudioFormat: migrate from class Error to C++ exceptions
Diffstat (limited to 'src/CheckAudioFormat.cxx')
-rw-r--r--src/CheckAudioFormat.cxx70
1 files changed, 26 insertions, 44 deletions
diff --git a/src/CheckAudioFormat.cxx b/src/CheckAudioFormat.cxx
index 5146f02ea..a6d0615d1 100644
--- a/src/CheckAudioFormat.cxx
+++ b/src/CheckAudioFormat.cxx
@@ -20,61 +20,43 @@
#include "config.h"
#include "CheckAudioFormat.hxx"
#include "AudioFormat.hxx"
-#include "util/Error.hxx"
-#include "util/Domain.hxx"
+#include "util/RuntimeError.hxx"
-#include <assert.h>
+#include <stdexcept>
-const Domain audio_format_domain("audio_format");
+#include <assert.h>
-bool
-audio_check_sample_rate(unsigned long sample_rate, Error &error)
+void
+CheckSampleRate(unsigned long sample_rate)
{
- if (!audio_valid_sample_rate(sample_rate)) {
- error.Format(audio_format_domain,
- "Invalid sample rate: %lu", sample_rate);
- return false;
- }
-
- return true;
+ if (!audio_valid_sample_rate(sample_rate))
+ throw FormatRuntimeError("Invalid sample rate: %lu",
+ sample_rate);
}
-bool
-audio_check_sample_format(SampleFormat sample_format, Error &error)
+void
+CheckSampleFormat(SampleFormat sample_format)
{
- if (!audio_valid_sample_format(sample_format)) {
- error.Format(audio_format_domain,
- "Invalid sample format: %u",
- unsigned(sample_format));
- return false;
- }
-
- return true;
+ if (!audio_valid_sample_format(sample_format))
+ throw FormatRuntimeError("Invalid sample format: %u",
+ unsigned(sample_format));
}
-bool
-audio_check_channel_count(unsigned channels, Error &error)
+void
+CheckChannelCount(unsigned channels)
{
- if (!audio_valid_channel_count(channels)) {
- error.Format(audio_format_domain,
- "Invalid channel count: %u", channels);
- return false;
- }
-
- return true;
+ if (!audio_valid_channel_count(channels))
+ throw FormatRuntimeError("Invalid channel count: %u",
+ channels);
}
-bool
-audio_format_init_checked(AudioFormat &af, unsigned long sample_rate,
- SampleFormat sample_format, unsigned channels,
- Error &error)
+AudioFormat
+CheckAudioFormat(unsigned long sample_rate,
+ SampleFormat sample_format, unsigned channels)
{
- if (audio_check_sample_rate(sample_rate, error) &&
- audio_check_sample_format(sample_format, error) &&
- audio_check_channel_count(channels, error)) {
- af = AudioFormat(sample_rate, sample_format, channels);
- assert(af.IsValid());
- return true;
- } else
- return false;
+ CheckSampleRate(sample_rate);
+ CheckSampleFormat(sample_format);
+ CheckChannelCount(channels);
+
+ return AudioFormat(sample_rate, sample_format, channels);
}