Ocean
Ocean::SampleMap< T > Class Template Reference

This class stores samples of e.g., sensor or tracking data in a map. More...

Inheritance diagram for Ocean::SampleMap< T >:

Public Types

enum  InterpolationStrategy { IS_INVALID , IS_TIMESTAMP_NEAREST , IS_TIMESTAMP_INTERPOLATE }
 Definition of individual interpolation strategies for samples. More...
 
typedef std::map< double, T > Map
 Definition of a map mapping timestamps to samples. More...
 

Public Member Functions

 SampleMap () noexcept
 Creates a new map with default capacity. More...
 
 SampleMap (const size_t capacity) noexcept
 Creates a new amp with specified capacity. More...
 
 SampleMap (const SampleMap &sampleMap) noexcept
 Copy constructor. More...
 
 SampleMap (SampleMap &&sampleMap) noexcept
 Move constructor. More...
 
void insert (const T &sample, const double &timestamp)
 Inserts a new sample with corresponding timestamp. More...
 
bool sample (T &value, double *sampleTimestamp=nullptr) const
 Returns the most recent sample. More...
 
bool sample (const double &timestamp, T &value) const
 Returns the sample with a specific timestamp. More...
 
bool sample (const double &timestamp, const InterpolationStrategy interpolationStrategy, T &value, double *timestampDistance=nullptr, double *sampleTimestamp=nullptr) const
 Returns the sample best matching with a specified timestamp. More...
 
std::vector< std::pair< double, T > > samples () const
 Returns all samples stores in this map. More...
 
Map data () const
 Returns all samples stores in this map. More...
 
size_t size () const
 Returns the number of samples currently stored in this map. More...
 
size_t capacity () const
 Returns the capacity of this map (the number of samples this map can store). More...
 
bool isEmpty () const
 Returns whether this map is empty. More...
 
void clear ()
 Removes all samples from this map. More...
 
SampleMap< T > & operator= (const SampleMap< T > &sampleMap) noexcept
 Copy operator. More...
 
SampleMap< T > & operator= (SampleMap< T > &&sampleMap) noexcept
 Move operator. More...
 

Protected Attributes

Map map_
 The map holding the actual samples. More...
 
size_t capacity_
 The capacity of this map, with range [1, infinity). More...
 
Lock lock_
 The lock of this map. More...
 

Detailed Description

template<typename T>
class Ocean::SampleMap< T >

This class stores samples of e.g., sensor or tracking data in a map.

Samples are stored in a round robin method.
Whenever the map does not have an empty spot left, the oldest sample will be replaced by the newest sample.
The implementation is thread-safe.

Template Parameters
TThe type of the sample to be stored

Member Typedef Documentation

◆ Map

template<typename T >
typedef std::map<double, T> Ocean::SampleMap< T >::Map

Definition of a map mapping timestamps to samples.

Member Enumeration Documentation

◆ InterpolationStrategy

template<typename T >
enum Ocean::SampleMap::InterpolationStrategy

Definition of individual interpolation strategies for samples.

Enumerator
IS_INVALID 

An invalid strategy.

IS_TIMESTAMP_NEAREST 

The sample with nearest/closest timestamp is used.

IS_TIMESTAMP_INTERPOLATE 

The sample is interpolated based on two samples.

Constructor & Destructor Documentation

◆ SampleMap() [1/4]

template<typename T >
Ocean::SampleMap< T >::SampleMap
noexcept

Creates a new map with default capacity.

◆ SampleMap() [2/4]

template<typename T >
Ocean::SampleMap< T >::SampleMap ( const size_t  capacity)
explicitnoexcept

Creates a new amp with specified capacity.

Parameters
capacityThe number of samples the new map can store, with range [1, infinity), -1 to create a map without capacity restrictions

◆ SampleMap() [3/4]

template<typename T >
Ocean::SampleMap< T >::SampleMap ( const SampleMap< T > &  sampleMap)
noexcept

Copy constructor.

Parameters
sampleMapThe map to be copied

◆ SampleMap() [4/4]

template<typename T >
Ocean::SampleMap< T >::SampleMap ( SampleMap< T > &&  sampleMap)
noexcept

Move constructor.

Parameters
sampleMapThe map to be moved

Member Function Documentation

◆ capacity()

template<typename T >
size_t Ocean::SampleMap< T >::capacity
inline

Returns the capacity of this map (the number of samples this map can store).

The capacity of this map, with range [1, infinity)

◆ clear()

template<typename T >
void Ocean::SampleMap< T >::clear
inline

Removes all samples from this map.

◆ data()

template<typename T >
SampleMap< T >::Map Ocean::SampleMap< T >::data

Returns all samples stores in this map.

Returns
All samples as a standard map

◆ insert()

template<typename T >
void Ocean::SampleMap< T >::insert ( const T &  sample,
const double &  timestamp 
)

Inserts a new sample with corresponding timestamp.

In case, a sample with same timestamp exists already, the given sample will replace the existing sample.
In case, the map does not have an empty spot left, the oldest sample will be replaced by the given sample.

Parameters
sampleThe new sample to be inserted, must be valid
timestampThe timestamp of the sample, must be valid

◆ isEmpty()

template<typename T >
bool Ocean::SampleMap< T >::isEmpty
inline

Returns whether this map is empty.

Returns
True, if so

◆ operator=() [1/2]

template<typename T >
SampleMap< T > & Ocean::SampleMap< T >::operator= ( const SampleMap< T > &  sampleMap)
noexcept

Copy operator.

Parameters
sampleMapThe map to be copied
Returns
Reference to this object

◆ operator=() [2/2]

template<typename T >
SampleMap< T > & Ocean::SampleMap< T >::operator= ( SampleMap< T > &&  sampleMap)
noexcept

Move operator.

Parameters
sampleMapThe map to be moved
Returns
Reference to this object

◆ sample() [1/3]

template<typename T >
bool Ocean::SampleMap< T >::sample ( const double &  timestamp,
const InterpolationStrategy  interpolationStrategy,
T &  value,
double *  timestampDistance = nullptr,
double *  sampleTimestamp = nullptr 
) const

Returns the sample best matching with a specified timestamp.

In case, the given timestamp does not fit to an existing sample, the resulting sample will be based on the specified interpolation strategy.

Parameters
timestampThe timestamp for which a sample will be determined, must be valid
interpolationStrategyThe interpolation strategy to be applied in case the timestamp does not fit with an existing sample
valueThe resulting sample
timestampDistanceOptional resulting minimal time distance between the requested timestamp and the sample(s) used to create the resulting value, with range [0, infinity)
sampleTimestampThe timestamp of the returning sample; nullptr if not of interest
Returns
True, if a sample could be determined

◆ sample() [2/3]

template<typename T >
bool Ocean::SampleMap< T >::sample ( const double &  timestamp,
T &  value 
) const

Returns the sample with a specific timestamp.

Parameters
timestampTimestamp of the sample to be returned
valueThe resulting sample with the requested timestamp
Returns
True, if succeeded (if a sample with the timestamp existed)

◆ sample() [3/3]

template<typename T >
bool Ocean::SampleMap< T >::sample ( T &  value,
double *  sampleTimestamp = nullptr 
) const

Returns the most recent sample.

Parameters
valueThe resulting sample
sampleTimestampThe timestamp of the returning sample; nullptr if not of interest
Returns
True, if succeeded

◆ samples()

template<typename T >
std::vector< std::pair< double, T > > Ocean::SampleMap< T >::samples

Returns all samples stores in this map.

Returns
All samples as vector of pairs

◆ size()

template<typename T >
size_t Ocean::SampleMap< T >::size
inline

Returns the number of samples currently stored in this map.

Returns
The map's samples, with range [0, capacity()]

Field Documentation

◆ capacity_

template<typename T >
size_t Ocean::SampleMap< T >::capacity_
protected

The capacity of this map, with range [1, infinity).

◆ lock_

template<typename T >
Lock Ocean::SampleMap< T >::lock_
mutableprotected

The lock of this map.

◆ map_

template<typename T >
Map Ocean::SampleMap< T >::map_
protected

The map holding the actual samples.


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