HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicFileFormatContext.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_CONTEXT_H
8 #define PXR_USD_PCP_DYNAMIC_FILE_FORMAT_CONTEXT_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/pcp/api.h"
12 #include "pxr/usd/pcp/node.h"
13 
15 
16 class PcpPrimIndex_StackFrame;
17 class PcpCache;
18 
19 /// \class PcpDynamicFileFormatContext
20 ///
21 /// Context object for the current state of a prim index that is being built
22 /// that allows implementations of PcpDynamicFileFormatInterface to compose
23 /// field values when generating dynamic file format arguments. The context
24 /// allows us to iterate over all nodes that have already been composed looking
25 /// for the strongest opinion for a relevant field.
27 {
28 public:
29  using VtValueVector = std::vector<VtValue>;
30 
31  PCP_API
32  ~PcpDynamicFileFormatContext() = default;
33 
34  /// Compose the \p value of the given \p field and return its current
35  /// strongest opinion. For dictionary valued fields this will be a
36  /// dictionary containing the strongest value for each individual key.
37  /// Returns true if a value for the field was found.
38  PCP_API
39  bool ComposeValue(const TfToken &field, VtValue *value) const;
40 
41  /// Compose the \p values of the given \p field returning all available
42  /// opinions ordered from strongest to weakest. For dictionary valued
43  /// fields, the dictionaries from each opinion are not composed together
44  /// at each step and are instead returned in the list as is.
45  /// Returns true if a value for the field was found.
46  ///
47  /// Note that this is slower than ComposeValue, especially for
48  /// non-dictionary valued fields, and should only be used if knowing more
49  /// than just the strongest value is necessary.
50  PCP_API
51  bool ComposeValueStack(const TfToken &field,
52  VtValueVector *values) const;
53 
54  /// Compose the \p value of the default field of the attribute with the
55  /// given \p attributeName and return its current strongest opinion.
56  /// Returns true if a value for the field was found.
57  PCP_API
59  const TfToken &attributeName, VtValue *value) const;
60 
61 private:
62  /// Constructs a context.
63  /// \p parentNode and \p previousFrame are used to traverse the
64  /// current state of the prim index graph when composing the opinions on
65  /// fields. \p composedFieldNames is the set of field names that is
66  /// to be updated with the names of fields that ComposeValue and
67  /// ComposeValueStack are called on for dependency tracking.
69  const PcpNodeRef &parentNode,
70  const SdfPath &pathInNode,
71  int arcNum,
72  PcpPrimIndex_StackFrame *previousFrame,
73  TfToken::Set *composedFieldNames,
74  TfToken::Set *composedAttributeNames);
75 
76  /// Access to private constructor. Should only be called by prim indexing.
78  const PcpNodeRef &, const SdfPath&, int, PcpPrimIndex_StackFrame *,
80 
81  /// Returns whether the given \p field is allowed to be used to generate
82  /// file format arguments. It can also return whether the value type of
83  /// the field is a dictionary if needed.
84  bool _IsAllowedFieldForArguments(
85  const TfToken &field, bool *fieldValueIsDictionary = nullptr) const;
86 
87 private:
88  PcpNodeRef _parentNode;
89  SdfPath _pathInNode;
90  int _arcNum;
91  PcpPrimIndex_StackFrame *_previousStackFrame;
92 
93  // Cached names of fields that had values composed by this context.
94  TfToken::Set *_composedFieldNames;
95 
96  // Cached names of attributes that had default values composed by this
97  // context.
98  TfToken::Set *_composedAttributeNames;
99 
100  // Declare private helper.
101  class _ComposeValueHelper;
102 };
103 
105 
106 #endif // PXR_USD_PCP_DYNAMIC_FILE_FORMAT_CONTEXT_H
GLsizei const GLfloat * value
Definition: glcorearb.h:824
PCP_API bool ComposeValue(const TfToken &field, VtValue *value) const
Definition: cache.h:76
std::vector< VtValue > VtValueVector
Definition: token.h:70
PCP_API ~PcpDynamicFileFormatContext()=default
Definition: path.h:273
PCP_API bool ComposeValueStack(const TfToken &field, VtValueVector *values) const
PCP_API bool ComposeAttributeDefaultValue(const TfToken &attributeName, VtValue *value) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
friend PcpDynamicFileFormatContext Pcp_CreateDynamicFileFormatContext(const PcpNodeRef &, const SdfPath &, int, PcpPrimIndex_StackFrame *, TfToken::Set *, TfToken::Set *)
Access to private constructor. Should only be called by prim indexing.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: value.h:146
std::set< TfToken, TfTokenFastArbitraryLessThan > Set
Definition: token.h:166
#define PCP_API
Definition: api.h:23