Replace BOOST_FOREACH by C++ 11 for range loop.

This commit is contained in:
gallaert 2020-04-09 21:15:39 +01:00 committed by James Turner
parent 825d93423d
commit c9a4c0dac1
20 changed files with 230 additions and 266 deletions

View File

@ -18,18 +18,17 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <simgear_config.h>
#include <simgear/debug/BufferedLogCallback.hxx>
#include <boost/foreach.hpp>
#include <simgear/sg_inlines.h>
#include <simgear/threads/SGThread.hxx>
#include <cstdlib> // for malloc
#include <cstring>
#include <mutex>
namespace simgear
{
@ -41,7 +40,7 @@ public:
unsigned int m_stamp;
unsigned int m_maxLength;
};
BufferedLogCallback::BufferedLogCallback(sgDebugClass c, sgDebugPriority p) :
simgear::LogCallback(c,p),
d(new BufferedLogCallbackPrivate)
@ -52,19 +51,19 @@ BufferedLogCallback::BufferedLogCallback(sgDebugClass c, sgDebugPriority p) :
BufferedLogCallback::~BufferedLogCallback()
{
BOOST_FOREACH(unsigned char* msg, d->m_buffer) {
for (auto msg : d->m_buffer) {
free(msg);
}
}
void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage)
{
SG_UNUSED(file);
SG_UNUSED(line);
if (!shouldLog(c, p)) return;
vector_cstring::value_type msg;
if (aMessage.size() >= d->m_maxLength) {
msg = (vector_cstring::value_type) malloc(d->m_maxLength);
@ -73,17 +72,17 @@ void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
} else {
msg = (vector_cstring::value_type) strdup(aMessage.c_str());
}
std::lock_guard<std::mutex> g(d->m_mutex);
d->m_buffer.push_back(msg);
d->m_stamp++;
}
unsigned int BufferedLogCallback::stamp() const
{
return d->m_stamp;
}
unsigned int BufferedLogCallback::threadsafeCopy(vector_cstring& aOutput)
{
std::lock_guard<std::mutex> g(d->m_mutex);
@ -91,11 +90,11 @@ unsigned int BufferedLogCallback::threadsafeCopy(vector_cstring& aOutput)
aOutput.resize(sz);
memcpy(aOutput.data(), d->m_buffer.data(), sz * sizeof(vector_cstring::value_type));
return d->m_stamp;
}
}
void BufferedLogCallback::truncateAt(unsigned int t)
{
d->m_maxLength = t;
}
} // of namespace simgear

View File

@ -24,14 +24,13 @@
#include "logstream.hxx"
#include <cstring>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <mutex>
#include <boost/foreach.hpp>
#include <simgear/sg_inlines.h>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGQueue.hxx>
@ -63,7 +62,7 @@ LogCallback::LogCallback(sgDebugClass c, sgDebugPriority p) :
bool LogCallback::shouldLog(sgDebugClass c, sgDebugPriority p) const
{
if ((c & m_class) != 0 && p >= m_priority)
return true;
if (c == SG_OSG) // always have OSG logging as it OSG logging is configured separately.
@ -164,10 +163,10 @@ public:
/* <line> can be -ve to indicate that m_fileLine was false, but we
want to show file:line information regardless of m_fileLine. */
m_file
<< file
<< ":"
<< file
<< ":"
<< abs(line)
<< ": "
<< ": "
;
}
m_file
@ -202,7 +201,7 @@ public:
{
if (!shouldLog(c, p)) return;
//fprintf(stderr, "%s\n", aMessage.c_str());
if (file && line > 0) {
fprintf(stderr, "%8.2f %s:%i: [%.8s]:%-10s %s\n", logTimer.elapsedMSec()/1000.0, file, line, debugPriorityToString(p), debugClassToString(c), aMessage.c_str());
}
@ -303,10 +302,10 @@ public:
* window; stdout/stderr will not appear (except in logfiles as they do now)
* 4) When started from the Console (with --console) open a new console window
* 5) Ensure that IO redirection still works when started from the console
*
*
* Notes:
* 1) fgfs needs to be a GUI subsystem app - which it already is
* 2) What can't be done is to make the cmd prompt run fgfs synchronously;
* 2) What can't be done is to make the cmd prompt run fgfs synchronously;
* this is only something that can be done via "start /wait fgfs".
*/
@ -330,7 +329,7 @@ public:
}
} else {
/*
* Attempt to attach to the console process of the parent process; when launched from cmd.exe this should be the console,
* Attempt to attach to the console process of the parent process; when launched from cmd.exe this should be the console,
* when launched via the RUN menu explorer, or another GUI app that wasn't started from the console this will fail.
* When it fails we will redirect to the NUL device. This is to ensure that we have valid streams.
* Later on in the initialisation sequence the --console option will be processed and this will cause the requestConsole() to
@ -360,7 +359,7 @@ public:
if (!stdout_isNull){
if (!m_stdout_isRedirectedAlready)
freopen("conout$", "w", stdout);
else
else
/*
* for already redirected streams we need to attach the stream to the OS handle that is open.
* - this comes from part of the answer http://stackoverflow.com/a/13841522
@ -379,7 +378,7 @@ public:
}
}
//http://stackoverflow.com/a/25927081
//Clear the error state for each of the C++ standard stream objects.
//Clear the error state for each of the C++ standard stream objects.
std::wcout.clear();
std::cout.clear();
std::wcerr.clear();
@ -532,7 +531,7 @@ public:
PauseThread pause(this);
m_logPriority = p;
m_logClass = c;
BOOST_FOREACH(simgear::LogCallback* cb, m_consoleCallbacks) {
for (auto cb : m_consoleCallbacks) {
cb->setLogLevels(c, p);
}
}
@ -542,7 +541,7 @@ public:
// Testing mode, so always log.
if (m_testMode) return true;
// SG_OSG (OSG notify) - will always be displayed regardless of FG log settings as OSG log level is configured
// SG_OSG (OSG notify) - will always be displayed regardless of FG log settings as OSG log level is configured
// separately and thus it makes more sense to allow these message through.
if (static_cast<unsigned>(p) == static_cast<unsigned>(SG_OSG)) return true;
@ -822,7 +821,7 @@ namespace simgear
{
void requestConsole()
{
{
sglog().requestConsole();
}

View File

@ -35,7 +35,6 @@
#include <stdexcept>
#include <mutex>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <simgear/simgear_config.h>
@ -125,7 +124,7 @@ Client::Client() :
static bool didInitCurlGlobal = false;
static std::mutex initMutex;
std::lock_guard<std::mutex> g(initMutex);
if (!didInitCurlGlobal) {
curl_global_init(CURL_GLOBAL_ALL);
@ -183,15 +182,15 @@ void Client::update(int waitTimeout)
&curlWriteFDs,
&curlErrorFDs,
&maxFD);
struct timeval timeout;
long t;
curl_multi_timeout(d->curlMulti, &t);
if ((t < 0) || (t > waitTimeout)) {
t = waitTimeout;
}
timeout.tv_sec = t / 1000;
timeout.tv_usec = (t % 1000) * 1000;
::select(maxFD, &curlReadFDs, &curlWriteFDs, &curlErrorFDs, &timeout);
@ -489,7 +488,7 @@ bool isRedirectStatus(int code)
{
return ((code >= 300) && (code < 400));
}
size_t Client::requestHeaderCallback(char *rawBuffer, size_t size, size_t nitems, void *userdata)
{
size_t byteSize = size * nitems;
@ -504,7 +503,7 @@ size_t Client::requestHeaderCallback(char *rawBuffer, size_t size, size_t nitems
return byteSize;
}
}
if (req->readyState() == HTTP::Request::OPENED) {
req->responseStart(h);
return byteSize;

View File

@ -5,8 +5,6 @@
#include <signal.h>
#include <iostream>
#include <boost/foreach.hpp>
#include <simgear/io/sg_file.hxx>
#include <simgear/io/HTTPClient.hxx>
@ -29,17 +27,17 @@ public:
_complete(false),
_file(NULL)
{
}
void setFile(SGFile* f)
{
_file = f;
}
bool complete() const
{ return _complete; }
void addHeader(const string& h)
{
int colonPos = h.find(':');
@ -47,22 +45,22 @@ public:
cerr << "malformed header: " << h << endl;
return;
}
string key = h.substr(0, colonPos);
requestHeader(key) = h.substr(colonPos + 1);
}
protected:
virtual void onDone()
{
_complete = true;
}
}
virtual void gotBodyData(const char* s, int n)
{
_file->write(s, n);
}
private:
private:
bool _complete;
SGFile* _file;
};
@ -74,7 +72,7 @@ int main(int argc, char* argv[])
string proxy, proxyAuth;
string_list headers;
string url;
for (int a=0; a<argc;++a) {
if (argv[a][0] == '-') {
if (!strcmp(argv[a], "--user-agent")) {
@ -105,7 +103,7 @@ int main(int argc, char* argv[])
proxyHost = proxy.substr(0, colonPos);
proxyPort = strutils::to_int(proxy.substr(colonPos + 1));
}
cl.setProxy(proxyHost, proxyPort, proxyAuth);
}
@ -123,23 +121,23 @@ int main(int argc, char* argv[])
}
ARequest* req = new ARequest(url);
BOOST_FOREACH(string h, headers) {
for (const auto& h : headers) {
req->addHeader(h);
}
req->setFile(outFile);
cl.makeRequest(req);
while (!req->complete()) {
cl.update();
SGTimeStamp::sleepForMSec(100);
}
if (req->responseCode() != 200) {
cerr << "got response:" << req->responseCode() << endl;
cerr << "\treason:" << req->responseReason() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -41,7 +41,6 @@
#include <simgear/misc/strutils.hxx>
#include <simgear/debug/logstream.hxx>
#include <boost/foreach.hpp>
#include <cstring>
#include <cstdlib>
@ -122,7 +121,7 @@ Dir Dir::tempDir(const std::string& templ)
"mkdtemp failed: " << simgear::strutils::error_string(errno));
return Dir();
}
return Dir(SGPath(buf));
#else
#if defined(SG_WINDOWS)
@ -138,7 +137,7 @@ Dir Dir::tempDir(const std::string& templ)
SG_LOG(SG_IO, SG_WARN, "failed to create temporary directory at " << p);
return Dir();
}
return t;
#endif
}
@ -154,7 +153,7 @@ PathList Dir::children(int types, const std::string& nameFilter) const
if (types == 0) {
types = TYPE_FILE | TYPE_DIR | NO_DOT_OR_DOTDOT;
}
#if defined(SG_WINDOWS)
std::wstring search(_path.wstr());
if (nameFilter.empty()) {
@ -162,18 +161,18 @@ PathList Dir::children(int types, const std::string& nameFilter) const
} else {
search += simgear::strutils::convertUtf8ToWString("\\*" + nameFilter);
}
WIN32_FIND_DATAW fData;
HANDLE find = FindFirstFileW(search.c_str(), &fData);
if (find == INVALID_HANDLE_VALUE) {
int err = GetLastError();
if (err != ERROR_FILE_NOT_FOUND) {
SG_LOG(SG_GENERAL, SG_WARN, "Dir::children: FindFirstFile failed:" <<
SG_LOG(SG_GENERAL, SG_WARN, "Dir::children: FindFirstFile failed:" <<
_path << " with error:" << err);
}
return result;
}
bool done = false;
for (bool done = false; !done; done = (FindNextFileW(find, &fData) == 0)) {
if (fData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
@ -181,7 +180,7 @@ PathList Dir::children(int types, const std::string& nameFilter) const
continue;
}
}
std::string utf8File = simgear::strutils::convertWStringToUtf8(fData.cFileName);
if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (types & NO_DOT_OR_DOTDOT) {
@ -212,32 +211,32 @@ PathList Dir::children(int types, const std::string& nameFilter) const
SG_LOG(SG_GENERAL, SG_WARN, "Dir::children: opendir failed:" << _path);
return result;
}
int filterLen = nameFilter.size();
while (true) {
struct dirent* entry = readdir(dp);
if (!entry) {
break; // done iteration
}
// skip hidden files (names beginning with '.') unless requested
if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.') &&
strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
continue;
}
SGPath f = file(entry->d_name);
if (!f.exists()) {
continue; // stat() failed
}
if (f.isDir()) {
// directory handling
if (!(types & TYPE_DIR)) {
continue;
}
if (types & NO_DOT_OR_DOTDOT) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
continue;
@ -258,17 +257,17 @@ PathList Dir::children(int types, const std::string& nameFilter) const
if (nameLen < filterLen) {
continue; // name is shorter than the filter
}
char* nameSuffix = entry->d_name + (nameLen - filterLen);
if (strcmp(nameSuffix, nameFilter.c_str())) {
continue;
}
}
// passed all criteria, add to our result vector
result.push_back(file(entry->d_name));
}
closedir(dp);
#endif
@ -316,7 +315,7 @@ SGPath Dir::file(const std::string& name) const
SGPath childPath = _path;
childPath.set_cached(true);
childPath.append(name);
return childPath;
return childPath;
}
bool Dir::create(mode_t mode)
@ -324,7 +323,7 @@ bool Dir::create(mode_t mode)
if (exists()) {
return false; // already exists
}
// recursively create parent directories
Dir pr(parent());
if (!pr.path().isNull() && !pr.exists()) {
@ -333,7 +332,7 @@ bool Dir::create(mode_t mode)
return false;
}
}
// finally, create ourselves
#if defined(SG_WINDOWS)
std::wstring ps = _path.wstr();
@ -347,7 +346,7 @@ bool Dir::create(mode_t mode)
"directory creation failed for '" << _path.utf8Str() << "': " <<
simgear::strutils::error_string(errno));
}
return (err == 0);
}
@ -359,20 +358,20 @@ bool Dir::removeChildren() const
bool ok;
PathList cs = children(NO_DOT_OR_DOTDOT | INCLUDE_HIDDEN | TYPE_FILE | TYPE_DIR);
BOOST_FOREACH(SGPath path, cs) {
for (auto path : cs) {
if (path.isDir()) {
Dir childDir(path);
ok = childDir.remove(true);
} else {
ok = path.remove();
}
if (!ok) {
SG_LOG(SG_IO, SG_WARN, "failed to remove:" << path);
return false;
}
} // of child iteration
return true;
}
@ -382,7 +381,7 @@ bool Dir::remove(bool recursive)
SG_LOG(SG_IO, SG_WARN, "attempt to remove non-existant dir:" << _path);
return false;
}
if (recursive) {
if (!removeChildren()) {
SG_LOG(SG_IO, SG_WARN, "Dir at:" << _path << " failed to remove children");

View File

@ -18,7 +18,6 @@
#include <simgear_config.h>
#include <simgear/package/Catalog.hxx>
#include <boost/foreach.hpp>
#include <algorithm>
#include <fstream>
#include <cstring>
@ -49,7 +48,7 @@ bool checkVersion(const std::string& aVersion, SGPropertyNode_ptr props)
}
return false;
}
SGPropertyNode_ptr alternateForVersion(const std::string& aVersion, SGPropertyNode_ptr props)
{
for (auto v : props->getChildren("alternate-version")) {
@ -59,7 +58,7 @@ SGPropertyNode_ptr alternateForVersion(const std::string& aVersion, SGPropertyNo
}
}
}
return {};
}
@ -131,7 +130,7 @@ protected:
return;
} // of version check failed
// validate what we downloaded, in case it's now corrupted
// (i.e someone uploaded bad XML data)
if (!m_owner->validatePackages()) {
@ -150,7 +149,7 @@ protected:
m_owner->writeTimestamp();
m_owner->refreshComplete(Delegate::STATUS_REFRESHED);
}
void onFail() override
{
// network level failure
@ -206,17 +205,17 @@ CatalogRef Catalog::createFromPath(Root* aRoot, const SGPath& aPath)
} else {
SG_LOG(SG_GENERAL, SG_DEBUG, "creating catalog from:" << aPath);
}
// check for the marker file we write, to mark a catalog as disabled
const SGPath disableMarkerFile = aPath / "_disabled_";
CatalogRef c = new Catalog(aRoot);
c->m_installRoot = aPath;
if (disableMarkerFile.exists()) {
c->m_userEnabled = false;
}
c->parseProps(props);
c->parseTimestamp();
@ -233,7 +232,7 @@ CatalogRef Catalog::createFromPath(Root* aRoot, const SGPath& aPath)
return c;
}
bool Catalog::validatePackages() const
{
for (auto pack : packages()) {
@ -242,7 +241,7 @@ bool Catalog::validatePackages() const
return false;
}
}
return true;
}
@ -285,10 +284,10 @@ bool Catalog::removeDirectory()
Dir d(m_installRoot);
if (!m_installRoot.exists())
return true;
return d.remove(true /* recursive */);
}
PackageList const&
Catalog::packages() const
{
@ -299,7 +298,7 @@ PackageList
Catalog::packagesMatching(const SGPropertyNode* aFilter) const
{
PackageList r;
BOOST_FOREACH(PackageRef p, m_packages) {
for (auto p : m_packages) {
if (p->matches(aFilter)) {
r.push_back(p);
}
@ -311,7 +310,7 @@ PackageList
Catalog::packagesNeedingUpdate() const
{
PackageList r;
BOOST_FOREACH(PackageRef p, m_packages) {
for (auto p : m_packages) {
if (!p->isInstalled()) {
continue;
}
@ -327,7 +326,7 @@ PackageList
Catalog::installedPackages() const
{
PackageList r;
BOOST_FOREACH(PackageRef p, m_packages) {
for (auto p : m_packages) {
if (p->isInstalled()) {
r.push_back(p);
}
@ -570,7 +569,7 @@ bool Catalog::isEnabled() const
{
if (!m_userEnabled)
return false;
switch (m_status) {
case Delegate::STATUS_SUCCESS:
case Delegate::STATUS_REFRESHED:
@ -592,7 +591,7 @@ void Catalog::setUserEnabled(bool b)
{
if (m_userEnabled == b)
return;
m_userEnabled = b;
SGPath disableMarkerFile = installRoot() / "_disabled_";
if (m_userEnabled) {
@ -604,15 +603,15 @@ void Catalog::setUserEnabled(bool b)
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to remove catalog-disable marker file:" << disableMarkerFile);
}
}
Delegate::StatusCode effectiveStatus = m_status;
if ((m_status == Delegate::STATUS_SUCCESS) && !m_userEnabled) {
effectiveStatus = Delegate::USER_DISABLED;
}
m_root->catalogRefreshStatus(this, effectiveStatus);
}
void Catalog::processAlternate(SGPropertyNode_ptr alt)
{
std::string altId;
@ -620,19 +619,19 @@ void Catalog::processAlternate(SGPropertyNode_ptr alt)
if (idPtr) {
altId = std::string(idPtr);
}
std::string altUrl;
if (alt->getStringValue("url")) {
altUrl = std::string(alt->getStringValue("url"));
}
CatalogRef existing;
if (!altId.empty()) {
existing = root()->getCatalogById(altId);
} else {
existing = root()->getCatalogByUrl(altUrl);
}
if (existing && (existing != this)) {
// we already have the alternate, so just go quiet here
changeStatus(Delegate::FAIL_VERSION);
@ -650,13 +649,13 @@ void Catalog::processAlternate(SGPropertyNode_ptr alt)
changeStatus(Delegate::FAIL_VERSION);
return;
}
SG_LOG(SG_GENERAL, SG_INFO, "Migrating catalog " << id() << " to new URL:" << altUrl);
setUrl(altUrl);
Downloader* dl = new Downloader(this, altUrl);
root()->makeHTTPRequest(dl);
}
} // of namespace pkg
} // of namespace simgear

View File

@ -20,7 +20,6 @@
#include <simgear/package/Package.hxx>
#include <cassert>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <simgear/debug/logstream.hxx>
@ -144,19 +143,19 @@ bool Package::matches(const SGPropertyNode* aFilter) const
return false;
}
bool Package::matchesDescription(const std::string &search) const
{
std::string n(search);
boost::to_lower(n);
bool localized;
auto d = getLocalisedString(m_props, "description", &localized);
boost::to_lower(d);
if (d.find(n) != std::string::npos) {
return true;
}
// try non-localized description too, if the abovce was a localized one
if (localized) {
const std::string baseDesc = m_props->getStringValue("description");
@ -165,7 +164,7 @@ bool Package::matchesDescription(const std::string &search) const
return true;
}
}
// try each variant's description
for (auto var : m_props->getChildren("variant")) {
auto vd = getLocalisedString(var, "description", &localized);
@ -175,7 +174,7 @@ bool Package::matchesDescription(const std::string &search) const
return true;
}
}
if (localized) {
// try non-localized variant description
std::string vd = var->getStringValue("description");
@ -185,7 +184,7 @@ bool Package::matchesDescription(const std::string &search) const
}
}
} // of variant iteration
return false;
}
@ -298,7 +297,7 @@ string_set Package::tags() const
{
return m_tags;
}
bool Package::hasTag(const std::string& tag) const
{
return m_tags.find(tag) != m_tags.end();
@ -344,11 +343,11 @@ std::string Package::getLocalisedString(const SGPropertyNode* aRoot, const char*
// we now check first in /sim/localized/<locale>/name first
const auto& locale = m_catalog->root()->getLocale();
if (isLocalized) *isLocalized = false;
if (locale.empty()) {
return aRoot->getStringValue(aName);
}
const SGPropertyNode* localeRoot;
if (aRoot->hasChild("localized")) {
localeRoot = aRoot->getChild("localized")->getChild(locale);
@ -369,7 +368,7 @@ PackageList Package::dependencies() const
{
PackageList result;
BOOST_FOREACH(SGPropertyNode* dep, m_props->getChildren("depends")) {
for (auto dep : m_props->getChildren("depends")) {
std::string depName = dep->getStringValue("id");
unsigned int rev = dep->getIntValue("revision", 0);
@ -410,7 +409,7 @@ std::string Package::nameForVariant(const std::string& vid) const
return name();
}
BOOST_FOREACH(SGPropertyNode* var, m_props->getChildren("variant")) {
for (auto var : m_props->getChildren("variant")) {
if (vid == var->getStringValue("id")) {
return var->getStringValue("name");
}
@ -546,19 +545,19 @@ bool Package::validate() const
{
if (m_id.empty())
return false;
std::string nm(m_props->getStringValue("name"));
if (nm.empty())
return false;
std::string dir(m_props->getStringValue("dir"));
if (dir.empty())
return false;
return true;
}
} // of namespace pkg
} // of namespace simgear

View File

@ -19,7 +19,6 @@
#include <simgear/package/Root.hxx>
#include <boost/foreach.hpp>
#include <cstring>
#include <map>
#include <deque>
@ -50,7 +49,7 @@ namespace {
return strutils::encodeHex(sha1_result(&info), HASH_LENGTH);
}
} // of anonymous namespace
namespace pkg {
typedef std::map<std::string, CatalogRef> CatalogDict;
@ -70,7 +69,7 @@ public:
m_realUrl = aUrl;
}
}
std::string realUrl() const
{
return m_realUrl;
@ -105,7 +104,7 @@ public:
d->installStatusChanged(install, status);
}
}
void fireStartInstall(InstallRef install)
{
for (auto d : delegates) {
@ -151,7 +150,7 @@ public:
std::string u = dl->realUrl();
if (status == Delegate::STATUS_SUCCESS) {
thumbnailCache[u].requestPending = false;
// if this was a network load, rather than a re-load from the disk cache,
// then persist to disk now.
if (strutils::starts_with(request->url(), "http")) {
@ -201,7 +200,7 @@ public:
std::string u = pendingThumbnails.front();
pendingThumbnails.pop_front();
thumbnailDownloadRequest = new Root::ThumbnailDownloader(this, u);
if (http) {
@ -217,7 +216,7 @@ public:
d->finishUninstall(pkg);
}
}
SGPath pathInCache(const std::string& url) const
{
const auto hash = hashForUrl(url);
@ -226,7 +225,7 @@ public:
if (pos == std::string::npos) {
return SGPath();
}
return path / "ThumbnailCache" / (hash + url.substr(pos));
}
@ -243,14 +242,14 @@ public:
assert(it != thumbnailCache.end());
it->second.pathOnDisk = cachePath;
}
bool checkPersistentCache(const std::string& url)
{
SGPath cachePath = pathInCache(url);
if (!cachePath.exists()) {
return false;
}
// check age, if it's too old, expire and download again
int age = time(nullptr) - cachePath.modTime();
const int cacheMaxAge = SECONDS_PER_DAY * 7;
@ -259,15 +258,15 @@ public:
// cache refresh might fail
return false;
}
loadFromPersistentCache(url, cachePath);
return true;
}
void loadFromPersistentCache(const std::string& url, const SGPath& path)
{
assert(path.exists());
auto it = thumbnailCache.find(url);
if (it == thumbnailCache.end()) {
ThumbnailCacheEntry entry;
@ -276,12 +275,12 @@ public:
} else {
assert(it->second.pathOnDisk.isNull() || (it->second.pathOnDisk == path));
}
sg_ifstream thumbnailStream(path, std::ios::in | std::ios::binary);
string bytes = thumbnailStream.read_all();
fireDataForThumbnail(url, reinterpret_cast<const uint8_t*>(bytes.data()), bytes.size());
}
DelegateVec delegates;
SGPath path;
@ -299,14 +298,14 @@ public:
HTTP::Request_ptr thumbnailDownloadRequest;
StringDeque pendingThumbnails;
struct ThumbnailCacheEntry
{
int retryCount = 0;
bool requestPending = false;
SGPath pathOnDisk;
};
std::map<std::string, ThumbnailCacheEntry> thumbnailCache;
typedef std::map<PackageRef, InstallRef> InstallCache;
@ -320,7 +319,7 @@ void Root::ThumbnailDownloader::onDone()
m_owner->thumbnailDownloadComplete(this, Delegate::STATUS_SUCCESS, m_buffer);
return;
}
if (responseCode() != 200) {
auto status = (responseCode() == 403) ? Delegate::FAIL_HTTP_FORBIDDEN : Delegate::FAIL_DOWNLOAD;
SG_LOG(SG_NETWORK, SG_INFO, "thumbnail download failure: " << url() << " with reason " << responseCode());
@ -349,7 +348,7 @@ unsigned int Root::maxAgeSeconds() const
void Root::setHTTPClient(HTTP::Client* aHTTP)
{
d->http = aHTTP;
BOOST_FOREACH(HTTP::Request_ptr req, d->httpPendingRequests) {
for (auto req : d->httpPendingRequests) {
d->http->makeRequest(req);
}
@ -398,7 +397,7 @@ Root::Root(const SGPath& aPath, const std::string& aVersion) :
if (!thumbsCacheDir.exists()) {
thumbsCacheDir.create(0755);
}
for (SGPath c : dir.children(Dir::TYPE_DIR | Dir::NO_DOT_OR_DOTDOT)) {
// note this will set the catalog status, which will insert into
// disabled catalogs automatically if necesary
@ -449,10 +448,10 @@ CatalogRef Root::getCatalogByUrl(const std::string& aUrl) const
{ return (v.second->url() == aUrl); });
if (it == d->catalogs.end())
return {};
return it->second;
}
PackageRef Root::getPackageById(const std::string& aName) const
{
size_t lastDot = aName.rfind('.');
@ -491,7 +490,7 @@ CatalogList Root::catalogs() const
return r;
}
CatalogList Root::allCatalogs() const
{
CatalogList r = catalogs();
@ -597,7 +596,7 @@ void Root::scheduleToUpdate(InstallRef aInstall)
if (!aInstall) {
throw sg_exception("missing argument to scheduleToUpdate");
}
auto it = std::find(d->updateDeque.begin(), d->updateDeque.end(), aInstall);
if (it != d->updateDeque.end()) {
// already scheduled to update
@ -724,17 +723,17 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason)
d->firePackagesChanged();
}
}
bool Root::removeCatalog(CatalogRef cat)
{
if (!cat)
return false;
// normal remove path
if (!cat->id().empty()) {
return removeCatalogById(cat->id());
}
if (!cat->removeDirectory()) {
SG_LOG(SG_GENERAL, SG_WARN, "removeCatalog: failed to remove directory " << cat->installRoot());
}
@ -744,10 +743,10 @@ bool Root::removeCatalog(CatalogRef cat)
if (it != d->disabledCatalogs.end()) {
d->disabledCatalogs.erase(it);
}
// notify that a catalog is being removed
d->firePackagesChanged();
return true;
}

View File

@ -24,7 +24,6 @@
#include <simgear/package/Root.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <boost/foreach.hpp>
#include <iostream>
#include <cstring>
@ -98,7 +97,7 @@ void printPackageInfo(pkg::Package* pkg)
if (pkg->properties()->hasChild("author")) {
cout << "Authors:" << endl;
BOOST_FOREACH(SGPropertyNode* author, pkg->properties()->getChildren("author")) {
for (auto author : pkg->properties()->getChildren("author")) {
if (author->hasChild("name")) {
cout << "\t" << author->getStringValue("name") << endl;
@ -174,7 +173,7 @@ int main(int argc, char** argv)
pkg->install()->uninstall();
} else if (!strcmp(argv[1], "update-all")) {
pkg::PackageList updates = root->packagesNeedingUpdate();
BOOST_FOREACH(pkg::Package* p, updates) {
for (auto p : updates) {
root->scheduleToUpdate(p->install());
}
} else if (!strcmp(argv[1], "list-updated")) {
@ -185,7 +184,7 @@ int main(int argc, char** argv)
}
cout << updates.size() << " packages have updates" << endl;
BOOST_FOREACH(pkg::Package* p, updates) {
for (auto p : updates) {
cout << "\t" << p->id() << " " << p->getLocalisedProp("name") << endl;
}
} else if (!strcmp(argv[1], "info")) {

View File

@ -21,8 +21,6 @@
#include "PropertyBasedMgr.hxx"
#include <boost/foreach.hpp>
#include <stdexcept>
#include <string>
@ -78,7 +76,7 @@ namespace simgear
if( name.empty() )
return PropertyBasedElementPtr();
BOOST_FOREACH(PropertyBasedElementPtr el, _elements)
for (auto el : _elements)
if( el && el->getProps()->getStringValue("name") == name )
return el;

View File

@ -22,8 +22,6 @@
#include <fstream>
#include <limits>
#include <boost/foreach.hpp>
#include <cpl_conv.h> // for CPLMalloc()
#include "ogr_spatialref.h"
@ -96,7 +94,7 @@ int SGDem::addRoot( const SGPath& root )
std::istringstream iss( p.file() );
getline(iss, prefix, '_');
if ( ((iss.rdstate() & std::ifstream::failbit ) == 0 ) &&
if ( ((iss.rdstate() & std::ifstream::failbit ) == 0 ) &&
(prefix == "level" ) ) {
iss >> level;
@ -234,7 +232,7 @@ SGDemSession SGDem::openSession( const SGGeod& min, const SGGeod& max, const SGP
int max_lat = (int)(ceil(max.getLatitudeDeg()+FP_ROUNDOFF_OUTSIDE));
// Create the session
SG_LOG( SG_TERRAIN, SG_INFO, "SGDem::OpenSession - create sesion obj - req from " <<
SG_LOG( SG_TERRAIN, SG_INFO, "SGDem::OpenSession - create sesion obj - req from " <<
min.getLongitudeDeg() << ", " << min.getLatitudeDeg() << " to " <<
max.getLongitudeDeg() << ", " << max.getLatitudeDeg() << " - getting " <<
min_lon << ", " << min_lat << " to " << max_lon << ", " << max_lat );
@ -251,7 +249,7 @@ SGDemSession SGDem::openSession( const SGGeod& min, const SGGeod& max, const SGP
SG_LOG( SG_TERRAIN, SG_INFO, "SGDem::OpenSession - Traverse tiles");
for (int lon = min_lon; lon < max_lon; lon += w) {
for (int lat = min_lat; lat < max_lat; lat += h) {
SG_LOG( SG_TERRAIN, SG_INFO, "SGDem::OpenSession - Create tile " <<
SG_LOG( SG_TERRAIN, SG_INFO, "SGDem::OpenSession - Create tile " <<
lon << ", " << lat << " from dir " << input );
unsigned wo = (lon+180)*8;
@ -291,7 +289,7 @@ unsigned short SGDem::getAlt( const SGDemSession& s, const SGGeod& loc ) const
int lvlIndex = s.getLvlIndex();
if ( lvlIndex >= 0 ) {
// be careful with coordinates that lie on session boundaries -
// be careful with coordinates that lie on session boundaries -
// on min, ok.
// on max - make sure we select the tile in the session...
int lvlWidth = levels[lvlIndex].getWidth();

View File

@ -8,7 +8,7 @@
* Author: Frank Warmerdam <warmerdam@pobox.com>
*
******************************************************************************
* Copyright (c) 2002, i3 - information integration and imaging
* Copyright (c) 2002, i3 - information integration and imaging
* Fort Collin, CO
* Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org>
*
@ -34,8 +34,6 @@
#include <iomanip>
#include <fstream>
#include <boost/foreach.hpp>
#include <cpl_conv.h> // for CPLMalloc()
#include "ogr_spatialref.h"
@ -163,14 +161,14 @@ GDALDatasetH SGDemTile::createTile( char **papszSrcFiles, const char *pszFilenam
{
const char *pszMethod = CSLFetchNameValue( papszTO, "METHOD" );
if( GDALGetProjectionRef( hSrcDS ) != NULL
if( GDALGetProjectionRef( hSrcDS ) != NULL
&& strlen(GDALGetProjectionRef( hSrcDS )) > 0
&& (pszMethod == NULL || EQUAL(pszMethod,"GEOTRANSFORM")) ) {
pszThisSourceSRS = GDALGetProjectionRef( hSrcDS );
} else if( GDALGetGCPProjection( hSrcDS ) != NULL
&& strlen(GDALGetGCPProjection(hSrcDS)) > 0
&& GDALGetGCPCount( hSrcDS ) > 1
&& strlen(GDALGetGCPProjection(hSrcDS)) > 0
&& GDALGetGCPCount( hSrcDS ) > 1
&& (pszMethod == NULL || EQUALN(pszMethod,"GCP_",4)) ) {
pszThisSourceSRS = GDALGetGCPProjection( hSrcDS );
} else if( pszMethod != NULL && EQUAL(pszMethod,"RPC") ) {
@ -229,7 +227,7 @@ GDALDatasetH SGDemTile::createTile( char **papszSrcFiles, const char *pszFilenam
nPixels = nForcePixels;
nLines = nForceLines;
}
else
else
{
fprintf(stderr, "UHOH - need force pixels/lines\n");
}
@ -238,7 +236,7 @@ GDALDatasetH SGDemTile::createTile( char **papszSrcFiles, const char *pszFilenam
/* Create the output file. */
/* -------------------------------------------------------------------- */
char** papszCreateOptions = CSLAddString( NULL, "COMPRESS=DEFLATE" );
hDstDS = GDALCreate( hDriver, pszFilename, nPixels, nLines,
hDstDS = GDALCreate( hDriver, pszFilename, nPixels, nLines,
nDstBandCount, eDT, papszCreateOptions );
CSLDestroy( papszCreateOptions );
@ -361,17 +359,17 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
CSLDestroy(papszMetadataNew);
/* copy band-level metadata and other info */
if ( GDALGetRasterCount( hSrcDS ) == GDALGetRasterCount( hDstDS ) )
if ( GDALGetRasterCount( hSrcDS ) == GDALGetRasterCount( hDstDS ) )
{
for ( int iBand = 0; iBand < GDALGetRasterCount( hSrcDS ); iBand++ )
{
hSrcBand = GDALGetRasterBand( hSrcDS, iBand + 1 );
hDstBand = GDALGetRasterBand( hDstDS, iBand + 1 );
/* copy metadata, except stats (#5319) */
papszMetadata = GDALGetMetadata( hSrcBand, NULL);
papszMetadata = GDALGetMetadata( hSrcBand, NULL);
if ( CSLCount(papszMetadata) > 0 )
{
//GDALSetMetadata( hDstBand, papszMetadata, NULL );
//GDALSetMetadata( hDstBand, papszMetadata, NULL );
char** papszMetadataNew = NULL;
for( int i = 0; papszMetadata != NULL && papszMetadata[i] != NULL; i++ )
{
@ -385,23 +383,23 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
if ( bCopyBandInfo ) {
pszSrcInfo = GDALGetDescription( hSrcBand );
if( pszSrcInfo != NULL && strlen(pszSrcInfo) > 0 )
GDALSetDescription( hDstBand, pszSrcInfo );
GDALSetDescription( hDstBand, pszSrcInfo );
pszSrcInfo = GDALGetRasterUnitType( hSrcBand );
if( pszSrcInfo != NULL && strlen(pszSrcInfo) > 0 )
GDALSetRasterUnitType( hDstBand, pszSrcInfo );
GDALSetRasterUnitType( hDstBand, pszSrcInfo );
}
}
}
}
/* remove metadata that conflicts between datasets */
else
else
{
CPLDebug("WARP", "Removing conflicting metadata from destination dataset (source #%d)", iSrc );
/* remove conflicting dataset-level metadata */
RemoveConflictingMetadata( hDstDS, GDALGetMetadata( hSrcDS, NULL ), pszMDConflictValue );
/* remove conflicting copy band-level metadata and other info */
if ( GDALGetRasterCount( hSrcDS ) == GDALGetRasterCount( hDstDS ) )
if ( GDALGetRasterCount( hSrcDS ) == GDALGetRasterCount( hDstDS ) )
{
for ( int iBand = 0; iBand < GDALGetRasterCount( hSrcDS ); iBand++ )
{
@ -416,13 +414,13 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
if( ! ( pszSrcInfo != NULL && strlen(pszSrcInfo) > 0 &&
pszDstInfo != NULL && strlen(pszDstInfo) > 0 &&
EQUAL( pszSrcInfo, pszDstInfo ) ) )
GDALSetDescription( hDstBand, "" );
GDALSetDescription( hDstBand, "" );
pszSrcInfo = GDALGetRasterUnitType( hSrcBand );
pszDstInfo = GDALGetRasterUnitType( hDstBand );
if( ! ( pszSrcInfo != NULL && strlen(pszSrcInfo) > 0 &&
pszDstInfo != NULL && strlen(pszDstInfo) > 0 &&
EQUAL( pszSrcInfo, pszDstInfo ) ) )
GDALSetRasterUnitType( hDstBand, "" );
GDALSetRasterUnitType( hDstBand, "" );
}
}
}
@ -465,7 +463,7 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
/* -------------------------------------------------------------------- */
/* Warp the transformer with a linear approximator */
/* -------------------------------------------------------------------- */
hTransformArg = GDALCreateApproxTransformer( GDALGenImgProjTransform,
hTransformArg = GDALCreateApproxTransformer( GDALGenImgProjTransform,
hTransformArg, dfErrorThreshold);
pfnTransformer = GDALApproxTransform;
GDALApproxTransformerOwnsSubtransformer(hTransformArg, TRUE);
@ -474,7 +472,7 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
/* Clear temporary INIT_DEST settings after the first image. */
/* -------------------------------------------------------------------- */
if( iSrc == 1 )
papszWarpOptions = CSLSetNameValue( papszWarpOptions,
papszWarpOptions = CSLSetNameValue( papszWarpOptions,
"INIT_DEST", NULL );
/* -------------------------------------------------------------------- */
@ -518,13 +516,13 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
if( bEnableSrcAlpha )
psWO->nSrcAlphaBand = GDALGetRasterCount(hSrcDS);
if( !bEnableDstAlpha
&& GDALGetRasterCount(hDstDS) == psWO->nBandCount+1
&& GDALGetRasterColorInterpretation(
GDALGetRasterBand(hDstDS,GDALGetRasterCount(hDstDS)))
if( !bEnableDstAlpha
&& GDALGetRasterCount(hDstDS) == psWO->nBandCount+1
&& GDALGetRasterColorInterpretation(
GDALGetRasterBand(hDstDS,GDALGetRasterCount(hDstDS)))
== GCI_AlphaBand )
{
printf( "Using band %d of destination image as alpha.\n",
printf( "Using band %d of destination image as alpha.\n",
GDALGetRasterCount(hDstDS) );
bEnableDstAlpha = TRUE;
@ -551,9 +549,9 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
printf( "Using internal nodata values (e.g. %g) for image %s.\n",
dfReal, pszSrcFile );
psWO->padfSrcNoDataReal = (double *)
psWO->padfSrcNoDataReal = (double *)
CPLMalloc(psWO->nBandCount*sizeof(double));
psWO->padfSrcNoDataImag = (double *)
psWO->padfSrcNoDataImag = (double *)
CPLMalloc(psWO->nBandCount*sizeof(double));
for( int i = 0; i < psWO->nBandCount; i++ )
@ -578,9 +576,9 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
/* else try to fill dstNoData from source bands */
if ( psWO->padfSrcNoDataReal != NULL )
{
psWO->padfDstNoDataReal = (double *)
psWO->padfDstNoDataReal = (double *)
CPLMalloc(psWO->nBandCount*sizeof(double));
psWO->padfDstNoDataImag = (double *)
psWO->padfDstNoDataImag = (double *)
CPLMalloc(psWO->nBandCount*sizeof(double));
printf( "Copying nodata values from source %s \n", pszSrcFile );
@ -597,13 +595,13 @@ void SGDemTile::doWarp( int iSrc, char* pszSrcFile, GDALDatasetH hDstDS, char**
{
psWO->padfDstNoDataReal[i] = psWO->padfSrcNoDataReal[i];
psWO->padfDstNoDataImag[i] = psWO->padfSrcNoDataImag[i];
CPLDebug("WARP", "srcNoData=%f dstNoData=%f",
CPLDebug("WARP", "srcNoData=%f dstNoData=%f",
psWO->padfSrcNoDataReal[i], psWO->padfDstNoDataReal[i] );
}
CPLDebug("WARP", "calling GDALSetRasterNoDataValue() for band#%d", i );
GDALSetRasterNoDataValue(
GDALGetRasterBand( hDstDS, psWO->panDstBands[i] ),
GDALSetRasterNoDataValue(
GDALGetRasterBand( hDstDS, psWO->panDstBands[i] ),
psWO->padfDstNoDataReal[i] );
}
}

View File

@ -36,7 +36,6 @@
#include <mutex>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/functional/hash.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
@ -106,7 +105,7 @@ bool loadShaderFromUTF8File(osg::Shader* shader, const std::string& fileName)
sg_ifstream inStream(SGPath::fromUtf8(fileName), std::ios::in | std::ios::binary);
if (!inStream.is_open())
return false;
shader->setShaderSource(inStream.read_all());
return true;
}
@ -261,8 +260,7 @@ int Effect::getGenerator(Effect::Generator what) const
Technique* Effect::chooseTechnique(RenderInfo* info, const std::string &scheme)
{
BOOST_FOREACH(ref_ptr<Technique>& technique, techniques)
{
for (auto& technique : techniques) {
if (technique->valid(info) == Technique::VALID &&
technique->getScheme() == scheme)
return technique.get();
@ -272,16 +270,14 @@ Technique* Effect::chooseTechnique(RenderInfo* info, const std::string &scheme)
void Effect::resizeGLObjectBuffers(unsigned int maxSize)
{
BOOST_FOREACH(const ref_ptr<Technique>& technique, techniques)
{
for (const auto& technique : techniques) {
technique->resizeGLObjectBuffers(maxSize);
}
}
void Effect::releaseGLObjects(osg::State* state) const
{
BOOST_FOREACH(const ref_ptr<Technique>& technique, techniques)
{
for (const auto& technique : techniques) {
technique->releaseGLObjects(state);
}
}
@ -929,8 +925,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
// resolvedProgramMap for a program using those shaders.
ProgramKey resolvedKey;
resolvedKey.attributes = prgKey.attributes;
BOOST_FOREACH(const ShaderKey& shaderKey, prgKey.shaders)
{
for (const auto& shaderKey : prgKey.shaders) {
// FIXME orig: const string& shaderName = shaderKey.first;
string shaderName = shaderKey.first;
Shader::Type stype = (Shader::Type)shaderKey.second;
@ -957,8 +952,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
return;
}
program = new Program;
BOOST_FOREACH(const ShaderKey& skey, resolvedKey.shaders)
{
for (const auto& skey : resolvedKey.shaders) {
const string& fileName = skey.first;
Shader::Type stype = (Shader::Type)skey.second;
ShaderMap::iterator sitr = shaderMap.find(skey);
@ -973,7 +967,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
}
}
}
BOOST_FOREACH(const ProgramKey::AttribKey& key, prgKey.attributes) {
for (const auto& key : prgKey.attributes) {
program->addBindAttribLocation(key.first, key.second);
}
const SGPropertyNode* pGeometryVerticesOut
@ -1551,7 +1545,7 @@ bool Effect_writeLocalData(const Object& obj, osgDB::Output& fw)
const Effect& effect = static_cast<const Effect&>(obj);
fw.indent() << "techniques " << effect.techniques.size() << "\n";
BOOST_FOREACH(const ref_ptr<Technique>& technique, effect.techniques) {
for (const auto& technique : effect.techniques) {
fw.writeObject(*technique);
}
return true;

View File

@ -7,8 +7,6 @@
#include "Pass.hxx"
#include "EffectCullVisitor.hxx"
#include <boost/foreach.hpp>
#include <iterator>
#include <vector>
#include <string>
@ -177,8 +175,7 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin,
}
EffectCullVisitor* ecv = dynamic_cast<EffectCullVisitor*>( cv );
EffectGeode::DrawablesIterator drawablesEnd = itr;
BOOST_FOREACH(ref_ptr<Pass>& pass, passes)
{
for (auto& pass : passes) {
osg::ref_ptr<osg::StateSet> ss = pass;
if (ecv && ( ! pass->getBufferUnitList().empty() || ! pass->getPositionedUniformMap().empty() ) ) {
ss = static_cast<osg::StateSet*>(
@ -220,7 +217,7 @@ void Technique::resizeGLObjectBuffers(unsigned int maxSize)
{
if (_shadowingStateSet.valid())
_shadowingStateSet->resizeGLObjectBuffers(maxSize);
BOOST_FOREACH(ref_ptr<Pass>& pass, passes) {
for (auto& pass : passes) {
pass->resizeGLObjectBuffers(maxSize);
}
_contextMap.resize(maxSize);
@ -230,8 +227,7 @@ void Technique::releaseGLObjects(osg::State* state) const
{
if (_shadowingStateSet.valid())
_shadowingStateSet->releaseGLObjects(state);
BOOST_FOREACH(const ref_ptr<Pass>& pass, passes)
{
for (const auto& pass : passes) {
pass->releaseGLObjects(state);
}
if (state == 0) {
@ -384,7 +380,7 @@ Expression* glslSupportedParser(const SGPropertyNode* exp,
expression::ExpParserRegistrar glslSupportedRegistrar("glsl-supported",
glslSupportedParser);
void Technique::setGLExtensionsPred(float glVersion,
const std::vector<std::string>& extensions)
{
@ -444,7 +440,7 @@ bool Technique_writeLocalData(const Object& obj, osgDB::Output& fw)
fw.writeObject(*tniq.getShadowingStateSet());
}
fw.indent() << "num_passes " << tniq.passes.size() << "\n";
BOOST_FOREACH(const ref_ptr<Pass>& pass, tniq.passes) {
for (const auto& pass : tniq.passes) {
fw.writeObject(*pass);
}
return true;

View File

@ -33,7 +33,6 @@
#include <string>
#include <mutex>
#include <boost/foreach.hpp>
#include "mat.hxx"
#include <osg/CullFace>
@ -520,8 +519,7 @@ void SGMaterial::buildEffectProperties(const SGReaderWriterOptions* options)
makeChild(binProp, "bin-number")->setIntValue(TRANSPARENT_BIN);
makeChild(binProp, "bin-name")->setStringValue("DepthSortedBin");
}
BOOST_FOREACH(_internal_state& matState, _status)
{
for (auto& matState : _status) {
SGPropertyNode_ptr effectProp = new SGPropertyNode();
copyProperties(propRoot, effectProp);
SGPropertyNode* effectParamProp = effectProp->getChild("parameters", 0);

View File

@ -34,7 +34,6 @@
#include <simgear/scene/util/OsgMath.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <boost/scoped_array.hpp>
#include <boost/foreach.hpp>
typedef std::map<std::string, osg::observer_ptr<simgear::Effect> > EffectMap;
static EffectMap lightEffectMap;
@ -68,8 +67,8 @@ public:
params->getNode("ambient")->setValue(_ambient * dim);
params->getNode("diffuse")->setValue(_diffuse * dim);
params->getNode("specular")->setValue(_specular * dim);
BOOST_FOREACH(osg::ref_ptr<simgear::Technique> & technique, effect->techniques) {
BOOST_FOREACH(osg::ref_ptr<simgear::Pass> & pass, technique->passes) {
for (auto& technique : effect->techniques) {
for (auto& pass : technique->passes) {
osg::Uniform* amb = pass->getUniform("Ambient");
if (amb)
amb->set(osg::Vec4f(_ambient.x() * dim, _ambient.y() * dim, _ambient.z() * dim, _ambient.w() * dim));

View File

@ -9,8 +9,6 @@
#include <utility>
#include <boost/foreach.hpp>
#include <osg/ref_ptr>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
@ -349,7 +347,7 @@ ref_ptr<Node> instantiateEffects(osg::Node* modelGroup,
SGPropertyNode* defaultNode = configNode->getChild("default");
if (defaultNode && defaultNode->getValue<bool>())
defaultEffectPropRoot = configNode;
BOOST_FOREACH(SGPropertyNode_ptr objNameNode, objectNames) {
for (auto objNameNode : objectNames) {
emap.insert(make_pair(objNameNode->getStringValue(), configNode));
}
configNode->removeChild("default");

View File

@ -29,7 +29,6 @@
#include <map>
#include <math.h>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <osg/Geode>

View File

@ -25,7 +25,6 @@
#endif
#include <vector>
#include <boost/foreach.hpp>
#include <osg/Geode>
#include <osg/Geometry>
@ -101,19 +100,19 @@ struct GlyphGeometry
osg::Vec2Array* uvs;
osg::Vec3Array* vertices;
osg::Vec3Array* normals;
void addGlyph(SGMaterialGlyph* glyph, double x, double y, double width, double height, const osg::Matrix& xform)
{
vertices->push_back(xform.preMult(osg::Vec3(thick, x, y)));
vertices->push_back(xform.preMult(osg::Vec3(thick, x + width, y)));
vertices->push_back(xform.preMult(osg::Vec3(thick, x + width, y + height)));
vertices->push_back(xform.preMult(osg::Vec3(thick, x, y + height)));
// texture coordinates
double xoffset = glyph->get_left();
double texWidth = glyph->get_width();
uvs->push_back(osg::Vec2(xoffset, 0));
uvs->push_back(osg::Vec2(xoffset + texWidth, 0));
uvs->push_back(osg::Vec2(xoffset + texWidth, 1));
@ -122,10 +121,10 @@ struct GlyphGeometry
// normals
for (int i=0; i<4; ++i)
normals->push_back(xform.preMult(osg::Vec3(0, -1, 0)));
quads->setCount(vertices->size());
}
void addSignCase(double caseWidth, double caseHeight, const osg::Matrix& xform)
{
int last = vertices->size();
@ -141,7 +140,7 @@ struct GlyphGeometry
uvs->push_back(osg::Vec2(0.75, 1));
uvs->push_back(osg::Vec2(0.75, 0));
uvs->push_back(osg::Vec2(1, 0));
for (int i=0; i<4; ++i)
normals->push_back(osg::Vec3(-1, 0.0, 0));
@ -150,7 +149,7 @@ struct GlyphGeometry
vertices->push_back(osg::Vec3(thick, -caseWidth, grounddist + caseHeight));
vertices->push_back(osg::Vec3(thick, caseWidth, grounddist + caseHeight));
vertices->push_back(osg::Vec3(-thick, caseWidth, grounddist + caseHeight));
uvs->push_back(osg::Vec2(1, texsize));
uvs->push_back(osg::Vec2(0.75, texsize));
uvs->push_back(osg::Vec2(0.75, 0));
@ -179,7 +178,7 @@ struct GlyphGeometry
(*vertices)[i]= xform.preMult((*vertices)[i]);
(*normals)[i] = xform.preMult((*normals)[i]);
}
quads->setCount(vertices->size());
}
};
@ -189,17 +188,17 @@ typedef std::map<Effect*, GlyphGeometry*> EffectGeometryMap;
GlyphGeometry* makeGeometry(Effect* eff, osg::Group* group)
{
GlyphGeometry* gg = new GlyphGeometry;
EffectGeode* geode = new EffectGeode;
geode->setEffect(eff);
gg->vertices = new osg::Vec3Array;
gg->normals = new osg::Vec3Array;
gg->uvs = new osg::Vec2Array;
osg::Vec4Array* cl = new osg::Vec4Array;
cl->push_back(osg::Vec4(1, 1, 1, 1));
osg::Geometry* geometry = new osg::Geometry;
geometry->setVertexArray(gg->vertices);
geometry->setNormalArray(gg->normals);
@ -207,7 +206,7 @@ GlyphGeometry* makeGeometry(Effect* eff, osg::Group* group)
geometry->setColorArray(cl);
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
geometry->setTexCoordArray(0, gg->uvs);
gg->quads = new osg::DrawArrays(GL_QUADS, 0, gg->vertices->size());
geometry->addPrimitiveSet(gg->quads);
geode->addDrawable(geometry);
@ -227,29 +226,29 @@ public:
EffectGeometryMap geometries;
osg::MatrixTransform* signsGroup;
GlyphGeometry* signCaseGeometry;
GlyphGeometry* getGeometry(Effect* eff)
{
EffectGeometryMap::iterator it = geometries.find(eff);
if (it != geometries.end()) {
return it->second;
}
GlyphGeometry* gg = makeGeometry(eff, signsGroup);
geometries[eff] = gg;
return gg;
}
void makeFace(const ElementVec& elements, double hpos, const osg::Matrix& xform)
{
BOOST_FOREACH(element_info* element, elements) {
for (auto element : elements) {
GlyphGeometry* gg = getGeometry(element->material->get_effect());
gg->addGlyph(element->glyph, hpos, grounddist, element->abswidth, element->height, xform);
hpos += element->abswidth;
delete element;
}
}
};
AirportSignBuilder::AirportSignBuilder(SGMaterialLib* mats, const SGGeod& center) :
@ -257,7 +256,7 @@ AirportSignBuilder::AirportSignBuilder(SGMaterialLib* mats, const SGGeod& center
{
d->signsGroup = new osg::MatrixTransform;
d->signsGroup->setMatrix(makeZUpFrame(center));
assert(mats);
d->materials = mats;
d->signCaseGeometry = d->getGeometry(d->materials->find("signcase", center)->get_effect());
@ -505,12 +504,12 @@ void AirportSignBuilder::addSign(const SGGeod& pos, double heading, const std::s
double boxwidth = std::max(total_width1, total_width2) * 0.5;
double hpos = -boxwidth;
SGMaterial *mat = d->materials->find("signcase", pos);
double coverSize = fabs(total_width1 - total_width2) * 0.5;
element_info* s1 = new element_info(mat, mat->get_glyph("cover1"), sign_height, coverSize);
element_info* s2 = new element_info(mat, mat->get_glyph("cover2"), sign_height, coverSize);
if (total_width1 < total_width2) {
if (total_width1 < total_width2) {
elements1.insert(elements1.begin(), s1);
elements1.push_back(s2);
} else if (total_width2 < total_width1) {
@ -520,25 +519,24 @@ void AirportSignBuilder::addSign(const SGGeod& pos, double heading, const std::s
delete s1;
delete s2;
}
// position the sign
const osg::Vec3 Z_AXIS(0, 0, 1);
osg::Matrix m(makeZUpFrame(pos));
m.preMultRotate(osg::Quat(SGMiscd::deg2rad(heading), Z_AXIS));
// apply the inverse of the group transform, so sign vertices
// are relative to the tile center, and hence have a magnitude which
// fits in a float with sufficent precision.
m.postMult(d->signsGroup->getInverseMatrix());
d->makeFace(elements1, hpos, m);
// Create back side
osg::Matrix back(m);
back.preMultRotate(osg::Quat(M_PI, Z_AXIS));
d->makeFace(elements2, hpos, back);
d->signCaseGeometry->addSignCase(boxwidth, sign_height, m);
}
} // of namespace simgear

View File

@ -11,7 +11,6 @@
# include <simgear_config.h>
#endif
#include <boost/foreach.hpp>
#include <simgear/compiler.h>
#include "SGBinding.hxx"
@ -103,7 +102,7 @@ SGBinding::fire (SGPropertyNode* params) const
if (params != NULL) {
copyProperties(params, _arg);
}
innerFire();
}
}
@ -132,14 +131,14 @@ SGBinding::fire (double setting) const
void fireBindingList(const SGBindingList& aBindings, SGPropertyNode* params)
{
BOOST_FOREACH(SGBinding_ptr b, aBindings) {
for (auto b : aBindings) {
b->fire(params);
}
}
void fireBindingListWithOffset(const SGBindingList& aBindings, double offset, double max)
{
BOOST_FOREACH(SGBinding_ptr b, aBindings) {
for (auto b : aBindings) {
b->fire(offset, max);
}
}
@ -147,16 +146,16 @@ void fireBindingListWithOffset(const SGBindingList& aBindings, double offset, do
SGBindingList readBindingList(const simgear::PropertyList& aNodes, SGPropertyNode* aRoot)
{
SGBindingList result;
BOOST_FOREACH(SGPropertyNode* node, aNodes) {
for (auto node : aNodes) {
result.push_back(new SGBinding(node, aRoot));
}
return result;
}
void clearBindingList(const SGBindingList& aBindings)
{
BOOST_FOREACH(SGBinding_ptr b, aBindings) {
for (auto b : aBindings) {
b->clear();
}
}
@ -167,7 +166,7 @@ bool anyBindingEnabled(const SGBindingList& aBindings)
return false;
}
BOOST_FOREACH(SGBinding_ptr b, aBindings) {
for (auto b : aBindings) {
if (b->test()) {
return true;
}
@ -175,4 +174,3 @@ bool anyBindingEnabled(const SGBindingList& aBindings)
return false;
}