Lines Matching refs:TValue
36 // template <typename TValue>
37 // TValue* Get(Key<T> key); // null if the value was never set, otherwise the value.
39 // template <typename TValue>
40 // void Set(Key<T> key, TValue value);
49 // template <typename TValue>
50 // struct FruitMapKey : VariantMapKey<TValue> {
59 // template <typename TValue>
60 // using Key = FruitMapKey<TValue>;
98 // Delete a value whose runtime type is that of the non-erased key's TValue.
101 // Clone a value whose runtime type is that of the non-erased key's TValue.
135 template <typename TValue>
138 // then that is used. Otherwise, the default value for the type TValue{} is returned.
139 TValue CreateDefaultValue() const {
141 return TValue{}; // NOLINT [readability/braces] [4]
143 return TValue(*default_value_);
149 explicit VariantMapKey(const TValue& default_value)
150 : default_value_(std::make_shared<TValue>(default_value)) {}
151 explicit VariantMapKey(TValue&& default_value)
152 : default_value_(std::make_shared<TValue>(default_value)) {}
158 return new VariantMapKey<TValue>(*this);
166 TValue* strong_value = reinterpret_cast<TValue*>(value);
167 return new TValue(*strong_value);
176 const std::default_delete<TValue> deleter = std::default_delete<TValue>();
177 deleter(reinterpret_cast<TValue*>(value));
186 std::shared_ptr<TValue> default_value_;
197 template <typename TValue>
198 struct VariantMapStringKey : VariantMapKey<TValue> {
214 template <typename TValue>
215 using Key = TKey<TValue>;
219 template <typename TValue>
220 const TValue* Get(const TKey<TValue>& key) const {
226 template <typename TValue>
227 TValue* Get(const TKey<TValue>& key) {
232 // The default value is either the key's default, or TValue{} if the key doesn't have a default.
233 template <typename TValue>
234 TValue GetOrDefault(const TKey<TValue>& key) const {
241 template <typename TValue>
243 ScopedRemove(VariantMap& map, const TKey<TValue>& key) : map_(map), key_(key) {}
249 const TKey<TValue>& key_;
255 template <typename TValue>
256 TValue ReleaseOrDefault(const TKey<TValue>& key) {
257 ScopedRemove<TValue> remove_on_return(*this, key);
259 TValue* ptr = Get(key);
268 template <typename TValue>
269 bool Exists(const TKey<TValue>& key) const {
274 // Note: Omit the `value` from TValue type deduction, deduce only from the `key` argument.
275 template <typename TValue>
276 void Set(const TKey<TValue>& key, const typename Identity<TValue>::type& value) {
278 auto* new_value = new TValue(value);
286 // Note: Omit the `value` from TValue type deduction, deduce only from the `key` argument.
287 template <typename TValue>
288 bool SetIfMissing(const TKey<TValue>& key, const typename Identity<TValue>::type& value) {
289 TValue* ptr = Get(key);
298 template <typename TValue>
299 void Remove(const TKey<TValue>& key) {
300 StaticAssertKeyType<TValue>();
378 template <typename TK, typename TValue, typename ... Rest>
379 void InitializeParameters(const TK& key, const TValue& value, const Rest& ... rest) {
381 std::is_same<TK, TKey<TValue>>::value, "The 0th/2nd/4th/etc parameters must be a key");
383 const TKey<TValue>& key_refined = key;
404 template <typename TValue>
405 typename StorageMap::iterator GetKeyValueIterator(const TKey<TValue>& key) {
406 StaticAssertKeyType<TValue>();
408 const TKey<TValue>* key_ptr = &key;
413 template <typename TValue>
414 typename StorageMap::const_iterator GetKeyValueIterator(const TKey<TValue>& key) const {
415 StaticAssertKeyType<TValue>();
417 const TKey<TValue>* key_ptr = &key;
422 template <typename TValue>
423 TValue* GetValuePtr(const TKey<TValue>& key) {
424 return const_cast<TValue*>(GetValueConstPtr(key));
427 template <typename TValue>
428 const TValue* GetValuePtr(const TKey<TValue>& key) const {
432 template <typename TValue>
433 const TValue* GetValueConstPtr(const TKey<TValue>& key) const {
439 return reinterpret_cast<const TValue*>(it->second);
442 template <typename TValue>
444 static_assert(std::is_base_of<VariantMapKey<TValue>, TKey<TValue>>::value,