Ocean
|
This class stores samples of e.g., sensor or tracking data in a map. More...
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 ×tamp) |
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 ×tamp, T &value) const |
Returns the sample with a specific timestamp. More... | |
bool | sample (const double ×tamp, 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... | |
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.
T | The type of the sample to be stored |
typedef std::map<double, T> Ocean::SampleMap< T >::Map |
Definition of a map mapping timestamps to samples.
enum Ocean::SampleMap::InterpolationStrategy |
|
noexcept |
Creates a new map with default capacity.
|
explicitnoexcept |
Creates a new amp with specified capacity.
capacity | The number of samples the new map can store, with range [1, infinity), -1 to create a map without capacity restrictions |
|
noexcept |
Copy constructor.
sampleMap | The map to be copied |
|
noexcept |
Move constructor.
sampleMap | The map to be moved |
|
inline |
Returns the capacity of this map (the number of samples this map can store).
The capacity of this map, with range [1, infinity)
|
inline |
Removes all samples from this map.
SampleMap< T >::Map Ocean::SampleMap< T >::data |
Returns all samples stores in this map.
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.
sample | The new sample to be inserted, must be valid |
timestamp | The timestamp of the sample, must be valid |
|
inline |
Returns whether this map is empty.
|
noexcept |
Copy operator.
sampleMap | The map to be copied |
|
noexcept |
Move operator.
sampleMap | The map to be moved |
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.
timestamp | The timestamp for which a sample will be determined, must be valid |
interpolationStrategy | The interpolation strategy to be applied in case the timestamp does not fit with an existing sample |
value | The resulting sample |
timestampDistance | Optional resulting minimal time distance between the requested timestamp and the sample(s) used to create the resulting value, with range [0, infinity) |
sampleTimestamp | The timestamp of the returning sample; nullptr if not of interest |
bool Ocean::SampleMap< T >::sample | ( | const double & | timestamp, |
T & | value | ||
) | const |
Returns the sample with a specific timestamp.
timestamp | Timestamp of the sample to be returned |
value | The resulting sample with the requested timestamp |
bool Ocean::SampleMap< T >::sample | ( | T & | value, |
double * | sampleTimestamp = nullptr |
||
) | const |
Returns the most recent sample.
value | The resulting sample |
sampleTimestamp | The timestamp of the returning sample; nullptr if not of interest |
std::vector< std::pair< double, T > > Ocean::SampleMap< T >::samples |
Returns all samples stores in this map.
|
inline |
Returns the number of samples currently stored in this map.
|
protected |
The capacity of this map, with range [1, infinity).
|
mutableprotected |
The lock of this map.
|
protected |
The map holding the actual samples.