Blender V4.3
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
5#pragma once
6
7#include "BLI_function_ref.hh"
8#include "BLI_generic_key.hh"
10
12
18 public:
19 virtual ~CachedValue() = default;
20
25 virtual void count_memory(MemoryCounter &memory) const = 0;
26};
27
34template<typename T>
35std::shared_ptr<const T> get(const GenericKey &key, FunctionRef<std::unique_ptr<T>()> compute_fn);
36
40std::shared_ptr<CachedValue> get_base(const GenericKey &key,
41 FunctionRef<std::unique_ptr<CachedValue>()> compute_fn);
42
47void set_approximate_size_limit(int64_t limit_in_bytes);
48
54void clear();
55
56/* -------------------------------------------------------------------- */
60template<typename T>
61inline std::shared_ptr<const T> get(const GenericKey &key,
62 FunctionRef<std::unique_ptr<T>()> compute_fn)
63{
64 return std::dynamic_pointer_cast<const T>(get_base(key, compute_fn));
65}
66
69} // namespace blender::memory_cache
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)
std::shared_ptr< const T > get(const GenericKey &key, FunctionRef< std::unique_ptr< T >()> compute_fn)
__int64 int64_t
Definition stdint.h:89