HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
children.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_SDF_CHILDREN_H
8 #define PXR_USD_SDF_CHILDREN_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/sdf/api.h"
13 #include "pxr/usd/sdf/path.h"
14 
15 #include <vector>
16 
18 
20 class SdfSpec;
21 
22 /// \class Sdf_Children
23 ///
24 /// Sdf_Children generically represents the children of an object. For
25 /// instance, it might be used for the name children of a prim or the
26 /// relationship targets of a relationship.
27 ///
28 /// The provided ChildPolicy class determines how this object behaves.
29 /// It primarily specifies how to map between keys (such as the name of
30 /// an object) and values (such as SpecHandles for those objects).
31 ///
32 template<class ChildPolicy>
34 {
35 public:
36  typedef typename ChildPolicy::KeyPolicy KeyPolicy;
37  typedef typename ChildPolicy::KeyType KeyType;
39  typedef typename ChildPolicy::FieldType FieldType;
41 
42  SDF_API
43  Sdf_Children();
44 
45  SDF_API
47 
48  SDF_API
49  Sdf_Children(const SdfLayerHandle &layer,
50  const SdfPath &parentPath, const TfToken &childrenKey,
51  const KeyPolicy& keyPolicy = KeyPolicy());
52 
53  /// Return whether this object is valid.
54  SDF_API
55  bool IsValid() const;
56 
57  /// Return the number of children that this object contains.
58  SDF_API
59  size_t GetSize() const;
60 
61  /// Return the child at the specified index.
62  SDF_API
63  ValueType GetChild(size_t index) const;
64 
65  /// Find the index of the specified key, or return the size if it's not found.
66  SDF_API
67  size_t Find(const KeyType &key) const;
68 
69  /// Find the key that corresponds to \a value, or return a default
70  /// constructed key if it's not found.
71  SDF_API
72  KeyType FindKey(const ValueType &value) const;
73 
74  /// Return true if this object and \a other are equivalent.
75  SDF_API
76  bool IsEqualTo(const This &other) const;
77 
78  /// Replace this object's children with the ones in \a values.
79  SDF_API
80  bool Copy(const std::vector<ValueType> & values, const std::string &type);
81 
82  /// Insert a new child at the specified \a index.
83  SDF_API
84  bool Insert(const ValueType& value, size_t index, const std::string &type);
85 
86  /// Erase the child with the specified key.
87  SDF_API
88  bool Erase(const KeyType& key, const std::string &type);
89 
90 private:
91  void _UpdateChildNames() const;
92 
93 private:
94  SdfLayerHandle _layer;
95  SdfPath _parentPath;
96  TfToken _childrenKey;
97  KeyPolicy _keyPolicy;
98 
99  mutable std::vector<FieldType> _childNames;
100  mutable bool _childNamesValid;
101 };
102 
104 
105 #endif // PXR_USD_SDF_CHILDREN_H
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfLayer)
SDF_API bool IsEqualTo(const This &other) const
Return true if this object and other are equivalent.
Definition: layer.h:81
ChildPolicy::KeyPolicy KeyPolicy
Definition: children.h:36
SDF_API size_t GetSize() const
Return the number of children that this object contains.
SDF_API Sdf_Children()
GLsizei const GLfloat * value
Definition: glcorearb.h:824
Definition: spec.h:32
SDF_API KeyType FindKey(const ValueType &value) const
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
SDF_API bool Copy(const std::vector< ValueType > &values, const std::string &type)
Replace this object's children with the ones in values.
ChildPolicy::FieldType FieldType
Definition: children.h:39
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
SDF_API ValueType GetChild(size_t index) const
Return the child at the specified index.
Definition: token.h:70
SDF_API bool Insert(const ValueType &value, size_t index, const std::string &type)
Insert a new child at the specified index.
ChildPolicy::ValueType ValueType
Definition: children.h:38
Definition: path.h:273
SDF_API bool Erase(const KeyType &key, const std::string &type)
Erase the child with the specified key.
Sdf_Children< ChildPolicy > This
Definition: children.h:40
#define SDF_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool ValueType
Definition: NanoVDB.h:5729
SDF_API bool IsValid() const
Return whether this object is valid.
ChildPolicy::KeyType KeyType
Definition: children.h:37
SDF_API size_t Find(const KeyType &key) const
Find the index of the specified key, or return the size if it's not found.