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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_CONTAINER_DATA_SOURCE_EDITOR_H
8 #define PXR_IMAGING_HD_CONTAINER_DATA_SOURCE_EDITOR_H
9 
11 
13 
15 
16 // utility for lazily constructing and composing data source hierarchies
18 {
19 public:
20 
23  HdContainerDataSourceHandle initialContainer)
24  : _initialContainer(initialContainer) {}
25 
26  // Replaces data source at given locator and descending locations
27  // (if given a container data source) by given data source.
28  HD_API
30  const HdDataSourceLocator &locator,
31  const HdDataSourceBaseHandle &dataSource);
32 
33  // Overlays data source at given location by given data source so that
34  // data sources in the initial container at descending locations can
35  // still come through.
36  HD_API
38  const HdDataSourceLocator &locator,
39  const HdContainerDataSourceHandle &containerDataSource);
40 
41  // Returns final container data source with all edits applied.
42  HD_API
43  HdContainerDataSourceHandle Finish();
44 
45 private:
46  HdContainerDataSourceHandle _FinishWithNoInitialContainer();
47 
48  struct _Node;
49  using _NodeSharedPtr = std::shared_ptr<_Node>;
50 
51  struct _Entry
52  {
53  HdDataSourceBaseHandle dataSource;
54  _NodeSharedPtr childNode;
55  };
56 
57  struct _Node
58  {
59  using EntryMap = TfDenseHashMap<TfToken, _Entry,
60  TfToken::HashFunctor, std::equal_to<TfToken>, 8>;
61  EntryMap entries;
62  };
63 
64  _NodeSharedPtr _root;
65  HdContainerDataSourceHandle _initialContainer;
66 
67  // Calling Set with a container data source should mask any existing
68  // container child values coming from _initialContainer. If that's defined,
69  // record the paths for which containers have been set in order to build
70  // a hierarchy with HdBlockDataSources as leaves to place between.
71  TfSmallVector<HdDataSourceLocator, 4> _directContainerSets;
72 
73  _NodeSharedPtr _GetNode(const HdDataSourceLocator & locator);
74 
75  class _NodeContainerDataSource : public HdContainerDataSource
76  {
77  public:
78  HD_DECLARE_DATASOURCE(_NodeContainerDataSource);
79  _NodeContainerDataSource(_NodeSharedPtr node);
80 
81  TfTokenVector GetNames() override;
82  HdDataSourceBaseHandle Get(const TfToken &name) override;
83 
84  private:
85  _NodeSharedPtr _node;
86  };
87 };
88 
90 
91 #endif
HdContainerDataSourceEditor(HdContainerDataSourceHandle initialContainer)
HD_API HdContainerDataSourceEditor & Overlay(const HdDataSourceLocator &locator, const HdContainerDataSourceHandle &containerDataSource)
#define HD_API
Definition: api.h:23
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
HD_API HdContainerDataSourceEditor & Set(const HdDataSourceLocator &locator, const HdDataSourceBaseHandle &dataSource)
#define HD_DECLARE_DATASOURCE(type)
Definition: dataSource.h:52
Definition: token.h:70
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
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:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API HdContainerDataSourceHandle Finish()