mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-03 17:19:43 +02:00
Accessor for shared pointer to track, given only a bare pointer
This commit is contained in:
parent
1fce8b54f2
commit
bd5d2bf114
@ -942,6 +942,8 @@ auto TrackList::Replace(Track * t, value_type &&with) -> value_type
|
||||
value_type holder;
|
||||
if (t && with) {
|
||||
auto node = t->GetNode();
|
||||
t->SetOwner(nullptr, {});
|
||||
|
||||
holder = std::move(*node);
|
||||
|
||||
Track *pTrack = with.get();
|
||||
@ -962,6 +964,7 @@ TrackNodePointer TrackList::Remove(Track *t)
|
||||
TrackNodePointer result(end());
|
||||
if (t) {
|
||||
auto node = t->GetNode();
|
||||
t->SetOwner(nullptr, {});
|
||||
|
||||
if (!isNull(node)) {
|
||||
value_type holder = std::move( *node );
|
||||
|
21
src/Track.h
21
src/Track.h
@ -109,6 +109,27 @@ class AUDACITY_DLL_API Track /* not final */
|
||||
public:
|
||||
mutable wxSize vrulerSize;
|
||||
|
||||
// Given a bare pointer, find a shared_ptr. But this is not possible for
|
||||
// a track not owned by any list, so the result can be null.
|
||||
template<typename Subclass = Track>
|
||||
inline static std::shared_ptr<Subclass> Pointer( Track *t )
|
||||
{
|
||||
if (t && t->mList)
|
||||
return std::static_pointer_cast<Subclass>(*t->mNode);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename Subclass = const Track>
|
||||
inline static std::shared_ptr<Subclass> Pointer( const Track *t )
|
||||
{
|
||||
if (t && t->mList) {
|
||||
std::shared_ptr<const Track> p{ *t->mNode };
|
||||
// Let you change the type, but not cast away the const
|
||||
return std::static_pointer_cast<Subclass>(p);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// An implementation is defined for call-through from subclasses, but
|
||||
// the inherited method is still marked pure virtual
|
||||
HitTestResult HitTest
|
||||
|
Loading…
x
Reference in New Issue
Block a user