Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
BS::multi_future< T > Class Template Reference

A helper class to facilitate waiting for and/or getting the results of multiple futures at once. More...

#include <BS_thread_pool.hpp>

Inheritance diagram for BS::multi_future< T >:
Collaboration diagram for BS::multi_future< T >:

Public Member Functions

 multi_future (const multi_future &)=delete
 
multi_futureoperator= (const multi_future &)=delete
 
 multi_future (multi_future &&)=default
 
multi_futureoperator= (multi_future &&)=default
 
std::conditional_t< std::is_void_v< T >, void, std::vector< T > > get ()
 Get the results from all the futures stored in this multi_future, rethrowing any stored exceptions.
 
size_t ready_count () const
 Check how many of the futures stored in this multi_future are ready.
 
bool valid () const
 Check if all the futures stored in this multi_future are valid.
 
void wait () const
 Wait for all the futures stored in this multi_future.
 
template<typename R , typename P >
bool wait_for (const std::chrono::duration< R, P > &duration) const
 Wait for all the futures stored in this multi_future, but stop waiting after the specified duration has passed. This function first waits for the first future for the desired duration. If that future is ready before the duration expires, this function waits for the second future for whatever remains of the duration. It continues similarly until the duration expires.
 
template<typename C , typename D >
bool wait_until (const std::chrono::time_point< C, D > &timeout_time) const
 Wait for all the futures stored in this multi_future, but stop waiting after the specified time point has been reached. This function first waits for the first future until the desired time point. If that future is ready before the time point is reached, this function waits for the second future until the desired time point. It continues similarly until the time point is reached.
 

Detailed Description

template<typename T>
class BS::multi_future< T >

A helper class to facilitate waiting for and/or getting the results of multiple futures at once.

Template Parameters
TThe return type of the futures.

Member Function Documentation

◆ get()

template<typename T >
std::conditional_t< std::is_void_v< T >, void, std::vector< T > > BS::multi_future< T >::get ( )
inline

Get the results from all the futures stored in this multi_future, rethrowing any stored exceptions.

Returns
If the futures return void, this function returns void as well. Otherwise, it returns a vector containing the results.
188 {
189 if constexpr (std::is_void_v<T>)
190 {
191 for (std::future<T>& future : *this)
192 future.get();
193 return;
194 }
195 else
196 {
197 std::vector<T> results;
198 results.reserve(this->size());
199 for (std::future<T>& future : *this)
200 results.push_back(future.get());
201 return results;
202 }
203 }
std::conditional_t< std::is_void_v< T >, void, std::vector< T > > get()
Get the results from all the futures stored in this multi_future, rethrowing any stored exceptions.
Definition BS_thread_pool.hpp:187
GOpaque< Size > size(const GMat &src)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ready_count()

template<typename T >
size_t BS::multi_future< T >::ready_count ( ) const
inline

Check how many of the futures stored in this multi_future are ready.

Returns
The number of ready futures.
211 {
212 size_t count = 0;
213 for (const std::future<T>& future : *this)
214 {
215 if (future.wait_for(std::chrono::duration<double>::zero()) == std::future_status::ready)
216 ++count;
217 }
218 return count;
219 }

◆ valid()

template<typename T >
bool BS::multi_future< T >::valid ( ) const
inline

Check if all the futures stored in this multi_future are valid.

Returns
true if all futures are valid, false if at least one of the futures is not valid.
227 {
228 bool is_valid = true;
229 for (const std::future<T>& future : *this)
230 is_valid = is_valid && future.valid();
231 return is_valid;
232 }
bool valid() const
Check if all the futures stored in this multi_future are valid.
Definition BS_thread_pool.hpp:226

◆ wait()

template<typename T >
void BS::multi_future< T >::wait ( ) const
inline

Wait for all the futures stored in this multi_future.

238 {
239 for (const std::future<T>& future : *this)
240 future.wait();
241 }
void wait() const
Wait for all the futures stored in this multi_future.
Definition BS_thread_pool.hpp:237

◆ wait_for()

template<typename T >
template<typename R , typename P >
bool BS::multi_future< T >::wait_for ( const std::chrono::duration< R, P > &  duration) const
inline

Wait for all the futures stored in this multi_future, but stop waiting after the specified duration has passed. This function first waits for the first future for the desired duration. If that future is ready before the duration expires, this function waits for the second future for whatever remains of the duration. It continues similarly until the duration expires.

Template Parameters
RAn arithmetic type representing the number of ticks to wait.
PAn std::ratio representing the length of each tick in seconds.
Parameters
durationThe amount of time to wait.
Returns
true if all futures have been waited for before the duration expired, false otherwise.
253 {
254 const std::chrono::time_point<std::chrono::steady_clock> start_time = std::chrono::steady_clock::now();
255 for (const std::future<T>& future : *this)
256 {
257 future.wait_for(duration - (std::chrono::steady_clock::now() - start_time));
258 if (duration < std::chrono::steady_clock::now() - start_time)
259 return false;
260 }
261 return true;
262 }

◆ wait_until()

template<typename T >
template<typename C , typename D >
bool BS::multi_future< T >::wait_until ( const std::chrono::time_point< C, D > &  timeout_time) const
inline

Wait for all the futures stored in this multi_future, but stop waiting after the specified time point has been reached. This function first waits for the first future until the desired time point. If that future is ready before the time point is reached, this function waits for the second future until the desired time point. It continues similarly until the time point is reached.

Template Parameters
CThe type of the clock used to measure time.
DAn std::chrono::duration type used to indicate the time point.
Parameters
timeout_timeThe time point at which to stop waiting.
Returns
true if all futures have been waited for before the time point was reached, false otherwise.
274 {
275 for (const std::future<T>& future : *this)
276 {
277 future.wait_until(timeout_time);
278 if (timeout_time < std::chrono::steady_clock::now())
279 return false;
280 }
281 return true;
282 }

The documentation for this class was generated from the following file: