| [534] | 1 | // toi.cc | 
|---|
|  | 2 | // Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999 | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include "toi.h" | 
|---|
|  | 5 | #include "tokenizer.h" | 
|---|
|  | 6 | #include "archexc.h" | 
|---|
| [634] | 7 | #include <stdio.h> | 
|---|
| [534] | 8 |  | 
|---|
|  | 9 | vector<TOI> TOI::alltois; | 
|---|
|  | 10 |  | 
|---|
|  | 11 | TOI::TOI(string n, int i, string opts, string u) | 
|---|
| [634] | 12 | : name(n), index(i), unit(u), ref(-1) | 
|---|
| [534] | 13 | { | 
|---|
|  | 14 | options = Tokenizer(opts).getTokenSet(); | 
|---|
|  | 15 | findref(); | 
|---|
|  | 16 | } | 
|---|
|  | 17 |  | 
|---|
|  | 18 | TOI::TOI(string n, int i, string opts, string u, string reqopts) | 
|---|
| [634] | 19 | : name(n), index(i), unit(u), ref(-1) | 
|---|
| [534] | 20 | { | 
|---|
|  | 21 | options = Tokenizer(opts).getTokenSet(); | 
|---|
|  | 22 | reqOptions = Tokenizer(reqopts).getTokenSet(); | 
|---|
|  | 23 | options.insert(reqOptions.begin(), reqOptions.end()); | 
|---|
|  | 24 | findref(); | 
|---|
|  | 25 | } | 
|---|
|  | 26 |  | 
|---|
|  | 27 | TOI::TOI(string n, int i, set<string> opts, string u) | 
|---|
| [634] | 28 | : name(n), options(opts), index(i), unit(u), ref(-1) | 
|---|
| [534] | 29 | { | 
|---|
|  | 30 | findref(); | 
|---|
|  | 31 | } | 
|---|
|  | 32 |  | 
|---|
|  | 33 | TOI::TOI(string s, string u) | 
|---|
| [634] | 34 | : index(unspec), unit(u), ref(-1) | 
|---|
| [534] | 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 |  | 
|---|
| [634] | 51 | // $CHECK$ a optimiser avec hash ou arbre... | 
|---|
| [534] | 52 | void 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 |  | 
|---|
| [555] | 64 | string TOI::fullName() const { | 
|---|
| [534] | 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 | } | 
|---|
| [555] | 71 | for (set<string>::const_iterator i = options.begin(); i!=options.end(); i++) { | 
|---|
| [534] | 72 | s += " " + *i; | 
|---|
|  | 73 | } | 
|---|
|  | 74 | if (unit != "") s += " (" + unit + ")"; | 
|---|
|  | 75 | return s; | 
|---|
|  | 76 | } | 
|---|