8#ifndef META_OCEAN_DEVICES_MEASUREMENT_H
9#define META_OCEAN_DEVICES_MEASUREMENT_H
61 using Metadata = std::unordered_map<std::string, Value>;
76 inline const Timestamp& timestamp()
const;
82 inline const Timestamp& relativeTimestamp()
const;
88 inline const ObjectIds& objectIds()
const;
94 inline const Metadata& metadata()
const;
100 inline void setRelativeTimestamp(
const Timestamp& relativeTimestamp);
162 IS_TIMESTAMP_INTERPOLATE
193 inline void makeWeak();
204 explicit inline operator bool()
const;
252 template <
typename TInternalId>
279 bool hasInternalObject(
const TInternalId& internalObjectId)
const;
294 ObjectId newInternalObjectId(
const TInternalId& internalObjectId,
const std::string& description);
300 void removeInternalObject(
const TInternalId& internalObjectId);
307 ObjectId externalObjectIdFromInternalObjectId(
const TInternalId& internalObjectId)
const;
315 TInternalId internalObjectIdFromExternalObjectId(
const ObjectId externalObjectId,
const TInternalId& invalidInternalId)
const;
366 inline size_t sampleCapacity()
const;
432 static constexpr ObjectId invalidObjectId();
503 return relativeTimestamp_;
518 ocean_assert(!relativeTimestamp_.isValid());
519 relativeTimestamp_ = relativeTimestamp;
522template <
typename TInternalId>
529template <
typename TInternalId>
532 return internalObjectIdMap_.find(internalObjectId) != internalObjectIdMap_.cend();
535template <
typename TInternalId>
540 return externalObjectIdMap_.find(externalObjectId) != externalObjectIdMap_.cend();
543template <
typename TInternalId>
546 const ObjectId externalObjectId = owner_.addUniqueObjectId(description);
548 internalObjectIdMap_.emplace(internalObjectId, externalObjectId);
549 externalObjectIdMap_.emplace(externalObjectId, internalObjectId);
551 return externalObjectId;
554template <
typename TInternalId>
557 const ObjectId externalObjectId = externalObjectIdFromInternalObjectId(internalObjectId);
559 internalObjectIdMap_.erase(internalObjectId);
560 externalObjectIdMap_.erase(externalObjectId);
563template <
typename TInternalId>
566 const typename InternalObjectIdMap::const_iterator i = internalObjectIdMap_.find(internalObjectId);
568 if (i == internalObjectIdMap_.cend())
570 ocean_assert(
false &&
"This must never happen!");
577template <
typename TInternalId>
580 const typename ExternalObjectIdMap::const_iterator i = externalObjectIdMap_.find(externalObjectId);
582 if (i == externalObjectIdMap_.cend())
584 ocean_assert(
false &&
"This must never happen!");
585 return invalidInternalId;
593 *
this = std::move(sampleEventSubscription);
603 measurement_.release();
606inline Measurement::SampleEventSubscription::operator bool()
const
608 return weakMeasurement_ !=
nullptr;
This class implements a container for callback functions.
Definition Callback.h:3456
Definition of a class holding the major and minor device type.
Definition devices/Device.h:62
This class is the base class for all devices of any type.
Definition devices/Device.h:28
unsigned int SubscriptionId
Definition of a subscription id for event callbacks.
Definition devices/Device.h:151
This class implements a helper class to simplify the mapping between internal object ids (of the actu...
Definition Measurement.h:254
InternalObjectIdMap internalObjectIdMap_
The map mapping internal object ids to external object ids.
Definition Measurement.h:338
ObjectMapper & operator=(const ObjectMapper &objectMapper)=delete
Disabled copy operator.
ObjectId newInternalObjectId(const TInternalId &internalObjectId, const std::string &description)
Adds a new internal pattern id.
Definition Measurement.h:544
bool hasExternalObject(const Measurement::ObjectId &externalObjectId) const
Returns whether this mapping object holds a specific external object.
Definition Measurement.h:536
ObjectMapper(Measurement &owner)
Default constructor.
Definition Measurement.h:523
std::unordered_map< TInternalId, ObjectId > InternalObjectIdMap
Definition of an unordered map mapping internal object ids to external object ids.
Definition Measurement.h:260
ObjectMapper(const ObjectMapper &objectMapper)=delete
Disabled copy constructor.
bool hasInternalObject(const TInternalId &internalObjectId) const
Returns whether this mapping object holds a specific internal object.
Definition Measurement.h:530
ObjectId externalObjectIdFromInternalObjectId(const TInternalId &internalObjectId) const
Converts the tracker's internal object id to an external object id.
Definition Measurement.h:564
TInternalId internalObjectIdFromExternalObjectId(const ObjectId externalObjectId, const TInternalId &invalidInternalId) const
Converts an external object id to the tracker tracker's internal object id.
Definition Measurement.h:578
ExternalObjectIdMap externalObjectIdMap_
The map mapping external object ids to internal object ids.
Definition Measurement.h:341
void removeInternalObject(const TInternalId &internalObjectId)
Removes a mapping between internal and external object.
Definition Measurement.h:555
std::unordered_map< ObjectId, TInternalId > ExternalObjectIdMap
Definition of an unordered map mapping external object ids to internal object ids.
Definition Measurement.h:265
Measurement & owner_
The owner of this mapper.
Definition Measurement.h:335
This class manages the lifetime of an event subscription for sample events.
Definition Measurement.h:169
SampleEventSubscription & operator=(const SampleEventSubscription &sampleEventSubscription)=delete
Disabled assign operator.
void release()
Explicitly releases the subscription.
SampleEventSubscription & operator=(SampleEventSubscription &&sampleEventSubscription)
Replaces the current event subscription with a new event subscription.
void makeWeak()
Makes this subscription object weak so that is does not hold a reference to the actual measurement ob...
Definition Measurement.h:601
~SampleEventSubscription()
Destructs the subscription object and unsubscribes the object event.
Definition Measurement.h:596
MeasurementRef measurement_
The measurement object to which the event subscription belongs.
Definition Measurement.h:232
SampleEventSubscription()=default
Default constructor for a not active subscription.
SampleEventSubscription(const Measurement &measurement, const SubscriptionId subscriptionId)
Creates an active subscription object.
Definition of a sample holding a measurement.
Definition Measurement.h:67
virtual ~Sample()
Destructs a sample.
const ObjectIds & objectIds() const
Returns the sample object ids specifying possible different measurement units.
Definition Measurement.h:506
Timestamp relativeTimestamp_
The relative sample timestamp.
Definition Measurement.h:131
ObjectIds objectIds_
Measurement unit object ids.
Definition Measurement.h:134
Metadata metadata_
The metadata of this sample.
Definition Measurement.h:137
void setRelativeTimestamp(const Timestamp &relativeTimestamp)
Sets the relative timestamp of this sample.
Definition Measurement.h:516
const Timestamp & relativeTimestamp() const
Returns the relative timestamp of this sample.
Definition Measurement.h:501
const Metadata & metadata() const
Returns the metadata of this sample.
Definition Measurement.h:511
Sample(const Timestamp ×tamp, ObjectIds &&objectIds, Metadata &&metadata=Metadata())
Creates a new measurement sample.
const Timestamp & timestamp() const
Returns the sample timestamp.
Definition Measurement.h:496
Sample(const Timestamp ×tamp, const ObjectIds &objectIds, const Metadata &metadata=Metadata())
Creates a new measurement sample.
Timestamp timestamp_
The sample timestamp.
Definition Measurement.h:128
This class implements the base class for all devices providing measurement samples.
Definition Measurement.h:40
ObjectId objectId(const std::string &description) const
Returns the object id for an object description.
SampleEventSubscription subscribeSampleEvent(SampleCallback &&callback)
Subscribes a callback event function for new measurement sample events.
void postNewSample(const SampleRef &newSample)
Posts a new measurement sample.
virtual SampleRef sample() const
Returns the most recent sample.
static constexpr ObjectId invalidObjectId()
Returns an invalid object id.
Definition Measurement.h:618
Strings objectDescriptions() const
Returns descriptions of all objects currently available.
ObjectId addUniqueObjectId(const std::string &description)
Creates a unique object id for a new object (e.g., a tracking object like an image,...
SampleSubscriptionMap sampleSubscriptionMap_
Map holding all sample event subscriptions.
Definition Measurement.h:484
std::unordered_map< SubscriptionId, SampleCallback > SampleSubscriptionMap
Definition of a map mapping subscription ids to event sample callback functions.
Definition Measurement.h:357
unsigned int ObjectId
Definition of an object id.
Definition Measurement.h:46
virtual SampleRef sample(const Timestamp timestamp) const
Returns the sample with a specific timestamp.
std::unordered_set< ObjectId > ObjectIdSet
Definition of an unordered set holding object ids.
Definition Measurement.h:56
std::vector< ObjectId > ObjectIds
Definition of a vector holding object ids.
Definition Measurement.h:51
SampleMap sampleMap_
The most recent measurement samples.
Definition Measurement.h:478
InterpolationStrategy
Definition of individual interpolation strategies for samples.
Definition Measurement.h:156
@ IS_INVALID
An invalid strategy.
Definition Measurement.h:158
@ IS_TIMESTAMP_NEAREST
The sample with nearest/closest timestamp is used.
Definition Measurement.h:160
virtual SampleRef sample(const Timestamp ×tamp, const InterpolationStrategy interpolationStrategy) const
Returns the sample best matching with a specified timestamp.
std::unordered_map< std::string, ObjectId > ObjectDescriptionToIdMap
Definition of an unordered map mapping descriptions to unique object ids.
Definition Measurement.h:347
size_t sampleCapacity() const
Returns the capacity of the internal sample container.
Definition Measurement.h:611
std::unordered_map< ObjectId, std::string > ObjectIdToDescriptionMap
Definition of an unordered map mapping unique object ids to descriptions.
Definition Measurement.h:352
ObjectDescriptionToIdMap objectDescriptionToIdMap_
The map mapping object descriptions to object ids.
Definition Measurement.h:490
Lock samplesLock_
Sample lock.
Definition Measurement.h:470
void unsubscribeSampleEvent(const SubscriptionId subscriptionId)
Unsubscribes a sample event callback function.
size_t sampleCapacity_
The maximal number of samples this measurement object can hold.
Definition Measurement.h:481
~Measurement() override
Destructs a measurement object.
bool setSampleCapacity(const size_t capacity)
Sets the capacity of the internal sample container.
std::unordered_map< std::string, Value > Metadata
Definition of an unordered map mapping keys to values.
Definition Measurement.h:61
std::string objectDescription(const ObjectId objectId) const
Returns the description of one object of this measurement.
ObjectIdToDescriptionMap objectIdToDescriptionMap_
The map mapping object ids to descriptions.
Definition Measurement.h:493
Measurement(const std::string &name, const DeviceType type)
Creates a new measurement object.
Lock subscriptionLock_
Subscription lock.
Definition Measurement.h:473
std::map< Timestamp, SampleRef > SampleMap
Definition of a map holding the most recent samples.
Definition Measurement.h:246
This class implements a recursive lock object.
Definition Lock.h:31
This template class implements a object reference with an internal reference counter.
Definition base/ObjectRef.h:58
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:135
This class implements a timestamp.
Definition Timestamp.h:43
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition Base.h:162
The namespace covering the entire Ocean framework.
Definition Accessor.h:15