blob: 0a6f87d7969ef80a76c8bdddc949e89781488e2f (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#include "artsmodulescommon.h"
#include "../runtime/sequenceutils.h"
#include <debug.h>
using namespace std;
namespace Arts {
namespace Environment {
class Container_impl : virtual public Container_skel {
protected:
string _dataDirectory;
Context _context;
vector<Item> _items;
Container self() { return Container::_from_base(_copy()); }
public:
~Container_impl()
{
// tell items we're going to leave before actually going away
clear();
}
string dataDirectory()
{
return _dataDirectory;
}
void dataDirectory(const string& newDataDirectory)
{
if(newDataDirectory != _dataDirectory)
{
_dataDirectory = newDataDirectory;
dataDirectory_changed(newDataDirectory);
}
}
Context context()
{
return _context;
}
void context(Context newContext)
{
_context = newContext;
}
vector<Item> *items()
{
return new vector<Item>(_items);
}
vector<string> *saveToList()
{
vector<string> *result = new vector<string>;
vector<Item>::iterator ii;
for(ii=_items.begin(); ii != _items.end(); ii++)
{
sqprintf(result,"item=%s",ii->_interfaceName().c_str());
vector<string> *itemresult = ii->saveToList();
addSubStringSeq(result,itemresult);
delete itemresult;
}
return result;
}
void clear()
{
/* FIXME: performance ;) */
while(!_items.empty())
removeItem(_items.front());
}
void loadFromList(const vector<string>& strlist)
{
string cmd,param;
unsigned long i;
clear();
for(i=0;i<strlist.size();i++)
{
if(parse_line(strlist[i],cmd,param)) // otherwise: empty or comment
{
if(cmd == "item")
{
Item item = createItem(param);
vector<string> *itemlist = getSubStringSeq(&strlist,i);
if(!item.isNull())
item.loadFromList(*itemlist);
else
{
// error handling
assert(false);
}
delete itemlist;
}
}
}
}
vector<Item>::iterator findItem(Item item)
{
vector<Item>::iterator i;
for(i = _items.begin(); i != _items.end(); i++)
if(i->_isEqual(item)) return i;
return _items.end();
}
void addItem(Item item)
{
vector<Item>::iterator i = findItem(item);
arts_return_if_fail(i == _items.end());
_items.push_back(item);
item.setContainer(self());
}
Item createItem(const string& name)
{
Item item = SubClass(name);
addItem(item);
return item;
}
void removeItem(Item item)
{
vector<Item>::iterator i = findItem(item);
arts_return_if_fail(i != _items.end());
_items.erase(i);
item.setContainer(Container::null());
}
};
REGISTER_IMPLEMENTATION(Container_impl);
}
}
|