EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
eduart::device::DeviceGroup Class Reference

Holds a set of IDevice pointers and provides type-filtered access and iteration. More...

#include <DeviceGroup.hpp>

Public Member Functions

 DeviceGroup (std::vector< device::IDevice * > devices)
 Constructs a group from the given device pointers.
 ~DeviceGroup ()=default
 Destructor.
std::vector< device::IDevice * > getDevices () const
 Returns all devices in the group.
unsigned int getDeviceCount () const
 Returns the number of devices in the group.
void invokeForEachDevice (std::function< void(device::IDevice *)> callback) const
 Invokes callback once per device in the group.
template<typename T>
std::vector< T * > getDevicesOfType () const
 Returns devices that are of type T (dynamic_cast).
template<typename T>
void invokeForEachDeviceOfType (std::function< void(T *)> callback) const
 Invokes callback for each device that is of type T.

Static Public Member Functions

template<typename Response, typename Predicate>
static bool waitForAll (std::vector< std::future< Response > > &futures, std::chrono::steady_clock::duration timeout, Predicate &&success_predicate) noexcept
 Waits until all futures are ready within the given timeout, then checks each result with a predicate.
template<typename T>
static DeviceGroup createFromDevicesOfType (std::vector< device::IDevice * > devices)
 Builds a DeviceGroup containing only devices of type T from the given list.

Detailed Description

Holds a set of IDevice pointers and provides type-filtered access and iteration.

Constructor & Destructor Documentation

◆ DeviceGroup()

eduart::device::DeviceGroup::DeviceGroup ( std::vector< device::IDevice * > devices)

Constructs a group from the given device pointers.

Parameters
[in]devicesPointers to devices to include in the group.

Member Function Documentation

◆ createFromDevicesOfType()

template<typename T>
DeviceGroup eduart::device::DeviceGroup::createFromDevicesOfType ( std::vector< device::IDevice * > devices)
static

Builds a DeviceGroup containing only devices of type T from the given list.

Template Parameters
TDevice type derived from IDevice.
Parameters
[in]devicesSource device list to filter.
Returns
DeviceGroup containing only the T* devices from devices.

◆ getDeviceCount()

unsigned int eduart::device::DeviceGroup::getDeviceCount ( ) const

Returns the number of devices in the group.

Returns
Number of devices in the group.

◆ getDevices()

std::vector< device::IDevice * > eduart::device::DeviceGroup::getDevices ( ) const

Returns all devices in the group.

Returns
Vector of IDevice pointers (order preserved).

◆ getDevicesOfType()

template<typename T>
std::vector< T * > eduart::device::DeviceGroup::getDevicesOfType ( ) const

Returns devices that are of type T (dynamic_cast).

Template Parameters
TDevice type derived from IDevice.
Returns
Vector of T* for devices that support the cast.

◆ invokeForEachDevice()

void eduart::device::DeviceGroup::invokeForEachDevice ( std::function< void(device::IDevice *)> callback) const

Invokes callback once per device in the group.

Parameters
[in]callbackCallable invoked with each device pointer.

◆ invokeForEachDeviceOfType()

template<typename T>
void eduart::device::DeviceGroup::invokeForEachDeviceOfType ( std::function< void(T *)> callback) const

Invokes callback for each device that is of type T.

Template Parameters
TDevice type derived from IDevice.
Parameters
[in]callbackCallable invoked with each T*.

◆ waitForAll()

template<typename Response, typename Predicate>
bool eduart::device::DeviceGroup::waitForAll ( std::vector< std::future< Response > > & futures,
std::chrono::steady_clock::duration timeout,
Predicate && success_predicate )
staticnoexcept

Waits until all futures are ready within the given timeout, then checks each result with a predicate.

Template Parameters
ResponseType of the future result.
PredicateCallable with signature bool(const Response&); if it returns false for any result, this returns false.
Parameters
[in,out]futuresVector of futures to wait on (will be moved-from / consumed).
[in]timeoutMaximum time to wait.
[in]success_predicateCalled once per future result; all must return true for this to return true.
Returns
true if all futures became ready within the timeout and the predicate returned true for every result; false otherwise.

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