void TrackList::Remove(Track * t, bool deletetrack) { if (t) { TrackListNode *node = (TrackListNode *) t->GetNode(); t->SetOwner(NULL, NULL); if (deletetrack) { delete t; } if (node) { if (node->prev) { node->prev->next = node->next; } else { head = node->next; } if (node->next) { node->next->prev = node->prev; RecalcPositions(node->next); } else { tail = node->prev; } UpdatedEvent(NULL); ResizedEvent(node->next); delete node; } } }
Track *TrackList::Add(std::shared_ptr<TrackKind> &&t) { push_back(t); auto n = end(); --n; t->SetOwner(this, n); RecalcPositions(n); UpdatedEvent(n); return back().get(); }
Track *TrackList::AddToHead(std::unique_ptr<TrackKind> &&t) { Track *pTrack; push_front(value_type(pTrack = t.release())); auto n = begin(); pTrack->SetOwner(this, n); RecalcPositions(n); UpdatedEvent(n); ResizedEvent(n); return front().get(); }
Track *TrackList::Add(std::unique_ptr<TrackKind> &&t) { Track *pTrack; push_back(value_type(pTrack = t.release())); auto n = end(); --n; pTrack->SetOwner(this, n); RecalcPositions(n); UpdatedEvent(n); return back().get(); }
void TrackList::Permute(const std::vector<TrackNodePointer> &permutation) { for (const auto iter : permutation) { value_type track = std::move(*iter); erase(iter); Track *pTrack = track.get(); pTrack->SetOwner(this, insert(end(), std::move(track))); } auto n = begin(); RecalcPositions(n); UpdatedEvent(n); ResizedEvent(n); }
void TrackList::Clear(bool deleteTracks /* = false */) { while (head) { TrackListNode *temp = head; head->t->SetOwner(NULL, NULL); if (deleteTracks) { delete head->t; } head = head->next; delete temp; } tail = NULL; UpdatedEvent(NULL); }
void TrackList::Replace(Track * t, Track * with, bool deletetrack) { if (t && with) { TrackListNode *node = (TrackListNode *) t->GetNode(); t->SetOwner(NULL, NULL); if (deletetrack) { delete t; } node->t = with; with->SetOwner(this, node); RecalcPositions(node); UpdatedEvent(node); ResizedEvent(node); } }
TrackNodePointer TrackList::Remove(Track *t) { TrackNodePointer result(end()); if (t) { auto node = t->GetNode(); if (!isNull(node)) { result = erase(node); if (!isNull(result)) { RecalcPositions(result); } UpdatedEvent(end()); ResizedEvent(result); } } return result; }
void TrackList::Add(Track * t) { TrackListNode *n = new TrackListNode; t->SetOwner(this, n); n->t = (Track *) t; n->prev = tail; n->next = NULL; if (tail) { tail->next = n; } tail = n; if (!head) { head = n; } RecalcPositions(n); UpdatedEvent(n); }
void TrackList::Replace(const Track * t, const Track * with, bool deletetrack) { Track *const mutableT = const_cast<Track*>(t); Track *const mutableWith = const_cast<Track*>(with); if (mutableT && with) { TrackListNode *node = const_cast<TrackListNode *>(mutableT->GetNode()); mutableT->SetOwner(NULL, NULL); if (deletetrack) { delete t; } node->t = mutableWith; mutableWith->SetOwner(this, node); RecalcPositions(node); UpdatedEvent(node); ResizedEvent(node); } }
void TrackList::AddToHead(Track * t) { TrackListNode *n = new TrackListNode; t->SetOwner(this, n); n->t = (Track *) t; n->prev = NULL; n->next = head; if (head) { head->prev = n; } head = n; if (!tail) { tail = n; } RecalcPositions(head); UpdatedEvent(n); ResizedEvent(n); }
// Precondition: if either of s1 or s2 are "linked", then // s1 and s2 must each be the FIRST node of the linked pair. // // This is used when you want to swap the track or pair of // tracks in s1 with the track or pair of tracks in s2. // The complication is that the tracks are stored in a single // linked list, and pairs of tracks are marked only by a flag // in one of the tracks. void TrackList::SwapNodes(TrackListNode * s1, TrackListNode * s2) { Track *link; Track *source[4]; TrackListNode *target[4]; // if a null pointer is passed in, we want to know about it wxASSERT(s1); wxASSERT(s2); // Deal with firat track in each team link = s1->t->GetLink(); if (!s1->t->GetLinked() && link) { s1 = (TrackListNode *) link->GetNode(); } link = s2->t->GetLink(); if (!s2->t->GetLinked() && link) { s2 = (TrackListNode *) link->GetNode(); } target[0] = s1; source[0] = target[0]->t; if (source[0]->GetLinked()) { target[1] = target[0]->next; source[1] = target[1]->t; } else { target[1] = NULL; source[1] = NULL; } target[2] = s2; source[2] = target[2]->t; if (source[2]->GetLinked()) { target[3] = target[2]->next; source[3] = target[3]->t; } else { target[3] = NULL; source[3] = NULL; } int s = 2; for (int t = 0; t < 4; t++) { if (target[t]) { target[t]->t = source[s]; target[t]->t->SetOwner(NULL, NULL); target[t]->t->SetOwner(this, target[t]); s = (s + 1) % 4; if (!source[s]) { s = (s + 1) % 4; } } } RecalcPositions(s1); UpdatedEvent(s1); ResizedEvent(s1); }
void TrackList::Clear() { ListOfTracks::clear(); UpdatedEvent(end()); }
// This is used when you want to swap the track or pair of // tracks in s1 with the track or pair of tracks in s2. // The complication is that the tracks are stored in a single // linked list, and pairs of tracks are marked only by a flag // in one of the tracks. void TrackList::SwapNodes(TrackNodePointer s1, TrackNodePointer s2) { // if a null pointer is passed in, we want to know about it wxASSERT(!isNull(s1)); wxASSERT(!isNull(s2)); // Deal with first track in each team Track *link; link = (*s1)->GetLink(); bool linked1 = link != nullptr; if (linked1 && !(*s1)->GetLinked()) { s1 = link->GetNode(); } link = (*s2)->GetLink(); bool linked2 = link != nullptr; if (linked2 && !(*s2)->GetLinked()) { s2 = link->GetNode(); } // Safety check... if (s1 == s2) return; // Be sure s1 is the earlier iterator if ((*s1)->GetIndex() >= (*s2)->GetIndex()) { std::swap(s1, s2); std::swap(linked1, linked2); } // Remove tracks value_type save11 = std::move(*s1), save12{}; s1 = erase(s1); if (linked1) { wxASSERT(s1 != s2); save12 = std::move(*s1), s1 = erase(s1); } const bool same = (s1 == s2); value_type save21 = std::move(*s2), save22{}; s2 = erase(s2); if (linked2) save22 = std::move(*s2), s2 = erase(s2); if (same) // We invalidated s1! s1 = s2; // Reinsert them Track *pTrack; if (save22) pTrack = save22.get(), pTrack->SetOwner(this, s1 = insert(s1, std::move(save22))); pTrack = save21.get(), pTrack->SetOwner(this, s1 = insert(s1, std::move(save21))); if (save12) pTrack = save12.get(), pTrack->SetOwner(this, s2 = insert(s2, std::move(save12))); pTrack = save11.get(), pTrack->SetOwner(this, s2 = insert(s2, std::move(save11))); // Now correct the Index in the tracks, and other things RecalcPositions(s1); UpdatedEvent(s1); ResizedEvent(s1); }