class
#include <audioreader.hpp>
v_1_0_0::AudioValidator Abstract base class for validation handlers for AudioReaderImpls.
Implements a class that just provides some assert methods that get a label, a current value, a proper value and an error message. The validating handler keeps an error list and can also return the latest error or the complete list of errors. Subclasses may decide to throw exceptions by implementing on_
.
It also provides default assertions for validating against CDDA, thereby delegating to CDDAValidator.
Subclasses must implement do_
to provide the list of supported audio codecs, i.e. codecs that are actively validated. If the subclass does not validate any aspects of the codec, it should return an empty set.
Derived classes
- class v_1_0_0::DefaultValidator
- Abstract base implementation of AudioValidator.
Public types
- using codec_set_type = std::set<Codec>
- Type of the codec set.
- using error_list_type = std::vector<std::string>
- Type of the error list.
Constructors, destructors, conversion operators
- AudioValidator()
- Empty constructor.
- ~AudioValidator() virtual noexcept
- Virtual default destructor.
Public functions
-
auto codecs() const -> codec_
set_ type - Returns the codec to validate.
- void error(const std::string& msg)
- Add an error to the internal error list.
-
auto get_errors() const -> const error_
list_ type& - Returns the current error list.
- auto has_errors() const -> bool
- Returns TRUE iff there are any errors occurred so far.
- auto last_error() const -> const std::string&
- Returns the last error that occurred.
- void validate_bits_per_sample(const int bits_per_sample)
- CDDA validation of the sample size.
- void validate_num_channels(const int num_channels)
- CDDA validation for stereo (must be 2).
- void validate_samples_per_second(const int samples_per_second)
- CDDA validation of the sampling rate (must be 44.100).
Protected functions
- auto assert_at_least(const std::string& label, int value, int proper_value, const std::string& error_msg) -> bool
- Returns TRUE iff value >= proper_value.
- auto assert_at_most(const std::string& label, int value, int proper_value, const std::string& error_msg) -> bool
- Returns TRUE iff value <= proper_value.
- auto assert_equals(const std::string& label, int value, int proper_value, const std::string& error_msg) -> bool
- Returns TRUE iff value == proper_value.
- auto assert_equals_u(const std::string& label, uint32_t value, uint32_t proper_value, const std::string& error_msg) -> bool
- Returns TRUE iff value == proper_value.
- auto assert_true(const std::string& label, bool value, const std::string& error_msg) -> bool
- Returns TRUE iff value is true.
- void fail_if(const bool condition)
- Call on_
failure() iff condition is TRUE. - void log_error_stack() const
- Logs every error on the error stack with ARCS_LOG_ERROR.
- void on_failure() pure virtual
- Hook called when one of the predefined validations fails.
Private functions
-
auto do_codecs() const -> codec_
set_ type pure virtual - Implements
codecs()
.
Function documentation
void arcsdec:: v_1_0_0:: AudioValidator:: error(const std::string& msg)
Add an error to the internal error list.
Parameters | |
---|---|
msg in | The error message to be added to the error list |
const error_ list_ type& arcsdec:: v_1_0_0:: AudioValidator:: get_errors() const
Returns the current error list.
Returns | Current list of errors |
---|
bool arcsdec:: v_1_0_0:: AudioValidator:: has_errors() const
Returns TRUE iff there are any errors occurred so far.
Returns | TRUE iff there are errors in the internal error list |
---|
const std::string& arcsdec:: v_1_0_0:: AudioValidator:: last_error() const
Returns the last error that occurred.
Returns | The last error that occurred |
---|
void arcsdec:: v_1_0_0:: AudioValidator:: validate_bits_per_sample(const int bits_per_sample)
CDDA validation of the sample size.
Parameters | |
---|---|
bits_per_sample in | The sample size to validate |
Returns | TRUE if the sample size equals CDDAValidator:: |
The number of bits per sample must conform to CDDAValidator::
Calls on_
when validation fails.
void arcsdec:: v_1_0_0:: AudioValidator:: validate_num_channels(const int num_channels)
CDDA validation for stereo (must be 2).
Parameters | |
---|---|
num_channels in | The number of channels to test |
Returns | TRUE if num_channels is equal to CDDAValidator:: |
The number of channels must conform to CDDAValidator::
Calls on_
when validation fails.
void arcsdec:: v_1_0_0:: AudioValidator:: validate_samples_per_second(const int samples_per_second)
CDDA validation of the sampling rate (must be 44.100).
Parameters | |
---|---|
samples_per_second in | The sampling rate to test |
Returns | TRUE if the sampling rate equals CDDAValidator:: |
The number of samples per second must conform to CDDAValidator::
Calls on_
when validation fails.
bool arcsdec:: v_1_0_0:: AudioValidator:: assert_at_least(const std::string& label,
int value,
int proper_value,
const std::string& error_msg) protected
Returns TRUE iff value >= proper_value.
Parameters | |
---|---|
label in | Label to log for this test |
value in | Value to be checked |
proper_value in | Value to check against |
error_msg in | Message to log in case value is smaller than proper_value |
Returns | TRUE if value is not smaller than proper_value, otherwise FALSE |
Always prints the label. Iff the comparison is not TRUE, error_msg is printed and a new error is added to the error list.
bool arcsdec:: v_1_0_0:: AudioValidator:: assert_at_most(const std::string& label,
int value,
int proper_value,
const std::string& error_msg) protected
Returns TRUE iff value <= proper_value.
Parameters | |
---|---|
label in | Label to log for this test |
value in | Value to be checked |
proper_value in | Value to check against |
error_msg in | Message to log in case value is bigger than proper_value |
Returns | TRUE if value is not bigger than proper_value, otherwise FALSE |
Always prints the label. Iff the comparison is not TRUE, error_msg is printed and a new error is added to the error list.
bool arcsdec:: v_1_0_0:: AudioValidator:: assert_equals(const std::string& label,
int value,
int proper_value,
const std::string& error_msg) protected
Returns TRUE iff value == proper_value.
Parameters | |
---|---|
label in | Label to log for this test |
value in | Value to be checked |
proper_value in | Value to check against |
error_msg in | Message to log in case value is not equal to proper_value |
Returns | TRUE if value is equal to proper_value, otherwise FALSE |
Always prints the label. Iff the comparison is not TRUE, error_msg is printed and a new error is added to the error list.
bool arcsdec:: v_1_0_0:: AudioValidator:: assert_equals_u(const std::string& label,
uint32_t value,
uint32_t proper_value,
const std::string& error_msg) protected
Returns TRUE iff value == proper_value.
Parameters | |
---|---|
label in | Label to log for this test |
value in | Value to be checked |
proper_value in | Value to check against |
error_msg in | Message to log in case value is not equal to proper_value |
Returns | TRUE if value is equal to proper_value, otherwise FALSE |
Always prints the label. Iff the comparison is not TRUE, error_msg is printed and a new error is added to the error list.
bool arcsdec:: v_1_0_0:: AudioValidator:: assert_true(const std::string& label,
bool value,
const std::string& error_msg) protected
Returns TRUE iff value is true.
Parameters | |
---|---|
label in | Label to log for this test |
value in | Value to be checked for being TRUE |
error_msg in | Message to log in case value is not TRUE |
Returns | TRUE if value is TRUE, otherwise FALSE |
Always prints the label. Iff the comparison is not TRUE, error_msg is printed and a new error is added to the error list.
void arcsdec:: v_1_0_0:: AudioValidator:: fail_if(const bool condition) protected
Call on_
Parameters | |
---|---|
condition in | Condition to check for TRUE |
void arcsdec:: v_1_0_0:: AudioValidator:: log_error_stack() const protected
Logs every error on the error stack with ARCS_LOG_ERROR.
Leaves the error stack unmodified.
codec_ set_ type arcsdec:: v_1_0_0:: AudioValidator:: do_codecs() const pure virtual private
Implements codecs()
.
Returns | List of supported codecs |
---|