Skip to content

Commit d190e5c

Browse files
committed
erase from std::list
1 parent 970be7e commit d190e5c

File tree

6 files changed

+45
-37
lines changed

6 files changed

+45
-37
lines changed

gran/granActor.c++

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ void granActor::unloadFile(char* dirName, char* fName) {
232232
if ((*it)->unused()) {
233233
delete *it;
234234
fileList.erase(it);
235-
}
236-
else
237-
fprintf(stderr, "vss: granActor can't unload soundfile %s because it's still in use.\n", fName);
235+
} else {
236+
fprintf(stderr, "vss: granActor file \"%s\" is still in use.\n", fName);
237+
}
238238
return;
239239
}
240240
}
@@ -245,12 +245,18 @@ void granActor::unloadFile(char* dirName, char* fName) {
245245
// (may crash, unless from the destructor, which then deletes the
246246
// VAlgorithms that are using these sfiles).
247247
void granActor::unloadAllFiles(int beFirm) {
248-
for (auto it = fileList.begin(); it != fileList.end(); ++it) {
249-
if (beFirm || (*it)->unused()) {
250-
delete *it;
251-
fileList.erase(it--);
252-
} else {
248+
if (beFirm) {
249+
for (auto f: fileList) delete f;
250+
fileList.clear();
251+
return;
252+
}
253+
for (auto it = fileList.begin(); it != fileList.end();) {
254+
if ((*it)->unused()) {
255+
delete *it;
256+
it = fileList.erase(it); // works with either list or vector
257+
} else {
253258
fprintf(stderr, "vss: granActor file %s is still in use.\n", (*it)->name());
259+
++it;
254260
}
255261
}
256262
}

later/laterActor.c++

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ LaterActor::LaterActor() {
55
setTypeName("LaterActor");
66
}
77

8-
LaterActor::~LaterActor() {}
9-
108
// Send and delete all messages whose time has come.
9+
// Like MessageGroup::act().
1110
void LaterActor::act()
1211
{
1312
VActor::act();
1413
const auto now = currentTime();
15-
for (auto it = messageList.begin(); it != messageList.end(); ++it) {
14+
for (auto it = messageList.begin(); it != messageList.end();) {
1615
if (now >= it->time) {
1716
actorMessageHandler(it->msg);
18-
messageList.erase(it--);
17+
it = messageList.erase(it);
18+
} else {
19+
++it;
1920
}
2021
}
2122
}

later/laterActor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
class LaterActor : public VActor
77
{
88
using Event = struct { float time; char msg[128]; };
9-
using EventList = std::list<Event>;
10-
EventList messageList;
9+
std::list<Event> messageList;
1110
public:
1211
LaterActor();
13-
~LaterActor();
1412
void act();
1513
int receiveMessage(const char*);
1614
void addMessage(float, char*);

msg/messageGroup.c++

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,17 @@ int MessageGroup::receiveMessage(const char* Message)
432432
}
433433

434434
// Process and delete all delayed data arrays whose time has come.
435+
// Like LaterActor::act().
435436
void MessageGroup::act()
436437
{
437438
VActor::act();
438439
const auto now = currentTime();
439-
for (auto it = dataList.begin(); it != dataList.end(); ++it) {
440+
for (auto it = dataList.begin(); it != dataList.end();) {
440441
if (now >= (*it)->time) {
441442
receiveData((*it)->data, (*it)->size);
442-
dataList.erase(it--);
443+
it = dataList.erase(it);
444+
} else {
445+
++it;
443446
}
444447
}
445448
}

msg/messageGroup.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@
66
#include <list>
77

88
// Parameterized messages.
9-
class ParamMsg
10-
{
11-
public:
9+
struct ParamMsg {
1210
char msg[256];
13-
ParamMsg() { msg[0] = '\0'; }
11+
ParamMsg() = delete;
1412
ParamMsg(char* m) { strcpy(msg, m); }
15-
~ParamMsg() {}
1613
};
1714

1815
// Store arrays to be received (handled) later.
19-
class DelayedData
20-
{
21-
public:
16+
struct DelayedData {
2217
float* data;
2318
int size;
2419
float time;
25-
DelayedData(): data(NULL), size(0), time(0.) {}
20+
DelayedData(): data(nullptr), size(0), time(0.0) {}
2621
DelayedData(float t, float* d, int s) : data(d), size(s), time(t) {}
27-
~DelayedData() { delete[] data; }
22+
~DelayedData() { delete [] data; }
2823
};
2924

3025
// ParticleActor derives from this, hence the virtuals.
@@ -69,8 +64,7 @@ class MessageGroup : public VActor
6964
virtual void receiveScheduledData(float, float*, int);
7065
virtual void endReceiveSchedule(int) {}
7166

72-
using DelayedDataList = std::list<DelayedData*>;
73-
DelayedDataList dataList;
67+
std::list<DelayedData*> dataList;
7468

7569
public:
7670
virtual void act();

samp/sampActor.c++

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,26 +199,32 @@ void sampActor::unloadFile(char* dirName, char* fName) {
199199
if ((*it)->unused()) {
200200
delete *it;
201201
fileList.erase(it);
202-
}
203-
else
204-
printf("vss error: SampleActor file \"%s\" is still in use.\n", fName);
202+
} else {
203+
fprintf(stderr, "vss: SampleActor file \"%s\" is still in use.\n", fName);
204+
}
205205
return;
206206
}
207207
}
208-
printf("vss warning: SampleActor did not find %s to unload.\n", fName);
208+
fprintf(stderr, "vss: SampleActor did not find %s to unload.\n", fName);
209209
}
210210

211211

212212
// Unload files not still in use. If beFirm, unload all files
213213
// (may crash, unless from the destructor, which then deletes the
214214
// VAlgorithms that are using these sfiles).
215215
void sampActor::unloadAllFiles(int beFirm) {
216-
for (auto it = fileList.begin(); it != fileList.end(); it++) {
217-
if (beFirm || (*it)->unused()) {
216+
if (beFirm) {
217+
for (auto f: fileList) delete f;
218+
fileList.clear();
219+
return;
220+
}
221+
for (auto it = fileList.begin(); it != fileList.end();) {
222+
if ((*it)->unused()) {
218223
delete *it;
219-
fileList.erase(it--);
224+
it = fileList.erase(it); // works with either list or vector
220225
} else {
221-
printf("vss error: SampleActor file %s is still in use.\n", (*it)->name());
226+
fprintf(stderr, "vss: SampleActor file %s is still in use.\n", (*it)->name());
227+
++it;
222228
}
223229
}
224230
}

0 commit comments

Comments
 (0)