source: Sophya/trunk/SophyaLib/SUtils/datacards.h@ 4052

Last change on this file since 4052 was 3011, checked in by ansari, 19 years ago

petite correction dans la doc / commentaires , Reza 07/07/2006

File size: 2.7 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2//
3// $Id: datacards.h,v 1.5 2006-07-07 11:16:02 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 "machdefs.h"
17#include <string.h>
18#include <string>
19#include <functional>
20#include <list>
21#include <vector>
22
23
24namespace SOPHYA {
25
26typedef int (*ProcCard)(string const& key, string const& toks);
27
28//! Class for decoding parameters from an ascii file.
29
30class DataCards {
31public:
32
33 DataCards();
34 DataCards(string const& fn);
35
36 // nom dans variable d'environnement SOPHYA_DATACARDS
37 // par defaut, sophya.datacards
38 // Si pas chemin complet, on tente dans repertoire
39 // en cours, puis dans SOPHYA_WORK
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() 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;
57
58 void Print(ostream& s) const;
59
60protected:
61 /*! \cond
62 Card structure - for internal use by DataCard
63 */
64 struct Card {
65 string kw;
66 vector<string> tokens;
67 bool operator == (Card const & b) const { return(kw == b.kw); }
68 bool operator < (Card const & b) const { return(kw < b.kw); }
69 };
70 struct CrdPF {
71 ProcCard pf;
72 string patt;
73 bool operator == (CrdPF const & b) const { return(pf == b.pf); }
74 bool operator < (CrdPF const & b) const { return(pf == b.pf); }
75 };
76 /*! \endcond */
77 void DoReadFile(string const& fn);
78
79 int ApplyPF(CrdPF & cpf, string const& key, string const& toks);
80 int ApplyPFL(string const& key, string const& toks);
81
82 void RemoveCard(string const& key);
83
84 Card* FindKey(string const& key) ;
85
86 typedef list<Card> CardList;
87 typedef list<CrdPF> CrdPFList;
88
89 CardList::const_iterator FindKeyC(string const& key) const;
90
91 CardList cards;
92 CrdPFList cpfs;
93
94 struct KeyEq : binary_function<Card, string, bool> {
95 bool operator()(const Card& x, const string& y) const { return x.kw == y; }
96 };
97};
98
99//! operator << overloading - calls Print()
100inline ostream& operator << (ostream& s, DataCards const & c)
101{ c.Print(s); return s; }
102
103} // namespace SOPHYA
104
105#endif
Note: See TracBrowser for help on using the repository browser.