attributeQuery.h
1 //
2 // Copyright 2016 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_USD_ATTRIBUTE_QUERY_H
25 #define PXR_USD_USD_ATTRIBUTE_QUERY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/attribute.h"
30 #include "pxr/usd/usd/common.h"
31 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/resolveTarget.h"
34 #include "pxr/usd/usd/timeCode.h"
35 
36 #include "pxr/base/tf/token.h"
37 
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
77 {
78 public:
80  USD_API
82 
84  USD_API
86 
88  USD_API
89  UsdAttributeQuery(UsdAttributeQuery &&other) = default;
90 
92  USD_API
93  explicit UsdAttributeQuery(const UsdAttribute& attr);
94 
97  USD_API
98  UsdAttributeQuery(const UsdPrim& prim, const TfToken& attrName);
99 
105  USD_API
106  UsdAttributeQuery(const UsdAttribute &attr,
107  const UsdResolveTarget &resolveTarget);
108 
112  USD_API
113  static std::vector<UsdAttributeQuery> CreateQueries(
114  const UsdPrim& prim, const TfTokenVector& attrNames);
115 
116  // --------------------------------------------------------------------- //
118  // --------------------------------------------------------------------- //
119 
121 
123  USD_API
124  const UsdAttribute& GetAttribute() const;
125 
128  bool IsValid() const {
129  return GetAttribute().IsValid();
130  }
131 
132 public:
134  explicit operator bool() const {
135  return IsValid();
136  }
137 
139  USD_API
141 
143  USD_API
144  UsdAttributeQuery &operator=(UsdAttributeQuery &&other) = default;
145 
147 
148  // --------------------------------------------------------------------- //
150  // --------------------------------------------------------------------- //
151 
153 
158  template <typename T>
159  bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
160  static_assert(SdfValueTypeTraits<T>::IsValueType,
161  "T must be an SdfValueType.");
162  return _Get(value, time);
163  }
166  USD_API
167  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
168 
171  //
175  USD_API
176  bool GetTimeSamples(std::vector<double>* times) const;
177 
182  USD_API
183  bool GetTimeSamplesInInterval(const GfInterval& interval,
184  std::vector<double>* times) const;
185 
198  USD_API
199  static bool GetUnionedTimeSamples(
200  const std::vector<UsdAttributeQuery> &attrQueries,
201  std::vector<double> *times);
202 
214  USD_API
216  const std::vector<UsdAttributeQuery> &attrQueries,
217  const GfInterval &interval,
218  std::vector<double> *times);
219 
223  USD_API
224  size_t GetNumTimeSamples() const;
225 
230  USD_API
231  bool GetBracketingTimeSamples(double desiredTime,
232  double* lower,
233  double* upper,
234  bool* hasTimeSamples) const;
235 
241  USD_API
242  bool HasValue() const;
243 
253  USD_API
254  bool HasAuthoredValueOpinion() const;
255 
260  USD_API
261  bool HasAuthoredValue() const;
262 
267  USD_API
268  bool HasFallbackValue() const;
269 
274  USD_API
275  bool ValueMightBeTimeVarying() const;
276 
278 
279 private:
280  void _Initialize();
281 
282  void _Initialize(const UsdResolveTarget &resolveTarget);
283 
284  template <typename T>
285  USD_API
286  bool _Get(T* value, UsdTimeCode time) const;
287 
288 private:
289  UsdAttribute _attr;
290  UsdResolveInfo _resolveInfo;
291  std::unique_ptr<UsdResolveTarget> _resolveTarget;
292 };
293 
294 PXR_NAMESPACE_CLOSE_SCOPE
295 
296 #endif // PXR_USD_USD_ATTRIBUTE_QUERY_H
USD_API UsdAttributeQuery()
Construct an invalid query object.
USD_API UsdAttributeQuery & operator=(const UsdAttributeQuery &other)
Copy assignment.
Object for efficiently making repeated queries for attribute values.
USD_API bool GetBracketingTimeSamples(double desiredTime, double *lower, double *upper, bool *hasTimeSamples) const
Populate lower and upper with the next greater and lesser value relative to the desiredTime.
USD_API bool HasValue() const
Return true if the attribute associated with this query has an authored default value,...
USD_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times.
static USD_API bool GetUnionedTimeSamplesInInterval(const std::vector< UsdAttributeQuery > &attrQueries, const GfInterval &interval, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times in the GfInterval,...
Container for information about the source of an attribute's value, i.e.
Definition: resolveInfo.h:68
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
USD_API size_t GetNumTimeSamples() const
Returns the number of time samples that have been authored.
USD_API const UsdAttribute & GetAttribute() const
Return the attribute associated with this query.
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
static USD_API std::vector< UsdAttributeQuery > CreateQueries(const UsdPrim &prim, const TfTokenVector &attrNames)
Construct new queries for the attributes named in attrNames under the prim prim.
USD_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this attribute's value changes over time,...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
USD_API bool HasAuthoredValueOpinion() const
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A basic mathematical interval class.
Definition: interval.h:50
bool IsValid() const
Return true if this query is valid (i.e.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of the attribute associated with this query at the reques...
USD_API bool HasFallbackValue() const
Return true if the attribute associated with this query has a fallback value provided by a registered...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition: timeCode.h:113
USD_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
bool IsValid() const
Return true if this is a valid object, false otherwise.
Definition: object.h:141
static USD_API bool GetUnionedTimeSamples(const std::vector< UsdAttributeQuery > &attrQueries, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times on all of the given...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
Defines a subrange of nodes and layers within a prim's prim index to consider when performing value r...
Definition: resolveTarget.h:73