Loading...
Searching...
No Matches
containerDataSourceEditor.h
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
27#include "pxr/imaging/hd/dataSource.h"
28
30
31PXR_NAMESPACE_OPEN_SCOPE
32
33// utility for lazily constructing and composing data source hierarchies
34class HdContainerDataSourceEditor
35{
36public:
37
38 HdContainerDataSourceEditor() {}
39 HdContainerDataSourceEditor(
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
46 HdContainerDataSourceEditor &Set(
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
54 HdContainerDataSourceEditor &Overlay(
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
62private:
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
106PXR_NAMESPACE_CLOSE_SCOPE
107
108#endif
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:116
static HD_API HdDataSourceBaseHandle Get(const Handle &container, const HdDataSourceLocator &locator)
A convenience function: given container, return the descendant identified by locator,...
Represents an object that can identify the location of a data source.
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
Definition: denseHashMap.h:58
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:179
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Functor to use for hash maps from tokens to other things.
Definition: token.h:166
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457