| [754] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 | // | 
|---|
| [895] | 3 | // $Id: datacards.h,v 1.2 2000-04-12 17:49:43 ansari Exp $ | 
|---|
| [754] | 4 | // | 
|---|
|  | 5 | // Datacards, acquisition EROS II | 
|---|
|  | 6 | // | 
|---|
|  | 7 | // | 
|---|
|  | 8 | // Eric Aubourg, Decembre 95 | 
|---|
|  | 9 | // Reza Ansari, Aout 96 | 
|---|
|  | 10 | // | 
|---|
|  | 11 | // DAPNIA/SPP (Saclay) / CEA    LAL - IN2P3/CNRS  (Orsay) | 
|---|
|  | 12 |  | 
|---|
|  | 13 | #ifndef DATACARDS_SEEN | 
|---|
|  | 14 | #define DATACARDS_SEEN | 
|---|
|  | 15 |  | 
|---|
| [895] | 16 | #include "machdefs.h" | 
|---|
| [754] | 17 | #include <string.h> | 
|---|
|  | 18 | #include <string> | 
|---|
|  | 19 | #include <functional> | 
|---|
|  | 20 | #include <list> | 
|---|
|  | 21 | #include <vector> | 
|---|
|  | 22 |  | 
|---|
|  | 23 |  | 
|---|
| [895] | 24 | namespace SOPHYA { | 
|---|
|  | 25 |  | 
|---|
| [754] | 26 | typedef int (*ProcCard)(string const& key, string const& toks); | 
|---|
|  | 27 |  | 
|---|
| [895] | 28 | //! Class for decoding parameters from  an ascii file. | 
|---|
|  | 29 |  | 
|---|
|  | 30 | class DataCards  { | 
|---|
| [754] | 31 | public: | 
|---|
| [895] | 32 |  | 
|---|
| [754] | 33 | DataCards(); | 
|---|
|  | 34 | DataCards(string const& fn); | 
|---|
|  | 35 |  | 
|---|
| [895] | 36 | // nom dans variable d'environnement SOPHYA_DATACARDS | 
|---|
|  | 37 | // par defaut, sophya.datacards | 
|---|
| [754] | 38 | // Si pas chemin complet, on tente dans repertoire | 
|---|
| [895] | 39 | // en cours, puis dans SOPHYA_WORK | 
|---|
| [754] | 40 |  | 
|---|
|  | 41 | virtual ~DataCards() {} | 
|---|
|  | 42 |  | 
|---|
|  | 43 | void    AddProcF(ProcCard f, string const& mtch="*"); | 
|---|
|  | 44 |  | 
|---|
|  | 45 | void    Clear(); | 
|---|
|  | 46 | void    ReadFile(string const& fn); | 
|---|
|  | 47 | void    AppendCard(string const& line); | 
|---|
|  | 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); | 
|---|
|  | 55 |  | 
|---|
| [895] | 56 | void    Print(ostream& s) const; | 
|---|
| [754] | 57 |  | 
|---|
| [895] | 58 | protected: | 
|---|
| [754] | 59 | struct Card { | 
|---|
|  | 60 | string kw; | 
|---|
|  | 61 | vector<string> tokens; | 
|---|
| [895] | 62 | bool operator == (Card const & b) const { return(kw == b.kw); } | 
|---|
|  | 63 | bool operator < (Card const & b) const { return(kw < b.kw); } | 
|---|
| [754] | 64 | }; | 
|---|
|  | 65 | struct CrdPF { | 
|---|
|  | 66 | ProcCard pf; | 
|---|
|  | 67 | string  patt; | 
|---|
| [895] | 68 | bool operator == (CrdPF const & b) const { return(pf == b.pf); } | 
|---|
|  | 69 | bool operator < (CrdPF const & b) const { return(pf == b.pf); } | 
|---|
| [754] | 70 | }; | 
|---|
|  | 71 |  | 
|---|
|  | 72 | void  DoReadFile(string const& fn); | 
|---|
|  | 73 |  | 
|---|
|  | 74 | int   ApplyPF(CrdPF & cpf, string const& key, string const& toks); | 
|---|
|  | 75 | int   ApplyPFL(string const& key, string const& toks); | 
|---|
|  | 76 |  | 
|---|
|  | 77 | void  RemoveCard(string const& key); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | Card* FindKey(string const& key); | 
|---|
| [895] | 80 |  | 
|---|
|  | 81 | typedef list<Card> CardList; | 
|---|
|  | 82 | typedef list<CrdPF> CrdPFList; | 
|---|
|  | 83 | CardList cards; | 
|---|
|  | 84 | CrdPFList cpfs; | 
|---|
|  | 85 |  | 
|---|
| [754] | 86 | struct KeyEq : binary_function<Card, string, bool> { | 
|---|
|  | 87 | bool operator()(const Card& x, const string& y) const { return x.kw == y; } | 
|---|
|  | 88 | }; | 
|---|
|  | 89 | }; | 
|---|
| [895] | 90 |  | 
|---|
|  | 91 | //! operator << overloading - calls Print() | 
|---|
|  | 92 | inline ostream& operator << (ostream& s, DataCards c) | 
|---|
|  | 93 | { c.Print(s); return s; } | 
|---|
|  | 94 |  | 
|---|
|  | 95 | } // namespace SOPHYA | 
|---|
|  | 96 |  | 
|---|
| [754] | 97 | #endif | 
|---|