HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
schema.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_IMAGING_HD_SCHEMA_H
9 #define PXR_IMAGING_HD_SCHEMA_H
10 
11 #include "pxr/imaging/hd/api.h"
12 
14 
16 
17 // ----------------------------------------------------------------------------
18 
19 /// Schema classes represent a structured view of the inherently unstructured
20 /// container data source passed into the constructor. They're used to
21 /// represent what fields a given object is expected to have.
22 /// Note that a schema can be applied to a container which doesn't contain
23 /// all of the named fields; in that case, some of the field accessors will
24 /// return null, and the caller should use default values for those fields.
25 class HdSchema
26 {
27 public:
28  HdSchema(HdContainerDataSourceHandle container)
29  : _container(container) {}
30 
31 
32  /// Returns the container data source that this schema is interpreting.
33  HD_API
34  HdContainerDataSourceHandle GetContainer() const;
35  HD_API
36  bool IsDefined() const;
37 
38  /// Returns \c true if this schema is applied on top of a non-null
39  /// container.
40  explicit operator bool() const { return IsDefined(); }
41 
43 
44 protected:
45  HdContainerDataSourceHandle _container;
46 
47  /// Returns a datasource of the requested type for the given name:
48  /// schema implementations can use this to ask for child containers,
49  /// sampled values, vectors, etc. If the key has the wrong type, this
50  /// function returns null.
51  template <typename T>
53  return _container ? T::Cast(
54  _container->Get(name)) : nullptr;
55  }
56 };
57 
59 
60 #endif
HD_API bool IsDefined() const
#define HD_API
Definition: api.h:23
T::Handle _GetTypedDataSource(TfToken name) const
Definition: schema.h:52
OutGridT const XformOp bool bool
Definition: token.h:70
HdContainerDataSourceHandle _container
Definition: schema.h:45
GLuint const GLchar * name
Definition: glcorearb.h:786
HdSchema(HdContainerDataSourceHandle container)
Definition: schema.h:28
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HD_API HdContainerDataSourceHandle GetContainer() const
Returns the container data source that this schema is interpreting.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void * Handle
Definition: plugin.h:27