blob: a9b19a502b057a25ae61da5d5f910997dcd968bc (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
|
#include "artsmodulescommon.h"
#include <debug.h>
using namespace std;
namespace Arts {
namespace Environment {
class Context_impl : virtual public Context_skel {
protected:
struct ContextEntry {
ContextEntry(const string& name, Object object)
: name(name), object(object)
{
}
ContextEntry(const ContextEntry& entry)
: name(entry.name), object(entry.object)
{
}
string name;
Object object;
};
list<ContextEntry> entries;
list<ContextEntry>::iterator findEntry(const string& name)
{
list<ContextEntry>::iterator i = entries.begin();
for(i = entries.begin(); i != entries.end(); i++)
if(i->name == name) return i;
return entries.end();
}
list<ContextEntry>::iterator findEntry(Object object)
{
list<ContextEntry>::iterator i = entries.begin();
for(i = entries.begin(); i != entries.end(); i++)
if(object._isEqual(i->object)) return i;
return entries.end();
}
public:
void addEntry(const string& name, Object object)
{
arts_return_if_fail(findEntry(name) != entries.end());
entries.push_back(ContextEntry(name, object));
}
string lookupEntry(Object object)
{
list<ContextEntry>::iterator i = findEntry(object);
if(i == entries.end())
return "";
else
return i->name;
}
void removeEntry(Object object)
{
list<ContextEntry>::iterator i = findEntry(object);
arts_return_if_fail(i != entries.end());
entries.erase(i);
}
};
REGISTER_IMPLEMENTATION(Context_impl);
}
}
|