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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
8 #define PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/pcp/api.h"
13 #include "pxr/base/tf/token.h"
14 
15 #include <memory>
16 #include <vector>
17 
19 
21 class VtValue;
22 
24 
25 /// \class PcpDynamicFileFormatDependencyData
26 ///
27 /// Contains the necessary information for storing a prim index's dependency
28 /// on dynamic file format arguments and determining if a field change affects
29 /// the prim index. This data structure does not store the prim index or its
30 /// path itself and is expected to be the data in some other data structure
31 /// that maps prim indexes to its dependencies.
32 ///
34 {
35 public:
36  /// Default constructor. This data will be empty.
37  PCP_API
39 
40  /// Move constructor.
41  PCP_API
44 
45  /// Copy constructor.
46  PCP_API
49 
50  /// Move assignment operator
51  PcpDynamicFileFormatDependencyData &operator=(
52  PcpDynamicFileFormatDependencyData &&rhs) {
53  Swap(rhs);
54  return *this;
55  }
56 
57  /// Copy assignment operator
58  PcpDynamicFileFormatDependencyData &operator=(
59  const PcpDynamicFileFormatDependencyData &rhs) {
60  PcpDynamicFileFormatDependencyData(rhs).Swap(*this);
61  return *this;
62  }
63 
64  /// Swap the contents of this dependency data with \p rhs.
65  inline void Swap(PcpDynamicFileFormatDependencyData& rhs) {
66  _data.swap(rhs._data);
67  }
68 
69  /// Same as Swap(), but standard name.
70  inline void swap(PcpDynamicFileFormatDependencyData &rhs) { Swap(rhs); }
71 
72  /// Returns whether this dependency data is empty.
73  inline bool IsEmpty() const {
74  return !_data;
75  }
76 
77  /// Adds dependency info from a single context that generated dynamic file
78  /// format arguments (usually a payload arc in the graph).
79  /// \p dynamicFileFormat is the file format that generated the arguments.
80  /// \p dependencyContextData is custom dependency information generated when
81  /// the file format generated its arguments. \p composedFieldNames is a
82  /// list of the fields that were composed on the prim to generate arguments.
83  PCP_API
85  const PcpDynamicFileFormatInterface *dynamicFileFormat,
86  VtValue &&dependencyContextData,
87  TfToken::Set &&composedFieldNames,
88  TfToken::Set &&composedAttributeNames);
89 
90  /// Takes all the dependency data from \p dependencyData and adds it to this
91  /// dependency.
92  PCP_API
94  PcpDynamicFileFormatDependencyData &&dependencyData);
95 
96  /// Returns a list of field names that were composed for any of the
97  /// dependency contexts that were added to this dependency.
98  PCP_API
99  const TfToken::Set &GetRelevantFieldNames() const;
100 
101  /// Returns a list of attribute names that were composed for any of the
102  /// dependency contexts that were added to this dependency.
103  PCP_API
105 
106  /// Given a \p field name and the changed field values in \p oldValue and
107  /// \p newValue, this returns whether this change can affect any of the file
108  /// format arguments generated by any of the contexts stored in this
109  /// dependency.
110  PCP_API
112  const TfToken &fieldName,
113  const VtValue& oldValue,
114  const VtValue& newValue) const;
115 
116  /// Given an \p attributeName and the changed attribute default values in
117  /// \p oldValue and \p newValue, this returns whether this default value
118  /// change can affect any of the file format arguments generated by any of
119  /// the contexts stored in this dependency.
120  PCP_API
122  const TfToken &attributeName,
123  const VtValue &oldValue,
124  const VtValue &newValue) const;
125 
126 private:
127  // Struct containing the entire contents of the dependency.
128  struct _Data
129  {
130  using _ContextData =
131  std::pair<const PcpDynamicFileFormatInterface *, VtValue>;
132  using _ContextDataVector = std::vector<_ContextData>;
133 
134  _ContextDataVector dependencyContexts;
135  TfToken::Set relevantFieldNames;
136  TfToken::Set relevantAttributeNames;
137 
138  // Helper for adding relevant fields. We avoid copying by taking the
139  // input set if our set is empty.
140  void _AddRelevantFieldNames(TfToken::Set &&fieldNames);
141 
142  // Helper for adding relevant attributes. We avoid copying by taking the
143  // input set if our set is empty.
144  void _AddRelevantAttributeNames(TfToken::Set &&attributeNames);
145  };
146 
147  // Pointer to data. Will be null if this an empty data object.
148  std::unique_ptr<_Data> _data;
149 };
150 
152 
153 #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:70
PCP_API void AppendDependencyData(PcpDynamicFileFormatDependencyData &&dependencyData)
PcpDynamicFileFormatDependencyData & operator=(PcpDynamicFileFormatDependencyData &&rhs)
Move assignment operator.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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:146
std::set< TfToken, TfTokenFastArbitraryLessThan > Set
Definition: token.h:166
TF_DECLARE_WEAK_PTRS(SdfFileFormat)
#define PCP_API
Definition: api.h:23
void Swap(PcpDynamicFileFormatDependencyData &rhs)
Swap the contents of this dependency data with rhs.