1
0
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:
Paul Licameli 2016-03-25 20:27:25 -04:00
parent 85bd752de7
commit de75a00c10
5 changed files with 19 additions and 19 deletions

View File

@ -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__

View File

@ -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++;

View File

@ -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> ;

View File

@ -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()) {

View File

@ -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);