diff --git a/source/graphics/ColladaManager.cpp b/source/graphics/ColladaManager.cpp index c7b806a010..c9613a57c8 100644 --- a/source/graphics/ColladaManager.cpp +++ b/source/graphics/ColladaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -219,23 +219,23 @@ public: } bool loaded = false; - for (VfsPaths::const_iterator it = pathnames.begin(); it != pathnames.end(); ++it) + for (const VfsPath& path : pathnames) { - LOGMESSAGE("Loading skeleton definitions from '%s'", it->string8()); + LOGMESSAGE("Loading skeleton definitions from '%s'", path.string8()); // Set the filename for the logger to report - set_logger(ColladaLog, const_cast(static_cast(&(*it)))); + set_logger(ColladaLog, const_cast(static_cast(&path))); CVFSFile skeletonFile; - if (skeletonFile.Load(m_VFS, *it) != PSRETURN_OK) + if (skeletonFile.Load(m_VFS, path) != PSRETURN_OK) { - LOGERROR("Failed to read skeleton defintions from '%s'", it->string8()); + LOGERROR("Failed to read skeleton defintions from '%s'", path.string8()); continue; } int ok = set_skeleton_definitions((const char*)skeletonFile.GetBuffer(), (int)skeletonFile.GetBufferSize()); if (ok < 0) { - LOGERROR("Failed to load skeleton definitions from '%s'", it->string8()); + LOGERROR("Failed to load skeleton definitions from '%s'", path.string8()); continue; } @@ -280,14 +280,14 @@ public: m_skeletonHashes.reserve(paths.size()*2); CFileInfo fileInfo; - for (VfsPaths::const_iterator it = paths.begin(); it != paths.end(); ++it) + for (const VfsPath& path : paths) { // This will cause an assertion failure if *it doesn't exist, // because fileinfo is not a NULL pointer, which is annoying but that // should never happen, unless there really is a problem - if (m_VFS->GetFileInfo(*it, &fileInfo) != INFO::OK) + if (m_VFS->GetFileInfo(path, &fileInfo) != INFO::OK) { - LOGERROR("Failed to stat '%s' for DAE caching", it->string8()); + LOGERROR("Failed to stat '%s' for DAE caching", path.string8()); } else { @@ -304,8 +304,8 @@ public: m_skeletonHashInvalidated = false; } - for (std::vector::const_iterator it = m_skeletonHashes.begin(); it != m_skeletonHashes.end(); ++it) - hash.Update((const u8*)&(*it), sizeof(*it)); + for (const u64& h : m_skeletonHashes) + hash.Update((const u8*)&h, sizeof(h)); } private: diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 262e4a1505..035dc34d35 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1470,18 +1470,18 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::un { VfsPaths pathnames; vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames); - for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it) + for (const VfsPath& path : pathnames) { // Only load new files (so when the insert succeeds) - if (Paths.insert(*it).second) + if (Paths.insert(path).second) { try { - m_ScriptInterface->LoadGlobalScriptFile(*it); + m_ScriptInterface->LoadGlobalScriptFile(path); } catch (PSERROR_Scripting& e) { - LOGERROR("GUI: Error executing script %s: %s", (*it).string8(), e.what()); + LOGERROR("GUI: Error executing script %s: %s", path.string8(), e.what()); } } } diff --git a/source/ps/TemplateLoader.cpp b/source/ps/TemplateLoader.cpp index 3a24366cbd..63ce3157a5 100644 --- a/source/ps/TemplateLoader.cpp +++ b/source/ps/TemplateLoader.cpp @@ -264,15 +264,14 @@ std::vector CTemplateLoader::FindPlaceableTemplates(const std::stri if (vfs::GetPathnames(g_VFS, templatePath / (directoryPath + "/"), fileFilter.c_str(), filenames) != INFO::OK) continue; - for (VfsPaths::iterator it = filenames.begin(); it != filenames.end(); ++it) + for (const VfsPath& filename : filenames) { - VfsPath filename = *it; // Strip the .xml extension VfsPath pathstem = filename.ChangeExtension(L""); // Strip the root from the path std::wstring name = pathstem.string().substr(ARRAY_SIZE(TEMPLATE_ROOT) - 1); - templates.push_back(std::string(name.begin(), name.end())); + templates.emplace_back(name.begin(), name.end()); } } diff --git a/source/renderer/PostprocManager.cpp b/source/renderer/PostprocManager.cpp index 8b9aa5d81b..fd35ea6126 100644 --- a/source/renderer/PostprocManager.cpp +++ b/source/renderer/PostprocManager.cpp @@ -514,21 +514,17 @@ void CPostprocManager::ApplyPostproc() std::vector CPostprocManager::GetPostEffects() { std::vector effects; - + const VfsPath path(L"shaders/effects/postproc/"); - + VfsPaths pathnames; - if(vfs::GetPathnames(g_VFS, path, 0, pathnames) < 0) + if (vfs::GetPathnames(g_VFS, path, 0, pathnames) < 0) LOGERROR("Error finding Post effects in '%s'", path.string8()); - for(size_t i = 0; i < pathnames.size(); i++) - { - if (pathnames[i].Extension() != L".xml") - continue; - - effects.push_back(pathnames[i].Basename().string()); - } - + for (const VfsPath& path : pathnames) + if (path.Extension() == L".xml") + effects.push_back(path.Basename().string()); + // Add the default "null" effect to the list. effects.push_back(L"default"); diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index 16dd4d5f6a..a4ae8cafa7 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -461,14 +461,12 @@ bool ScriptInterface::LoadGlobalScripts() // Load and execute *.js in the global scripts directory VfsPaths pathnames; vfs::GetPathnames(g_VFS, L"globalscripts/", L"*.js", pathnames); - for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it) - { - if (!LoadGlobalScriptFile(*it)) + for (const VfsPath& path : pathnames) + if (!LoadGlobalScriptFile(path)) { - LOGERROR("LoadGlobalScripts: Failed to load script %s", it->string8()); + LOGERROR("LoadGlobalScripts: Failed to load script %s", path.string8()); return false; } - } JSAutoRequest rq(m->m_cx); JS::RootedValue proto(m->m_cx); diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 428dd29ea7..aff0871f81 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -187,13 +187,12 @@ bool CSimulation2Impl::LoadScripts(CComponentManager& componentManager, std::set return false; bool ok = true; - for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it) + for (const VfsPath& path : pathnames) { - VfsPath filename = *it; if (loadedScripts) - loadedScripts->insert(filename); - LOGMESSAGE("Loading simulation script '%s'", filename.string8()); - if (!componentManager.LoadScript(filename)) + loadedScripts->insert(path); + LOGMESSAGE("Loading simulation script '%s'", path.string8()); + if (!componentManager.LoadScript(path)) ok = false; } return ok; diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index 800f373721..6bb85dc637 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -252,11 +252,11 @@ public: return false; } - for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it) + for (const VfsPath& path : pathnames) { - if (!m_ScriptInterface->LoadGlobalScriptFile(*it)) + if (!m_ScriptInterface->LoadGlobalScriptFile(path)) { - LOGERROR("Failed to load script %s", it->string8()); + LOGERROR("Failed to load script %s", path.string8()); return false; } } diff --git a/source/simulation2/components/tests/test_scripts.h b/source/simulation2/components/tests/test_scripts.h index f548e06f24..061f727344 100644 --- a/source/simulation2/components/tests/test_scripts.h +++ b/source/simulation2/components/tests/test_scripts.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -66,7 +66,7 @@ public: VfsPaths paths; TS_ASSERT_OK(vfs::GetPathnames(g_VFS, L"simulation/components/tests/", L"test_*.js", paths)); - for (size_t i = 0; i < paths.size(); ++i) + for (const VfsPath& path : paths) { CSimContext context; CComponentManager componentManager(context, g_ScriptRuntime, true); @@ -79,7 +79,7 @@ public: componentManager.LoadComponentTypes(); load_script(componentManager.GetScriptInterface(), L"simulation/components/tests/setup.js"); - load_script(componentManager.GetScriptInterface(), paths[i]); + load_script(componentManager.GetScriptInterface(), path); } } };