8 #ifndef META_OCEAN_DEVICES_MEASUREMENT_H
9 #define META_OCEAN_DEVICES_MEASUREMENT_H
61 typedef std::unordered_map<std::string, Value>
Metadata;
76 inline const Timestamp& timestamp()
const;
82 inline const ObjectIds& objectIds()
const;
88 inline const Metadata& metadata()
const;
147 IS_TIMESTAMP_INTERPOLATE
178 inline void makeWeak();
189 explicit inline operator bool()
const;
237 template <
typename TInternalId>
264 bool hasInternalObject(
const TInternalId& internalObjectId)
const;
279 ObjectId newInternalObjectId(
const TInternalId& internalObjectId,
const std::string& description);
285 void removeInternalObject(
const TInternalId& internalObjectId);
292 ObjectId externalObjectIdFromInternalObjectId(
const TInternalId& internalObjectId)
const;
300 TInternalId internalObjectIdFromExternalObjectId(
const ObjectId externalObjectId,
const TInternalId& invalidInternalId)
const;
351 inline size_t sampleCapacity()
const;
496 template <
typename TInternalId>
503 template <
typename TInternalId>
506 return internalObjectIdMap_.find(internalObjectId) != internalObjectIdMap_.cend();
509 template <
typename TInternalId>
514 return externalObjectIdMap_.find(externalObjectId) != externalObjectIdMap_.cend();
517 template <
typename TInternalId>
520 const ObjectId externalObjectId = owner_.addUniqueObjectId(description);
522 internalObjectIdMap_.emplace(internalObjectId, externalObjectId);
523 externalObjectIdMap_.emplace(externalObjectId, internalObjectId);
525 return externalObjectId;
528 template <
typename TInternalId>
531 const ObjectId externalObjectId = externalObjectIdFromInternalObjectId(internalObjectId);
533 internalObjectIdMap_.erase(internalObjectId);
534 externalObjectIdMap_.erase(externalObjectId);
537 template <
typename TInternalId>
540 const typename InternalObjectIdMap::const_iterator i = internalObjectIdMap_.find(internalObjectId);
542 if (i == internalObjectIdMap_.cend())
544 ocean_assert(
false &&
"This must never happen!");
551 template <
typename TInternalId>
554 const typename ExternalObjectIdMap::const_iterator i = externalObjectIdMap_.find(externalObjectId);
556 if (i == externalObjectIdMap_.cend())
558 ocean_assert(
false &&
"This must never happen!");
559 return invalidInternalId;
567 *
this = std::move(sampleEventSubscription);
577 measurement_.release();
580 inline Measurement::SampleEventSubscription::operator bool()
const
582 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:239
InternalObjectIdMap internalObjectIdMap_
The map mapping internal object ids to external object ids.
Definition: Measurement.h:323
ObjectId newInternalObjectId(const TInternalId &internalObjectId, const std::string &description)
Adds a new internal pattern id.
Definition: Measurement.h:518
bool hasExternalObject(const Measurement::ObjectId &externalObjectId) const
Returns whether this mapping object holds a specific external object.
Definition: Measurement.h:510
ObjectMapper(Measurement &owner)
Default constructor.
Definition: Measurement.h:497
ObjectMapper(const ObjectMapper &objectMapper)=delete
Disabled copy constructor.
std::unordered_map< ObjectId, TInternalId > ExternalObjectIdMap
Definition of an unordered map mapping external object ids to internal object ids.
Definition: Measurement.h:250
bool hasInternalObject(const TInternalId &internalObjectId) const
Returns whether this mapping object holds a specific internal object.
Definition: Measurement.h:504
ObjectId externalObjectIdFromInternalObjectId(const TInternalId &internalObjectId) const
Converts the tracker's internal object id to an external object id.
Definition: Measurement.h:538
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:552
ExternalObjectIdMap externalObjectIdMap_
The map mapping external object ids to internal object ids.
Definition: Measurement.h:326
std::unordered_map< TInternalId, ObjectId > InternalObjectIdMap
Definition of an unordered map mapping internal object ids to external object ids.
Definition: Measurement.h:245
void removeInternalObject(const TInternalId &internalObjectId)
Removes a mapping between internal and external object.
Definition: Measurement.h:529
ObjectMapper & operator=(const ObjectMapper &objectMapper)=delete
Disabled copy operator.
Measurement & owner_
The owner of this mapper.
Definition: Measurement.h:320
This class manages the lifetime of an event subscription for sample events.
Definition: Measurement.h:154
SampleEventSubscription & operator=(const SampleEventSubscription &sampleEventSubscription)=delete
Disabled assign operator.
void release()
Explicitly releases the subscription.
void makeWeak()
Makes this subscription object weak so that is does not hold a reference to the actual measurement ob...
Definition: Measurement.h:575
~SampleEventSubscription()
Destructs the subscription object and unsubscribes the object event.
Definition: Measurement.h:570
MeasurementRef measurement_
The measurement object to which the event subscription belongs.
Definition: Measurement.h:217
SampleEventSubscription()=default
Default constructor for a not active subscription.
SampleEventSubscription & operator=(SampleEventSubscription &&sampleEventSubscription)
Replaces the current event subscription with a new event 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:486
ObjectIds objectIds_
Measurement unit object ids.
Definition: Measurement.h:119
Metadata metadata_
The metadata of this sample.
Definition: Measurement.h:122
const Metadata & metadata() const
Returns the metadata of this sample.
Definition: Measurement.h:491
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:481
Sample(const Timestamp ×tamp, const ObjectIds &objectIds, const Metadata &metadata=Metadata())
Creates a new measurement sample.
Timestamp timestamp_
Sample timestamp.
Definition: Measurement.h:116
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.
unsigned int ObjectId
Definition of an object id.
Definition: Measurement.h:46
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:592
std::unordered_map< std::string, Value > Metadata
Definition of an unordered map mapping keys to values.
Definition: Measurement.h:61
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,...
std::unordered_set< ObjectId > ObjectIdSet
Definition of an unordered set holding object ids.
Definition: Measurement.h:56
SampleSubscriptionMap sampleSubscriptionMap_
Map holding all sample event subscriptions.
Definition: Measurement.h:469
virtual SampleRef sample(const Timestamp timestamp) const
Returns the sample with a specific timestamp.
SampleMap sampleMap_
The most recent measurement samples.
Definition: Measurement.h:463
InterpolationStrategy
Definition of individual interpolation strategies for samples.
Definition: Measurement.h:141
@ IS_INVALID
An invalid strategy.
Definition: Measurement.h:143
@ IS_TIMESTAMP_NEAREST
The sample with nearest/closest timestamp is used.
Definition: Measurement.h:145
virtual SampleRef sample(const Timestamp ×tamp, const InterpolationStrategy interpolationStrategy) const
Returns the sample best matching with a specified timestamp.
size_t sampleCapacity() const
Returns the capacity of the internal sample container.
Definition: Measurement.h:585
Callback< void, const Measurement *, const SampleRef & > SampleCallback
Definition of a callback function to subscribe for new measurement sample events.
Definition: Measurement.h:135
std::unordered_map< SubscriptionId, SampleCallback > SampleSubscriptionMap
Definition of a map mapping subscription ids to event sample callback functions.
Definition: Measurement.h:342
std::map< Timestamp, SampleRef > SampleMap
Definition of a map holding the most recent samples.
Definition: Measurement.h:231
std::vector< ObjectId > ObjectIds
Definition of a vector holding object ids.
Definition: Measurement.h:51
ObjectDescriptionToIdMap objectDescriptionToIdMap_
The map mapping object descriptions to object ids.
Definition: Measurement.h:475
ObjectRef< Sample > SampleRef
Definition of an object reference for samples.
Definition: Measurement.h:128
Lock samplesLock_
Sample lock.
Definition: Measurement.h:455
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:466
~Measurement() override
Destructs a measurement object.
bool setSampleCapacity(const size_t capacity)
Sets the capacity of the internal sample container.
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:478
Measurement(const std::string &name, const DeviceType type)
Creates a new measurement object.
Lock subscriptionLock_
Subscription lock.
Definition: Measurement.h:458
std::unordered_map< std::string, ObjectId > ObjectDescriptionToIdMap
Definition of an unordered map mapping descriptions to unique object ids.
Definition: Measurement.h:332
std::unordered_map< ObjectId, std::string > ObjectIdToDescriptionMap
Definition of an unordered map mapping unique object ids to descriptions.
Definition: Measurement.h:337
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:36
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition: Base.h:162
SmartDeviceRef< Measurement > MeasurementRef
Definition of a smart object reference for a measurement.
Definition: Measurement.h:24
const ObjectId invalidObjectId
Definition of an invalid object id.
Definition: rendering/Rendering.h:65
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15