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_SDF_SITE_UTILS_H
25 #define PXR_USD_SDF_SITE_UTILS_H
26 
27 /// \file sdf/siteUtils.h
28 ///
29 /// Convenience API for working with SdfSite.
30 ///
31 /// These functions simply forward to the indicated functions on SdfLayer.
32 
33 #include "pxr/pxr.h"
34 #include "pxr/usd/sdf/site.h"
35 #include "pxr/usd/sdf/layer.h"
36 #include "pxr/usd/sdf/primSpec.h"
37 #include "pxr/usd/sdf/propertySpec.h"
38 #include "pxr/usd/sdf/spec.h"
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 inline
43 SdfSpecHandle
SdfGetObjectAtPath(const SdfSite & site)44 SdfGetObjectAtPath(const SdfSite& site)
45 {
46     return site.layer->GetObjectAtPath(site.path);
47 }
48 
49 inline
50 SdfPrimSpecHandle
SdfGetPrimAtPath(const SdfSite & site)51 SdfGetPrimAtPath(const SdfSite& site)
52 {
53     return site.layer->GetPrimAtPath(site.path);
54 }
55 
56 inline
57 SdfPropertySpecHandle
SdfGetPropertyAtPath(const SdfSite & site)58 SdfGetPropertyAtPath(const SdfSite& site)
59 {
60     return site.layer->GetPropertyAtPath(site.path);
61 }
62 
63 inline
64 bool
SdfHasField(const SdfSite & site,const TfToken & field)65 SdfHasField(const SdfSite& site, const TfToken& field)
66 {
67     return site.layer->HasField(site.path, field);
68 }
69 
70 template <class T>
71 inline bool
SdfHasField(const SdfSite & site,const TfToken & field,T * value)72 SdfHasField(const SdfSite& site, const TfToken& field, T* value)
73 {
74     return site.layer->HasField(site.path, field, value);
75 }
76 
77 inline
78 const VtValue
SdfGetField(const SdfSite & site,const TfToken & field)79 SdfGetField(const SdfSite& site, const TfToken& field)
80 {
81     return site.layer->GetField(site.path, field);
82 }
83 
84 template <class T>
85 inline
86 T
87 SdfGetFieldAs(const SdfSite& site, const TfToken& field,
88               const T& defaultValue = T())
89 {
90     return site.layer->GetFieldAs<T>(site.path, field, defaultValue);
91 }
92 
93 PXR_NAMESPACE_CLOSE_SCOPE
94 
95 #endif // PXR_USD_SDF_SITE_UTILS_H
96