-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassTable.cc
More file actions
53 lines (46 loc) · 1.2 KB
/
ClassTable.cc
File metadata and controls
53 lines (46 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "ClassTable.h"
#include <utility>
#include <iostream>
using namespace std;
ClassTable::ClassTable() :
counter(9)
{
// pre-fill the table with primitive types i.e. "pseudo-classes"
table.insert(make_pair("bool", 1));
table.insert(make_pair("char", 2));
table.insert(make_pair("float", 3));
table.insert(make_pair("double", 4));
table.insert(make_pair("byte", 5));
table.insert(make_pair("short", 6));
table.insert(make_pair("int", 7));
table.insert(make_pair("long", 8));
}
void ClassTable::mapClass(string className)
{
table.insert(make_pair(className, counter));
// cerr << className << ": " << counter << endl;
counter++;
}
int ClassTable::findClassID(string className)
{
if (table.find(className) != table.end()) {
return table[className];
} else {
return -1;
}
}
int ClassTable::mapOrFind(string className)
{
if (table.find(className) == table.end()) {
mapClass(className);
}
return table[className];
}
void ClassTable::dumpTable(ofstream &dumpFile)
{
for ( auto it = table.begin();
it != table.end();
++it ) {
dumpFile << it->second << " " << it->first << endl;
}
}