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 |
|
---|
8 | vector<TOI> TOI::alltois;
|
---|
9 |
|
---|
10 | TOI::TOI(string n, int i, string opts, string u)
|
---|
11 | : name(n), index(i), unit(u)
|
---|
12 | {
|
---|
13 | options = Tokenizer(opts).getTokenSet();
|
---|
14 | findref();
|
---|
15 | }
|
---|
16 |
|
---|
17 | TOI::TOI(string n, int i, string opts, string u, string reqopts)
|
---|
18 | : name(n), index(i), unit(u)
|
---|
19 | {
|
---|
20 | options = Tokenizer(opts).getTokenSet();
|
---|
21 | reqOptions = Tokenizer(reqopts).getTokenSet();
|
---|
22 | options.insert(reqOptions.begin(), reqOptions.end());
|
---|
23 | findref();
|
---|
24 | }
|
---|
25 |
|
---|
26 | TOI::TOI(string n, int i, set<string> opts, string u)
|
---|
27 | : name(n), options(opts), index(i), unit(u)
|
---|
28 | {
|
---|
29 | findref();
|
---|
30 | }
|
---|
31 |
|
---|
32 | TOI::TOI(string s, string u)
|
---|
33 | : index(unspec), unit(u)
|
---|
34 | {
|
---|
35 | vector<string> v = Tokenizer(s).getTokenVector();
|
---|
36 | if (v.empty()) throw ArchExc("TOI::TOI called with empty string");
|
---|
37 | vector<string>::iterator i = v.begin();
|
---|
38 | name = *i;
|
---|
39 | i++;
|
---|
40 | if (i == v.end()) return;
|
---|
41 | string& s1 = *i;
|
---|
42 | if (s1[0]>='0' && s1[0]<='9') {
|
---|
43 | index = atoi(s1.c_str());
|
---|
44 | i++;
|
---|
45 | }
|
---|
46 | options = set<string>(i, v.end());
|
---|
47 | findref();
|
---|
48 | }
|
---|
49 |
|
---|
50 | void TOI::findref() {
|
---|
51 | for (vector<TOI>::iterator i = alltois.begin();
|
---|
52 | i != alltois.end(); i++) {
|
---|
53 | if ((*i).name == name && (*i).index == index && (*i).options == options) {
|
---|
54 | ref = (*i).ref;
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | ref = alltois.size();
|
---|
59 | alltois.push_back(*this);
|
---|
60 | }
|
---|
61 |
|
---|
62 | string TOI::fullName() const {
|
---|
63 | string s = name;
|
---|
64 | if (index == all) { s += " all";}
|
---|
65 | else if (index != unspec) {
|
---|
66 | char idx[20]; sprintf(idx, "%d", index);
|
---|
67 | s += string(" ")+idx;
|
---|
68 | }
|
---|
69 | for (set<string>::const_iterator i = options.begin(); i!=options.end(); i++) {
|
---|
70 | s += " " + *i;
|
---|
71 | }
|
---|
72 | if (unit != "") s += " (" + unit + ")";
|
---|
73 | return s;
|
---|
74 | }
|
---|