HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pageCache.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_EXEC_EF_PAGE_CACHE_H
8 #define PXR_EXEC_EF_PAGE_CACHE_H
9 
10 ///\file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/ef/api.h"
16 #include "pxr/exec/ef/vectorKey.h"
17 
19 
20 ///////////////////////////////////////////////////////////////////////////////
21 ///
22 /// \class Ef_PageCache
23 ///
24 /// \brief Organizes output-to-value caches into logical groups, called pages.
25 /// Pages are keyed off of VdfVector values, such as for example,
26 /// time values.
27 ///
29 {
30 public:
31  /// Destructor.
32  ///
33  EF_API
34  ~Ef_PageCache();
35 
36  /// Construct a new Ef_PageCache, which uses VdfVectors holding type T
37  /// values as keys.
38  ///
39  /// The client is responsible for deleting the heap allocated return
40  /// value.
41  ///
42  template < typename T >
43  static Ef_PageCache *New() {
44  return new Ef_PageCache(&_KeyFactory<T>);
45  }
46 
47  /// Get the output-to-value cache associated with the given key,
48  /// if one exists.
49  ///
50  EF_API
51  Ef_OutputValueCache *Get(const VdfVector &key) const;
52 
53  /// Get the output-to-value cache associated with the given key,
54  /// or create a new, empty output-to-value cache if one does not
55  /// already exist.
56  ///
57  EF_API
59 
60  /// Clear the entire page cache.
61  ///
62  EF_API
63  size_t Clear();
64 
65  /// Type of the cache map.
66  ///
67  typedef
70 
71  /// Type of the cache map iterator.
72  ///
73  typedef
74  typename CacheMap::iterator
76 
77  /// Returns an iterator to the output-to-value cache in the first page.
78  ///
80  return _cache.begin();
81  }
82 
83  /// Returns an iterator past the output-to-value cache in the last page.
84  ///
86  return _cache.end();
87  }
88 
89 private:
90  // The type of the factory function, which is responsible for creating a
91  // Ef_VectorKey from a given VdfVector.
92  using _KeyFactoryFunction =
93  Ef_VectorKey::StoredType (*) (const VdfVector &);
94 
95  // Constructor.
96  EF_API
97  Ef_PageCache(_KeyFactoryFunction keyFactory);
98 
99  // A factory functor, which creates an Ef_VectorKey (for use as a key in
100  // a hash map) from a VdfVector holding data of type T.
101  template < typename T >
102  static Ef_VectorKey::StoredType _KeyFactory(const VdfVector &value) {
104  }
105 
106 private:
107  // The map of pages to output-to-value caches.
108  CacheMap _cache;
109 
110  // The key factory function for building new Ef_VectorKeys.
111  _KeyFactoryFunction _keyFactory;
112 
113 };
114 
116 
117 #endif
Ef_VectorKey::Map< Ef_OutputValueCache * >::Type CacheMap
Definition: pageCache.h:69
The derived Ef_VectorKey type, which implements the methods for generating hashes and equality compar...
Definition: vectorKey.h:125
iterator end()
Definition: hashmap.h:301
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
iterator begin()
Definition: pageCache.h:79
EF_API Ef_OutputValueCache * Get(const VdfVector &key) const
An output-to-value storage for caching. The class provides accessor types for thread-safe, as well as unprotected access.
iterator begin()
Definition: hashmap.h:291
CacheMap::iterator iterator
Definition: pageCache.h:75
std::shared_ptr< Ef_VectorKey > StoredType
Definition: vectorKey.h:41
Organizes output-to-value caches into logical groups, called pages. Pages are keyed off of VdfVector ...
Definition: pageCache.h:28
_Base::iterator iterator
Definition: hashmap.h:265
EF_API Ef_OutputValueCache * GetOrCreate(const VdfVector &key)
EF_API size_t Clear()
static Ef_PageCache * New()
Definition: pageCache.h:43
EF_API ~Ef_PageCache()
iterator end()
Definition: pageCache.h:85
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define EF_API
Definition: api.h:25