Blender V5.0
BLI_memory_cache.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_function_ref.hh"
12#include "BLI_generic_key.hh"
14
16
22 public:
23 virtual ~CachedValue() = default;
24
29 virtual void count_memory(MemoryCounter &memory) const = 0;
30};
31
38template<typename T>
39std::shared_ptr<const T> get(const GenericKey &key, FunctionRef<std::unique_ptr<T>()> compute_fn);
40
44std::shared_ptr<CachedValue> get_base(const GenericKey &key,
45 FunctionRef<std::unique_ptr<CachedValue>()> compute_fn);
46
51void set_approximate_size_limit(int64_t limit_in_bytes);
52
58void clear();
59
65void remove_if(FunctionRef<bool(const GenericKey &)> predicate);
66
67/* -------------------------------------------------------------------- */
70
71template<typename T>
72inline std::shared_ptr<const T> get(const GenericKey &key,
73 FunctionRef<std::unique_ptr<T>()> compute_fn)
74{
75 return std::dynamic_pointer_cast<const T>(get_base(key, compute_fn));
76}
77
79
80} // namespace blender::memory_cache
long long int int64_t
virtual void count_memory(MemoryCounter &memory) const =0
void set_approximate_size_limit(int64_t limit_in_bytes)
std::shared_ptr< CachedValue > get_base(const GenericKey &key, FunctionRef< std::unique_ptr< CachedValue >()> compute_fn)
void remove_if(FunctionRef< bool(const GenericKey &)> predicate)
std::shared_ptr< const T > get(const GenericKey &key, FunctionRef< std::unique_ptr< T >()> compute_fn)