diff --git a/src/GUI/FGFontCache.cxx b/src/GUI/FGFontCache.cxx index 76d249a9c..cd73999e3 100755 --- a/src/GUI/FGFontCache.cxx +++ b/src/GUI/FGFontCache.cxx @@ -42,35 +42,22 @@ namespace { struct GuiFont { - const char* name; + const std::string name; puFont *font; - struct Predicate - : public std::unary_function - { - Predicate(const std::string& name_) : name(name_) {} - bool operator() (const GuiFont& f1) const - { - return (name == f1.name); - } - const std::string name; - }; }; -const GuiFont guifonts[] = { - { "default", &PUFONT_HELVETICA_12 }, - { "FIXED_8x13", &PUFONT_8_BY_13 }, - { "FIXED_9x15", &PUFONT_9_BY_15 }, - { "TIMES_10", &PUFONT_TIMES_ROMAN_10 }, - { "TIMES_24", &PUFONT_TIMES_ROMAN_24 }, - { "HELVETICA_10", &PUFONT_HELVETICA_10 }, - { "HELVETICA_12", &FONT_HELVETICA_12 }, - { "HELVETICA_14", &FONT_HELVETICA_14 }, - { "HELVETICA_18", &PUFONT_HELVETICA_18 }, - { "SANS_12B", &FONT_SANS_12B }, - { nullptr, nullptr } +const std::initializer_list guiFonts = { + {"default", &PUFONT_HELVETICA_12}, + {"FIXED_8x13", &PUFONT_8_BY_13}, + {"FIXED_9x15", &PUFONT_9_BY_15}, + {"TIMES_10", &PUFONT_TIMES_ROMAN_10}, + {"TIMES_24", &PUFONT_TIMES_ROMAN_24}, + {"HELVETICA_10", &PUFONT_HELVETICA_10}, + {"HELVETICA_12", &FONT_HELVETICA_12}, + {"HELVETICA_14", &FONT_HELVETICA_14}, + {"HELVETICA_18", &PUFONT_HELVETICA_18}, + {"SANS_12B", &FONT_SANS_12B}, }; - -const GuiFont* guifontsEnd = &guifonts[sizeof(guifonts)/ sizeof(guifonts[0])-1]; } FGFontCache* FGFontCache::instance() @@ -104,19 +91,18 @@ FGFontCache::~FGFontCache() } } -inline bool FGFontCache::FntParamsLess::operator()(const FntParams& f1, - const FntParams& f2) const +bool FGFontCache::FntParams::operator<(const FntParams& other) const { - int comp = f1.name.compare(f2.name); + int comp = name.compare(other.name); if (comp < 0) return true; else if (comp > 0) return false; - if (f1.size < f2.size) + if (size < other.size) return true; - else if (f1.size > f2.size) + else if (size > other.size) return false; - return f1.slant < f2.slant; + return slant < other.slant; } FGFontCache::FontCacheEntry* @@ -133,9 +119,12 @@ FGFontCache::getfnt(const std::string& fontName, float size, float slant) if (texi != _texFonts.end()) { texfont = texi->second; } else { - const GuiFont* guifont = std::find_if(&guifonts[0], guifontsEnd, - GuiFont::Predicate(fontName)); - if (guifont != guifontsEnd) { + auto guifont = std::find_if(guiFonts.begin(), guiFonts.end(), + [&fontName](const GuiFont& gf) { + return gf.name == fontName; + }); + + if (guifont != guiFonts.end()) { pufont = guifont->font; } } @@ -149,7 +138,7 @@ FGFontCache::getfnt(const std::string& fontName, float size, float slant) f->pufont = new puFont; f->pufont->initialize(static_cast(f->texfont), size, slant); } else { - f->pufont = guifonts[0].font; + f->pufont = guiFonts.begin()->font; } // insert into the cache diff --git a/src/GUI/FGFontCache.hxx b/src/GUI/FGFontCache.hxx index 57b438f05..c3fa2b7e3 100644 --- a/src/GUI/FGFontCache.hxx +++ b/src/GUI/FGFontCache.hxx @@ -48,11 +48,8 @@ private: : name(name_), size(size_), slant(slant_) { } - }; - struct FntParamsLess - : public std::binary_function - { - bool operator() (const FntParams& f1, const FntParams& f2) const; + + bool operator<(const FntParams& other) const; }; struct FontCacheEntry { @@ -71,7 +68,7 @@ private: SGPath _path; typedef std::map TexFontMap; - typedef std::map PuFontMap; + typedef std::map PuFontMap; TexFontMap _texFonts; PuFontMap _cache; diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 7589066b9..0f51d5886 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -284,7 +284,11 @@ public: simgear::requestConsole(); // ensure console is shown on Windows - std::sort(_aircraft.begin(), _aircraft.end(), ciLessLibC()); + std::sort(_aircraft.begin(), _aircraft.end(), + [](const std::string& lhs, const std::string& rhs) { + return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0; + }); + cout << "Available aircraft:" << endl; for ( unsigned int i = 0; i < _aircraft.size(); i++ ) { cout << _aircraft[i] << endl; @@ -353,16 +357,6 @@ private: return 0; } - // recommended in Meyers, Effective STL when internationalization and embedded - // NULLs aren't an issue. Much faster than the STL or Boost lex versions. - struct ciLessLibC : public std::binary_function - { - bool operator()(const std::string &lhs, const std::string &rhs) const - { - return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0; - } - }; - int _minStatus; string_list _aircraft; }; diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index ed3e2df49..14a9ad2c3 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -173,11 +173,11 @@ double testNan(double val) return val; } +} // namespace -struct UpdateFunctor : public std::unary_function +void FGModelMgr::update(double dt) { - void operator()(FGModelMgr::Instance* instance) const - { + std::for_each(_instances.begin(), _instances.end(), [](FGModelMgr::Instance* instance) { SGModelPlacement* model = instance->model; double roll, pitch, heading; roll = pitch = heading = 0.0; @@ -217,14 +217,7 @@ struct UpdateFunctor : public std::unary_function model->setHeadingDeg(heading); instance->model->update(); - } -}; -} - -void -FGModelMgr::update (double dt) -{ - std::for_each(_instances.begin(), _instances.end(), UpdateFunctor()); + }); } void diff --git a/src/Viewer/CameraGroup_legacy.cxx b/src/Viewer/CameraGroup_legacy.cxx index 6d7b09692..5b004dedf 100644 --- a/src/Viewer/CameraGroup_legacy.cxx +++ b/src/Viewer/CameraGroup_legacy.cxx @@ -1192,11 +1192,13 @@ void CameraGroup::resized() const CameraInfo* CameraGroup::getGUICamera() const { - ConstCameraIterator result - = std::find_if(camerasBegin(), camerasEnd(), - FlagTester(GUI)); + auto result = std::find_if(camerasBegin(), camerasEnd(), + [](const osg::ref_ptr& cam) { + return cam->flags & GUI; + }); + if (result == camerasEnd()) { - return NULL; + return nullptr; } return *result; diff --git a/src/Viewer/WindowSystemAdapter.hxx b/src/Viewer/WindowSystemAdapter.hxx index b57ea1771..460121672 100644 --- a/src/Viewer/WindowSystemAdapter.hxx +++ b/src/Viewer/WindowSystemAdapter.hxx @@ -130,28 +130,5 @@ protected: }; -/** - * Class for testing if flags are set in an object with a flags member. - */ -template -class FlagTester : public std::unary_function, bool> -{ -public: - /** Initialize with flags to test for. - * @param flags logical or of flags to test. - */ - FlagTester(unsigned flags_) : flags(flags_) {} - /** test operator - * @param obj An object with a flags member - * @return true if flags member of obj contains any of the flags - * (bitwise and with flags is nonzero). - */ - bool operator() (const osg::ref_ptr& obj) - { - return (obj->flags & flags) != 0; - } - unsigned flags; -}; - } #endif