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 
106  /// Takes all the dependency data from \p dependencyData and adds it to this
107  /// dependency.
108  PCP_API
110  PcpDynamicFileFormatDependencyData &&dependencyData);
111 
112  /// Returns a list of field names that were composed for any of the
113  /// dependency contexts that were added to this dependency.
114  PCP_API
115  const TfToken::Set &GetRelevantFieldNames() const;
116 
117  /// Given a \p field name and the changed field values in \p oldAndNewValues
118  /// this return whether this change can affect any of the file format
119  /// arguments generated by any of the contexts stored in this dependency.
120  PCP_API
121  bool CanFieldChangeAffectFileFormatArguments(const TfToken &fieldName,
122  const VtValue& oldValue,
123  const VtValue& newValue) const;
124 
125 private:
126  // Struct containing the entire contents of the dependency.
127  struct _Data
128  {
129  using _ContextData =
130  std::pair<const PcpDynamicFileFormatInterface *, VtValue>;
131  using _ContextDataVector = std::vector<_ContextData>;
132 
133  _ContextDataVector dependencyContexts;
134  TfToken::Set relevantFieldNames;
135 
136  // Helper for adding relevant fields. We avoid copying by taking the
137  // input set if our set is empty.
138  void _AddRelevantFieldNames(TfToken::Set &&fieldNames);
139  };
140 
141  // Pointer to data. Will be null if this an empty data object.
142  std::unique_ptr<_Data> _data;
143 };
144 
146 
147 #endif // PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
PcpDynamicFileFormatDependencyData & operator=(const PcpDynamicFileFormatDependencyData &rhs)
Copy assignment operator.
PCP_API bool CanFieldChangeAffectFileFormatArguments(const TfToken &fieldName, const VtValue &oldValue, const VtValue &newValue) 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.
PCP_API void AddDependencyContext(const PcpDynamicFileFormatInterface *dynamicFileFormat, VtValue &&dependencyContextData, TfToken::Set &&composedFieldNames)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool IsEmpty() const
Returns whether this dependency data is empty.
void swap(PcpDynamicFileFormatDependencyData &rhs)
Same as Swap(), but standard name.
Definition: value.h:174
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.