Changeset 1258 in Sophya for trunk/SophyaLib/SUtils
- Timestamp:
- Oct 24, 2000, 7:35:04 PM (25 years ago)
- Location:
- trunk/SophyaLib/SUtils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SUtils/datacards.cc
r1197 r1258 1 /// $Id: datacards.cc,v 1. 4 2000-09-22 10:37:44ansari Exp $1 /// $Id: datacards.cc,v 1.5 2000-10-24 17:35:03 ansari Exp $ 2 2 // 3 3 // Datacards, acquisition EROS II … … 191 191 /*! Returns true if \b key is present in the list */ 192 192 bool 193 DataCards::HasKey(string const& key) 194 { 195 return FindKey(key) != NULL;193 DataCards::HasKey(string const& key) const 194 { 195 return (FindKeyC(key) != cards.end()); 196 196 } 197 197 198 198 //! Returns the total number of cards 199 199 int 200 DataCards::NbCards() 200 DataCards::NbCards() const 201 201 { 202 202 return(cards.size()); … … 205 205 /*! Returns the number of parameters for card \b key. (-1) if \b key not present */ 206 206 int 207 DataCards::NbParam(string const& key) 208 { 209 DataCards::Card * p = FindKey(key); 210 if (!p) return(-1); 211 else return(p->tokens.size()); 207 DataCards::NbParam(string const& key) const 208 { 209 DataCards::CardList::const_iterator it = FindKeyC(key); 210 if (it == cards.end()) return(-1); 211 else return((*it).tokens.size()); 212 } 213 214 /*! Returns the key for card number \b num. */ 215 string 216 DataCards::GetKey(int num) const 217 { 218 if ((num < 0) || (num >= cards.size()) ) return(""); 219 int k = 0; 220 CardList::const_iterator i; 221 for(i=cards.begin(); i != cards.end(); i++) { 222 if (k == num) return((*i).kw); 223 else k++; 224 } 225 return(""); 226 } 227 228 /*! Returns the list of parameters for card \b key. */ 229 string 230 DataCards::GetParams(string const& key) const 231 { 232 string rs; 233 DataCards::CardList::const_iterator it = FindKeyC(key); 234 if (it == cards.end()) return(rs); 235 for (int k=0; k<(*it).tokens.size(); k++) { 236 rs += ' '; rs += (*it).tokens[k]; 237 } 238 return(rs); 212 239 } 213 240 214 241 /*! Returns the parameter number \b numero for card \b key */ 215 242 string 216 DataCards::SParam(string const& key, int numero, string def) 217 { 218 DataCards::Card * p = FindKey(key);219 if ( !p) return def;220 if ( (numero < 0) || (numero >= p->tokens.size()) ) return def;221 return p->tokens[numero];243 DataCards::SParam(string const& key, int numero, string def) const 244 { 245 DataCards::CardList::const_iterator it = FindKeyC(key); 246 if (it == cards.end()) return(def); 247 if ( (numero < 0) || (numero >= (*it).tokens.size()) ) return def; 248 return (*it).tokens[numero]; 222 249 } 223 250 224 251 /*! Returns the parameter number \b numero for card \b key, converted to type long */ 225 252 long 226 DataCards::IParam(string const& key, int numero, long def) 253 DataCards::IParam(string const& key, int numero, long def) const 227 254 { 228 255 string p = SParam(key, numero, ""); … … 236 263 /*! Returns the parameter number \b numero for card \b key, converted to type double */ 237 264 double 238 DataCards::DParam(string const& key, int numero, double def) 265 DataCards::DParam(string const& key, int numero, double def) const 239 266 { 240 267 string p = SParam(key, numero, ""); … … 327 354 328 355 DataCards::Card * 329 DataCards::FindKey(string const& key) 356 DataCards::FindKey(string const& key) 330 357 { 331 358 /* … … 335 362 CardList::iterator i; 336 363 for(i=cards.begin(); i != cards.end(); i++) 337 if ((*i).kw == key) return & *i;364 if ((*i).kw == key) return &(*i); 338 365 339 366 return NULL; … … 341 368 342 369 343 370 DataCards::CardList::const_iterator 371 DataCards::FindKeyC(string const& key) const 372 { 373 CardList::const_iterator i; 374 for(i=cards.begin(); i != cards.end(); i++) 375 if ((*i).kw == key) return i; 376 return cards.end(); 377 } -
trunk/SophyaLib/SUtils/datacards.h
r1197 r1258 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: datacards.h,v 1. 3 2000-09-22 10:37:44 ansari Exp $3 // $Id: datacards.h,v 1.4 2000-10-24 17:35:04 ansari Exp $ 4 4 // 5 5 // Datacards, acquisition EROS II … … 47 47 void AppendCard(string const& line); 48 48 49 int NbCards(); 50 bool HasKey(string const& key); 51 int NbParam(string const& key); 52 string SParam(string const& key, int numero = 0, string def=""); 53 long IParam(string const& key, int numero = 0, long def = 0); 54 double DParam(string const& key, int numero = 0, double def = 0); 49 int NbCards() const; 50 bool HasKey(string const& key) const; 51 int NbParam(string const& key) const; 52 string GetKey(int num) const; 53 string GetParams(string const& key) const; 54 string SParam(string const& key, int numero = 0, string def="") const; 55 long IParam(string const& key, int numero = 0, long def = 0) const; 56 double DParam(string const& key, int numero = 0, double def = 0) const; 55 57 56 58 void Print(ostream& s) const; … … 77 79 void RemoveCard(string const& key); 78 80 79 Card* FindKey(string const& key) ;81 Card* FindKey(string const& key) ; 80 82 81 83 typedef list<Card> CardList; 82 84 typedef list<CrdPF> CrdPFList; 85 86 CardList::const_iterator FindKeyC(string const& key) const; 87 83 88 CardList cards; 84 89 CrdPFList cpfs;
Note:
See TracChangeset
for help on using the changeset viewer.