Use std::[tr1::]unordered_(set|map), not the wxWidgets container macros

This commit is contained in:
Paul Licameli 2018-01-08 16:38:52 -05:00
parent cd8ec5e6a8
commit cb403954fa
16 changed files with 103 additions and 34 deletions

View File

@ -22,6 +22,10 @@
#include <wx/hashmap.h>
#include <wx/mstream.h>
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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 "<?xml autosave>"
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<wxString, short>;
using IdMap = std::unordered_map<short, wxString>;
WX_DECLARE_OBJARRAY_WITH_DECL(IdMap, IdMapArray, class AUDACITY_DLL_API);
// This class's overrides do NOT throw AudacityException.

View File

@ -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 <unordered_map>
#endif
using AliasedFileHash = std::unordered_map<wxString, AliasedFile*>;
// 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<BlockFile *, BlockFilePtr>;
using BoolBlockFileHash = std::unordered_map<BlockFile *, bool>;
// Given a project, returns a single array of all SeqBlocks
// in the current set of tracks. Enumerating that array allows

View File

@ -22,6 +22,10 @@
#include "xml/XMLTagHandler.h"
#include "wxFileNameWrapper.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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<int, int>;
class BlockFile;
using BlockFilePtr = std::shared_ptr<BlockFile>;
WX_DECLARE_HASH_MAP(wxString, std::weak_ptr<BlockFile>, wxStringHash,
wxStringEqual, BlockHash);
using BlockHash = std::unordered_map< wxString, std::weak_ptr<BlockFile> >;
wxMemorySize GetFreeMemory();

View File

@ -42,7 +42,11 @@
#include "AudacityApp.h"
WX_DECLARE_STRING_HASH_MAP(wxString, LangHash);
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#endif
using LangHash = std::unordered_map<wxString, wxString>;
static bool TranslationExists(wxArrayString &audacityPathList, wxString code)
{

View File

@ -33,7 +33,16 @@ using std::isinf;
// To define function
#include <tr1/functional>
// To define unordered_set
#include <tr1/unordered_set>
// To define unordered_map and hash
#include <tr1/unordered_map>
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<typename T> 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__

View File

@ -50,7 +50,11 @@
#include "Experimental.h"
WX_DECLARE_STRING_HASH_MAP(wxArrayString, ProviderMap);
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#endif
using ProviderMap = std::unordered_map<wxString, wxArrayString>;
// ============================================================================
//
@ -390,7 +394,7 @@ struct ItemData
int stateWidth;
};
WX_DECLARE_STRING_HASH_MAP(ItemData, ItemDataMap);
using ItemDataMap = std::unordered_map<wxString, ItemData>;
enum
{

View File

@ -168,7 +168,6 @@ typedef std::map<PluginID, PluginDescriptor> PluginMap;
typedef wxArrayString PluginIDList;
class ProviderMap;
class PluginRegistrationDialog;
class PluginManager final : public PluginManagerInterface

View File

@ -41,6 +41,10 @@
#include "widgets/wxPanelWrapper.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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")

View File

@ -36,8 +36,12 @@ UndoManager
#include "UndoManager.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_set>
#endif
using ConstBlockFilePtr = const BlockFile*;
WX_DECLARE_HASH_SET(ConstBlockFilePtr, wxPointerHash, wxPointerEqual, Set );
using Set = std::unordered_set<ConstBlockFilePtr>;
struct UndoStackElem {

View File

@ -28,6 +28,10 @@
#include "audacity/Types.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#endif
struct MenuBarListEntry
{
MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_)
@ -88,8 +92,8 @@ using SubMenuList = std::vector < movable_ptr<SubMenuListEntry> >;
// so we don't want the structures to relocate with vector operations.
using CommandList = std::vector<movable_ptr<CommandListEntry>>;
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<wxString, CommandListEntry*>;
using CommandIDHash = std::unordered_map<int, CommandListEntry*>;
class AudacityProject;

View File

@ -64,6 +64,10 @@ greater use in future.
#include "../Experimental.h"
#include "../commands/ScreenshotCommand.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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("<Current Settings>");
const wxString Effect::kFactoryDefaultsIdent = wxT("<Factory Defaults>");
WX_DECLARE_VOIDPTR_HASH_MAP( bool, t2bHash );
using t2bHash = std::unordered_map< void*, bool >;
Effect::Effect()
{

View File

@ -34,9 +34,13 @@ effects.
#include "../PluginManager.h"
#include "Effect.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#endif
using EffectArray = std::vector <Effect*> ;
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(Effect *, EffectMap, class AUDACITY_DLL_API);
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(std::shared_ptr<Effect>, EffectOwnerMap, class AUDACITY_DLL_API);
using EffectMap = std::unordered_map<wxString, Effect *>;
using EffectOwnerMap = std::unordered_map< wxString, std::shared_ptr<Effect> >;
#if defined(EXPERIMENTAL_EFFECTS_RACK)
class EffectRack;

View File

@ -39,6 +39,10 @@
#include "LoadLV2.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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<wxString, wxArrayInt>;
WX_DEFINE_ARRAY_PTR(LilvInstance *, LV2SlaveArray);
class LV2EffectSettingsDialog;

View File

@ -43,6 +43,10 @@ Functions that find and load all LV2 plugins on the system.
#include "LoadLV2.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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<wxString, LilvNode*>;
LilvWorld *gWorld = NULL;

View File

@ -22,6 +22,10 @@ LRN
#include "../FileNames.h"
#include "../widgets/wxPanelWrapper.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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<wxString, FFmpegPreset>;
class FFmpegPresets : XMLTagHandler
{

View File

@ -24,6 +24,10 @@
#include "ImageRoll.h"
#include "wxPanelWrapper.h"
#ifndef __AUDACITY_OLD_STD__
#include <unordered_map>
#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<void*, int>;
WX_DEFINE_ARRAY(ExpandingToolBar *, ExpandingToolBarArray);
WX_DECLARE_OBJARRAY(wxRect, wxArrayRect);