From fc7be67f2a219d94d4ec8724c463aa70e46a2b20 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Fri, 1 Jan 2021 03:46:43 +0100 Subject: [PATCH] Fixed: build with gcc < 5.5 - std::hash --- examples/ui.cpp | 4 ++-- finalcut.spec.in | 2 +- src/include/final/fc.h | 10 +++++++++- src/include/final/fdialog.h | 4 ++-- src/include/final/flineedit.h | 4 ++-- src/include/final/flistbox.h | 6 +++--- src/include/final/flistview.h | 6 +++--- src/include/final/fscrollview.h | 4 ++-- src/include/final/ftermlinux.h | 22 +++++++++++++++------- src/include/final/ftextview.h | 4 ++-- 10 files changed, 41 insertions(+), 25 deletions(-) diff --git a/examples/ui.cpp b/examples/ui.cpp index 4937a305..3c62adbc 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -813,7 +813,7 @@ void MyDialog::cb_about() finalcut::FMessageBox info ( "About" , line + L" FINAL CUT " + line + L"\n\n" L"Version " + libver + L"\n\n" - L"(c) 2020 by Markus Gans" + L"(c) 2021 by Markus Gans" , finalcut::FMessageBox::ButtonType::Ok , finalcut::FMessageBox::ButtonType::Reject , finalcut::FMessageBox::ButtonType::Reject @@ -1046,7 +1046,7 @@ int main (int argc, char* argv[]) { const finalcut::FString ver{F_VERSION}; // Library version const finalcut::FString title { "FINAL CUT " + ver - + " (C) 2020 by Markus Gans" }; + + " (C) 2021 by Markus Gans" }; // Create the application object app finalcut::FApplication app{argc, argv}; diff --git a/finalcut.spec.in b/finalcut.spec.in index 7275db84..7a3b9868 100644 --- a/finalcut.spec.in +++ b/finalcut.spec.in @@ -1,7 +1,7 @@ # # spec file for package finalcut # -# Copyright (c) 2020 by Markus Gans +# Copyright (c) 2021 by Markus Gans # %define sover 0 diff --git a/src/include/final/fc.h b/src/include/final/fc.h index d1608eaa..fd6f6016 100644 --- a/src/include/final/fc.h +++ b/src/include/final/fc.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2015-2020 Markus Gans * +* Copyright 2015-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -799,6 +799,14 @@ enum class FKey : uInt32 Incomplete = UINT32_MAX }; +struct FKeyHash +{ + std::size_t operator () (const FKey& p) const + { + return std::hash()(uInt32(p)); + } +}; + constexpr FKey operator >> (const FKey& k, const uInt32 n) noexcept { return FKey(uInt32(k) >> n); diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 348e6617..b9249e61 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2012-2020 Markus Gans * +* Copyright 2012-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -167,7 +167,7 @@ class FDialog : public FWindow }; // Using-declaration - using KeyMap = std::unordered_map>; + using KeyMap = std::unordered_map, FKeyHash>; // Constant static constexpr std::size_t MENU_BTN = 3; diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 3f0a8144..615f8a82 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2012-2020 Markus Gans * +* Copyright 2012-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -166,7 +166,7 @@ class FLineEdit : public FWidget private: // Using-declaration using offsetPair = std::pair; - using KeyMap = std::unordered_map>; + using KeyMap = std::unordered_map, FKeyHash>; // Constants static constexpr auto NOT_SET = static_cast(-1); diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 01ee8c54..a3bd172a 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2014-2020 Markus Gans * +* Copyright 2014-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -275,8 +275,8 @@ class FListBox : public FWidget private: // Using-declaration - using KeyMap = std::unordered_map>; - using KeyMapResult = std::unordered_map>; + using KeyMap = std::unordered_map, FKeyHash>; + using KeyMapResult = std::unordered_map, FKeyHash>; using LazyInsert = std::function; // Enumeration diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index d23c6fd6..37add427 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2017-2020 Markus Gans * +* Copyright 2017-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -406,8 +406,8 @@ class FListView : public FWidget struct Header; // forward declaration // Using-declaration - using KeyMap = std::unordered_map>; - using KeyMapResult = std::unordered_map>; + using KeyMap = std::unordered_map, FKeyHash>; + using KeyMapResult = std::unordered_map, FKeyHash>; using HeaderItems = std::vector
; using SortTypes = std::vector; diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index c309b2b4..71cdedf6 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -4,7 +4,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2017-2020 Markus Gans * +* Copyright 2017-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -150,7 +150,7 @@ class FScrollView : public FWidget private: // Using-declaration - using KeyMap = std::unordered_map>; + using KeyMap = std::unordered_map, FKeyHash>; // Constants static constexpr std::size_t vertical_border_spacing = 2; diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 832bd493..c837c54e 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2018-2020 Markus Gans * +* Copyright 2018-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -130,6 +130,16 @@ class FTermLinux final uChar : 4; // padding bits }; + struct ModifierKeyHash + { + std::size_t operator () (const ModifierKey& m_key) const + { + uChar m{}; + std::memcpy(&m, &m_key, sizeof(uChar)); + return std::hash()(m); + } + }; + struct RGB { uChar red; @@ -152,13 +162,11 @@ class FTermLinux final { std::size_t operator () (const Pair& pair) const { - uChar m{}; - std::memcpy(&m, &pair.modifier, sizeof(uChar)); size_t seed = 0; - const auto h1 = std::hash()(m); - const auto h2 = std::hash()(pair.key); - seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2); + const auto hash1 = ModifierKeyHash()(pair.modifier); + const auto hash2 = FKeyHash()(pair.key); + seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } }; diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 343c23df..88aa3b59 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2014-2020 Markus Gans * +* Copyright 2014-2021 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -138,7 +138,7 @@ class FTextView : public FWidget private: // Using-declaration - using KeyMap = std::unordered_map>; + using KeyMap = std::unordered_map, FKeyHash>; // Accessors std::size_t getTextHeight() const;