Loading...
Searching...
No Matches
containerDataSourceEditor.h
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
10#include "pxr/imaging/hd/dataSource.h"
11
13
14PXR_NAMESPACE_OPEN_SCOPE
15
79class HdContainerDataSourceEditor
80{
81public:
82
83 HdContainerDataSourceEditor() {}
84 HdContainerDataSourceEditor(
85 HdContainerDataSourceHandle initialContainer)
86 : _initialContainer(initialContainer) {}
87
88 // Replaces data source at given locator and descending locations
89 // (if given a container data source) by given data source.
90 HD_API
91 HdContainerDataSourceEditor &Set(
92 const HdDataSourceLocator &locator,
93 const HdDataSourceBaseHandle &dataSource);
94
95 // Overlays data source at given location by given data source so that
96 // data sources in the initial container at descending locations can
97 // still come through.
98 HD_API
99 HdContainerDataSourceEditor &Overlay(
100 const HdDataSourceLocator &locator,
101 const HdContainerDataSourceHandle &containerDataSource);
102
103 // Returns final container data source with all edits applied.
104 HD_API
105 HdContainerDataSourceHandle Finish();
106
110 HD_API
111 static HdDataSourceLocatorSet ComputeDirtyLocators(
112 const HdDataSourceLocatorSet &locatorSet);
113
114private:
115 HdContainerDataSourceHandle _FinishWithNoInitialContainer();
116
117 struct _Node;
118 using _NodeSharedPtr = std::shared_ptr<_Node>;
119
120 struct _Entry
121 {
122 HdDataSourceBaseHandle dataSource;
123 _NodeSharedPtr childNode;
124 };
125
126 struct _Node
127 {
128 using EntryMap = TfDenseHashMap<TfToken, _Entry,
129 TfToken::HashFunctor, std::equal_to<TfToken>, 8>;
130 EntryMap entries;
131 };
132
133 _NodeSharedPtr _root;
134 HdContainerDataSourceHandle _initialContainer;
135
136 // Calling Set with a container data source should mask any existing
137 // container child values coming from _initialContainer. If that's defined,
138 // record the paths for which containers have been set in order to build
139 // a hierarchy with HdBlockDataSources as leaves to place between.
140 TfSmallVector<HdDataSourceLocator, 4> _directContainerSets;
141
142 _NodeSharedPtr _GetNode(const HdDataSourceLocator & locator);
143
144 class _NodeContainerDataSource : public HdContainerDataSource
145 {
146 public:
147 HD_DECLARE_DATASOURCE(_NodeContainerDataSource);
148 _NodeContainerDataSource(_NodeSharedPtr node);
149
150 TfTokenVector GetNames() override;
151 HdDataSourceBaseHandle Get(const TfToken &name) override;
152
153 private:
154 _NodeSharedPtr _node;
155 };
156};
157
158PXR_NAMESPACE_CLOSE_SCOPE
159
160#endif
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:99
Represents an object that can identify the location of a data source.
Represents a set of data source locators closed under descendancy.
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
Definition: denseHashMap.h:41
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440