mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
cscore: Refactor sink and source creation
Also make sources and sinks members of Instance private, with appropriate accessor functions.
This commit is contained in:
@@ -50,11 +50,13 @@ class UnlimitedHandleResource {
|
||||
|
||||
std::shared_ptr<TStruct> Get(THandle handle);
|
||||
|
||||
void Free(THandle handle);
|
||||
std::shared_ptr<TStruct> Free(THandle handle);
|
||||
|
||||
template <typename T>
|
||||
wpi::ArrayRef<T> GetAll(wpi::SmallVectorImpl<T>& vec);
|
||||
|
||||
std::vector<std::shared_ptr<TStruct>> FreeAll();
|
||||
|
||||
// @param func functor with (THandle, const TStruct&) parameters
|
||||
template <typename F>
|
||||
void ForEach(F func);
|
||||
@@ -121,14 +123,17 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Get(
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
inline void UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(
|
||||
inline std::shared_ptr<TStruct>
|
||||
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(
|
||||
THandle handle) {
|
||||
auto index =
|
||||
handle.GetTypedIndex(static_cast<typename THandle::Type>(typeValue));
|
||||
if (index < 0) return;
|
||||
if (index < 0) return nullptr;
|
||||
std::lock_guard<TMutex> sync(m_handleMutex);
|
||||
if (index >= static_cast<int>(m_structures.size())) return;
|
||||
if (index >= static_cast<int>(m_structures.size())) return nullptr;
|
||||
auto rv = std::move(m_structures[index]);
|
||||
m_structures[index].reset();
|
||||
return rv;
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
@@ -140,6 +145,15 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::GetAll(
|
||||
return vec;
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
inline std::vector<std::shared_ptr<TStruct>>
|
||||
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::FreeAll() {
|
||||
std::lock_guard<TMutex> sync(m_handleMutex);
|
||||
auto rv = std::move(m_structures);
|
||||
m_structures.clear();
|
||||
return rv;
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
template <typename F>
|
||||
inline void
|
||||
|
||||
Reference in New Issue
Block a user