mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
Define movable_ptr and make_movable, use __AUDACITY_OLD_STD__ in fewer places
This commit is contained in:
parent
85bd752de7
commit
de75a00c10
@ -481,4 +481,19 @@ static char*THIS_FILE = __FILE__;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Frequently, we need to use a vector or list of unique_ptr if we can, but default
|
||||
// to shared_ptr if we can't (because containers know how to copy elements only,
|
||||
// not move them).
|
||||
#ifdef __AUDACITY_OLD_STD__
|
||||
|
||||
template<typename T> using movable_ptr = std::shared_ptr<T>;
|
||||
#define make_movable std::make_shared
|
||||
|
||||
#else
|
||||
|
||||
template<typename T> using movable_ptr = std::unique_ptr<T>;
|
||||
#define make_movable std::make_unique
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __AUDACITY_MEMORY_X_H__
|
||||
|
@ -265,17 +265,10 @@ void UndoManager::PushState(const TrackList * l,
|
||||
|
||||
// Assume tags was duplicted before any changes.
|
||||
// Just save a new shared_ptr to it.
|
||||
#ifdef __AUDACITY_OLD_STD__
|
||||
stack.push_back(
|
||||
std::make_shared<UndoStackElem>
|
||||
make_movable<UndoStackElem>
|
||||
(std::move(tracksCopy),
|
||||
longDescription, shortDescription, selectedRegion, tags)
|
||||
#else
|
||||
stack.emplace_back(
|
||||
std::make_unique<UndoStackElem>
|
||||
(std::move(tracksCopy),
|
||||
longDescription, shortDescription, selectedRegion, tags)
|
||||
#endif
|
||||
);
|
||||
|
||||
current++;
|
||||
|
@ -71,11 +71,7 @@ struct UndoState {
|
||||
SelectedRegion selectedRegion; // by value
|
||||
};
|
||||
|
||||
#ifdef __AUDACITY_OLD_STD__
|
||||
using UndoStack = std::vector <std::shared_ptr<UndoStackElem>>;
|
||||
#else
|
||||
using UndoStack = std::vector <std::unique_ptr<UndoStackElem>>;
|
||||
#endif
|
||||
using UndoStack = std::vector <movable_ptr<UndoStackElem>>;
|
||||
|
||||
using SpaceArray = std::vector <wxLongLong_t> ;
|
||||
|
||||
|
@ -811,7 +811,7 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
|
||||
{
|
||||
{
|
||||
// Make a unique_ptr or shared_ptr as appropriate:
|
||||
auto entry = CommandList::value_type{ safenew CommandListEntry() };
|
||||
auto entry = make_movable<CommandListEntry>();
|
||||
|
||||
wxString labelPrefix;
|
||||
if (!mSubMenuList.empty()) {
|
||||
|
@ -83,11 +83,7 @@ using SubMenuList = std::vector < SubMenuListEntry >;
|
||||
|
||||
// This is an array of pointers, not structures, because the hash maps also point to them,
|
||||
// so we don't want the structures to relocate with vector operations.
|
||||
#ifdef __AUDACITY_OLD_STD__
|
||||
using CommandList = std::vector < std::shared_ptr<CommandListEntry> >;
|
||||
#else
|
||||
using CommandList = std::vector < std::unique_ptr<CommandListEntry> >;
|
||||
#endif
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user