diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-09-25 22:20:52 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-25 22:20:52 +0200 |
| commit | 63a81274aa1423ebb593cad9dfe0501853e1c1c5 (patch) | |
| tree | 875ede6e77315ffa98b889cb8119695cf3632d06 /src | |
| parent | 6698e6e33ba41a6d0ad30b02f9fb5ef18d788ad6 (diff) | |
Cleanup: remove use of an exception in favour of an optional.
Diffstat (limited to 'src')
| -rw-r--r-- | src/exceptions.cc | 7 | ||||
| -rw-r--r-- | src/exceptions.h | 7 | ||||
| -rw-r--r-- | src/main_sound_configuration.cc | 10 | ||||
| -rw-r--r-- | src/main_sound_configuration.h | 7 |
4 files changed, 11 insertions, 20 deletions
diff --git a/src/exceptions.cc b/src/exceptions.cc index fce1b583..ebcd70da 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -179,13 +179,6 @@ MainSoundConfigurationError::MainSoundConfigurationError (std::string s) } -UnknownChannelIdError::UnknownChannelIdError (std::string id) - : runtime_error(String::compose("Unrecognised channel ID '%1'", id)) -{ - -} - - NoReelsError::NoReelsError () : runtime_error("Cannot write a CPL which has no reels") { diff --git a/src/exceptions.h b/src/exceptions.h index 49f5a21e..5ccd616c 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -330,13 +330,6 @@ public: }; -class UnknownChannelIdError : public std::runtime_error -{ -public: - UnknownChannelIdError (std::string s); -}; - - class NoReelsError : public std::runtime_error { public: diff --git a/src/main_sound_configuration.cc b/src/main_sound_configuration.cc index c22da40b..f9bb07c1 100644 --- a/src/main_sound_configuration.cc +++ b/src/main_sound_configuration.cc @@ -83,9 +83,9 @@ MainSoundConfiguration::MainSoundConfiguration(string s) if (i == "-") { _channels.push_back(optional<Channel>()); } else { - try { - _channels.push_back(mca_id_to_channel(i)); - } catch (UnknownChannelIdError&) { + if (auto channel = mca_id_to_channel(i)) { + _channels.push_back(*channel); + } else { _valid = false; } } @@ -155,7 +155,7 @@ MainSoundConfiguration::set_mapping(int index, Channel c) } -Channel +optional<Channel> dcp::mca_id_to_channel(string id) { transform(id.begin(), id.end(), id.begin(), ::tolower); @@ -192,7 +192,7 @@ dcp::mca_id_to_channel(string id) return Channel::SIGN_LANGUAGE; } - throw UnknownChannelIdError(id); + return {}; } diff --git a/src/main_sound_configuration.h b/src/main_sound_configuration.h index 2c872ba2..8c4ac596 100644 --- a/src/main_sound_configuration.h +++ b/src/main_sound_configuration.h @@ -53,7 +53,12 @@ enum class MCASoundField extern std::string channel_to_mca_id(Channel c, MCASoundField field); -extern Channel mca_id_to_channel(std::string); + +/** @param id MCA channel ID + * @return Corresponding dcp::Channel, or empty if the id is not recognised. + */ +extern boost::optional<Channel> mca_id_to_channel(std::string id); + extern std::string channel_to_mca_name(Channel c, MCASoundField field); extern ASDCP::UL channel_to_mca_universal_label(Channel c, MCASoundField field, ASDCP::Dictionary const* dict); |
