24 #ifndef PXR_USD_SDF_LIST_EDITOR_H 25 #define PXR_USD_SDF_LIST_EDITOR_H 31 #include "pxr/usd/sdf/listOp.h" 32 #include "pxr/usd/sdf/path.h" 33 #include "pxr/usd/sdf/schema.h" 36 #include <boost/noncopyable.hpp> 37 #include <boost/optional.hpp> 41 PXR_NAMESPACE_OPEN_SCOPE
51 template <
class TypePolicy>
53 :
public boost::noncopyable
56 typedef Sdf_ListEditor<TypePolicy> This;
59 typedef typename TypePolicy::value_type value_type;
60 typedef std::vector<value_type> value_vector_type;
62 virtual ~Sdf_ListEditor() =
default;
64 SdfLayerHandle GetLayer()
const 66 return _owner ? _owner->GetLayer() : SdfLayerHandle();
71 return _owner ? _owner->GetPath() :
SdfPath();
79 bool IsExpired()
const 89 else if (IsOrderedOnly()) {
90 return !_GetOperations(SdfListOpTypeOrdered).empty();
93 return (!_GetOperations(SdfListOpTypeAdded).empty() ||
94 !_GetOperations(SdfListOpTypePrepended).empty() ||
95 !_GetOperations(SdfListOpTypeAppended).empty() ||
96 !_GetOperations(SdfListOpTypeDeleted).empty() ||
97 !_GetOperations(SdfListOpTypeOrdered).empty());
101 virtual bool IsExplicit()
const = 0;
102 virtual bool IsOrderedOnly()
const = 0;
104 virtual SdfAllowed PermissionToEdit(SdfListOpType op)
const 110 if (!_owner->PermissionToEdit()) {
117 virtual bool CopyEdits(
const Sdf_ListEditor& rhs) = 0;
118 virtual bool ClearEdits() = 0;
119 virtual bool ClearEditsAndMakeExplicit() = 0;
121 typedef std::function<
122 boost::optional<value_type>(
const value_type&)
132 virtual void ModifyItemEdits(
const ModifyCallback& cb) = 0;
134 typedef std::function<
135 boost::optional<value_type>(SdfListOpType,
const value_type&)
146 virtual void ApplyEditsToList(
147 value_vector_type* vec,
148 const ApplyCallback& cb = ApplyCallback()) = 0;
151 size_t GetSize(SdfListOpType op)
const 153 return _GetOperations(op).size();
157 value_type Get(SdfListOpType op,
size_t i)
const 159 return _GetOperations(op)[i];
163 value_vector_type GetVector(SdfListOpType op)
const 165 return _GetOperations(op);
170 size_t Count(SdfListOpType op,
const value_type& val)
const 172 const value_vector_type& ops = _GetOperations(op);
173 return std::count(ops.begin(), ops.end(), _typePolicy.Canonicalize(val));
178 size_t Find(SdfListOpType op,
const value_type& val)
const 180 const value_vector_type& vec = _GetOperations(op);
181 typename value_vector_type::const_iterator findIt =
182 std::find(vec.begin(), vec.end(), _typePolicy.Canonicalize(val));
183 if (findIt != vec.end()) {
184 return std::distance(vec.begin(), findIt);
192 virtual bool ReplaceEdits(
193 SdfListOpType op,
size_t index,
size_t n,
194 const value_vector_type& elems) = 0;
197 virtual void ApplyList(SdfListOpType op,
const Sdf_ListEditor& rhs) = 0;
204 Sdf_ListEditor(
const SdfSpecHandle& owner,
const TfToken& field,
205 const TypePolicy& typePolicy)
208 _typePolicy(typePolicy)
212 const SdfSpecHandle& _GetOwner()
const 217 const TfToken& _GetField()
const 222 const TypePolicy& _GetTypePolicy()
const 227 virtual bool _ValidateEdit(SdfListOpType op,
228 const value_vector_type& oldValues,
229 const value_vector_type& newValues)
const 246 typename value_vector_type::const_iterator
247 oldValuesTail = oldValues.begin(),
248 newValuesTail = newValues.begin();
249 auto oldEnd = oldValues.end(), newEnd = newValues.end();
250 while (oldValuesTail != oldEnd && newValuesTail != newEnd &&
251 *oldValuesTail == *newValuesTail) {
252 ++oldValuesTail, ++newValuesTail;
255 for (
auto i = newValuesTail; i != newEnd; ++i) {
257 for (
auto j = newValues.begin(); j != i; ++j) {
260 "field '%s' on <%s>",
263 this->GetPath().GetText());
271 _owner->GetSchema().GetFieldDefinition(_field);
277 for (
auto i = newValuesTail; i != newEnd; ++i) {
278 if (
SdfAllowed isValid = fieldDef->IsValidListValue(*i)) { }
289 virtual void _OnEdit(SdfListOpType op,
290 const value_vector_type& oldValues,
291 const value_vector_type& newValues)
const 295 virtual const value_vector_type& _GetOperations(SdfListOpType op)
const = 0;
298 SdfSpecHandle _owner;
300 TypePolicy _typePolicy;
304 template <
class TypePolicy>
306 operator<<(std::ostream& s,
const Sdf_ListEditor<TypePolicy>& x)
309 typedef typename Sdf_ListEditor<TypePolicy>::value_vector_type
312 static void _Write(std::ostream& s,
const value_vector_type& v)
315 for (
size_t i = 0, n = v.size(); i < n; ++i) {
328 else if (x.IsExplicit()) {
329 Util::_Write(s, x.GetVector(SdfListOpTypeExplicit));
334 if (!x.IsOrderedOnly()) {
336 Util::_Write(s, x.GetVector(SdfListOpTypeAdded));
337 s <<
"'prepended': ";
338 Util::_Write(s, x.GetVector(SdfListOpTypePrepended));
340 Util::_Write(s, x.GetVector(SdfListOpTypeAppended));
341 s <<
", 'deleted': ";
342 Util::_Write(s, x.GetVector(SdfListOpTypeDeleted));
346 Util::_Write(s, x.GetVector(SdfListOpTypeOrdered));
351 PXR_NAMESPACE_CLOSE_SCOPE
353 #endif // PXR_USD_SDF_LIST_EDITOR_H A scene description container that can combine with other such containers to form simple component as...
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Base class for all Sdf spec classes.
Token for efficient comparison, assignment, and hashing of known strings.
Class defining various attributes for a field.
Indicates if an operation is allowed and, if not, why not.
A path value used to locate objects in layers or scenegraphs.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
Convert an arbitrary type into a string.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...