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 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_CHILDREN_H
25 #define PXR_USD_SDF_CHILDREN_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/api.h"
30 #include "pxr/usd/sdf/path.h"
31 
32 #include <vector>
33 
35 
37 class SdfSpec;
38 
39 /// \class Sdf_Children
40 ///
41 /// Sdf_Children generically represents the children of an object. For
42 /// instance, it might be used for the name children of a prim or the
43 /// relationship targets of a relationship.
44 ///
45 /// The provided ChildPolicy class determines how this object behaves.
46 /// It primarily specifies how to map between keys (such as the name of
47 /// an object) and values (such as SpecHandles for those objects).
48 ///
49 template<class ChildPolicy>
51 {
52 public:
53  typedef typename ChildPolicy::KeyPolicy KeyPolicy;
54  typedef typename ChildPolicy::KeyType KeyType;
56  typedef typename ChildPolicy::FieldType FieldType;
58 
59  SDF_API
60  Sdf_Children();
61 
62  SDF_API
64 
65  SDF_API
66  Sdf_Children(const SdfLayerHandle &layer,
67  const SdfPath &parentPath, const TfToken &childrenKey,
68  const KeyPolicy& keyPolicy = KeyPolicy());
69 
70  /// Return whether this object is valid.
71  SDF_API
72  bool IsValid() const;
73 
74  /// Return the number of children that this object contains.
75  SDF_API
76  size_t GetSize() const;
77 
78  /// Return the child at the specified index.
79  SDF_API
80  ValueType GetChild(size_t index) const;
81 
82  /// Find the index of the specified key, or return the size if it's not found.
83  SDF_API
84  size_t Find(const KeyType &key) const;
85 
86  /// Find the key that corresponds to \a value, or return a default
87  /// constructed key if it's not found.
88  SDF_API
89  KeyType FindKey(const ValueType &value) const;
90 
91  /// Return true if this object and \a other are equivalent.
92  SDF_API
93  bool IsEqualTo(const This &other) const;
94 
95  /// Replace this object's children with the ones in \a values.
96  SDF_API
97  bool Copy(const std::vector<ValueType> & values, const std::string &type);
98 
99  /// Insert a new child at the specified \a index.
100  SDF_API
101  bool Insert(const ValueType& value, size_t index, const std::string &type);
102 
103  /// Erase the child with the specified key.
104  SDF_API
105  bool Erase(const KeyType& key, const std::string &type);
106 
107 private:
108  void _UpdateChildNames() const;
109 
110 private:
111  SdfLayerHandle _layer;
112  SdfPath _parentPath;
113  TfToken _childrenKey;
114  KeyPolicy _keyPolicy;
115 
116  mutable std::vector<FieldType> _childNames;
117  mutable bool _childNamesValid;
118 };
119 
121 
122 #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:97
ChildPolicy::KeyPolicy KeyPolicy
Definition: children.h:53
SDF_API size_t GetSize() const
Return the number of children that this object contains.
SDF_API Sdf_Children()
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
Definition: spec.h:49
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:56
SDF_API ValueType GetChild(size_t index) const
Return the child at the specified index.
Definition: token.h:87
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:55
Definition: path.h:290
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:57
#define SDF_API
Definition: api.h:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: core.h:1131
type
Definition: core.h:1059
bool ValueType
Definition: NanoVDB.h:5729
SDF_API bool IsValid() const
Return whether this object is valid.
ChildPolicy::KeyType KeyType
Definition: children.h:54
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.