From cb403954faabac9225d3615e0b8f1bc321914cad Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 8 Jan 2018 16:38:52 -0500 Subject: [PATCH] Use std::[tr1::]unordered_(set|map), not the wxWidgets container macros --- src/AutoRecovery.h | 8 ++++++-- src/Dependencies.cpp | 13 +++++++------ src/DirManager.h | 9 ++++++--- src/Languages.cpp | 6 +++++- src/MemoryX.h | 26 ++++++++++++++++++++++++++ src/PluginManager.cpp | 8 ++++++-- src/PluginManager.h | 1 - src/Tags.h | 14 +++++--------- src/UndoManager.cpp | 6 +++++- src/commands/CommandManager.h | 8 ++++++-- src/effects/Effect.cpp | 6 +++++- src/effects/EffectManager.h | 8 ++++++-- src/effects/lv2/LV2Effect.h | 6 +++++- src/effects/lv2/LoadLV2.cpp | 6 +++++- src/export/ExportFFmpegDialogs.h | 6 +++++- src/widgets/ExpandingToolBar.h | 6 +++++- 16 files changed, 103 insertions(+), 34 deletions(-) diff --git a/src/AutoRecovery.h b/src/AutoRecovery.h index 47b012886..87856ca04 100644 --- a/src/AutoRecovery.h +++ b/src/AutoRecovery.h @@ -22,6 +22,10 @@ #include #include +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + // // Show auto recovery dialog if there are projects to recover. Should be // called once at Audacity startup. @@ -68,8 +72,8 @@ private: // Should be plain ASCII #define AutoSaveIdent "" -WX_DECLARE_STRING_HASH_MAP_WITH_DECL(short, NameMap, class AUDACITY_DLL_API); -WX_DECLARE_HASH_MAP_WITH_DECL(short, wxString, wxIntegerHash, wxIntegerEqual, IdMap, class AUDACITY_DLL_API); +using NameMap = std::unordered_map; +using IdMap = std::unordered_map; WX_DECLARE_OBJARRAY_WITH_DECL(IdMap, IdMapArray, class AUDACITY_DLL_API); // This class's overrides do NOT throw AudacityException. diff --git a/src/Dependencies.cpp b/src/Dependencies.cpp index 4df22a5bd..1dcb3d41e 100644 --- a/src/Dependencies.cpp +++ b/src/Dependencies.cpp @@ -56,15 +56,16 @@ AliasedFile s. #include "WaveClip.h" #include "widgets/ErrorDialog.h" -WX_DECLARE_HASH_MAP(wxString, AliasedFile *, - wxStringHash, wxStringEqual, AliasedFileHash); +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + +using AliasedFileHash = std::unordered_map; // These two hash types are used only inside short scopes // so it is safe to key them by plain pointers. -WX_DECLARE_HASH_MAP(BlockFile *, BlockFilePtr, - wxPointerHash, wxPointerEqual, ReplacedBlockFileHash); -WX_DECLARE_HASH_MAP(BlockFile *, bool, - wxPointerHash, wxPointerEqual, BoolBlockFileHash); +using ReplacedBlockFileHash = std::unordered_map; +using BoolBlockFileHash = std::unordered_map; // Given a project, returns a single array of all SeqBlocks // in the current set of tracks. Enumerating that array allows diff --git a/src/DirManager.h b/src/DirManager.h index fb311b3cc..61f817da3 100644 --- a/src/DirManager.h +++ b/src/DirManager.h @@ -22,6 +22,10 @@ #include "xml/XMLTagHandler.h" #include "wxFileNameWrapper.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + class wxHashTable; class BlockArray; class BlockFile; @@ -31,13 +35,12 @@ class SequenceTest; #define FSCKstatus_CHANGED 0x2 #define FSCKstatus_SAVE_AUP 0x4 // used in combination with FSCKstatus_CHANGED -WX_DECLARE_HASH_MAP(int, int, wxIntegerHash, wxIntegerEqual, DirHash); +using DirHash = std::unordered_map; class BlockFile; using BlockFilePtr = std::shared_ptr; -WX_DECLARE_HASH_MAP(wxString, std::weak_ptr, wxStringHash, - wxStringEqual, BlockHash); +using BlockHash = std::unordered_map< wxString, std::weak_ptr >; wxMemorySize GetFreeMemory(); diff --git a/src/Languages.cpp b/src/Languages.cpp index 58bc40697..88d0d9ff6 100644 --- a/src/Languages.cpp +++ b/src/Languages.cpp @@ -42,7 +42,11 @@ #include "AudacityApp.h" -WX_DECLARE_STRING_HASH_MAP(wxString, LangHash); +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + +using LangHash = std::unordered_map; static bool TranslationExists(wxArrayString &audacityPathList, wxString code) { diff --git a/src/MemoryX.h b/src/MemoryX.h index a9cff223e..3b0f4b0d2 100644 --- a/src/MemoryX.h +++ b/src/MemoryX.h @@ -33,7 +33,16 @@ using std::isinf; // To define function #include +// To define unordered_set +#include + +// To define unordered_map and hash +#include + namespace std { + using std::tr1::unordered_set; + using std::tr1::hash; + using std::tr1::unordered_map; using std::tr1::function; using std::tr1::shared_ptr; using std::tr1::weak_ptr; @@ -1139,4 +1148,21 @@ make_value_transform_iterator(const Iterator &iterator, Function function) return { iterator, NewFunction{ function } }; } +// For using std::unordered_map on wxString +namespace std +#ifdef __AUDACITY_OLD_STD__ + ::tr1 +#endif +{ + template struct hash; + template<> struct hash< wxString > { + size_t operator () (const wxString &str) const // noexcept + { + auto stdstr = str.ToStdWstring(); // no allocations, a cheap fetch + using Hasher = hash< decltype(stdstr) >; + return Hasher{}( stdstr ); + } + }; +}; + #endif // __AUDACITY_MEMORY_X_H__ diff --git a/src/PluginManager.cpp b/src/PluginManager.cpp index b04ab942f..c6511264a 100644 --- a/src/PluginManager.cpp +++ b/src/PluginManager.cpp @@ -50,7 +50,11 @@ #include "Experimental.h" -WX_DECLARE_STRING_HASH_MAP(wxArrayString, ProviderMap); +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + +using ProviderMap = std::unordered_map; // ============================================================================ // @@ -390,7 +394,7 @@ struct ItemData int stateWidth; }; -WX_DECLARE_STRING_HASH_MAP(ItemData, ItemDataMap); +using ItemDataMap = std::unordered_map; enum { diff --git a/src/PluginManager.h b/src/PluginManager.h index 1f6e4dc04..744191d5d 100644 --- a/src/PluginManager.h +++ b/src/PluginManager.h @@ -168,7 +168,6 @@ typedef std::map PluginMap; typedef wxArrayString PluginIDList; -class ProviderMap; class PluginRegistrationDialog; class PluginManager final : public PluginManagerInterface diff --git a/src/Tags.h b/src/Tags.h index 36069fc0e..538bd11ec 100644 --- a/src/Tags.h +++ b/src/Tags.h @@ -41,6 +41,10 @@ #include "widgets/wxPanelWrapper.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + class wxButton; class wxChoice; class wxComboBox; @@ -53,15 +57,7 @@ class ShuttleGui; class TagsEditor; class ComboEditor; -// We want a macro call like this: -// WX_DECLARE_USER_EXPORTED_STRING_HASH_MAP(wxString, TagMap, AUDACITY_DLL_API); -// Which wxWidgets does not supply! -// So use this undocumented variant: -WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString, TagMap,class AUDACITY_DLL_API ); -// Doing this means we can export class Tags without any worry, -// as every class it uses, including TagMap, is then exported. -// It's better than using #pragma warning(disable: 4251) -// and relying on the relevant parts of class Tags being private. +using TagMap = std::unordered_map< wxString, wxString >; #define TAG_TITLE wxT("TITLE") #define TAG_ARTIST wxT("ARTIST") diff --git a/src/UndoManager.cpp b/src/UndoManager.cpp index 0e7cbe6de..4b54223ed 100644 --- a/src/UndoManager.cpp +++ b/src/UndoManager.cpp @@ -36,8 +36,12 @@ UndoManager #include "UndoManager.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + using ConstBlockFilePtr = const BlockFile*; -WX_DECLARE_HASH_SET(ConstBlockFilePtr, wxPointerHash, wxPointerEqual, Set ); +using Set = std::unordered_set; struct UndoStackElem { diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index a7d69f399..539e03fd5 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -28,6 +28,10 @@ #include "audacity/Types.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + struct MenuBarListEntry { MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_) @@ -88,8 +92,8 @@ using SubMenuList = std::vector < movable_ptr >; // so we don't want the structures to relocate with vector operations. using CommandList = std::vector>; -WX_DECLARE_STRING_HASH_MAP_WITH_DECL(CommandListEntry *, CommandNameHash, class AUDACITY_DLL_API); -WX_DECLARE_HASH_MAP_WITH_DECL(int, CommandListEntry *, wxIntegerHash, wxIntegerEqual, CommandIDHash, class AUDACITY_DLL_API); +using CommandNameHash = std::unordered_map; +using CommandIDHash = std::unordered_map; class AudacityProject; diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 670392797..0128961ed 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -64,6 +64,10 @@ greater use in future. #include "../Experimental.h" #include "../commands/ScreenshotCommand.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + static const int kDummyID = 20000; static const int kSaveAsID = 20001; static const int kImportID = 20002; @@ -88,7 +92,7 @@ const wxString Effect::kFactoryPresetIdent = wxT("Factory Preset:"); const wxString Effect::kCurrentSettingsIdent = wxT(""); const wxString Effect::kFactoryDefaultsIdent = wxT(""); -WX_DECLARE_VOIDPTR_HASH_MAP( bool, t2bHash ); +using t2bHash = std::unordered_map< void*, bool >; Effect::Effect() { diff --git a/src/effects/EffectManager.h b/src/effects/EffectManager.h index f1c713c51..64d5fc6b4 100644 --- a/src/effects/EffectManager.h +++ b/src/effects/EffectManager.h @@ -34,9 +34,13 @@ effects. #include "../PluginManager.h" #include "Effect.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + using EffectArray = std::vector ; -WX_DECLARE_STRING_HASH_MAP_WITH_DECL(Effect *, EffectMap, class AUDACITY_DLL_API); -WX_DECLARE_STRING_HASH_MAP_WITH_DECL(std::shared_ptr, EffectOwnerMap, class AUDACITY_DLL_API); +using EffectMap = std::unordered_map; +using EffectOwnerMap = std::unordered_map< wxString, std::shared_ptr >; #if defined(EXPERIMENTAL_EFFECTS_RACK) class EffectRack; diff --git a/src/effects/lv2/LV2Effect.h b/src/effects/lv2/LV2Effect.h index ffed0a8ac..5fafde806 100644 --- a/src/effects/lv2/LV2Effect.h +++ b/src/effects/lv2/LV2Effect.h @@ -39,6 +39,10 @@ #include "LoadLV2.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + #define LV2EFFECTS_VERSION wxT("1.0.0.0") #define LV2EFFECTS_FAMILY wxT("LV2") @@ -89,7 +93,7 @@ public: }; WX_DECLARE_OBJARRAY(LV2Port, LV2PortArray); -WX_DECLARE_STRING_HASH_MAP(wxArrayInt, LV2GroupMap); +using LV2GroupMap = std::unordered_map; WX_DEFINE_ARRAY_PTR(LilvInstance *, LV2SlaveArray); class LV2EffectSettingsDialog; diff --git a/src/effects/lv2/LoadLV2.cpp b/src/effects/lv2/LoadLV2.cpp index 6ddb031b4..20851f90c 100644 --- a/src/effects/lv2/LoadLV2.cpp +++ b/src/effects/lv2/LoadLV2.cpp @@ -43,6 +43,10 @@ Functions that find and load all LV2 plugins on the system. #include "LoadLV2.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + // ============================================================================ // Module registration entry point // @@ -69,7 +73,7 @@ DECLARE_BUILTIN_MODULE(LV2sEffectBuiltin); // LV2EffectsModule // /////////////////////////////////////////////////////////////////////////////// -WX_DECLARE_STRING_HASH_MAP(LilvNode *, UriHash); +using UriHash = std::unordered_map; LilvWorld *gWorld = NULL; diff --git a/src/export/ExportFFmpegDialogs.h b/src/export/ExportFFmpegDialogs.h index ce3f3afe5..0f02b0196 100644 --- a/src/export/ExportFFmpegDialogs.h +++ b/src/export/ExportFFmpegDialogs.h @@ -22,6 +22,10 @@ LRN #include "../FileNames.h" #include "../widgets/wxPanelWrapper.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + /// Identifiers for pre-set export types. enum FFmpegExposedFormat @@ -316,7 +320,7 @@ public: }; -WX_DECLARE_STRING_HASH_MAP(FFmpegPreset, FFmpegPresetMap); +using FFmpegPresetMap = std::unordered_map; class FFmpegPresets : XMLTagHandler { diff --git a/src/widgets/ExpandingToolBar.h b/src/widgets/ExpandingToolBar.h index ec2bc101d..c0546567e 100644 --- a/src/widgets/ExpandingToolBar.h +++ b/src/widgets/ExpandingToolBar.h @@ -24,6 +24,10 @@ #include "ImageRoll.h" #include "wxPanelWrapper.h" +#ifndef __AUDACITY_OLD_STD__ +#include +#endif + class wxDragImage; class AButton; @@ -36,7 +40,7 @@ class ToolBarGrabber; class ToolBarArrangement; -WX_DECLARE_VOIDPTR_HASH_MAP(int, WindowHash); +using WindowHash = std::unordered_map; WX_DEFINE_ARRAY(ExpandingToolBar *, ExpandingToolBarArray); WX_DECLARE_OBJARRAY(wxRect, wxArrayRect);