This is an automated email from the git hooks/post-receive script. hmmr-guest pushed a commit to branch WIP in repository aghermann.
commit 3266daa39e1fb342c3b7269ad76799cf47309a30 Author: Andrei Zavada <[email protected]> Date: Sun Oct 13 22:47:54 2013 +0300 improve on 3755a8a5f0d0593, new in common/lang.hh: enum TThrowOption --- upstream/src/aghermann/expdesign/dirlevel.cc | 2 +- upstream/src/aghermann/expdesign/loadsave.cc | 2 +- upstream/src/aghermann/ui/mw/loadsave.cc | 8 +-- upstream/src/aghermann/ui/sf/sf.cc | 4 +- upstream/src/common/config-validate.hh | 73 ++++++++++++++++---------- upstream/src/common/lang.hh | 7 ++- 6 files changed, 60 insertions(+), 36 deletions(-) diff --git a/upstream/src/aghermann/expdesign/dirlevel.cc b/upstream/src/aghermann/expdesign/dirlevel.cc index 481d95a..5c3cb43 100644 --- a/upstream/src/aghermann/expdesign/dirlevel.cc +++ b/upstream/src/aghermann/expdesign/dirlevel.cc @@ -85,7 +85,7 @@ load() try { C.readFile( path().c_str()); - config.get( C, agh::global::default_log_facility); + config.get( C, agh::global::default_log_facility, agh::TThrowOption::do_throw); saved = true; return 0; diff --git a/upstream/src/aghermann/expdesign/loadsave.cc b/upstream/src/aghermann/expdesign/loadsave.cc index d406e26..e7e7d90 100644 --- a/upstream/src/aghermann/expdesign/loadsave.cc +++ b/upstream/src/aghermann/expdesign/loadsave.cc @@ -29,7 +29,7 @@ load_settings() try { conf.readFile( EXPD_FILE); - config.get( conf, agh::global::default_log_facility); + config.get( conf, agh::global::default_log_facility, agh::TThrowOption::do_throw); for ( size_t t = 0; t < ach::TTunable::_basic_tunables; ++t ) { auto& A = conf.lookup(string("tunable.") + ach::tunable_name(t)); diff --git a/upstream/src/aghermann/ui/mw/loadsave.cc b/upstream/src/aghermann/ui/mw/loadsave.cc index 771fc0f..6fe5e56 100644 --- a/upstream/src/aghermann/ui/mw/loadsave.cc +++ b/upstream/src/aghermann/ui/mw/loadsave.cc @@ -86,14 +86,14 @@ load_settings() try { conf.readFile( CONF_FILE); - config.get( conf, agh::global::default_log_facility); + config.get( conf, agh::global::default_log_facility, agh::TThrowOption::do_throw); try { auto& SC = conf.lookup("ScoreCodes"); for ( size_t i = sigfile::SPage::TScore::none; i < sigfile::SPage::TScore::TScore_total; ++i ) ext_score_codes[i].assign( (const char*)SC[i]); } catch (...) { - fprintf( stderr, "SExpDesignUI::load_settings(): Something is wrong with section ScoreCodes in %s\n", CONF_FILE); + APPLOG_WARN ("Something is wrong with section ScoreCodes in \"%s\"", CONF_FILE); } for( auto &p : saving_colors() ) { try { @@ -105,11 +105,11 @@ load_settings() C.clr.alpha = V[3]; gtk_color_chooser_set_rgba( GTK_COLOR_CHOOSER (CwB[p.second].btn), &C.clr); } catch (...) { - fprintf( stderr, "SExpDesignUI::load_settings(): Something is wrong with Color.%s in %s\n", p.first, CONF_FILE); + APPLOG_WARN ("Something is wrong with Color.%s in \"%s\"", p.first, CONF_FILE); } } } catch (...) { - fprintf( stderr, "SExpDesignUI::load_settings(): Something is wrong with %s\n", CONF_FILE); + APPLOG_WARN( "Something is wrong with contents of \"%s\"", CONF_FILE); } // plus postprocess and extra checks diff --git a/upstream/src/aghermann/ui/sf/sf.cc b/upstream/src/aghermann/ui/sf/sf.cc index 3ce5e9c..e8c430d 100644 --- a/upstream/src/aghermann/ui/sf/sf.cc +++ b/upstream/src/aghermann/ui/sf/sf.cc @@ -741,10 +741,10 @@ load_montage() } catch (libconfig::FileIOException ex) { return; } - config.get( conf, agh::global::default_log_facility); + config.get( conf, agh::global::default_log_facility, agh::TThrowOption::no_throw); for ( auto &h : channels ) { - h.config.get( conf, agh::global::default_log_facility); + h.config.get( conf, agh::global::default_log_facility, agh::TThrowOption::no_throw); // postprocess a little h.selection_start = h.selection_start_time * h.samplerate(); diff --git a/upstream/src/common/config-validate.hh b/upstream/src/common/config-validate.hh index da52bcd..f2ba3e0 100644 --- a/upstream/src/common/config-validate.hh +++ b/upstream/src/common/config-validate.hh @@ -64,7 +64,7 @@ ensure_path( libconfig::Setting& S, libconfig::Setting::Type type, const string& template <typename T> void -put( libconfig::Config& C, const string& key, const T& value, agh::log::CLogFacility* lo = nullptr) +put( libconfig::Config& C, const string& key, const T& value, agh::log::CLogFacility* lo) { ensure_path( C.getRoot(), libconfig_type_id<T>(), key) = value; } @@ -99,8 +99,8 @@ put( libconfig::Config& C, const string& key, const array<T, N>& vl) struct IValidator { - virtual void get( const libconfig::Config&, agh::log::CLogFacility*) const = 0; - virtual void put( libconfig::Config&, agh::log::CLogFacility*) const = 0; + virtual void get( const libconfig::Config&, agh::log::CLogFacility*, agh::TThrowOption) const = 0; + virtual void put( libconfig::Config&, agh::log::CLogFacility*) const = 0; virtual ~IValidator() {} // -Wdelete-non-virtual-dtor }; @@ -134,21 +134,28 @@ struct SValidator : IValidator { : key (_key), rcp (_rcp), valf (_valf) {} - void get( const libconfig::Config& C, agh::log::CLogFacility* lo = nullptr) const + void + get( const libconfig::Config& C, + agh::log::CLogFacility* lo, + agh::TThrowOption throw_option) const { T tmp; if ( not C.lookupValue( key, tmp) ) { if ( lo ) - lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "key %s not found", key.c_str()); + lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "Key \"%s\" not found", key.c_str()); return; // leave at default } - if ( not valf(tmp) ) - throw invalid_argument( string("Bad value for \"") + key + "\""); - *rcp = tmp; + if ( not valf(tmp) ) { + lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "Bsd value for key \"%s\"", key.c_str()); + if ( throw_option == TThrowOption::do_throw ) + throw invalid_argument( string("Bad value for \"") + key + "\""); + } else + *rcp = tmp; } - void put( libconfig::Config& C, agh::log::CLogFacility* lo = nullptr) const + void + put( libconfig::Config& C, agh::log::CLogFacility* lo) const { - confval::put( C, key, *rcp); + confval::put( C, key, *rcp, lo); } }; @@ -175,17 +182,22 @@ struct SValidator : IValidator { template <> inline void SValidator<size_t>:: -get( const libconfig::Config& C, agh::log::CLogFacility* lo) const +get( const libconfig::Config& C, + agh::log::CLogFacility* lo, + agh::TThrowOption throw_option) const { int tmp; // libconfig doesn't deal in unsigned values if ( not C.lookupValue( key, tmp) ) { if (lo) - lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "key %s not found", key.c_str()); + lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "Key %s not found", key.c_str()); return; // leave at default } - if ( not valf(tmp) ) - throw invalid_argument( string("Bad value for \"") + key + "\""); - *rcp = tmp; + if ( tmp < 0 || not valf((size_t)tmp) ) { + lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "Bad value for key \"%s\"", key.c_str()); + if ( throw_option == TThrowOption::do_throw ) + throw invalid_argument( string("Bad value for \"") + key + "\""); + } else + *rcp = tmp; } @@ -193,26 +205,29 @@ template <typename T> void get( list<SValidator<T>>& vl, libconfig::Config& conf, - bool nothrow = true) + agh::log::CLogFacility* lo, + agh::TThrowOption throw_option) { for ( auto& V : vl ) - if ( nothrow ) + if ( throw_option == TThrowOption::no_throw ) try { - V.get( conf); + V.get( conf, lo); } catch ( exception& ex) { - fprintf( stderr, "confval::get(list): %s\n", ex.what()); + if ( lo ) + lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "get(list): %s", ex.what()); } else - V.get( conf); + V.get( conf, lo); } template <typename T> void put( list<SValidator<T>>& vl, - libconfig::Config& conf) + libconfig::Config& conf, + agh::log::CLogFacility* lo) { for ( auto& V : vl ) - V.put( conf); + V.put( conf, lo); } @@ -230,19 +245,23 @@ class CConfigKeys { } template <class K, class V> - CConfigKeys& operator()( const K& k, V* v) + CConfigKeys& + operator()( const K& k, V* v) { return S.push_back( new SValidator<V>(k, v)), *this; } template <class K, class V, class F> - CConfigKeys& operator()( const K& k, V* v, const F& f) + CConfigKeys& + operator()( const K& k, V* v, const F& f) { return S.push_back( new SValidator<V>(k, v, f)), *this; } - void get( libconfig::Config& C, agh::log::CLogFacility* lo) + void + get( libconfig::Config& C, agh::log::CLogFacility* lo, agh::TThrowOption throw_option) { for ( auto& K : S ) - K->get( C, lo); + K->get( C, lo, throw_option); } - void put( libconfig::Config& C, agh::log::CLogFacility* lo) + void + put( libconfig::Config& C, agh::log::CLogFacility* lo) { for ( auto& K : S ) K->put( C, lo); diff --git a/upstream/src/common/lang.hh b/upstream/src/common/lang.hh index 66f6edb..ce239f3 100644 --- a/upstream/src/common/lang.hh +++ b/upstream/src/common/lang.hh @@ -25,11 +25,16 @@ using namespace std; namespace agh { +// for functions to suppress some possibly benign exceptions: +enum class TThrowOption { + do_throw, + no_throw, +}; typedef unsigned long hash_t; inline int dbl_cmp( double x, double y) __attribute__ ((pure)); -inline int dbl_cmp( double x, double y) +inline int dbl_cmp( double x, double y) // optional precision maybe? { if ( fabs(x - y) > DBL_EPSILON ) return (x > y) ? 1 : -1; -- Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
