From ec3d818fc9fbdadfa8bd790de1976ea33884732c Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de> Date: Fri, 26 Oct 2012 23:38:56 +0200 Subject: [PATCH] fiter requires nonempty file selection, unless constructed with mode=IterTOL --- pub/src/curve.cpp | 22 ---------------------- pub/src/edif.cpp | 3 +-- pub/src/manip.cpp | 14 ++++++-------- pub/src/mem.cpp | 40 +++++++++++++++++----------------------- pub/src/mem.h | 13 ++++++++++--- 5 files changed, 34 insertions(+), 58 deletions(-) diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index 8514c418..7b2f9c23 100644 --- a/pub/src/curve.cpp +++ b/pub/src/curve.cpp @@ -268,8 +268,6 @@ double COlc::curve_val_sca( double farg, uint k, uint j ) const void NCurveFile::CreateFitcurve() { NOlm::IterateD fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fc( new COlc ); fc->askCurve( "Curve definition" ); @@ -327,8 +325,6 @@ void NCurveFile::ChangeExpr() ftmp->askCurve( "Replace curve definition by" ); NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fc; while( (fc=fiter()) ) { @@ -356,8 +352,6 @@ void NCurveFile::ChangeExpr() void NCurveFile::ChangeRange() { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; string expr = sask( "Fit range: boolean expression with" " restrictions on data (x,y,i,..) ?" ); @@ -381,8 +375,6 @@ void NCurveFile::ChangeRange() void NCurveFile::SetAllPars(void) { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fin; while( (fin=fiter()) ) { @@ -397,8 +389,6 @@ void NCurveFile::SetAllPars(void) void NCurveFile::ShowPar(void) { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fin; while( (fin=fiter()) ) @@ -475,8 +465,6 @@ string COlc::pInfoCat() const void NCurveFile::SetFixed( bool fix ) { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; static string sel; sel = wask( string(fix?"Fix":"Unfix") + " which parameters", sel ); @@ -505,8 +493,6 @@ void NCurveFile::SetFileReference( const string& which ) // "v-" switch convolution off { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; string expr; PTree T; @@ -590,8 +576,6 @@ void NCurveFile::setConv( PSpec *sv, uint *kv, uint *jv, uint k, uint j ) void NCurveFile::SetProperties( string which ) { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fc; while ( (fc=fiter()) ) { @@ -765,8 +749,6 @@ void NCurveFile::Fit( bool _allow_slow_conv ) allow_slow_conv = _allow_slow_conv; NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fc; while ( (fc=fiter()) ) { @@ -944,8 +926,6 @@ void NCurveFile::SetIntTuningPars( string which ) void NCurveFile::IntegralProperty() { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; POlc fin; @@ -1143,8 +1123,6 @@ namespace NCurveFile void NCurveFile::CumulativeDistribution(void) { NOlm::IterateC fiter; - if( !(fiter.size()) ) - throw "no curve to operate on"; static int nb = 3; nb = iask( "How many twofold divisions", nb ); diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp index 6497660b..66c37682 100644 --- a/pub/src/edif.cpp +++ b/pub/src/edif.cpp @@ -36,8 +36,7 @@ using boost::format; void NEdif::ShowFiles() { - NOlm::IterateO fiter; - fiter.choose_all(); + NOlm::IterateO fiter( NOlm::IterALL | NOlm::IterTOL ); POlo f; while( f = fiter() ) { POlc fc = P2C( f ); diff --git a/pub/src/manip.cpp b/pub/src/manip.cpp index 75c7db83..4a941a61 100644 --- a/pub/src/manip.cpp +++ b/pub/src/manip.cpp @@ -45,14 +45,12 @@ namespace NManip { void NManip::ProtectSpecs( bool on ) { NOlm::SelAssert(); - + NOlm::IterateO fiter; string sel; if( on ) sel = wask( "Protect which spectra from forthcoming operations" ); else sel = "-"; - - NOlm::IterateO fiter; POlo fio; while( fio = fiter() ) { CList lis( sel, 0, fio->nJ()-1 ); @@ -72,13 +70,13 @@ void NManip::ProtectSpecs( bool on ) void NManip::PtsSelect( bool sel_del ) { NOlm::SelAssert(); + NOlm::IterateD fiter; static string pSel = ""; pSel = wask( string( sel_del ? "Delete" : "Retain" ) + " which points", pSel ); CList pLis( pSel ); - NOlm::IterateD fiter; POld fin; while( (fin = fiter()) ) { POld fout( fin->new_old() ); @@ -113,13 +111,13 @@ void NManip::PtsSelect( bool sel_del ) void NManip::PtsAvge() { NOlm::SelAssert(); + NOlm::IterateD fiter; static string sel; sel = wask( "Start bins at points", sel ); if ( sel=="" || sel=="-" ) return; - NOlm::IterateD fiter; POld fin; while( fin = fiter() ) { POld fout( fin->new_old() ); @@ -166,13 +164,13 @@ void NManip::PtsAvge() void NManip::PtsAvgeFixed() { NOlm::SelAssert(); + NOlm::IterateD fiter; static int ng=2; ng = iask( "Number of points per bin", ng ); if ( ng<1 ) throw "invalid choice"; - NOlm::IterateD fiter; POld fin; while( fin = fiter() ) { POld fout( fin->new_old() ); @@ -211,6 +209,7 @@ void NManip::PtsAvgeFixed() void NManip::PtsAvgeByErr( const string& subcmd ) { NOlm::SelAssert(); + NOlm::IterateD fiter; bool mode_abs; if ( subcmd=="a" ) @@ -223,7 +222,6 @@ void NManip::PtsAvgeByErr( const string& subcmd ) static double errbound; errbound = dask( "keep error below", errbound ); - NOlm::IterateD fiter; POld fin; while( fin = fiter() ) { POld fout( fin->new_old() ); @@ -272,6 +270,7 @@ void NManip::PtsAvgeByErr( const string& subcmd ) void NManip::PtsSort() { NOlm::SelAssert(); + NOlm::IterateD fiter; string expr = sask("Sort points according to"); if (expr=="") return; @@ -279,7 +278,6 @@ void NManip::PtsSort() if( T->has_dummy() ) throw "dummy argument t not allowed when operating on data"; - NOlm::IterateD fiter; POld fin; while( fin = fiter() ) { uint k, n, i; diff --git a/pub/src/mem.cpp b/pub/src/mem.cpp index f068f685..f356dd39 100644 --- a/pub/src/mem.cpp +++ b/pub/src/mem.cpp @@ -158,14 +158,13 @@ void NOlm::JSelAsk( string quest, string *jSel, CList *jLis ) namespace NOlm { - class IterateBase { + class MyIterate { public: // TODO: should become private uint iV; CList Sel; public: - IterateBase(); + MyIterate( int mode ); void reset(); - void choose_all(); POlo get(); bool going() const; uint k() const; @@ -173,43 +172,41 @@ namespace NOlm { uint size() const; }; - IterateBase::IterateBase() + MyIterate::MyIterate( int mode ) { - Sel = FSel; + if ( mode & IterALL ) + Sel = CList(0,MOM.size()-1); + else + Sel = FSel; reset(); }; - void IterateBase::reset() + void MyIterate::reset() { iV = 0; }; - void IterateBase::choose_all() - { - Sel = CList(0,MOM.size()-1); - }; - - POlo IterateBase::get() + POlo MyIterate::get() { return MOM[Sel.V[iV++]]; } - bool IterateBase::going() const + bool MyIterate::going() const { return iV<Sel.size(); } - uint IterateBase::k() const + uint MyIterate::k() const { return Sel.V[iV-1]; } - uint IterateBase::iteration() const + uint MyIterate::iteration() const { return iV-1; } - uint IterateBase::size() const + uint MyIterate::size() const { return Sel.V.size(); } @@ -219,9 +216,11 @@ namespace NOlm { //* Iterators: Interface *// //**************************************************************************// -NOlm::IterateO::IterateO() +NOlm::IterateO::IterateO( int mode ) { - pimpl = new IterateBase(); + pimpl = new MyIterate( mode ); + if ( !(mode & IterTOL) && !size() ) + throw "empty file selection"; } NOlm::IterateO::~IterateO() @@ -239,11 +238,6 @@ void NOlm::IterateO::reset() return pimpl->reset(); } -void NOlm::IterateO::choose_all() -{ - return pimpl->choose_all(); -} - uint NOlm::IterateO::k() const { return pimpl->k(); diff --git a/pub/src/mem.h b/pub/src/mem.h index 18457a99..8211e414 100644 --- a/pub/src/mem.h +++ b/pub/src/mem.h @@ -11,6 +11,12 @@ namespace NOlm { // the data: extern vector<POlo> MOM; // the mother of all on-line data + class CFileSelection { + protected: + class MyFileSelection* pimpl; + public: + }; + // the current selection: extern CList FSel; extern CList FSelOld; @@ -32,15 +38,16 @@ namespace NOlm { void JSelAsk( string quest, string *jSel, class CList *JSel ); //! Iterate over files of all types. + const int IterALL = 1; // select all online files + const int IterTOL = 2; // tolerate empty selection class IterateO { protected: - class IterateBase* pimpl; + class MyIterate* pimpl; public: - IterateO(); + IterateO( int mode=0 ); ~IterateO(); POlo operator()(); void reset(); - void choose_all(); uint k() const; uint iteration() const; uint size() const; -- GitLab