source: Sophya/trunk/Poubelle/archTOI.old/toi.cc@ 658

Last change on this file since 658 was 634, checked in by ansari, 26 years ago

linux-ppc, gcc 2.95.1

File size: 1.8 KB
Line 
1// toi.cc
2// Eric Aubourg CEA/DAPNIA/SPP septembre 1999
3
4#include "toi.h"
5#include "tokenizer.h"
6#include "archexc.h"
7#include <stdio.h>
8
9vector<TOI> TOI::alltois;
10
11TOI::TOI(string n, int i, string opts, string u)
12: name(n), index(i), unit(u), ref(-1)
13{
14 options = Tokenizer(opts).getTokenSet();
15 findref();
16}
17
18TOI::TOI(string n, int i, string opts, string u, string reqopts)
19: name(n), index(i), unit(u), ref(-1)
20{
21 options = Tokenizer(opts).getTokenSet();
22 reqOptions = Tokenizer(reqopts).getTokenSet();
23 options.insert(reqOptions.begin(), reqOptions.end());
24 findref();
25}
26
27TOI::TOI(string n, int i, set<string> opts, string u)
28: name(n), options(opts), index(i), unit(u), ref(-1)
29{
30 findref();
31}
32
33TOI::TOI(string s, string u)
34: index(unspec), unit(u), ref(-1)
35{
36 vector<string> v = Tokenizer(s).getTokenVector();
37 if (v.empty()) throw ArchExc("TOI::TOI called with empty string");
38 vector<string>::iterator i = v.begin();
39 name = *i;
40 i++;
41 if (i == v.end()) return;
42 string& s1 = *i;
43 if (s1[0]>='0' && s1[0]<='9') {
44 index = atoi(s1.c_str());
45 i++;
46 }
47 options = set<string>(i, v.end());
48 findref();
49}
50
51// $CHECK$ a optimiser avec hash ou arbre...
52void TOI::findref() {
53 for (vector<TOI>::iterator i = alltois.begin();
54 i != alltois.end(); i++) {
55 if ((*i).name == name && (*i).index == index && (*i).options == options) {
56 ref = (*i).ref;
57 return;
58 }
59 }
60 ref = alltois.size();
61 alltois.push_back(*this);
62}
63
64string TOI::fullName() const {
65 string s = name;
66 if (index == all) { s += " all";}
67 else if (index != unspec) {
68 char idx[20]; sprintf(idx, "%d", index);
69 s += string(" ")+idx;
70 }
71 for (set<string>::const_iterator i = options.begin(); i!=options.end(); i++) {
72 s += " " + *i;
73 }
74 if (unit != "") s += " (" + unit + ")";
75 return s;
76}
Note: See TracBrowser for help on using the repository browser.