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  HD_API
59  HdContainerDataSourceHandle Finish();
60 
61 private:
62  HdContainerDataSourceHandle _FinishWithNoInitialContainer();
63 
64  struct _Node;
65  using _NodeSharedPtr = std::shared_ptr<_Node>;
66 
67  struct _Entry
68  {
69  HdDataSourceBaseHandle dataSource;
70  _NodeSharedPtr childNode;
71  };
72 
73  struct _Node
74  {
75  using EntryMap = TfDenseHashMap<TfToken, _Entry,
76  TfToken::HashFunctor, std::equal_to<TfToken>, 8>;
77  EntryMap entries;
78  };
79 
80  _NodeSharedPtr _root;
81  HdContainerDataSourceHandle _initialContainer;
82 
83  // Calling Set with a container data source should mask any existing
84  // container child values coming from _initialContainer. If that's defined,
85  // record the paths for which containers have been set in order to build
86  // a hierarchy with HdBlockDataSources as leaves to place between.
87  TfSmallVector<HdDataSourceLocator, 4> _directContainerSets;
88 
89  _NodeSharedPtr _GetNode(const HdDataSourceLocator & locator);
90 
91  class _NodeContainerDataSource : public HdContainerDataSource
92  {
93  public:
94  HD_DECLARE_DATASOURCE(_NodeContainerDataSource);
95  _NodeContainerDataSource(_NodeSharedPtr node);
96 
97  TfTokenVector GetNames() override;
98  HdDataSourceBaseHandle Get(const TfToken &name) override;
99 
100  private:
101  _NodeSharedPtr _node;
102  };
103 };
104 
106 
107 #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:64
Definition: token.h:87
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
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:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_API HdContainerDataSourceHandle Finish()