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