Loading...
Searching...
No Matches
stageCacheContext.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_USD_USD_STAGE_CACHE_CONTEXT_H
25#define PXR_USD_USD_STAGE_CACHE_CONTEXT_H
26
27#include "pxr/pxr.h"
28#include "pxr/usd/usd/api.h"
29#include "pxr/base/tf/stacked.h"
30
31#include <vector>
32
33PXR_NAMESPACE_OPEN_SCOPE
34
35
36class UsdStageCache;
37
38// Private helper wrapper class, holds a const reference to a stage cache.
39struct Usd_NonPopulatingStageCacheWrapper {
40 explicit Usd_NonPopulatingStageCacheWrapper(const UsdStageCache &cache)
41 : cache(cache) {}
42 const UsdStageCache &cache;
43};
44
45// Using a template arg for 'cache' in UsdUseButDoNotPopulateCache enforces
46// lvalue requirement: rvalues will not bind to function template non-const
47// reference parameters.
48
53template <class StageCache>
54Usd_NonPopulatingStageCacheWrapper
55UsdUseButDoNotPopulateCache(StageCache &cache) {
56 return Usd_NonPopulatingStageCacheWrapper(cache);
57}
58
59enum UsdStageCacheContextBlockType
60{
64 UsdBlockStageCaches,
68 UsdBlockStageCachePopulation,
69
70 Usd_NoBlock
71};
72
121TF_DEFINE_STACKED(UsdStageCacheContext, true, USD_API)
122{
123public:
126 : _rwCache(&cache)
127 , _isReadOnlyCache(false)
128 , _blockType(Usd_NoBlock) {}
129
132 explicit UsdStageCacheContext(Usd_NonPopulatingStageCacheWrapper holder)
133 : _roCache(&holder.cache)
134 , _isReadOnlyCache(true)
135 , _blockType(Usd_NoBlock) {}
136
139 explicit UsdStageCacheContext(UsdStageCacheContextBlockType blockType)
140 : _blockType(blockType) {}
141
142private:
143 friend class UsdStage;
144
145 static std::vector<const UsdStageCache *> _GetReadOnlyCaches();
146 static std::vector<const UsdStageCache *> _GetReadableCaches();
147 static std::vector<UsdStageCache *> _GetWritableCaches();
148
149 // A blocking context is encoded with both members variables null.
150 union {
151 UsdStageCache *_rwCache;
152 const UsdStageCache *_roCache;
153 };
154 bool _isReadOnlyCache;
155 UsdStageCacheContextBlockType _blockType;
156};
157
158
159PXR_NAMESPACE_CLOSE_SCOPE
160
161#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:85
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:151