diff --git a/TODO b/TODO index cd88fbcf583a4dd585f7b815eb9f9330c7184f1a..0c525226b4c21c5341d2de5e8ce7472aa7d31269 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ - convolutand must not be defined over full energy range - when include file is not found: "terminate called after throwing an instance of 'std::string'" -- fc funzt nicht für Kurven == TO CHECK == diff --git a/pub/CHANGELOG b/pub/CHANGELOG index 5fa492b0a5912a02886024556f4ff283174caa43..45ac1aac0f46665d0b4c2f3b74fa1d826171b964 100644 --- a/pub/CHANGELOG +++ b/pub/CHANGELOG @@ -3,6 +3,8 @@ Release 2.1.0c - bugfixes, among them: - let op ignore data files - set weight to lin if data have no error bars +- internal changes: + - simplified index.cpp, removed test mode Release 2.1.0b of 15may10: diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp index 2011f670647b0af7428d0912e55531ffb1fbfec1..288a123a41ff979b50bf11905352c28f4c993f79 100644 --- a/pub/src/edif.cpp +++ b/pub/src/edif.cpp @@ -255,9 +255,8 @@ user_choice: goto make_table; } else if (choice=="" || choice=="q") { return; - } else if (Choice.parse(choice, 0, AllR.size())) { - goto user_choice; - } + } else + Choice.parse( choice, 0, AllR.size() ); // It's a list diff --git a/pub/src/index.cpp b/pub/src/index.cpp index 69986942f68af7be3d8b9766e776c25f204489c5..e70186f25bf2cc8a407657cf4829a82274ca8195 100644 --- a/pub/src/index.cpp +++ b/pub/src/index.cpp @@ -19,28 +19,25 @@ using namespace std; namespace IndexParse { - enum bla { TEST, LIST, SET } client; - void* saveto; - void newval(uint val); - uint p0, pn; - - bool ParseTest(string inp, uint v0=0, uint vn=0); - bool ParseSet(set<uint> *T, string inp, uint v0=0, uint vn=0); - bool ParseList(vector<uint> *V, string inp, uint v0=0, uint vn=0); - bool ParseExe(string inp); - bool ParseSkipinterval(string inp); - bool ParseSkipfactor(string inp, int *val); - bool ParseInterval(string inp, int skip); - bool ParseValue(string inp, int which, uint *val); - - inline bool onlytest() { return client==TEST; }; - inline bool limgiven() { return (pn > 0); }; - inline bool allowoutoflim() { return client==TEST; } + enum bla { LIST, SET } client; + void* saveto; + void newval(uint val); + uint p0, pn; + + void ParseSet(set<uint> *T, string inp, uint v0=0, uint vn=0); + void ParseList(vector<uint> *V, string inp, uint v0=0, uint vn=0); + void ParseExe(string inp); + void ParseSkipinterval(string inp); + void ParseSkipfactor(string inp, int *val); + void ParseInterval(string inp, int skip); + void ParseValue(string inp, int which, uint *val); + + inline bool limgiven() { return (pn > 0); }; } namespace IndexDialog { - extern const char* helptext; - char decode(const string& resp, string *rval ); + extern const char* helptext; + char decode(const string& resp, string *rval ); } @@ -50,101 +47,101 @@ namespace IndexDialog { IndexList IndexList::append(const IndexList& L) { - for (uint i=0; i<L.V.size(); ++i) - V.push_back(L.V[i]); - return *this; + for (uint i=0; i<L.V.size(); ++i) + V.push_back(L.V[i]); + return *this; } IndexList IndexList::append(const uint val) { - V.push_back(val); - return *this; + V.push_back(val); + return *this; } IndexList IndexList::clear(void) { - V.clear(); - return *this; + V.clear(); + return *this; } IndexList IndexList::reverse(void) { - std::reverse(V.begin(), V.end()); - return *this; + std::reverse(V.begin(), V.end()); + return *this; } IndexList IndexList::sort(void) { - std::sort(V.begin(), V.end()); - return *this; + std::sort(V.begin(), V.end()); + return *this; } IndexList IndexList::complement(const IndexList Vec2, const uint v0, const uint vn) { - clear(); - IndexList VecS(Vec2); - VecS.sort(); - uint iS, v; - for (iS=0; iS<VecS.size() && VecS.V[iS]<v0; iS++) ; - for (v=v0; v<vn; ++v) { - if (iS>=VecS.size()) break; - if (VecS.V[iS]==v) - iS++; - else - V.push_back(v); - } - for (; v<vn; ++v) - V.push_back(v); - return *this; + clear(); + IndexList VecS(Vec2); + VecS.sort(); + uint iS, v; + for (iS=0; iS<VecS.size() && VecS.V[iS]<v0; iS++) ; + for (v=v0; v<vn; ++v) { + if (iS>=VecS.size()) break; + if (VecS.V[iS]==v) + iS++; + else + V.push_back(v); + } + for (; v<vn; ++v) + V.push_back(v); + return *this; } // *** from text *** -bool IndexList::parse(const string s, const uint v0, const uint vn) +void IndexList::parse(const string s, const uint v0, const uint vn) { - return (IndexParse::ParseList(&V, s, v0, vn)); + return (IndexParse::ParseList(&V, s, v0, vn)); } // *** info *** bool IndexList::contains(const uint val) const { - for (uint i=0; i<size(); i++) - if (val==V[i]) return 1; - return 0; + for (uint i=0; i<size(); i++) + if (val==V[i]) return 1; + return 0; } string IndexList::str(void) const { - if(!V.size()) { - return "-"; - } - string s; - vector<uint> VV=V; - vector<uint>::iterator iV; - iV=VV.begin(); - uint vi, vd; - while(iV<V.end()) { - s += strg(vi=*(iV++)); - if(iV>=V.end()) break; - vd = *(iV++) - vi; - if(iV>=V.end()) { - s += "," + strg(vi+vd); - break; - } - if (*iV!=vi+2*vd) { - s += ","; - iV--; - continue; - } - while(iV<V.end() && *(iV-1)+vd==*iV) iV++; - s += "-" + strg(*(iV-1)); - if (vd!=1) s += "." + strg(vd); - if(iV>=V.end()) break; - s += ","; - } - return s; + if(!V.size()) { + return "-"; + } + string s; + vector<uint> VV=V; + vector<uint>::iterator iV; + iV=VV.begin(); + uint vi, vd; + while(iV<V.end()) { + s += strg(vi=*(iV++)); + if(iV>=V.end()) break; + vd = *(iV++) - vi; + if(iV>=V.end()) { + s += "," + strg(vi+vd); + break; + } + if (*iV!=vi+2*vd) { + s += ","; + iV--; + continue; + } + while(iV<V.end() && *(iV-1)+vd==*iV) iV++; + s += "-" + strg(*(iV-1)); + if (vd!=1) s += "." + strg(vd); + if(iV>=V.end()) break; + s += ","; + } + return s; } @@ -154,92 +151,89 @@ string IndexList::str(void) const IndexSet IndexSet::insert(const IndexSet Set) { - IndexSetIterator II(Set); - uint val; - while(II(&val)) T.insert(val); - return *this; + IndexSetIterator II(Set); + uint val; + while(II(&val)) T.insert(val); + return *this; } IndexSet IndexSet::insert(const uint val) { - T.insert(val); - return *this; + T.insert(val); + return *this; } IndexSet IndexSet::clear(void) { - T.clear(); - return *this; + T.clear(); + return *this; } IndexSet IndexSet::complement(const IndexSet Set2, - const uint v0, const uint vn) + const uint v0, const uint vn) { - clear(); - IndexSetIterator II(Set2); - uint v2; - uint v = v0; - while (II(&v2)) { - while (v<v2 && v<vn) T.insert(v++); - if (v>=vn) return *this; - v++; // v is now =v2+1 - } - while (v<vn) T.insert(v++); - return *this; + clear(); + IndexSetIterator II(Set2); + uint v2; + uint v = v0; + while (II(&v2)) { + while (v<v2 && v<vn) T.insert(v++); + if (v>=vn) return *this; + v++; // v is now =v2+1 + } + while (v<vn) T.insert(v++); + return *this; } // *** from text *** -bool IndexSet::parse(const string s, const uint v0, const uint vn) +void IndexSet::parse(const string s, const uint v0, const uint vn) { - bool ret = IndexParse::ParseSet(&T, s, v0, vn); - // printf("DEBUG %u %u [%s] %d\n", v0, vn, s.c_str(), ret); - if (ret) clear(); - return ret; + IndexParse::ParseSet(&T, s, v0, vn); } -bool IndexSet::ask(const string quest, const string def, - const uint v0, const uint vn) +void IndexSet::ask(const string quest, const string def, + const uint v0, const uint vn) { - string ans = index_ask(quest, def, v0, vn); - return parse(ans, v0, vn); + string ans = index_ask(quest, def, v0, vn); + parse(ans, v0, vn); } // *** info *** bool IndexSet::contains(const uint val) const { - return (T.find(val)!=T.end()); + return (T.find(val)!=T.end()); } string IndexSet::str(void) const { - if(!T.size()) { - return "-"; - } - string s; - set<uint>::iterator pos=T.begin(); - uint vi, vd; - while(pos!=T.end()) { - s += strg(vi=*(pos++)); - if(pos==T.end()) break; - vd = *(pos++) - vi; - if(pos==T.end()) { - s += "," + strg(vi+vd); - break; - } - if (*pos!=vi+2*vd) { - s += ","; - pos--; - continue; - } - while(pos!=T.end() && *(--pos)+vd==*(++pos)) pos++; - s += "-" + strg(*((--pos)++)); - if (vd!=1) s += "." + strg(vd); - if(pos==T.end()) break; - s += ","; - } - return s; + if(!T.size()) { + return "-"; + } + string s; + set<uint>::iterator pos=T.begin(); + uint vi, vd; + while(pos!=T.end()) { + s += strg(vi=*(pos++)); + if(pos==T.end()) break; + vd = *(pos++) - vi; + if(pos==T.end()) { + s += "," + strg(vi+vd); + break; + } + if (*pos!=vi+2*vd) { + s += ","; + pos--; + continue; + } + while(pos!=T.end() && *(--pos)+vd==*(++pos)) pos++; + s += "-" + strg(*((--pos)++)); + if (vd!=1) s += "." + strg(vd); + if(pos==T.end()) break; + s += ","; + } + return s; } @@ -247,189 +241,154 @@ string IndexSet::str(void) const // *** interfaces *** -bool IndexParse::ParseTest(string inp, uint v0, uint vn) +void IndexParse::ParseSet(set<uint> *T, string inp, uint v0, uint vn) { - p0 = v0; pn = vn; - client = TEST; - saveto = 0; - return ParseExe(inp); + p0 = v0; pn = vn; + saveto = (void *) T; + T->clear(); + ParseExe(inp); } -bool IndexParse::ParseSet(set<uint> *T, string inp, uint v0, uint vn) +void IndexParse::ParseList(vector<uint> *V, string inp, uint v0, uint vn) { - p0 = v0; pn = vn; - client = SET; - saveto = (void *) T; - T->clear(); - return ParseExe(inp); -} - -bool IndexParse::ParseList(vector<uint> *V, string inp, uint v0, uint vn) -{ - p0 = v0; pn = vn; - client = LIST; - saveto = (void *) V; - V->clear(); - return ParseExe(inp); + p0 = v0; pn = vn; + saveto = (void *) V; + V->clear(); + ParseExe(inp); } void IndexParse::newval(uint val) { - switch (client) { - case TEST: - return; - case LIST: - ((vector<uint> *) saveto)->push_back(val); - return; - case SET: - ((set<uint> *) saveto)->insert(val); - return; - } + switch (client) { + case LIST: + ((vector<uint> *) saveto)->push_back(val); + return; + case SET: + ((set<uint> *) saveto)->insert(val); + return; + } } // *** parse the input string *** -#define ERRLII cout << "! invalid input: " - -bool IndexParse::ParseExe(string inp) +void IndexParse::ParseExe(string inp) { - if(inp==string("-")) return 0; // valid empty list - string::size_type ji=0, jf; - while (ji<inp.size()) { - if ((jf=inp.find(',', ji)) == string::npos) jf = inp.size(); - if (ParseSkipinterval(inp.substr(ji,jf-ji))) return 1; - ji = jf+1; - } - return 0; + if(inp==string("-")) return; // valid empty list + string::size_type ji=0, jf; + while (ji<inp.size()) { + if ((jf=inp.find(',', ji)) == string::npos) jf = inp.size(); + ParseSkipinterval( inp.substr(ji,jf-ji) ); + ji = jf+1; + } } -bool IndexParse::ParseSkipinterval(string inp) +void IndexParse::ParseSkipinterval(string inp) { - // cout << inp << endl; - int skip; - string::size_type j; - if ((j=inp.find('.')) != string::npos) { - if (ParseSkipfactor(inp.substr(j+1), &skip)) return 1; - } else { - skip = 1; - j = inp.size(); - } - return ParseInterval(inp.substr(0,j), skip); + // cout << inp << endl; + int skip; + string::size_type j; + if ((j=inp.find('.')) != string::npos) { + ParseSkipfactor( inp.substr(j+1), &skip ); + } else { + skip = 1; + j = inp.size(); + } + ParseInterval(inp.substr(0,j), skip); } -bool IndexParse::ParseSkipfactor(string inp, int *skip) +void IndexParse::ParseSkipfactor(string inp, int *skip) { - char dummy; - if (sscanf(inp.c_str(), "%d%c", skip, &dummy)!=1 || *skip==0) { - ERRLII "invalid skip factor [" << inp << "]\n"; - *skip = 0; - return 1; - } - return 0; + char dummy; + if (sscanf(inp.c_str(), "%d%c", skip, &dummy)!=1 || *skip==0) + throw "invalid skip factor " + inp; } -bool IndexParse::ParseInterval(string inp, int skip) +void IndexParse::ParseInterval(string inp, int skip) { - // cout << "intv: " << inp << endl; - string::size_type j; - uint vi, vf; - bool xv=0; // vf exists ? - if (inp==string("*")) { - if (!limgiven()) return !onlytest(); - vi = p0; - vf = p0+pn-1; - xv = 1; - } else if ((j=inp.find('-')) != string::npos) { - if (ParseValue(inp.substr(j+1), +1, &vf)) return 1; - if (ParseValue(inp.substr(0,j), -1, &vi)) return 1; - xv = 1; - } else { - if (ParseValue(inp, 0, &vi)) return 1; - vf = vi; - } - if(skip>0 && vi>vf) { - ERRLII "invalid interval [" << inp << "]\n"; - return 1; - } else if (skip==0) { - ERRLII "PROGRAM ERROR (skip=0 should not arrive in ParseIntv\n"; - return 1; - } else if (skip<0 && vi<vf) { - printf("! ascending interval [%s] with skip=%u<0\n", - inp.c_str(), skip); - return 1; - } - - if (onlytest()) return 0; - if (skip>0) - for (uint vv=vi; vv<=vf; vv += skip) - newval(vv); - else - for (uint vv=vf; vv>=vi; vv += skip) - newval(vv); - return 0; + // cout << "intv: " << inp << endl; + string::size_type j; + uint vi, vf; + bool xv=0; // vf exists ? + if (inp==string("*")) { + if ( !limgiven() ) + throw string( "'*' invalid since no limits are given" ); + vi = p0; + vf = p0+pn-1; + xv = 1; + } else if ((j=inp.find('-')) != string::npos) { + ParseValue( inp.substr(j+1), +1, &vf ); + ParseValue( inp.substr(0,j), -1, &vi ); + xv = 1; + } else { + ParseValue( inp, 0, &vi ); + vf = vi; + } + if(skip>0 && vi>vf) + throw "invalid interval " + inp; + else if (skip==0) + throw string( "BUG: skip=0 should not occur in ParseIntv" ); + else if (skip<0 && vi<vf) + throw "ascending interval " + inp + " with negative skip factor"; + + if (skip>0) + for (uint vv=vi; vv<=vf; vv += skip) + newval(vv); + else + for (uint vv=vf; vv>=vi; vv += skip) + newval(vv); } -bool IndexParse::ParseValue(string inp, int which, uint *val) +void IndexParse::ParseValue(string inp, int which, uint *val) { - char dummy; - if (inp==string("*")) { - if (!limgiven()) return !onlytest(); - if (which==-1) - *val = p0; - else if (which==+1) - *val = p0+pn-1; - else { - ERRLII "list value * out of context\n"; - return 1; - } - } else if (sscanf(inp.c_str(), "%d%c", val, &dummy)!=1 || (int)*val<0) { - ERRLII "invalid list value [" << inp << "]\n"; - return 1; - } - // printf("DEBUG %d %d [%d %d] %d\n", - // limgiven(), allowoutoflim(), 0, pn, *val); - if (limgiven() && !allowoutoflim() && (p0>*val || *val>=p0+pn)) { - ERRLII "list value [" << inp << "] out of bounds " - << "(" << p0 << "," << pn << "( \n"; - return 1; - } - return 0; + char dummy; + if (inp==string("*")) { + if (!limgiven()) + throw string( "'-*' invalid since no limits are given" ); + if (which==-1) + *val = p0; + else if (which==+1) + *val = p0+pn-1; + else + throw string( "list value * out of context" ); + } else if (sscanf(inp.c_str(), "%d%c", val, &dummy)!=1 || (int)*val<0) + throw "invalid list value " + inp; + + if ( limgiven() && (p0>*val || *val>=p0+pn) ) + throw "list value " + inp + " out of bounds " + + strg(p0) + ".." + strg(pn); } // *** user interaction *** const char * IndexDialog::helptext = - "a list (a set of indices):\n" - " list: <empty_list> | <finite_list> | <infinite_list>\n" - " empty_list: -\n" - " finite_list: <range_with_skip> { , <range_with_skip> }\n" - " infinite_list: *\n" - " range_with_skip: <range> [ . <skip> ]\n" - " range: <bound> [ - <bound>]\n" - " skip: (integer >= 1)\n" - " bound: * | (integer >= 0)\n"; + "a list (a set of indices):\n" + " list: <empty_list> | <finite_list> | <infinite_list>\n" + " empty_list: -\n" + " finite_list: <range_with_skip> { , <range_with_skip> }\n" + " infinite_list: *\n" + " range_with_skip: <range> [ . <skip> ]\n" + " range: <bound> [ - <bound>]\n" + " skip: (integer >= 1)\n" + " bound: * | (integer >= 0)\n"; char IndexDialog::decode(const string& resp, string *rval ) { - if ( resp=="" ) { - return 'd'; - } else if ( resp=="?" ) { - return 'h'; - } - *rval = resp; - if (!(IndexParse::ParseTest(*rval, 0, 0))) // 0,0 Altlast(Constraints) - return 'v'; - else - return 'h'; + if ( resp=="" ) { + return 'd'; + } else if ( resp=="?" ) { + return 'h'; + } + *rval = resp; + // IndexParse::ParseTest( *rval, 0, 0 ); + return 'v'; } string index_ask( const string& quest, string def, uint p0, uint pn ) { - uint lims[2]; - lims[0] = p0; - lims[1] = pn; - int defflag = ASK_DEF_GIVEN*(def!="") | ASK_WORD; - return myask( quest, defflag, def, def, - IndexDialog::helptext, IndexDialog::decode ); + uint lims[2]; + lims[0] = p0; + lims[1] = pn; + int defflag = ASK_DEF_GIVEN*(def!="") | ASK_WORD; + return myask( quest, defflag, def, def, + IndexDialog::helptext, IndexDialog::decode ); } - diff --git a/pub/src/index.h b/pub/src/index.h index 10e947895b8c29c8f9cac66611f5e605de0c7ac3..e3f692c9070533be213cff0be8088da014bd23dc 100644 --- a/pub/src/index.h +++ b/pub/src/index.h @@ -3,131 +3,130 @@ class IndexList { // unsorted - friend class IndexListIterator; + friend class IndexListIterator; - private: - vector<uint> V; +private: + vector<uint> V; - public: - // Constructors: - IndexList(void) { }; // create empty vector - IndexList(const uint val) { V.push_back(val); }; - IndexList(const uint v0, const uint vn) { - for (uint v=v0; v<vn; ++v) V.push_back(v); }; +public: + // Constructors: + IndexList(void) { }; // create empty vector + IndexList(const uint val) { V.push_back(val); }; + IndexList(const uint v0, const uint vn) { + for (uint v=v0; v<vn; ++v) V.push_back(v); }; - // Modify: - IndexList append (const IndexList& Vec2); - IndexList append (const uint val); + // Modify: + IndexList append (const IndexList& Vec2); + IndexList append (const uint val); - IndexList clear(void); - IndexList reverse(void); - IndexList sort(void); + IndexList clear(void); + IndexList reverse(void); + IndexList sort(void); - IndexList complement(const IndexList Vec2, - const uint v0, const uint vn); + IndexList complement(const IndexList Vec2, + const uint v0, const uint vn); - // from text (return true if string was valid): - bool parse(const string s, const uint v0=0, const uint vn=0); - - // Info: - uint size(void) const { return V.size(); }; - bool contains (const uint val) const; - // uint operator[] (const uint i) const { return T[i]; }; - // int issorted(void) const; - string str(void) const; - const char* c_str(void) const { return str().c_str(); } ; + // from text (return true if string was valid): + void parse(const string s, const uint v0=0, const uint vn=0); + + // Info: + uint size(void) const { return V.size(); }; + bool contains (const uint val) const; + // uint operator[] (const uint i) const { return T[i]; }; + // int issorted(void) const; + string str(void) const; + const char* c_str(void) const { return str().c_str(); } ; }; class IndexSet { // sorted - friend class IndexSetIterator; + friend class IndexSetIterator; - private: - set<uint> T; +private: + set<uint> T; - public: - // Constructors: - IndexSet(void) { }; // create empty vector - IndexSet(const uint val) { T.insert(val); }; - IndexSet(const uint v0, const uint vn) { - for (uint v=v0; v<vn; ++v) T.insert(v); }; +public: + // Constructors: + IndexSet(void) { }; // create empty vector + IndexSet(const uint val) { T.insert(val); }; + IndexSet(const uint v0, const uint vn) { + for (uint v=v0; v<vn; ++v) T.insert(v); }; - // Modify: - IndexSet insert (const IndexSet Set2); - IndexSet insert (const uint val); + // Modify: + IndexSet insert (const IndexSet Set2); + IndexSet insert (const uint val); - IndexSet clear(void); + IndexSet clear(); - IndexSet complement(const IndexSet Set2, - const uint v0, const uint vn); + IndexSet complement( const IndexSet Set2, const uint v0, const uint vn ); - // from text (returns 0 if string is valid): - bool parse(const string s, const uint v0=0, const uint vn=0); - - bool ask(const string quest, const string def, - const uint v0=0, const uint vn=0); - bool ask(const string quest, const IndexSet set, - const uint v0=0, const uint vn=0) { - return ask(quest, set.str(), v0, vn); }; - - // Info: - uint size(void) const { return T.size(); }; - bool contains (const uint val) const; - // int issorted(void) const; - string str(void) const; - const char* c_str(void) const { return str().c_str(); } ; + // from text (returns 0 if string is valid): + void parse( const string s, const uint v0=0, const uint vn=0 ); + + void ask( const string quest, const string def, + const uint v0=0, const uint vn=0 ); + void ask( const string quest, const IndexSet set, + const uint v0=0, const uint vn=0 ) { + ask(quest, set.str(), v0, vn); }; + + // Info: + uint size() const { return T.size(); }; + bool contains (const uint val) const; + // int issorted() const; + string str() const; + const char* c_str() const { return str().c_str(); } ; }; class IndexListIterator : private IndexList { - private: - uint i; - public: - IndexListIterator(void) { i=0; }; - IndexListIterator(const IndexList List) { i=0; V=List.V; }; - void reset(void) { i=0; }; - void reset(const IndexList List) { i=0; V=List.V; }; - uint operator()(uint *val) { - if (i>=size()) return 0; - *val = V[i++]; - return i; - }; +private: + uint i; +public: + IndexListIterator() { i=0; }; + IndexListIterator(const IndexList List) { i=0; V=List.V; }; + void reset() { i=0; }; + void reset(const IndexList List) { i=0; V=List.V; }; + uint operator()(uint *val) { + if (i>=size()) return 0; + *val = V[i++]; + return i; + }; }; class IndexSetIterator : private IndexSet { - private: - set<uint>::iterator pos; - uint i; - int dir; - public: - IndexSetIterator(void) { reset(); }; - IndexSetIterator(const IndexSet Set) { reset(Set); }; - void reset(void) { pos=T.begin(); i=0; dir=+1; }; - void reset(const IndexSet Set) { T=Set.T; reset(); }; - void setback(void) { pos=T.end(); i=T.size(); dir=-1; }; - void setback(const IndexSet Set) { T=Set.T; setback(); }; - bool operator()(uint *val) { - if (dir>0) { - if (pos==T.end()) return 0; - *val = *(pos++); - return ++i; - } else { - if (pos==T.begin()) return 0; - *val = *(--pos); - return i--; - } - }; - void stepback(void) { - if (dir>0) --pos; - else ++pos; - }; +private: + set<uint>::iterator pos; + uint i; + int dir; +public: + IndexSetIterator() { reset(); }; + IndexSetIterator(const IndexSet Set) { reset(Set); }; + void reset() { pos=T.begin(); i=0; dir=+1; }; + void reset(const IndexSet Set) { T=Set.T; reset(); }; + void setback() { pos=T.end(); i=T.size(); dir=-1; }; + void setback(const IndexSet Set) { T=Set.T; setback(); }; + bool operator()(uint *val) { + if (dir>0) { + if (pos==T.end()) return 0; + *val = *(pos++); + return ++i; + } else { + if (pos==T.begin()) return 0; + *val = *(--pos); + return i--; + } + }; + void stepback() { + if (dir>0) --pos; + else ++pos; + }; }; class IndexSelection { - private: - string S; +private: + string S; - public: - void ask(); +public: + void ask(); }; diff --git a/pub/src/manip.cpp b/pub/src/manip.cpp index e446265787ba44ddc5fc71ecd00ff0823331624d..87ea23635b3b034bcbdb92fc54bfefc963ad338c 100644 --- a/pub/src/manip.cpp +++ b/pub/src/manip.cpp @@ -126,9 +126,7 @@ void NManip::PtsAvge() sout->copy_z_base( sin ); IndexSet Groups; - if (Groups.parse(groups, 0, sin->size())) - throw "File " + strg(fiter.k()) + ", spectrum " + strg(j) + - " invalid group"; + Groups.parse( groups, 0, sin->size() ); if (!Groups.contains(0)) throw string( "Group must start at 0" ); Groups.insert(sin->size()); @@ -861,8 +859,7 @@ void NManip::ZDelete() fout->V.push_back( fin->new_zentry( j ) ); IndexSet ISel; - if ( ISel.parse(sel, 0, fin->ZCo.size()) ) - throw ( "invalid selection for file " + strg( fiter.k() ) ); + ISel.parse( sel, 0, fin->ZCo.size() ); IndexSetIterator II; II.setback(ISel);