Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
DataPoint< T > Class Template Reference

Represents data measured using a sensor at a given time. More...

#include <data.h>

Public Member Functions

 DataPoint ()
 Construct an invalid DataPoint, holding no data.
 
 DataPoint (T data)
 Construct a new DataPoint object, measured now.
 
 DataPoint (datatime_t time, T data)
 Construct a new DataPoint object, measured at the given time.
 
 operator bool () const
 Check if this measurement is valid.
 
bool isFresh (std::chrono::milliseconds duration) const
 Check if this measurement was taken recently.
 
bool isValid () const
 Check if this measurement is valid.
 
datatime_t getTime () const
 Get the time at which the measurement was taken.
 
getData () const
 Get the value of this data point.
 
getDataOrElse (T defaultData)
 Get the value of this data point, defaulting to a given value if this data point is invalid.
 
template<typename F>
DataPoint< std::invoke_result_t< F, T > > transform (const F &f)
 Transforms the data in this datapoint by the given function.
 

Detailed Description

template<typename T>
class DataPoint< T >

Represents data measured using a sensor at a given time.

Template Parameters
TThe type of data measured from the sensor.

Constructor & Destructor Documentation

◆ DataPoint() [1/2]

template<typename T>
robot::types::DataPoint< T >::DataPoint ( T data)
inline

Construct a new DataPoint object, measured now.

Parameters
dataThe piece of data

◆ DataPoint() [2/2]

template<typename T>
robot::types::DataPoint< T >::DataPoint ( datatime_t time,
T data )
inline

Construct a new DataPoint object, measured at the given time.

Parameters
timeThe time at which the data was measured.
dataThe piece of data.

Member Function Documentation

◆ getData()

template<typename T>
T robot::types::DataPoint< T >::getData ( ) const
inline

Get the value of this data point.

Returns
T The value of this data point.
Exceptions
bad_datapoint_accessIf this data point is not valid.

◆ getDataOrElse()

template<typename T>
T robot::types::DataPoint< T >::getDataOrElse ( T defaultData)
inline

Get the value of this data point, defaulting to a given value if this data point is invalid.

Parameters
defaultDataThe value to return if this data point is not valid.
Returns
T The value of this data point, or defaultData.

◆ getTime()

template<typename T>
datatime_t robot::types::DataPoint< T >::getTime ( ) const
inline

Get the time at which the measurement was taken.

UB if data point is not valid.

Returns
datatime_t The time at which the measurement was taken.

◆ isFresh()

template<typename T>
bool robot::types::DataPoint< T >::isFresh ( std::chrono::milliseconds duration) const
inline

Check if this measurement was taken recently.

Parameters
durationThe data is fresh if it was taken at most this many milliseconds ago.
Returns
true if the data is valid and was measured at most duration milliseconds ago, false otherwise.

◆ isValid()

template<typename T>
bool robot::types::DataPoint< T >::isValid ( ) const
inline

Check if this measurement is valid.

Returns
bool True iff this data point has a value.

◆ operator bool()

template<typename T>
robot::types::DataPoint< T >::operator bool ( ) const
inline

Check if this measurement is valid.

Equivalent to isValid().

Returns
bool True iff this datapoint has a value.

◆ transform()

template<typename T>
template<typename F>
DataPoint< std::invoke_result_t< F, T > > robot::types::DataPoint< T >::transform ( const F & f)
inline

Transforms the data in this datapoint by the given function.

Template Parameters
FA callable type that accepts T and outputs some other type.
Parameters
fThe function that transforms data.
Returns
DataPoint<std::invoke_result_t<F, T>> A new datapoint that holds the output of f(getData()) and has the same timestamp as this datapoint if it's valid, otherwise an empty datapoint.

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