Skip to content

Commit 1cb22d5

Browse files
authored
Use C++11 range based loops (#3)
1 parent c8bc5eb commit 1cb22d5

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int CFunctions::amxLoadPlugin(lua_State *luaVM) {
8383
#endif
8484

8585
HMODULE hPlugin = loadLib(pluginPath.c_str());
86-
86+
8787
if(!hPlugin) {
8888
lua_pushboolean(luaVM, 0);
8989
return 1;
@@ -184,8 +184,8 @@ int CFunctions::amxLoad(lua_State *luaVM) {
184184
amx_TimeInit(amx);
185185
amx_FileInit(amx);
186186
err = amx_SAMPInit(amx);
187-
for(map< string, SampPlugin* >::iterator it = loadedPlugins.begin(); it != loadedPlugins.end(); it++) {
188-
AmxLoad_t* pfnAmxLoad = it->second->AmxLoad;
187+
for (const auto& plugin : loadedPlugins) {
188+
AmxLoad_t* pfnAmxLoad = plugin.second->AmxLoad;
189189
if (pfnAmxLoad) {
190190
err = pfnAmxLoad(amx);
191191
}
@@ -290,8 +290,8 @@ int CFunctions::amxCall(lua_State *luaVM) {
290290
cell ret;
291291
int err = amx_Exec(amx, &ret, fnIndex);
292292
// Release string arguments
293-
for(vector<cell>::iterator it = stringsToRelease.begin(); it != stringsToRelease.end(); it++) {
294-
amx_Release(amx, *it);
293+
for (const auto& amxStringAddr : stringsToRelease) {
294+
amx_Release(amx, amxStringAddr);
295295
}
296296
if(err != AMX_ERR_NONE) {
297297
if(err == AMX_ERR_SLEEP)
@@ -377,16 +377,16 @@ int CFunctions::amxUnload(lua_State *luaVM) {
377377
return 1;
378378
}
379379
// Call all plugins' AmxUnload function
380-
for(map< string, SampPlugin* >::iterator piIt = loadedPlugins.begin(); piIt != loadedPlugins.end(); piIt++) {
381-
AmxUnload_t *pfnAmxUnload = piIt->second->AmxUnload;
380+
for (const auto& plugin : loadedPlugins) {
381+
AmxUnload_t *pfnAmxUnload = plugin.second->AmxUnload;
382382
if (pfnAmxUnload) {
383383
pfnAmxUnload(amx);
384384
}
385385
}
386386
// Close any open databases
387387
if(loadedDBs.find(amx) != loadedDBs.end()) {
388-
for(map< int, sqlite3 * >::iterator dbIt = loadedDBs[amx].begin(); dbIt != loadedDBs[amx].end(); dbIt++)
389-
sqlite3_close(dbIt->second);
388+
for (const auto& db : loadedDBs[amx])
389+
sqlite3_close(db.second);
390390
loadedDBs.erase(amx);
391391
}
392392
// Unload
@@ -402,13 +402,13 @@ int CFunctions::amxUnload(lua_State *luaVM) {
402402

403403
// amxUnloadAllPlugins()
404404
int CFunctions::amxUnloadAllPlugins(lua_State *luaVM) {
405-
for (map< string, SampPlugin* >::iterator it = loadedPlugins.begin(); it != loadedPlugins.end(); it++) {
406-
Unload_t* Unload = it->second->Unload;
405+
for (const auto& plugin : loadedPlugins) {
406+
Unload_t* Unload = it.second->Unload;
407407
if (Unload) {
408408
Unload();
409409
}
410-
freeLib(it->second->pPluginPointer);
411-
delete it->second;
410+
freeLib(it.second->pPluginPointer);
411+
delete it.second;
412412
}
413413
loadedPlugins.clear();
414414
vecPfnProcessTick.clear();
@@ -492,9 +492,9 @@ int CFunctions::pawn(lua_State *luaVM) {
492492

493493
int fnIndex;
494494
AMX *amx = NULL;
495-
for(vector<AMX *>::iterator it = amxs.begin(); it != amxs.end(); it++) {
496-
if(amx_FindPublic(*it, fnName, &fnIndex) == AMX_ERR_NONE) {
497-
amx = *it;
495+
for (const auto& it : amxs) {
496+
if(amx_FindPublic(it, fnName, &fnIndex) == AMX_ERR_NONE) {
497+
amx = it;
498498
break;
499499
}
500500
}

amx-deps/src/ml_base.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ void logprintf(char *fmt, ...) {
116116
int AMXCallPublicFilterScript(char *fnName) {
117117
int fnIndex = -1;
118118
cell ret = 0;
119-
for(map< AMX *, AMXPROPS >::iterator it = loadedAMXs.begin(); it != loadedAMXs.end(); it++) {
120-
if(amx_FindPublic(it->first, "OnFilterScriptInit", &fnIndex) != AMX_ERR_NONE)
119+
for (const auto& it : loadedAMXs) {
120+
if(amx_FindPublic(it.first, "OnFilterScriptInit", &fnIndex) != AMX_ERR_NONE)
121121
continue;
122-
if(amx_FindPublic(it->first, fnName, &fnIndex) != AMX_ERR_NONE)
122+
if(amx_FindPublic(it.first, fnName, &fnIndex) != AMX_ERR_NONE)
123123
continue;
124-
amx_Exec(it->first, &ret, fnIndex);
124+
amx_Exec(it.first, &ret, fnIndex);
125125
return ret;
126126
}
127127
return 0;
@@ -130,12 +130,12 @@ int AMXCallPublicFilterScript(char *fnName) {
130130
int AMXCallPublicGameMode(char *fnName) {
131131
int fnIndex = -1;
132132
cell ret = 0;
133-
for(map< AMX *, AMXPROPS >::iterator it = loadedAMXs.begin(); it != loadedAMXs.end(); it++) {
134-
if(amx_FindPublic(it->first, "OnGameModeInit", &fnIndex) != AMX_ERR_NONE)
133+
for(const auto& it : loadedAMXs) {
134+
if(amx_FindPublic(it.first, "OnGameModeInit", &fnIndex) != AMX_ERR_NONE)
135135
continue;
136-
if(amx_FindPublic(it->first, fnName, &fnIndex) != AMX_ERR_NONE)
136+
if(amx_FindPublic(it.first, fnName, &fnIndex) != AMX_ERR_NONE)
137137
continue;
138-
amx_Exec(it->first, &ret, fnIndex);
138+
amx_Exec(it.first, &ret, fnIndex);
139139
return ret;
140140
}
141141
return 0;

amx-deps/src/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ void lua_pushremotevalues(lua_State *localVM, lua_State *remoteVM, int num) {
187187

188188
vector<AMX *> getResourceAMXs(lua_State *luaVM) {
189189
vector<AMX *> amxs;
190-
for(map< AMX *, AMXPROPS >::iterator it = loadedAMXs.begin(); it != loadedAMXs.end(); it++) {
191-
if(it->second.resourceVM == luaVM)
192-
amxs.push_back(it->first);
190+
for (const auto& it : loadedAMXs) {
191+
if (it.second.resourceVM == luaVM)
192+
amxs.push_back(it.first);
193193
}
194194
return amxs;
195195
}

0 commit comments

Comments
 (0)