Improved exception raised from invalid analysis strings.
Now all invalid strings are reported. Also swapped asynchronous logging sink for synchronous.
This commit is contained in:
@@ -44,7 +44,7 @@ bool in_array(string &value, const container &array)
|
||||
\param end - An iterator pointing to the point at which to stop analysing strings.
|
||||
*/
|
||||
template<typename Iter>
|
||||
Iter check_analyses_valid(Iter iterator, Iter end)
|
||||
std::list<string> check_analyses_valid(Iter iterator, Iter end)
|
||||
{
|
||||
static std::list<string> valid_analyses = {
|
||||
"RMS",
|
||||
@@ -63,13 +63,14 @@ Iter check_analyses_valid(Iter iterator, Iter end)
|
||||
"SKEWNESS",
|
||||
"HARM_RATIO"
|
||||
};
|
||||
std::list<string> invalid;
|
||||
|
||||
while(iterator != end)
|
||||
{
|
||||
if(!in_array(*iterator, valid_analyses)) {
|
||||
return iterator;
|
||||
invalid.push_back(*iterator);
|
||||
}
|
||||
++iterator;
|
||||
}
|
||||
return iterator;
|
||||
return invalid;
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ class Logger {
|
||||
static void log_formatter(boost::log::record_view const& rec, boost::log::formatting_ostream& strm);
|
||||
|
||||
// Define types for logging backends
|
||||
typedef boost::log::sinks::asynchronous_sink<boost::log::sinks::text_ostream_backend> console_backend;
|
||||
typedef boost::log::sinks::asynchronous_sink<boost::log::sinks::text_file_backend> file_backend;
|
||||
typedef boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend> console_backend;
|
||||
typedef boost::log::sinks::synchronous_sink<boost::log::sinks::text_file_backend> file_backend;
|
||||
|
||||
// Define a sink for console output and for log file output
|
||||
boost::shared_ptr<console_backend> console_sink;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "AudioDatabase.h"
|
||||
#include <stdexcept>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -20,14 +22,15 @@ AudioDatabase::AudioDatabase(
|
||||
log->info("Audio directory: " + audio_dir);
|
||||
// Remove duplicate strings from vector of analyses.
|
||||
std::vector<string>::iterator it;
|
||||
it = std::unique (analyses.begin(), analyses.end()); // 10 20 30 20 10 ? ? ? ?
|
||||
it = std::unique (analyses.begin(), analyses.end());
|
||||
analyses.resize(std::distance(analyses.begin(),it));
|
||||
|
||||
// Check that all analysis strings supplied refer to valid analyses.
|
||||
vector<string>::const_iterator valid = check_analyses_valid(analyses.begin(), analyses.end());
|
||||
if(valid != analyses.end()) {
|
||||
string err = "The analysis string supplied to the AudioDatabase constructor is not valid: " + *valid;
|
||||
throw std::runtime_error(err);
|
||||
list<string> invalid = check_analyses_valid(analyses.begin(), analyses.end());
|
||||
if(!invalid.empty()) {
|
||||
string err = "The following analysis string(s) supplied to the AudioDatabase constructor are not valid: ";
|
||||
string invalid_strings = boost::algorithm::join(invalid, " ");
|
||||
throw std::runtime_error(err + invalid_strings);
|
||||
}
|
||||
|
||||
this->database_dir = database_dir;
|
||||
|
||||
+3
-3
@@ -70,8 +70,8 @@ Logger::Logger() {
|
||||
};
|
||||
|
||||
Logger::~Logger() {
|
||||
Logger::console_sink->flush();
|
||||
Logger::file_sink->flush();
|
||||
Logger::console_sink->flush();
|
||||
}
|
||||
void Logger::trace(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::trace) << str;
|
||||
@@ -91,12 +91,12 @@ void Logger::warning(std::string str) {
|
||||
|
||||
void Logger::error(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::error) << str;
|
||||
Logger::console_sink->flush();
|
||||
Logger::file_sink->flush();
|
||||
Logger::console_sink->flush();
|
||||
}
|
||||
|
||||
void Logger::fatal(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::fatal) << str;
|
||||
Logger::console_sink->flush();
|
||||
Logger::file_sink->flush();
|
||||
Logger::console_sink->flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user