10 #ifndef __FRC_ROBORIO__
14 #include <wpi/SmallVector.h>
16 #include "NotifyListener.h"
22 template <
typename ListenerType>
24 struct private_init {};
42 unsigned int* newUid) {
43 *newUid = emplace_back_impl(param, callback);
46 size_type size()
const {
return m_vector.size(); }
58 std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>> emplace_back(
59 void* param, ListenerType callback,
unsigned int* newUid);
63 std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>> erase(
74 unsigned int emplace_back_impl(
void* param, ListenerType callback);
78 void erase_impl(
unsigned int uid);
81 template <
typename ListenerType>
85 : m_vector(copyFrom->m_vector), m_free(copyFrom->m_free) {}
87 template <
typename ListenerType>
88 std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>>
89 HalCallbackListenerVectorImpl<ListenerType>::emplace_back(
90 void* param, ListenerType callback,
unsigned int* newUid) {
92 std::make_shared<HalCallbackListenerVectorImpl<ListenerType>>(
93 this, private_init());
94 newVector->m_vector = m_vector;
95 newVector->m_free = m_free;
96 *newUid = newVector->emplace_back_impl(param, callback);
100 template <
typename ListenerType>
101 std::shared_ptr<HalCallbackListenerVectorImpl<ListenerType>>
102 HalCallbackListenerVectorImpl<ListenerType>::erase(
unsigned int uid) {
104 std::make_shared<HalCallbackListenerVectorImpl<ListenerType>>(
105 this, private_init());
106 newVector->m_vector = m_vector;
107 newVector->m_free = m_free;
108 newVector->erase_impl(uid);
112 template <
typename ListenerType>
113 unsigned int HalCallbackListenerVectorImpl<ListenerType>::emplace_back_impl(
114 void* param, ListenerType callback) {
116 if (m_free.empty()) {
117 uid = m_vector.size();
118 m_vector.emplace_back(param, callback);
122 m_vector[uid] = HalCallbackListener<ListenerType>(param, callback);
127 template <
typename ListenerType>
128 void HalCallbackListenerVectorImpl<ListenerType>::erase_impl(
unsigned int uid) {
130 if (uid >= m_vector.size() || !m_vector[uid])
return;
131 m_free.push_back(uid);
132 m_vector[uid] = HalCallbackListener<ListenerType>();
135 typedef HalCallbackListenerVectorImpl<HAL_NotifyCallback> NotifyListenerVector;
136 typedef HalCallbackListenerVectorImpl<HAL_BufferCallback> BufferListenerVector;
137 typedef HalCallbackListenerVectorImpl<HAL_ConstBufferCallback>
138 ConstBufferListenerVector;
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: hostname.h:17
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:868
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: NotifyListenerVector.h:18
Definition: NotifyListenerVector.h:23
Definition: NotifyListener.h:27