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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*
* RTFL
*
* Copyright 2015 Sebastian Geerken <sgeerken@dillo.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version; with the following exception:
*
* The copyright holders of RTFL give you permission to link this file
* statically or dynamically against all versions of the graphviz
* library, which are published by AT&T Corp. under one of the following
* licenses:
*
* - Common Public License version 1.0 as published by International
* Business Machines Corporation (IBM), or
* - Eclipse Public License version 1.0 as published by the Eclipse
* Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "objdelete_controller.hh"
using namespace lout::object;
using namespace lout::misc;
using namespace lout::container::typed;
using namespace rtfl::tools;
namespace rtfl {
namespace objects {
ObjDeleteController::ObjInfo::ObjInfo (const char *id)
{
numCreated = 0;
numDeleted = 0;
origId = strdup (id);
mappedId = strdup (id);
}
ObjDeleteController::ObjInfo::~ObjInfo ()
{
free (origId);
free (mappedId);
}
void ObjDeleteController::ObjInfo::use ()
{
numCreated = max (numCreated, 1);
}
void ObjDeleteController::ObjInfo::objCreate ()
{
numCreated++;
}
void ObjDeleteController::ObjInfo::objDelete ()
{
numCreated--;
if (numCreated <= 0) {
numCreated = 0;
numDeleted++;
free (mappedId);
mappedId = (char*) malloc ((strlen (origId) + 10 + 1) * sizeof (char));
sprintf (mappedId, "%s-%d", origId, numDeleted);
}
}
ObjDeleteController::ObjDeleteController (ObjectsController *successor)
{
this->successor = successor;
successor->setObjectsSource (this);
setObjectsSink (successor);
objInfos = new HashTable<String, ObjInfo> (true, true);
}
ObjDeleteController::~ObjDeleteController ()
{
delete objInfos;
}
void ObjDeleteController::objMsg (CommonLineInfo *info, const char *id,
const char *aspect, int prio,
const char *message)
{
successor->objMsg (info, mapId (id), aspect, prio, message);
}
void ObjDeleteController::objMark (CommonLineInfo *info, const char *id,
const char *aspect, int prio,
const char *message)
{
successor->objMark (info, mapId (id), aspect, prio, message);
}
void ObjDeleteController::objMsgStart (CommonLineInfo *info, const char *id)
{
successor->objMsgStart (info, mapId (id));
}
void ObjDeleteController::objMsgEnd (CommonLineInfo *info, const char *id)
{
successor->objMsgEnd (info, mapId (id));
}
void ObjDeleteController::objEnter (CommonLineInfo *info, const char *id,
const char *aspect, int prio,
const char *funname, const char *args)
{
successor->objEnter (info, mapId (id), aspect, prio, funname, args);
}
void ObjDeleteController::objLeave (CommonLineInfo *info, const char *id,
const char *vals)
{
successor->objLeave (info, mapId (id), vals);
}
void ObjDeleteController::objCreate (CommonLineInfo *info, const char *id,
const char *klass)
{
ensureObjInfo(id)->objCreate ();
successor->objCreate (info, mapId (id), klass);
}
void ObjDeleteController::objIdent (CommonLineInfo *info, const char *id1,
const char *id2)
{
successor->objIdent (info, mapId (id1), mapId (id2));
}
void ObjDeleteController::objNoIdent (CommonLineInfo *info)
{
successor->objNoIdent (info);
}
void ObjDeleteController::objAssoc (CommonLineInfo *info, const char *parent,
const char *child)
{
successor->objAssoc (info, mapId (parent), mapId (child));
}
void ObjDeleteController::objSet (CommonLineInfo *info, const char *id,
const char *var, const char *val)
{
successor->objSet (info, mapId (id), var, val);
}
void ObjDeleteController::objClassColor (CommonLineInfo *info,
const char *klass, const char *color)
{
successor->objClassColor (info, klass, color);
}
void ObjDeleteController::objObjectColor (CommonLineInfo *info, const char *id,
const char *color)
{
successor->objObjectColor (info, mapId (id), color);
}
void ObjDeleteController::objDelete (CommonLineInfo *info, const char *id)
{
successor->objDelete (info, mapId (id));
ensureObjInfo(id)->objDelete ();
}
const char *ObjDeleteController::mapId (const char *id)
{
ObjInfo *objInfo = ensureObjInfo (id);
objInfo->use ();
return objInfo->getMappedId ();
}
ObjDeleteController::ObjInfo *ObjDeleteController::getObjInfo (const char *id)
{
String key (id);
return objInfos->get (&key);
}
ObjDeleteController::ObjInfo *ObjDeleteController::ensureObjInfo (const char
*id)
{
ObjInfo *objInfo = getObjInfo (id);
if (objInfo == NULL) {
objInfo = new ObjInfo (id);
objInfos->put (new String (id), objInfo);
}
return objInfo;
}
} // namespace objects
} // namespace rtfl
|