5
5
#ifndef ESP_SENSOR_MANAGEDSENSORBASE_H_
6
6
#define ESP_SENSOR_MANAGEDSENSORBASE_H_
7
7
8
- #include < Corrade/Containers/StringStl .h>
8
+ #include < Corrade/Utility/FormatStl .h>
9
9
#include < Corrade/Utility/Macros.h>
10
10
11
11
#include " esp/core/managedContainers/AbstractManagedObject.h"
12
12
#include " esp/sensor/Sensor.h"
13
+ #include " esp/sensor/VisualSensor.h"
13
14
14
15
namespace Cr = Corrade;
15
16
namespace Mn = Magnum;
16
17
namespace esp {
17
18
namespace sensor {
18
19
19
20
/* *
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.
22
23
*/
23
- template <class T >
24
- class AbstractManagedSensor
24
+ class ManagedSensorBase
25
25
: public esp::core::managedContainers::AbstractManagedObject {
26
26
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);
35
29
}
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_; }
40
38
41
39
/* *
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 .
44
42
*/
45
- std::string getObjectInfoHeader () const override {
46
- return " Type," + getSensorObjInfoHeaderInternal ();
47
- }
43
+ void setHandle (CORRADE_UNUSED const std::string& name) override {}
48
44
49
45
/* *
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.
52
47
*/
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 ();
58
51
}
59
- return Cr::Utility::formatString ( " Unknown classkey {}, " , classKey_) ;
52
+ return " " ;
60
53
}
61
54
62
- protected:
63
55
/* *
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 .
66
58
*/
59
+ void setID (CORRADE_UNUSED int ID) override {}
67
60
68
- virtual std::string getSensorObjInfoHeaderInternal () const = 0;
69
61
/* *
70
- * @brief Specialization-specific extension of getObjectInfo, comma
71
- * separated info ideal for saving to csv
62
+ * @brief Retrieve this object's unique ID.
72
63
*/
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
+ }
75
75
76
76
/* *
77
77
* @brief This function accesses the underlying shared pointer of this
78
78
* object's @p weakObjRef_ if it exists; if not, it provides a message.
79
79
* @return Either a shared pointer of this wrapper's object, or nullptr if
80
80
* DNE.
81
81
*/
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 ();
84
85
if (!sp) {
85
86
// TODO: Verify object is removed from manager here?
86
87
ESP_ERROR ()
87
- << " This sensor object no longer exists. Please delete any variable "
88
+ << " This sensor object no longer exists. Please delete any variable "
88
89
" references." ;
89
90
}
90
- return sp ;
91
+ return std::static_pointer_cast<T>(sp) ;
91
92
} // getObjectReference
92
93
93
94
/* *
@@ -105,16 +106,17 @@ class AbstractManagedSensor
105
106
* @brief Weak ref to object. If user has copy of this wrapper but object
106
107
* has been deleted, this will be nullptr.
107
108
*/
108
- WeakObjRef weakObjRef_{};
109
+ std::weak_ptr< void > weakObjRef_{};
109
110
110
111
/* *
111
112
* @brief Name of instancing class responsible for this managed object
112
113
*/
113
114
std::string classKey_;
114
115
115
116
public:
116
- ESP_SMART_POINTERS (AbstractManagedSensor<T> )
117
+ ESP_SMART_POINTERS (ManagedSensorBase )
117
118
}; // class AbstractManagedSensor
119
+
118
120
} // namespace sensor
119
121
} // namespace esp
120
122
0 commit comments