55#ifndef ESP_SENSOR_MANAGEDSENSORBASE_H_
66#define ESP_SENSOR_MANAGEDSENSORBASE_H_
77
8- #include < Corrade/Containers/StringStl .h>
8+ #include < Corrade/Utility/FormatStl .h>
99#include < Corrade/Utility/Macros.h>
1010
1111#include " esp/core/managedContainers/AbstractManagedObject.h"
1212#include " esp/sensor/Sensor.h"
13+ #include " esp/sensor/VisualSensor.h"
1314
1415namespace Cr = Corrade;
1516namespace Mn = Magnum;
1617namespace esp {
1718namespace sensor {
1819
1920/* *
20- * @brief Base class template for wrapper for sensor objects of all kinds to
21- * enable Managed Container access.
21+ * @brief Base class for wrappers of sensor objects of all kinds to enable
22+ * Managed Container access.
2223 */
23- template <class T >
24- class AbstractManagedSensor
24+ class ManagedSensorBase
2525 : public esp::core::managedContainers::AbstractManagedObject {
2626 public:
27- static_assert (std::is_base_of<esp::sensor::Sensor, T>::value,
28- " AbstractManagedSensor :: Managed sensor object type must be "
29- " derived from esp::sensor::Sensor" );
30-
31- typedef std::weak_ptr<T> WeakObjRef;
32-
33- explicit AbstractManagedSensor (const std::string& classKey) {
34- AbstractManagedSensor::setClassKey (classKey);
27+ explicit ManagedSensorBase (const std::string& classKey) {
28+ ManagedSensorBase::setClassKey (classKey);
3529 }
36-
37- void setObjectRef (const std::shared_ptr<T>& objRef) { weakObjRef_ = objRef; }
38-
39- ~AbstractManagedSensor () override = default ;
30+ ~ManagedSensorBase () override = default ;
31+ /* *
32+ * @brief Get the instancing class of the ManagedSensorBase instance. Should
33+ * only be set from implementer's constructor. Used as key in constructor
34+ * function pointer maps in @ref
35+ * esp::core::managedContainers::ManagedContainer.
36+ */
37+ std::string getClassKey () const override { return classKey_; }
4038
4139 /* *
42- * @brief Retrieve a comma-separated string holding the header values for the
43- * info returned for this managed object .
40+ * @brief Managed Sensor objects manage their own handles, so this is
41+ * currently unsettable .
4442 */
45- std::string getObjectInfoHeader () const override {
46- return " Type," + getSensorObjInfoHeaderInternal ();
47- }
43+ void setHandle (CORRADE_UNUSED const std::string& name) override {}
4844
4945 /* *
50- * @brief Retrieve a comma-separated informational string about the contents
51- * of this managed object.
46+ * @brief Retrieve this Managed Sensor object's unique handle.
5247 */
53- std::string getObjectInfo () const override {
54- if (auto sp = this ->getObjectReference ()) {
55- namespace CrUt = Cr::Utility;
56- return Cr::Utility::formatString (" {},{}," , classKey_,
57- getSensorObjInfoInternal (sp));
48+ std::string getHandle () const override {
49+ if (auto sp = getObjectReferenceInternal<Sensor>()) {
50+ return sp->getSensorHandle ();
5851 }
59- return Cr::Utility::formatString ( " Unknown classkey {}, " , classKey_) ;
52+ return " " ;
6053 }
6154
62- protected:
6355 /* *
64- * @brief Retrieve a comma-separated string holding the header values for
65- * the info returned for this managed object, type-specific .
56+ * @brief Managed Sensor objects manage their own IDs, so this is
57+ * unsettable .
6658 */
59+ void setID (CORRADE_UNUSED int ID) override {}
6760
68- virtual std::string getSensorObjInfoHeaderInternal () const = 0;
6961 /* *
70- * @brief Specialization-specific extension of getObjectInfo, comma
71- * separated info ideal for saving to csv
62+ * @brief Retrieve this object's unique ID.
7263 */
73- virtual std::string getSensorObjInfoInternal (
74- std::shared_ptr<T>& sp) const = 0;
64+ int getID () const override {
65+ if (auto sp = getObjectReferenceInternal<Sensor>()) {
66+ return sp->getSensorID ();
67+ }
68+ return ID_UNDEFINED;
69+ } // getID()
70+
71+ protected:
72+ void setObjectRefInternal (const std::shared_ptr<void >& objRef) {
73+ weakObjRef_ = objRef;
74+ }
7575
7676 /* *
7777 * @brief This function accesses the underlying shared pointer of this
7878 * object's @p weakObjRef_ if it exists; if not, it provides a message.
7979 * @return Either a shared pointer of this wrapper's object, or nullptr if
8080 * DNE.
8181 */
82- std::shared_ptr<T> inline getObjectReference () const {
83- std::shared_ptr<T> sp = weakObjRef_.lock ();
82+ template <class T >
83+ std::shared_ptr<T> inline getObjectReferenceInternal () const {
84+ std::shared_ptr<void > sp = weakObjRef_.lock ();
8485 if (!sp) {
8586 // TODO: Verify object is removed from manager here?
8687 ESP_ERROR ()
87- << " This sensor object no longer exists. Please delete any variable "
88+ << " This sensor object no longer exists. Please delete any variable "
8889 " references." ;
8990 }
90- return sp ;
91+ return std::static_pointer_cast<T>(sp) ;
9192 } // getObjectReference
9293
9394 /* *
@@ -105,16 +106,17 @@ class AbstractManagedSensor
105106 * @brief Weak ref to object. If user has copy of this wrapper but object
106107 * has been deleted, this will be nullptr.
107108 */
108- WeakObjRef weakObjRef_{};
109+ std::weak_ptr< void > weakObjRef_{};
109110
110111 /* *
111112 * @brief Name of instancing class responsible for this managed object
112113 */
113114 std::string classKey_;
114115
115116 public:
116- ESP_SMART_POINTERS (AbstractManagedSensor<T> )
117+ ESP_SMART_POINTERS (ManagedSensorBase )
117118}; // class AbstractManagedSensor
119+
118120} // namespace sensor
119121} // namespace esp
120122
0 commit comments