HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicFileFormatDependencyData.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
25 #define PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
30 #include "pxr/base/tf/token.h"
31 
32 #include <memory>
33 #include <vector>
34 
36 
38 class VtValue;
39 
41 
42 /// \class PcpDynamicFileFormatDependencyData
43 ///
44 /// Contains the necessary information for storing a prim index's dependency
45 /// on dynamic file format arguments and determining if a field change affects
46 /// the prim index. This data structure does not store the prim index or its
47 /// path itself and is expected to be the data in some other data structure
48 /// that maps prim indexes to its dependencies.
49 ///
51 {
52 public:
53  /// Default constructor. This data will be empty.
54  PCP_API
56 
57  /// Move constructor.
58  PCP_API
61 
62  /// Copy constructor.
63  PCP_API
66 
67  /// Move assignment operator
68  PcpDynamicFileFormatDependencyData &operator=(
69  PcpDynamicFileFormatDependencyData &&rhs) {
70  Swap(rhs);
71  return *this;
72  }
73 
74  /// Copy assignment operator
75  PcpDynamicFileFormatDependencyData &operator=(
76  const PcpDynamicFileFormatDependencyData &rhs) {
77  PcpDynamicFileFormatDependencyData(rhs).Swap(*this);
78  return *this;
79  }
80 
81  /// Swap the contents of this dependency data with \p rhs.
82  inline void Swap(PcpDynamicFileFormatDependencyData& rhs) {
83  _data.swap(rhs._data);
84  }
85 
86  /// Same as Swap(), but standard name.
87  inline void swap(PcpDynamicFileFormatDependencyData &rhs) { Swap(rhs); }
88 
89  /// Returns whether this dependency data is empty.
90  inline bool IsEmpty() const {
91  return !_data;
92  }
93 
94  /// Adds dependency info from a single context that generated dynamic file
95  /// format arguments (usually a payload arc in the graph).
96  /// \p dynamicFileFormat is the file format that generated the arguments.
97  /// \p dependencyContextData is custom dependency information generated when
98  /// the file format generated its arguments. \p composedFieldNames is a
99  /// list of the fields that were composed on the prim to generate arguments.
100  PCP_API
102  const PcpDynamicFileFormatInterface *dynamicFileFormat,
103  VtValue &&dependencyContextData,
104  TfToken::Set &&composedFieldNames,
105  TfToken::Set &&composedAttributeNames);
106 
107  /// Takes all the dependency data from \p dependencyData and adds it to this
108  /// dependency.
109  PCP_API
111  PcpDynamicFileFormatDependencyData &&dependencyData);
112 
113  /// Returns a list of field names that were composed for any of the
114  /// dependency contexts that were added to this dependency.
115  PCP_API
116  const TfToken::Set &GetRelevantFieldNames() const;
117 
118  /// Returns a list of attribute names that were composed for any of the
119  /// dependency contexts that were added to this dependency.
120  PCP_API
122 
123  /// Given a \p field name and the changed field values in \p oldValue and
124  /// \p newValue, this returns whether this change can affect any of the file
125  /// format arguments generated by any of the contexts stored in this
126  /// dependency.
127  PCP_API
129  const TfToken &fieldName,
130  const VtValue& oldValue,
131  const VtValue& newValue) const;
132 
133  /// Given an \p attributeName and the changed attribute default values in
134  /// \p oldValue and \p newValue, this returns whether this default value
135  /// change can affect any of the file format arguments generated by any of
136  /// the contexts stored in this dependency.
137  PCP_API
139  const TfToken &attributeName,
140  const VtValue &oldValue,
141  const VtValue &newValue) const;
142 
143 private:
144  // Struct containing the entire contents of the dependency.
145  struct _Data
146  {
147  using _ContextData =
148  std::pair<const PcpDynamicFileFormatInterface *, VtValue>;
149  using _ContextDataVector = std::vector<_ContextData>;
150 
151  _ContextDataVector dependencyContexts;
152  TfToken::Set relevantFieldNames;
153  TfToken::Set relevantAttributeNames;
154 
155  // Helper for adding relevant fields. We avoid copying by taking the
156  // input set if our set is empty.
157  void _AddRelevantFieldNames(TfToken::Set &&fieldNames);
158 
159  // Helper for adding relevant attributes. We avoid copying by taking the
160  // input set if our set is empty.
161  void _AddRelevantAttributeNames(TfToken::Set &&attributeNames);
162  };
163 
164  // Pointer to data. Will be null if this an empty data object.
165  std::unique_ptr<_Data> _data;
166 };
167 
169 
170 #endif // PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
PCP_API bool CanAttributeDefaultValueChangeAffectFileFormatArguments(const TfToken &attributeName, const VtValue &oldValue, const VtValue &newValue) const
PcpDynamicFileFormatDependencyData & operator=(const PcpDynamicFileFormatDependencyData &rhs)
Copy assignment operator.
PCP_API bool CanFieldChangeAffectFileFormatArguments(const TfToken &fieldName, const VtValue &oldValue, const VtValue &newValue) const
PCP_API const TfToken::Set & GetRelevantAttributeNames() const
PCP_API PcpDynamicFileFormatDependencyData()=default
Default constructor. This data will be empty.
PCP_API const TfToken::Set & GetRelevantFieldNames() const
Definition: token.h:87
PCP_API void AppendDependencyData(PcpDynamicFileFormatDependencyData &&dependencyData)
PcpDynamicFileFormatDependencyData & operator=(PcpDynamicFileFormatDependencyData &&rhs)
Move assignment operator.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool IsEmpty() const
Returns whether this dependency data is empty.
PCP_API void AddDependencyContext(const PcpDynamicFileFormatInterface *dynamicFileFormat, VtValue &&dependencyContextData, TfToken::Set &&composedFieldNames, TfToken::Set &&composedAttributeNames)
void swap(PcpDynamicFileFormatDependencyData &rhs)
Same as Swap(), but standard name.
Definition: value.h:167
std::set< TfToken, TfTokenFastArbitraryLessThan > Set
Definition: token.h:183
TF_DECLARE_WEAK_PTRS(SdfFileFormat)
#define PCP_API
Definition: api.h:40
void Swap(PcpDynamicFileFormatDependencyData &rhs)
Swap the contents of this dependency data with rhs.