12#ifndef WSFTRACKLIST_HPP
13#define WSFTRACKLIST_HPP
16#include <unordered_map>
19#include "UtScriptAccessible.hpp"
52 unsigned int GetTrackCount()
const {
return static_cast<unsigned int>(mTrackList.size()); }
58 T*
GetTrackEntry(
unsigned int aEntryIndex) {
return mTrackList[aEntryIndex].get(); }
64 const T*
GetTrackEntry(
unsigned int aEntryIndex)
const {
return mTrackList[aEntryIndex].get(); }
82 using TrackIdMap = std::unordered_map<WsfTrackId, T*, WsfTrackId>;
84 std::vector<std::unique_ptr<T>> mTrackList;
85 TrackIdMap mTrackIdMap;
94 return "WsfTrackList";
99 return "WsfLocalTrackList";
112 for (
const auto&
trackPtr : aSrc.mTrackList)
128 mTrackIdMap[aTrackPtr->GetTrackId()] = aTrackPtr.get();
129 mTrackList.push_back(std::move(aTrackPtr));
141 bool trackDeleted =
false;
145 std::find_if(mTrackList.begin(),
147 [aTrackId](
const std::unique_ptr<T>& aTrackPtr) { return aTrackPtr->GetTrackId() == aTrackId; });
150 auto idIter = mTrackIdMap.find(aTrackId);
152 if (trackIter != mTrackList.end())
154 mTrackList.erase(trackIter);
160 if (idIter != mTrackIdMap.end())
162 mTrackIdMap.erase(idIter);
163 assert(trackDeleted);
167 assert(!trackDeleted);
192 auto iter = mTrackIdMap.find(aTrackId);
193 if (iter != mTrackIdMap.end())
220 std::unique_ptr<T>
trackPtr{
nullptr};
224 std::find_if(mTrackList.begin(),
226 [aTrackId](
const std::unique_ptr<T>& aTrackPtr) { return aTrackPtr->GetTrackId() == aTrackId; });
227 if (trackIter != mTrackList.end())
230 mTrackList.erase(trackIter);
235 auto idIter = mTrackIdMap.find(aTrackId);
236 if (idIter != mTrackIdMap.end())
238 mTrackIdMap.erase(idIter);
255 unsigned int nextIndex =
static_cast<unsigned int>(mTrackList.size());
256 if (aEntryIndex <
static_cast<unsigned int>(mTrackList.size()))
259 auto trackIter = mTrackList.begin();
260 std::advance(trackIter, aEntryIndex);
261 assert(trackIter != mTrackList.end());
264 auto idIter = mTrackIdMap.find((*trackIter)->GetTrackId());
265 assert(idIter != mTrackIdMap.end());
271 if (aEntryIndex !=
static_cast<unsigned int>(mTrackList.size()))
273 nextIndex = aEntryIndex;
constexpr const char * UtScriptClassName< WsfTrackList >()
Definition WsfTrackList.hpp:92
constexpr const char * UtScriptClassName< WsfLocalTrackList >()
Definition WsfTrackList.hpp:97
WsfTrackListT< WsfLocalTrack > WsfLocalTrackList
Definition WsfTrackList.hpp:89
WsfTrackListT< WsfTrack > WsfTrackList
Definition WsfTrackList.hpp:88
Definition WsfTrackId.hpp:33
A 'Track List' is a container for a list of 'Track' objects.
Definition WsfTrackList.hpp:38
std::unique_ptr< T > RemoveTrack(const WsfTrackId &aTrackId)
Remove the indicated track from the track list but don't delete the track object itself.
Definition WsfTrackList.hpp:218
T * FindTrack(const WsfTrackId &aTrackId)
Find the requested track.
Definition WsfTrackList.hpp:190
void AddTrack(std::unique_ptr< T > aTrackPtr)
Add a track to the track list.
Definition WsfTrackList.hpp:126
const T * GetTrackEntry(unsigned int aEntryIndex) const
Definition WsfTrackList.hpp:64
virtual ~WsfTrackListT()=default
WsfTrackListT< T > & operator=(const WsfTrackListT< T > &aRhs)=delete
WsfTrackListT< T > * Clone() const
Clone this object.
Definition WsfTrackList.hpp:67
unsigned int DeleteTrackEntry(unsigned int aEntryIndex)
Definition WsfTrackList.hpp:253
const T * FindTrack(const WsfTrackId &aTrackId) const
Find the requested track.
Definition WsfTrackList.hpp:207
bool DeleteTrack(const WsfTrackId &aTrackId)
Delete the indicated track from the track list and delete the track object.
Definition WsfTrackList.hpp:139
void DeleteAllTracks()
Delete all the tracks in the track list.
Definition WsfTrackList.hpp:176
unsigned int GetTrackCount() const
Definition WsfTrackList.hpp:52
WsfTrackListT(const WsfTrackListT< T > &aSrc)
Definition WsfTrackList.hpp:110
T * GetTrackEntry(unsigned int aEntryIndex)
Definition WsfTrackList.hpp:58