[658] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | //
|
---|
| 3 | // $Id: datacards.h,v 1.1.1.1 1999-11-26 16:37:09 ansari Exp $
|
---|
| 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 |
|
---|
| 16 | #include <string.h>
|
---|
| 17 | #include <string>
|
---|
| 18 | #include <functional>
|
---|
| 19 | #include <list>
|
---|
| 20 | #include <vector>
|
---|
| 21 | #include <string>
|
---|
| 22 |
|
---|
| 23 | #include "peida.h"
|
---|
| 24 |
|
---|
| 25 | typedef int (*ProcCard)(string const& key, string const& toks);
|
---|
| 26 |
|
---|
| 27 | class DataCards EXC_AWARE {
|
---|
| 28 | public:
|
---|
| 29 | DataCards();
|
---|
| 30 | DataCards(string const& fn);
|
---|
| 31 |
|
---|
| 32 | // nom dans variable d'environnement PEIDA_DATACARDS
|
---|
| 33 | // par defaut, peida.datacards
|
---|
| 34 | // Si pas chemin complet, on tente dans repertoire
|
---|
| 35 | // en cours, puis dans PEIDA_WORK
|
---|
| 36 |
|
---|
| 37 | virtual ~DataCards() {}
|
---|
| 38 |
|
---|
| 39 | void AddProcF(ProcCard f, string const& mtch="*");
|
---|
| 40 |
|
---|
| 41 | void Clear();
|
---|
| 42 | void ReadFile(string const& fn);
|
---|
| 43 | void AppendCard(string const& line);
|
---|
| 44 |
|
---|
| 45 | int NbCards();
|
---|
| 46 | bool HasKey(string const& key);
|
---|
| 47 | int NbParam(string const& key);
|
---|
| 48 | string SParam(string const& key, int numero = 0, string def="");
|
---|
| 49 | long IParam(string const& key, int numero = 0, long def = 0);
|
---|
| 50 | double DParam(string const& key, int numero = 0, double def = 0);
|
---|
| 51 |
|
---|
| 52 | friend ostream& operator << (ostream& s, DataCards c);
|
---|
| 53 |
|
---|
| 54 | public:
|
---|
| 55 | struct Card {
|
---|
| 56 | string kw;
|
---|
| 57 | vector<string> tokens;
|
---|
| 58 | STRUCTCOMPF(Card,kw)
|
---|
| 59 | };
|
---|
| 60 | typedef list<Card> CardList;
|
---|
| 61 | struct CrdPF {
|
---|
| 62 | ProcCard pf;
|
---|
| 63 | string patt;
|
---|
| 64 | STRUCTCOMPF(CrdPF,pf)
|
---|
| 65 | };
|
---|
| 66 | typedef list<CrdPF> CrdPFList;
|
---|
| 67 | protected:
|
---|
| 68 | CardList cards;
|
---|
| 69 | CrdPFList cpfs;
|
---|
| 70 |
|
---|
| 71 | void DoReadFile(string const& fn);
|
---|
| 72 |
|
---|
| 73 | int ApplyPF(CrdPF & cpf, string const& key, string const& toks);
|
---|
| 74 | int ApplyPFL(string const& key, string const& toks);
|
---|
| 75 |
|
---|
| 76 | void RemoveCard(string const& key);
|
---|
| 77 |
|
---|
| 78 | Card* FindKey(string const& key);
|
---|
| 79 | struct KeyEq : binary_function<Card, string, bool> {
|
---|
| 80 | bool operator()(const Card& x, const string& y) const { return x.kw == y; }
|
---|
| 81 | };
|
---|
| 82 | };
|
---|
| 83 | #endif
|
---|