-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabelset.cpp
More file actions
62 lines (43 loc) · 782 Bytes
/
labelset.cpp
File metadata and controls
62 lines (43 loc) · 782 Bytes
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
54
55
56
57
58
59
60
61
#include "labelset.h"
LabelSet::LabelSet(): mNullstub("nullstub")
{
}
LabelSet::~LabelSet()
{
Clear();
}
void LabelSet::Clear()
{
unsigned int i;
for(i=0; i<mNodes.size(); i++)
{
Node* node = mNodes[i];
delete node;
}
mNodes.clear();
}
unsigned int LabelSet::Add(const char* name)
{
Node* node = new Node;
node->name.assign(name);
node->label = mNodes.size();
mNodes.push_back(node);
return node->label;
}
unsigned int LabelSet::Find(const char* name) const
{
unsigned int i;
for(i=0; i<mNodes.size(); i++)
{
Node* node = mNodes[i];
if (node->name.compare(name) == 0)
return node->label;
}
return ~0;
}
const std::string& LabelSet::Lookup(unsigned int label) const
{
if (label == ~1)
return mNullstub;
return mNodes[label]->name;
}