diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-01-14 23:50:38 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-01-19 22:48:28 +0100 |
| commit | eb28997f188c905af40054e4139251ebf1756ae4 (patch) | |
| tree | 91214593633d2a391587e46e2f2375d2fc47ad3b /src/main_sound_configuration.h | |
| parent | d4024848dfe293b06440d20a9f48894b2b008316 (diff) | |
Make MainSoundConfiguration behave "correctly" with badly-formatted strings.
Add some documentation for a design "principle" when handling malformatted
data, and make MainSoundConfiguration adhere to that.
Diffstat (limited to 'src/main_sound_configuration.h')
| -rw-r--r-- | src/main_sound_configuration.h | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/main_sound_configuration.h b/src/main_sound_configuration.h index d0ddd1f2..1f9c18e9 100644 --- a/src/main_sound_configuration.h +++ b/src/main_sound_configuration.h @@ -35,6 +35,8 @@ #ifndef LIBDCP_MAIN_SOUND_CONFIGURATION_H #define LIBDCP_MAIN_SOUND_CONFIGURATION_H + +#include "exceptions.h" #include "types.h" #include <string> @@ -61,25 +63,48 @@ extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, class MainSoundConfiguration { public: + /** Set up a MainSoundConfiguration from a string. If the string is valid, valid() will + * subsequently return true and all accessors can be called. Otherwise, all accessors + * except to_string() will throw a MainSoundConfigurationError and to_string() will + * return the original invalid string. + */ explicit MainSoundConfiguration(std::string); MainSoundConfiguration (MCASoundField field_, int channels); MCASoundField field () const { + throw_if_invalid(); return _field; } int channels () const { + throw_if_invalid(); return _channels.size(); } boost::optional<Channel> mapping (int index) const; void set_mapping (int index, Channel channel); - std::string to_string () const; + std::string to_string() const { + return _configuration; + } + + bool valid() const { + return _valid; + } private: - MCASoundField _field; - std::vector<boost::optional<Channel>> _channels; + void update_string(); + + void throw_if_invalid() const { + if (!_valid) { + throw MainSoundConfigurationError(_configuration); + } + } + + std::string _configuration; + mutable bool _valid = true; + mutable MCASoundField _field; + mutable std::vector<boost::optional<Channel>> _channels; }; |
