MCPcopy Create free account
hub / github.com/SmingHub/Sming / Value

Class Value

Sming/Core/Data/ObjectMap.h:62–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 * @note ObjectMap `operator[]` returns one of these, which provides behaviour consistent with V*
61 */
62 class Value
63 {
64 public:
65 Value(ObjectMap<K, V>& map, const K& key) : map(map), key(key)
66 {
67 }
68
69 const K& getKey() const
70 {
71 return key;
72 }
73
74 V* getValue() const
75 {
76 return map.find(key);
77 }
78
79 Value& operator=(V* newValue)
80 {
81 map.set(key, newValue);
82 return *this;
83 }
84
85 operator V*() const
86 {
87 return getValue();
88 }
89
90 V* operator->() const
91 {
92 return getValue();
93 }
94
95 /**
96 * @brief Remove this value from the map
97 * @retval bool true if the value was found and removed
98 */
99 bool remove()
100 {
101 return map.remove(key);
102 }
103
104 /**
105 * @brief Get the value for a given key and remove it from the map, without destroying it
106 * @retval V*
107 * @note The returned object must be freed by the caller when no longer required
108 */
109 V* extract()
110 {
111 return map.extract(key);
112 }
113
114 private:
115 ObjectMap<K, V>& map;
116 K key;
117 };
118
119 /**

Callers 2

valueAtMethod · 0.85
getMethod · 0.85

Calls 2

getValueFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected