Loading...
Searching...
No Matches
stageCacheContext.h
1//
2// Copyright 2016 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_USD_USD_STAGE_CACHE_CONTEXT_H
8#define PXR_USD_USD_STAGE_CACHE_CONTEXT_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
12#include "pxr/base/tf/stacked.h"
13
14#include <vector>
15
16PXR_NAMESPACE_OPEN_SCOPE
17
18
19class UsdStageCache;
20
21// Private helper wrapper class, holds a const reference to a stage cache.
22struct Usd_NonPopulatingStageCacheWrapper {
23 explicit Usd_NonPopulatingStageCacheWrapper(const UsdStageCache &cache)
24 : cache(cache) {}
25 const UsdStageCache &cache;
26};
27
28// Using a template arg for 'cache' in UsdUseButDoNotPopulateCache enforces
29// lvalue requirement: rvalues will not bind to function template non-const
30// reference parameters.
31
36template <class StageCache>
37Usd_NonPopulatingStageCacheWrapper
38UsdUseButDoNotPopulateCache(StageCache &cache) {
39 return Usd_NonPopulatingStageCacheWrapper(cache);
40}
41
42enum UsdStageCacheContextBlockType
43{
47 UsdBlockStageCaches,
51 UsdBlockStageCachePopulation,
52
53 Usd_NoBlock
54};
55
104TF_DEFINE_STACKED(UsdStageCacheContext, true, USD_API)
105{
106public:
109 : _rwCache(&cache)
110 , _isReadOnlyCache(false)
111 , _blockType(Usd_NoBlock) {}
112
115 explicit UsdStageCacheContext(Usd_NonPopulatingStageCacheWrapper holder)
116 : _roCache(&holder.cache)
117 , _isReadOnlyCache(true)
118 , _blockType(Usd_NoBlock) {}
119
122 explicit UsdStageCacheContext(UsdStageCacheContextBlockType blockType)
123 : _blockType(blockType) {}
124
125private:
126 friend class UsdStage;
127
128 static std::vector<const UsdStageCache *> _GetReadOnlyCaches();
129 static std::vector<const UsdStageCache *> _GetReadableCaches();
130 static std::vector<UsdStageCache *> _GetWritableCaches();
131
132 // A blocking context is encoded with both members variables null.
133 union {
134 UsdStageCache *_rwCache;
135 const UsdStageCache *_roCache;
136 };
137 bool _isReadOnlyCache;
138 UsdStageCacheContextBlockType _blockType;
139};
140
141
142PXR_NAMESPACE_CLOSE_SCOPE
143
144#endif // PXR_USD_USD_STAGE_CACHE_CONTEXT_H
A context object that lets the UsdStage::Open() API read from or read from and write to a UsdStageCac...
UsdStageCacheContext(Usd_NonPopulatingStageCacheWrapper holder)
Bind a cache for calls to UsdStage::Open() to read from.
UsdStageCacheContext(UsdStageCache &cache)
Bind a cache for calls to UsdStage::Open() to read from and write to.
UsdStageCacheContext(UsdStageCacheContextBlockType blockType)
Disable cache use completely (with UsdBlockStageCaches) or only for writing (with UsdBlockStageCacheW...
A strongly concurrency safe collection of UsdStageRefPtr s, enabling sharing across multiple clients ...
Definition: stageCache.h:68
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:136