This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
16// utility for lazily constructing and composing data source hierarchies
17class HdContainerDataSourceEditor
18{
19public:
20
21 HdContainerDataSourceEditor() {}
22 HdContainerDataSourceEditor(
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
29 HdContainerDataSourceEditor &Set(
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
37 HdContainerDataSourceEditor &Overlay(
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
45private:
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
89PXR_NAMESPACE_CLOSE_SCOPE
90
91#endif
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:99
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: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