HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
containerDataSourceEditor.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_IMAGING_HD_CONTAINER_DATA_SOURCE_EDITOR_H
25 #define PXR_IMAGING_HD_CONTAINER_DATA_SOURCE_EDITOR_H
26 
28 
30 
32 
33 // utility for lazily constructing and composing data source hierarchies
35 {
36 public:
37 
40  HdContainerDataSourceHandle initialContainer)
41  : _initialContainer(initialContainer) {}
42 
43  // Replaces data source at given locator and descending locations
44  // (if given a container data source) by given data source.
45  HD_API
47  const HdDataSourceLocator &locator,
48  const HdDataSourceBaseHandle &dataSource);
49 
50  // Overlays data source at given location by given data source so that
51  // data sources in the initial container at descending locations can
52  // still come through.
53  HD_API
55  const HdDataSourceLocator &locator,
56  const HdContainerDataSourceHandle &containerDataSource);
57 
58  // Returns final container data source with all edits applied.
59  HD_API
60  HdContainerDataSourceHandle Finish();
61 
62 private:
63  HdContainerDataSourceHandle _FinishWithNoInitialContainer();
64 
65  struct _Node;
66  using _NodeSharedPtr = std::shared_ptr<_Node>;
67 
68  struct _Entry
69  {
70  HdDataSourceBaseHandle dataSource;
71  _NodeSharedPtr childNode;
72  };
73 
74  struct _Node
75  {
76  using EntryMap = TfDenseHashMap<TfToken, _Entry,
77  TfToken::HashFunctor, std::equal_to<TfToken>, 8>;
78  EntryMap entries;
79  };
80 
81  _NodeSharedPtr _root;
82  HdContainerDataSourceHandle _initialContainer;
83 
84  // Calling Set with a container data source should mask any existing
85  // container child values coming from _initialContainer. If that's defined,
86  // record the paths for which containers have been set in order to build
87  // a hierarchy with HdBlockDataSources as leaves to place between.
88  TfSmallVector<HdDataSourceLocator, 4> _directContainerSets;
89 
90  _NodeSharedPtr _GetNode(const HdDataSourceLocator & locator);
91 
92  class _NodeContainerDataSource : public HdContainerDataSource
93  {
94  public:
95  HD_DECLARE_DATASOURCE(_NodeContainerDataSource);
96  _NodeContainerDataSource(_NodeSharedPtr node);
97 
98  TfTokenVector GetNames() override;
99  HdDataSourceBaseHandle Get(const TfToken &name) override;
100 
101  private:
102  _NodeSharedPtr _node;
103  };
104 };
105 
107 
108 #endif
HdContainerDataSourceEditor(HdContainerDataSourceHandle initialContainer)
HD_API HdContainerDataSourceEditor & Overlay(const HdDataSourceLocator &locator, const HdContainerDataSourceHandle &containerDataSource)
#define HD_API
Definition: api.h:40
Functor to use for hash maps from tokens to other things.
Definition: token.h:166
HD_API HdContainerDataSourceEditor & Set(const HdDataSourceLocator &locator, const HdDataSourceBaseHandle &dataSource)
#define HD_DECLARE_DATASOURCE(type)
Definition: dataSource.h:69
Definition: token.h:87
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
GLuint const GLchar * name
Definition: glcorearb.h:786
static HD_API HdDataSourceBaseHandle Get(const Handle &container, const HdDataSourceLocator &locator)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_API HdContainerDataSourceHandle Finish()