HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
layer.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_LAYER_H
8 #define PXR_USD_SDF_LAYER_H
9 
10 /// \file sdf/layer.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/sdf/api.h"
14 #include "pxr/usd/sdf/data.h"
16 #include "pxr/usd/sdf/identity.h"
17 #include "pxr/usd/sdf/layerHints.h"
20 #include "pxr/usd/sdf/path.h"
21 #include "pxr/usd/sdf/proxyTypes.h"
22 #include "pxr/usd/sdf/spec.h"
23 #include "pxr/usd/sdf/types.h"
24 #include "pxr/usd/ar/ar.h"
25 #include "pxr/usd/ar/assetInfo.h"
28 #include "pxr/base/vt/value.h"
30 
31 #include <atomic>
32 #include <functional>
33 #include <memory>
34 #include <optional>
35 #include <set>
36 #include <string>
37 #include <vector>
38 
40 
43 
44 class SdfChangeList;
45 struct Sdf_AssetInfo;
46 
47 /// \class SdfLayer
48 ///
49 /// A scene description container that can combine with other such containers
50 /// to form simple component assets, and successively larger aggregates. The
51 /// contents of an SdfLayer adhere to the SdfData data model. A layer can be
52 /// ephemeral, or be an asset accessed and serialized through the ArAsset and
53 /// ArResolver interfaces.
54 ///
55 /// The SdfLayer class provides a consistent API for accesing and serializing
56 /// scene description, using any data store provided by Ar plugins. Sdf
57 /// itself provides a UTF-8 text format for layers identified by the ".usda"
58 /// identifier extension, but via the SdfFileFormat abstraction, allows
59 /// downstream modules and plugins to adapt arbitrary data formats to the
60 /// SdfData/SdfLayer model.
61 ///
62 /// The FindOrOpen() method returns a new SdfLayer object with scene
63 /// description from any supported asset format. Once read, a layer
64 /// remembers which asset it was read from. The Save() method saves the layer
65 /// back out to the original asset. You can use the Export() method to write
66 /// the layer to a different location. You can use the GetIdentifier() method
67 /// to get the layer's Id or GetRealPath() to get the resolved, full URI.
68 ///
69 /// Layer identifiers are UTF-8 encoded strings. A layer's file format is
70 /// determined via the identifier's extension (as resolved by Ar) with [A-Z]
71 /// (and no other characters) explicitly case folded.
72 ///
73 /// Layers can have a timeCode range (startTimeCode and endTimeCode). This range
74 /// represents the suggested playback range, but has no impact on the extent of
75 /// the animation data that may be stored in the layer. The metadatum
76 /// "timeCodesPerSecond" is used to annotate how the time ordinate for samples
77 /// contained in the file scales to seconds. For example, if timeCodesPerSecond
78 /// is 24, then a sample at time ordinate 24 should be viewed exactly one second
79 /// after the sample at time ordinate 0.
80 ///
81 class SdfLayer
82  : public TfRefBase
83  , public TfWeakBase
84 {
85 public:
86  /// Destructor
87  SDF_API
88  virtual ~SdfLayer();
89 
90  /// Noncopyable
91  SdfLayer(const SdfLayer&) = delete;
92  SdfLayer& operator=(const SdfLayer&) = delete;
93 
94  ///
95  /// \name Primary API
96  /// @{
97 
98  /// Returns the schema this layer adheres to. This schema provides details
99  /// about the scene description that may be authored in this layer.
100  SDF_API const SdfSchemaBase& GetSchema() const;
101 
102  /// Returns the file format used by this layer.
103  SDF_API const SdfFileFormatConstPtr& GetFileFormat() const;
104 
105  /// Type for specifying additional file format-specific arguments to
106  /// layer API.
107  typedef std::map<std::string, std::string> FileFormatArguments;
108 
109  /// Returns the file format-specific arguments used during the construction
110  /// of this layer.
112 
113  /// Creates a new empty layer with the given identifier.
114  ///
115  /// Additional arguments may be supplied via the \p args parameter.
116  /// These arguments may control behavior specific to the layer's
117  /// file format.
118  SDF_API
119  static SdfLayerRefPtr CreateNew(const std::string &identifier,
120  const FileFormatArguments &args =
122 
123  /// Creates a new empty layer with the given identifier for a given file
124  /// format class.
125  ///
126  /// This function has the same behavior as the other CreateNew function,
127  /// but uses the explicitly-specified \p fileFormat instead of attempting
128  /// to discern the format from \p identifier.
129  SDF_API
130  static SdfLayerRefPtr CreateNew(const SdfFileFormatConstPtr& fileFormat,
131  const std::string &identifier,
132  const FileFormatArguments &args =
134 
135  /// Creates a new empty layer with the given identifier for a given file
136  /// format class.
137  ///
138  /// The new layer will not be dirty and will not be saved.
139  ///
140  /// Additional arguments may be supplied via the \p args parameter.
141  /// These arguments may control behavior specific to the layer's
142  /// file format.
143  SDF_API
144  static SdfLayerRefPtr New(const SdfFileFormatConstPtr& fileFormat,
145  const std::string &identifier,
146  const FileFormatArguments &args =
148 
149  /// Return an existing layer with the given \p identifier and \p args. If
150  /// the layer can't be found, an error is posted and a null layer is
151  /// returned.
152  ///
153  /// Arguments in \p args will override any arguments specified in
154  /// \p identifier.
155  SDF_API
156  static SdfLayerHandle Find(
157  const std::string &identifier,
159 
160  /// Return an existing layer with the given \p identifier and \p args.
161  /// The given \p identifier will be resolved relative to the \p anchor
162  /// layer. If the layer can't be found, an error is posted and a null
163  /// layer is returned.
164  ///
165  /// If the \p anchor layer is invalid, a coding error is raised, and a null
166  /// handle is returned.
167  ///
168  /// Arguments in \p args will override any arguments specified in
169  /// \p identifier.
170  SDF_API
171  static SdfLayerHandle FindRelativeToLayer(
172  const SdfLayerHandle &anchor,
173  const std::string &identifier,
175 
176  /// Return an existing layer with the given \p identifier and \p args, or
177  /// else load it. If the layer can't be found or loaded, an error is posted
178  /// and a null layer is returned.
179  ///
180  /// Arguments in \p args will override any arguments specified in
181  /// \p identifier.
182  SDF_API
183  static SdfLayerRefPtr FindOrOpen(
184  const std::string &identifier,
186 
187  /// Return an existing layer with the given \p identifier and \p args, or
188  /// else load it. The given \p identifier will be resolved relative to the
189  /// \p anchor layer. If the layer can't be found or loaded, an error is
190  /// posted and a null layer is returned.
191  ///
192  /// If the \p anchor layer is invalid, issues a coding error and returns
193  /// a null handle.
194  ///
195  /// Arguments in \p args will override any arguments specified in
196  /// \p identifier.
197  SDF_API
199  const SdfLayerHandle &anchor,
200  const std::string &identifier,
202 
203  /// Load the given layer from disk as a new anonymous layer. If the
204  /// layer can't be found or loaded, an error is posted and a null
205  /// layer is returned.
206  ///
207  /// The anonymous layer does not retain any knowledge of the backing
208  /// file on the filesystem.
209  ///
210  /// \p metadataOnly is a flag that asks for only the layer metadata
211  /// to be read in, which can be much faster if that is all that is
212  /// required. Note that this is just a hint: some FileFormat readers
213  /// may disregard this flag and still fully populate the layer contents.
214  ///
215  /// An optional \p tag may be specified. See CreateAnonymous for details.
216  SDF_API
218  const std::string &layerPath,
219  bool metadataOnly = false,
220  const std::string& tag = std::string());
221 
222  /// Returns the data from the absolute root path of this layer.
223  SDF_API
224  SdfDataRefPtr GetMetadata() const;
225 
226  /// Return hints about the layer's current contents. Any operation that
227  /// dirties the layer will invalidate all hints.
228  /// \sa SdfLayerHints
229  SDF_API
230  SdfLayerHints GetHints() const;
231 
232  /// Returns handles for all layers currently held by the layer registry.
233  SDF_API
235 
236  /// Returns whether this layer has no significant data.
237  SDF_API
238  bool IsEmpty() const;
239 
240  /// Returns true if this layer streams data from its serialized data
241  /// store on demand, false otherwise.
242  ///
243  /// Layers with streaming data are treated differently to avoid pulling
244  /// in data unnecessarily. For example, reloading a streaming layer
245  /// will not perform fine-grained change notification, since doing
246  /// so would require the full contents of the layer to be loaded.
247  SDF_API
248  bool StreamsData() const;
249 
250  /// Returns true if this layer is detached from its serialized data
251  /// store, false otherwise.
252  ///
253  /// Detached layers are isolated from external changes to their serialized
254  /// data.
255  SDF_API
256  bool IsDetached() const;
257 
258  /// Copies the content of the given layer into this layer.
259  /// Source layer is unmodified.
260  SDF_API
261  void TransferContent(const SdfLayerHandle& layer);
262 
263  /// Creates a new \e anonymous layer with an optional \p tag. An anonymous
264  /// layer is a layer with a system assigned identifier, that cannot be
265  /// saved to disk via Save(). Anonymous layers have an identifier, but no
266  /// real path or other asset information fields.
267  ///
268  /// Anonymous layers may be tagged, which can be done to aid debugging
269  /// subsystems that make use of anonymous layers. The tag becomes the
270  /// display name of an anonymous layer, and is also included in the
271  /// generated identifier. Untagged anonymous layers have an empty display
272  /// name.
273  ///
274  /// Additional arguments may be supplied via the \p args parameter.
275  /// These arguments may control behavior specific to the layer's
276  /// file format.
277  SDF_API
279  const std::string& tag = std::string(),
281 
282  /// Create an anonymous layer with a specific \p format.
283  SDF_API
285  const std::string &tag, const SdfFileFormatConstPtr &format,
287 
288  /// Returns true if this layer is an anonymous layer.
289  SDF_API
290  bool IsAnonymous() const;
291 
292  /// Returns true if the \p identifier is an anonymous layer unique
293  /// identifier.
294  SDF_API
295  static bool IsAnonymousLayerIdentifier(const std::string& identifier);
296 
297  /// Returns the display name for the given \p identifier, using the same
298  /// rules as GetDisplayName.
299  SDF_API
300  static std::string GetDisplayNameFromIdentifier(
301  const std::string& identifier);
302 
303  /// @}
304  /// \name File I/O
305  /// @{
306 
307  /// Returns \c true if successful, \c false if an error occurred.
308  /// Returns \c false if the layer has no remembered file name or the
309  /// layer type cannot be saved. The layer will not be overwritten if the
310  /// file exists and the layer is not dirty unless \p force is true.
311  SDF_API
312  bool Save(bool force = false) const;
313 
314  /// Exports this layer to a file.
315  /// Returns \c true if successful, \c false if an error occurred.
316  ///
317  /// If \p comment is not empty, the layer gets exported with the given
318  /// comment. Additional arguments may be supplied via the \p args parameter.
319  /// These arguments may control behavior specific to the exported layer's
320  /// file format.
321  ///
322  /// Note that the file name or comment of the original layer is not
323  /// updated. This only saves a copy of the layer to the given filename.
324  /// Subsequent calls to Save() will still save the layer to it's
325  /// previously remembered file name.
326  SDF_API
327  bool Export(const std::string& filename,
328  const std::string& comment = std::string(),
329  const FileFormatArguments& args = FileFormatArguments()) const;
330 
331  /// Writes this layer to the given string.
332  ///
333  /// Returns \c true if successful and sets \p result, otherwise
334  /// returns \c false.
335  SDF_API
336  bool ExportToString(std::string* result) const;
337 
338  /// Reads this layer from the given string.
339  ///
340  /// Returns \c true if successful, otherwise returns \c false.
341  SDF_API
342  bool ImportFromString(const std::string &string);
343 
344  /// Clears the layer of all content.
345  ///
346  /// This restores the layer to a state as if it had just been created
347  /// with CreateNew(). This operation is Undo-able.
348  ///
349  /// The fileName and whether journaling is enabled are not affected
350  /// by this method.
351  SDF_API
352  void Clear();
353 
354  /// Reloads the layer from its persistent representation.
355  ///
356  /// This restores the layer to a state as if it had just been created
357  /// with FindOrOpen(). This operation is Undo-able.
358  ///
359  /// The fileName and whether journaling is enabled are not affected
360  /// by this method.
361  ///
362  /// When called with force = false (the default), Reload attempts to
363  /// avoid reloading layers that have not changed on disk. It does so
364  /// by comparing the file's modification time (mtime) to when the
365  /// file was loaded. If the layer has unsaved modifications, this
366  /// mechanism is not used, and the layer is reloaded from disk. If the
367  /// layer has any
368  /// \ref GetExternalAssetDependencies "external asset dependencies"
369  /// their modification state will also be consulted when determining if
370  /// the layer needs to be reloaded.
371  ///
372  /// Passing true to the \p force parameter overrides this behavior,
373  /// forcing the layer to be reloaded from disk regardless of whether
374  /// it has changed.
375  SDF_API
376  bool Reload(bool force = false);
377 
378  /// Reloads the specified layers.
379  ///
380  /// Returns \c false if one or more layers failed to reload.
381  ///
382  /// See \c Reload() for a description of the \p force flag.
383  ///
384  SDF_API
385  static bool ReloadLayers(const std::set<SdfLayerHandle>& layers,
386  bool force = false);
387 
388  /// Imports the content of the given layer path, replacing the content
389  /// of the current layer.
390  /// Note: If the layer path is the same as the current layer's real path,
391  /// no action is taken (and a warning occurs). For this case use
392  /// Reload().
393  SDF_API
394  bool Import(const std::string &layerPath);
395 
396  /// @}
397  /// \name External references
398  /// @{
399 
400  /// \deprecated
401  /// Use GetCompositionAssetDependencies instead.
402  SDF_API
403  std::set<std::string> GetExternalReferences() const;
404 
405  /// \deprecated
406  /// Use UpdateCompositionAssetDependency instead.
407  SDF_API
409  const std::string &oldAssetPath,
410  const std::string &newAssetPath=std::string());
411 
412  /// Return paths of all assets this layer depends on due to composition
413  /// fields.
414  ///
415  /// This includes the paths of all layers referred to by reference,
416  /// payload, and sublayer fields in this layer. This function only returns
417  /// direct composition dependencies of this layer, i.e. it does not recurse
418  /// to find composition dependencies from its dependent layer assets.
419  SDF_API
420  std::set<std::string> GetCompositionAssetDependencies() const;
421 
422  /// Updates the asset path of a composation dependency in this layer.
423  ///
424  /// If \p newAssetPath is supplied, the update works as "rename", updating
425  /// any occurrence of \p oldAssetPath to \p newAssetPath in all reference,
426  /// payload, and sublayer fields.
427  ///
428  /// If \p newAssetPath is not given, this update behaves as a "delete",
429  /// removing all occurrences of \p oldAssetPath from all reference, payload,
430  /// and sublayer fields.
431  SDF_API
433  const std::string &oldAssetPath,
434  const std::string &newAssetPath=std::string());
435 
436  /// Returns a set of resolved paths to all external asset dependencies
437  /// the layer needs to generate its contents. These are additional asset
438  /// dependencies that are determined by the layer's
439  /// \ref SdfFileFormat::GetExternalAssetDependencies "file format" and
440  /// will be consulted during Reload() when determining if the layer needs
441  /// to be reloaded. This specifically does not include dependencies related
442  /// to composition, i.e. this will not include assets from references,
443  /// payloads, and sublayers.
444  SDF_API
445  std::set<std::string> GetExternalAssetDependencies() const;
446 
447  /// @}
448  /// \name Identification
449  ///
450  /// A layer's identifier is a string that uniquely identifies a layer.
451  /// At minimum, it is the string by which the layer was created, either
452  /// via FindOrOpen or CreateNew. If additional arguments were passed
453  /// to those functions, those arguments will be encoded in the identifier.
454  ///
455  /// For example:
456  /// FindOrOpen('foo.usda', args={'a':'b', 'c':'d'}).identifier
457  /// => "foo.usda:SDF_FORMAT_ARGS:a=b&c=d"
458  ///
459  /// Note that this means the identifier may in general not be a path.
460  ///
461  /// The identifier format is subject to change; consumers should NOT
462  /// parse layer identifiers themselves, but should use the supplied
463  /// SplitIdentifier and CreateIdentifier helper functions.
464  ///
465  /// @{
466 
467  /// Splits the given layer identifier into its constituent layer path
468  /// and arguments.
469  SDF_API
470  static bool SplitIdentifier(
471  const std::string& identifier,
472  std::string* layerPath,
473  FileFormatArguments* arguments);
474 
475  /// Splits the given layer identifier and returns its constituent layer path
476  /// and arguments as a pair of strings.
477  ///
478  /// First element of the pair is the layer path, and the second element is
479  /// the arguments string.
480  SDF_API
481  static std::pair<std::string, std::string> SplitIdentifier(
482  const std::string& identifier);
483 
484  /// Joins the given layer path and arguments into an identifier.
485  SDF_API
486  static std::string CreateIdentifier(
487  const std::string& layerPath,
488  const FileFormatArguments& arguments);
489 
490  /// Returns the layer identifier.
491  SDF_API
492  const std::string& GetIdentifier() const;
493 
494  /// Sets the layer identifier.
495  /// Note that the new identifier must have the same arguments (if any)
496  /// as the old identifier.
497  SDF_API
498  void SetIdentifier(const std::string& identifier);
499 
500  /// Update layer asset information. Calling this method re-resolves the
501  /// layer identifier, which updates asset information such as the layer's
502  /// resolved path and other asset info. This may be used to update the
503  /// layer after external changes to the underlying asset system.
504  SDF_API
505  void UpdateAssetInfo();
506 
507  /// Returns the layer's display name.
508  ///
509  /// The display name is the base filename of the identifier.
510  SDF_API
511  std::string GetDisplayName() const;
512 
513  /// Returns the resolved path for this layer. This is the path where
514  /// this layer exists or may exist after a call to Save().
515  SDF_API
516  const ArResolvedPath& GetResolvedPath() const;
517 
518  /// Returns the resolved path for this layer. This is equivalent to
519  /// GetResolvedPath().GetPathString().
520  SDF_API
521  const std::string& GetRealPath() const;
522 
523  /// Returns the file extension to use for this layer.
524  /// If this layer was loaded from disk, it should match the extension
525  /// of the file format it was loaded as; if this is an anonymous
526  /// in-memory layer it will be the default extension.
527  SDF_API
528  std::string GetFileExtension() const;
529 
530  /// Returns the asset system version of this layer. If a layer is loaded
531  /// from a location that is not version managed, or a configured asset
532  /// system is not present when the layer is loaded or created, the version
533  /// is empty. By default, asset version tracking is disabled; this method
534  /// returns empty unless asset version tracking is enabled.
535  SDF_API
536  const std::string& GetVersion() const;
537 
538  /// Returns the layer identifier in asset path form. In the presence of a
539  /// properly configured path resolver, the asset path is a double-slash
540  /// prefixed depot path. If the path resolver is not configured, the asset
541  /// path of a layer is empty.
542  SDF_API
543  const std::string& GetRepositoryPath() const;
544 
545  /// Returns the asset name associated with this layer.
546  SDF_API
547  const std::string& GetAssetName() const;
548 
549  /// Returns resolve information from the last time the layer identifier
550  /// was resolved.
551  SDF_API
552  const VtValue& GetAssetInfo() const;
553 
554  /// Returns the path to the asset specified by \p assetPath using this layer
555  /// to anchor the path if necessary. Returns \p assetPath if it's empty or
556  /// an anonymous layer identifier.
557  ///
558  /// This method can be used on asset paths that are authored in this layer
559  /// to create new asset paths that can be copied to other layers. These new
560  /// asset paths should refer to the same assets as the original asset
561  /// paths. For example, if the underlying ArResolver is filesystem-based and
562  /// \p assetPath is a relative filesystem path, this method might return the
563  /// absolute filesystem path using this layer's location as the anchor.
564  ///
565  /// The returned path should in general not be assumed to be an absolute
566  /// filesystem path or any other specific form. It is "absolute" in that it
567  /// should resolve to the same asset regardless of what layer it's authored
568  /// in.
569  SDF_API
570  std::string ComputeAbsolutePath(const std::string& assetPath) const;
571 
572  /// @}
573 
574  /// \name Fields
575  ///
576  /// All scene description for a given object is stored as a set of
577  /// key/value pairs called fields. These methods provide direct access to
578  /// those fields, though most clients should use the Spec API to ensure
579  /// data consistency.
580  ///
581  /// These methods all take SdfPath to identify the queried spec.
582  ///
583  /// @{
584 
585  /// Return the spec type for \a path. This returns SdfSpecTypeUnknown if no
586  /// spec exists at \a path.
587  SDF_API
588  SdfSpecType GetSpecType(const SdfPath& path) const;
589 
590  /// Return whether a spec exists at \a path.
591  SDF_API
592  bool HasSpec(const SdfPath& path) const;
593 
594  /// Return the names of all the fields that are set at \p path.
595  SDF_API
596  std::vector<TfToken> ListFields(const SdfPath& path) const;
597 
598  /// Return whether a value exists for the given \a path and \a fieldName.
599  /// Optionally returns the value if it exists.
600  SDF_API
601  bool HasField(const SdfPath& path, const TfToken& fieldName,
602  VtValue *value=NULL) const;
603  SDF_API
604  bool HasField(const SdfPath& path, const TfToken& fieldName,
605  SdfAbstractDataValue *value) const;
606 
607  /// Returns \c true if the object has a non-empty value with name
608  /// \p name and type \p T. If value ptr is provided, returns the
609  /// value found.
610  template <class T>
611  bool HasField(const SdfPath& path, const TfToken &name,
612  T* value) const
613  {
614  if (!value) {
615  return HasField(path, name, static_cast<VtValue *>(NULL));
616  }
617 
618  SdfAbstractDataTypedValue<T> outValue(value);
619  const bool hasValue = HasField(
620  path, name, static_cast<SdfAbstractDataValue *>(&outValue));
621 
623  return hasValue && outValue.isValueBlock;
624  }
625 
626  return hasValue && (!outValue.isValueBlock);
627  }
628 
629  /// Return the type of the value for \p name on spec \p path. If no such
630  /// field exists, return typeid(void).
631  std::type_info const &GetFieldTypeid(
632  const SdfPath &path, const TfToken &name) const {
633  return _data->GetTypeid(path, name);
634  }
635 
636  /// Return whether a value exists for the given \a path and \a fieldName and
637  /// \a keyPath. The \p keyPath is a ':'-separated path addressing an
638  /// element in sub-dictionaries. Optionally returns the value if it exists.
639  SDF_API
640  bool HasFieldDictKey(const SdfPath& path,
641  const TfToken &fieldName,
642  const TfToken &keyPath,
643  VtValue *value=NULL) const;
644  SDF_API
645  bool HasFieldDictKey(const SdfPath& path,
646  const TfToken &fieldName,
647  const TfToken &keyPath,
648  SdfAbstractDataValue *value) const;
649 
650  /// Returns \c true if the object has a non-empty value with name \p name
651  /// and \p keyPath and type \p T. If value ptr is provided, returns the
652  /// value found. The \p keyPath is a ':'-separated path addressing an
653  /// element in sub-dictionaries.
654  template <class T>
655  bool HasFieldDictKey(const SdfPath& path, const TfToken &name,
656  const TfToken &keyPath, T* value) const
657  {
658  if (!value) {
659  return HasFieldDictKey(path, name, keyPath,
660  static_cast<VtValue *>(NULL));
661  }
662 
663  SdfAbstractDataTypedValue<T> outValue(value);
664  return HasFieldDictKey(path, name, keyPath,
665  static_cast<SdfAbstractDataValue *>(&outValue));
666  }
667 
668 
669  /// Return the value for the given \a path and \a fieldName. Returns an
670  /// empty value if none is set.
671  SDF_API
672  VtValue GetField(const SdfPath& path,
673  const TfToken& fieldName) const;
674 
675  /// Return the value for the given \a path and \a fieldName. Returns the
676  /// provided \a defaultValue value if none is set.
677  template <class T>
678  inline T GetFieldAs(const SdfPath& path,
679  const TfToken& fieldName, const T& defaultValue = T()) const
680  {
681  return _data->GetAs<T>(path, fieldName, defaultValue);
682  }
683 
684  /// Return the value for the given \a path and \a fieldName at \p
685  /// keyPath. Returns an empty value if none is set. The \p keyPath is a
686  /// ':'-separated path addressing an element in sub-dictionaries.
687  SDF_API
689  const TfToken& fieldName,
690  const TfToken& keyPath) const;
691 
692  /// Set the value of the given \a path and \a fieldName.
693  SDF_API
694  void SetField(const SdfPath& path, const TfToken& fieldName,
695  const VtValue& value);
696  SDF_API
697  void SetField(const SdfPath& path, const TfToken& fieldName,
699 
700  /// Set the value of the given \a path and \a fieldName.
701  template <class T>
702  void SetField(const SdfPath& path, const TfToken& fieldName,
703  const T& val)
704  {
705  // Ideally, this would make use of the SdfAbstractDataConstValue
706  // API to avoid unnecessarily copying the value into a VtValue.
707  // However, Sdf needs to create a VtValue for change processing.
708  // If the underlying SdAbstractData implementation also needs a
709  // VtValue, using the SdfAbstractDataConstValue API would cause
710  // another copy to be made. So, it's more efficient to just create
711  // the VtValue once here and push that along.
712  SetField(path, fieldName, VtValue(val));
713  }
714 
715  /// Set the value of the given \a path and \a fieldName. The \p keyPath is a
716  /// ':'-separated path addressing an element in sub-dictionaries.
717  SDF_API
718  void SetFieldDictValueByKey(const SdfPath& path,
719  const TfToken& fieldName,
720  const TfToken& keyPath,
721  const VtValue& value);
722  SDF_API
723  void SetFieldDictValueByKey(const SdfPath& path,
724  const TfToken& fieldName,
725  const TfToken& keyPath,
727 
728  /// Set the value of the given \a path and \a fieldName. The \p keyPath is
729  /// a ':'-separated path addressing an element in sub-dictionaries.
730  template <class T>
731  void SetFieldDictValueByKey(const SdfPath& path,
732  const TfToken& fieldName,
733  const TfToken& keyPath,
734  const T& val)
735  {
736  // Ideally, this would make use of the SdfAbstractDataConstValue
737  // API to avoid unnecessarily copying the value into a VtValue.
738  // However, Sdf needs to create a VtValue for change processing.
739  // If the underlying SdAbstractData implementation also needs
740  // VtValue, using the SdfAbstractDataConstValue API would cause
741  // another copy to be made. So, it's more efficient to just create
742  // the VtValue once here and push that along.
743  SetFieldDictValueByKey(path, fieldName, keyPath, VtValue(val));
744  }
745 
746  /// Remove the field at \p path and \p fieldName, if one exists.
747  SDF_API
748  void EraseField(const SdfPath& path, const TfToken& fieldName);
749 
750  /// Remove the field at \p path and \p fieldName and \p keyPath, if one
751  /// exists. The \p keyPath is a ':'-separated path addressing an
752  /// element in sub-dictionaries.
753  SDF_API
754  void EraseFieldDictValueByKey(const SdfPath& path,
755  const TfToken& fieldName,
756  const TfToken& keyPath);
757 
758  /// \name Traversal
759  /// @{
760 
761  /// Callback function for Traverse. This callback will be invoked with
762  /// the path of each spec that is visited.
763  /// \sa Traverse
764  typedef std::function<void(const SdfPath&)> TraversalFunction;
765 
766  // Traverse will perform a traversal of the scene description hierarchy
767  // rooted at \a path, calling \a func on each spec that it finds.
768  SDF_API
769  void Traverse(const SdfPath& path, const TraversalFunction& func);
770 
771  /// @}
772 
773  /// \name Metadata
774  /// @{
775 
776  /// Returns the color configuration asset-path for this layer.
777  ///
778  /// The default value is an empty asset-path.
779  SDF_API
781 
782  /// Sets the color configuration asset-path for this layer.
783  SDF_API
784  void SetColorConfiguration(const SdfAssetPath &colorConfiguration);
785 
786  /// Returns true if color configuration metadata is set in this layer.
787  /// \sa GetColorConfiguration(), SetColorConfiguration()
788  SDF_API
789  bool HasColorConfiguration() const;
790 
791  /// Clears the color configuration metadata authored in this layer.
792  /// \sa HasColorConfiguration(), SetColorConfiguration()
793  SDF_API
795 
796  /// Returns the color management system used to interpret the color
797  /// configuration asset-path authored in this layer.
798  ///
799  /// The default value is an empty token, which implies that the clients
800  /// will have to determine the color management system from the color
801  /// configuration asset path (i.e. from its file extension), if it's
802  /// specified.
803  SDF_API
805 
806  /// Sets the color management system used to interpret the color
807  /// configuration asset-path authored this layer.
808  SDF_API
809  void SetColorManagementSystem(const TfToken &cms);
810 
811  /// Returns true if colorManagementSystem metadata is set in this layer.
812  /// \sa GetColorManagementSystem(), SetColorManagementSystem()
813  SDF_API
814  bool HasColorManagementSystem() const;
815 
816  /// Clears the 'colorManagementSystem' metadata authored in this layer.
817  /// \sa HascolorManagementSystem(), SetColorManagementSystem()
818  SDF_API
820 
821  /// Returns the comment string for this layer.
822  ///
823  /// The default value for comment is "".
824  SDF_API
825  std::string GetComment() const;
826 
827  /// Sets the comment string for this layer.
828  SDF_API
829  void SetComment(const std::string &comment);
830 
831  /// Return the defaultPrim metadata for this layer. This field
832  /// indicates the name or path of which prim should be targeted by a
833  /// reference or payload to this layer that doesn't specify a prim path.
834  ///
835  /// The default value is the empty token.
836  SDF_API
837  TfToken GetDefaultPrim() const;
838 
839  /// Return this layer's default prim metadata interpreted as an absolute
840  /// prim path regardless of whether it was authored as a root prim name or a
841  /// prim path. For example, if the authored default prim value is
842  /// "rootPrim", return </rootPrim>. If the authored default prim value is
843  /// "/path/to/non/root/prim", return </path/to/non/root/prim>. If the
844  /// authored default prim value cannot be interpreted as a prim path,
845  /// return the empty SdfPath.
846  ///
847  /// The default value is an empty path.
848  SDF_API
850 
851  /// Set the default prim metadata for this layer. The prim at this path
852  /// will be targeted by a reference or a payload to this layer that doesn't
853  /// specify a prim path.
854  /// Note that this can be a name if it refers to a root prim, or a path to
855  /// any prim in this layer. E.g. "rootPrim", "/path/to/non/root/prim" or
856  /// "/rootPrim". See GetDefaultPrim().
857  SDF_API
858  void SetDefaultPrim(const TfToken &name);
859 
860  /// Clear the default prim metadata for this layer. See GetDefaultPrim()
861  /// and SetDefaultPrim().
862  SDF_API
863  void ClearDefaultPrim();
864 
865  /// Return true if the default prim metadata is set in this layer. See
866  /// GetDefaultPrim() and SetDefaultPrim().
867  SDF_API
868  bool HasDefaultPrim();
869 
870  /// Converts the given \p defaultPrim token into a prim path.
871  ///
872  /// If the input token is the string representation of an absolute prim,
873  /// that path is returned. If the token represents a relative prim path, the
874  /// returned path is coverted into a absolute path anchored to the absolute
875  /// root path. If the token does not represent a valid relative or absolute
876  /// prim path, an empty path is returned.
877  SDF_API
878  static SdfPath ConvertDefaultPrimTokenToPath(const TfToken &defaultPrim);
879 
880  /// Converts the path \p primPath into a token value that can be used to
881  /// set the default prim metadata for the layer to refer to the prim at that
882  /// path.
883  ///
884  /// If the given path is a root prim path, the returned token will just be
885  /// the name of the prim. For all other prim paths, this will return the
886  /// absolute path as a string token. If the path is not a prim path, this
887  /// will return an empty token.
888  SDF_API
889  static TfToken ConvertDefaultPrimPathToToken(const SdfPath &primPath);
890 
891  /// Returns the documentation string for this layer.
892  ///
893  /// The default value for documentation is "".
894  SDF_API
895  std::string GetDocumentation() const;
896 
897  /// Sets the documentation string for this layer.
898  SDF_API
899  void SetDocumentation(const std::string &documentation);
900 
901  /// Returns the layer's start timeCode.
902  ///
903  /// The start and end timeCodes of a layer represent the suggested playback
904  /// range. However, time-varying content is not limited to the timeCode range
905  /// of the layer.
906  ///
907  /// The default value for startTimeCode is 0.
908  SDF_API
909  double GetStartTimeCode() const;
910 
911  /// Sets the layer's start timeCode.
912  SDF_API
913  void SetStartTimeCode(double startTimecode);
914 
915  /// Returns true if the layer has a startTimeCode opinion.
916  SDF_API
917  bool HasStartTimeCode() const;
918 
919  /// Clear the startTimeCode opinion.
920  SDF_API
921  void ClearStartTimeCode();
922 
923  /// Returns the layer's end timeCode.
924  /// The start and end timeCode of a layer represent a suggested playback range.
925  /// However, time-varying content is not limited to the timeCode range of the
926  /// layer.
927  ///
928  /// The default value for endTimeCode is 0.
929  SDF_API
930  double GetEndTimeCode() const;
931 
932  /// Sets the layer's end timeCode.
933  SDF_API
934  void SetEndTimeCode(double endTimeCode);
935 
936  /// Returns true if the layer has an endTimeCode opinion.
937  SDF_API
938  bool HasEndTimeCode() const;
939 
940  /// Clear the endTimeCode opinion.
941  SDF_API
942  void ClearEndTimeCode();
943 
944  /// Returns the layer's timeCodes per second.
945  ///
946  /// Scales the time ordinate for samples contained in the file to seconds.
947  /// If timeCodesPerSecond is 24, then a sample at time ordinate 24 should
948  /// be viewed exactly one second after the sample at time ordinate 0.
949  ///
950  /// If this layer doesn't have an authored value for timeCodesPerSecond, but
951  /// it does have an authored value for framesPerSecond, this method will
952  /// return the value of framesPerSecond. This "dynamic fallback" allows
953  /// layers to lock framesPerSecond and timeCodesPerSecond to the same value
954  /// by specifying only framesPerSecond.
955  ///
956  /// The default value of timeCodesPerSecond, used only if there is no
957  /// authored value for either timeCodesPerSecond or framesPerSecond, is 24.
958  SDF_API
959  double GetTimeCodesPerSecond() const;
960 
961  /// Sets the layer's timeCodes per second
962  SDF_API
963  void SetTimeCodesPerSecond(double timeCodesPerSecond);
964 
965  /// Returns true if the layer has a timeCodesPerSecond opinion.
966  SDF_API
967  bool HasTimeCodesPerSecond() const;
968 
969  /// Clear the timeCodesPerSecond opinion.
970  SDF_API
972 
973  /// Returns the layer's frames per second.
974  ///
975  /// This makes an advisory statement about how the contained data can be
976  /// most usefully consumed and presented. It's primarily an indication of
977  /// the expected playback rate for the data, but a timeline editing tool
978  /// might also want to use this to decide how to scale and label its
979  /// timeline.
980  ///
981  /// The default value for framesPerSecond is 24.
982  SDF_API
983  double GetFramesPerSecond() const;
984 
985  /// Sets the layer's frames per second
986  SDF_API
987  void SetFramesPerSecond(double framesPerSecond);
988 
989  /// Returns true if the layer has a frames per second opinion.
990  SDF_API
991  bool HasFramesPerSecond() const;
992 
993  /// Clear the framesPerSecond opinion.
994  SDF_API
995  void ClearFramesPerSecond();
996 
997  /// Returns the layer's frame precision.
998  SDF_API
999  int GetFramePrecision() const;
1000 
1001  /// Sets the layer's frame precision.
1002  SDF_API
1003  void SetFramePrecision(int framePrecision);
1004 
1005  /// Returns true if the layer has a frames precision opinion.
1006  SDF_API
1007  bool HasFramePrecision() const;
1008 
1009  /// Clear the framePrecision opinion.
1010  SDF_API
1011  void ClearFramePrecision();
1012 
1013  /// Returns the layer's owner.
1014  SDF_API
1015  std::string GetOwner() const;
1016 
1017  /// Sets the layer's owner.
1018  SDF_API
1019  void SetOwner(const std::string& owner);
1020 
1021  /// Returns true if the layer has an owner opinion.
1022  SDF_API
1023  bool HasOwner() const;
1024 
1025  /// Clear the owner opinion.
1026  SDF_API
1027  void ClearOwner();
1028 
1029  /// Returns the layer's session owner.
1030  /// Note: This should only be used by session layers.
1031  SDF_API
1032  std::string GetSessionOwner() const;
1033 
1034  /// Sets the layer's session owner.
1035  /// Note: This should only be used by session layers.
1036  SDF_API
1037  void SetSessionOwner(const std::string& owner);
1038 
1039  /// Returns true if the layer has a session owner opinion.
1040  SDF_API
1041  bool HasSessionOwner() const;
1042 
1043  // Clear the session owner opinion.
1044  SDF_API
1045  void ClearSessionOwner();
1046 
1047  /// Returns true if the layer's sublayers are expected to have owners.
1048  SDF_API
1049  bool GetHasOwnedSubLayers() const;
1050 
1051  /// Sets whether the layer's sublayers are expected to have owners.
1052  SDF_API
1053  void SetHasOwnedSubLayers(bool);
1054 
1055  /// Returns the CustomLayerData dictionary associated with this layer.
1056  ///
1057  /// This is a dictionary is custom metadata that is associated with
1058  /// this layer. It allows users to encode any set of information for
1059  /// human or program consumption.
1060  SDF_API
1062 
1063  /// Sets the CustomLayerData dictionary associated with this layer.
1064  SDF_API
1065  void SetCustomLayerData(const VtDictionary& value);
1066 
1067  /// Returns true if CustomLayerData is authored on the layer.
1068  SDF_API
1069  bool HasCustomLayerData() const;
1070 
1071  /// Clears out the CustomLayerData dictionary associated with this layer.
1072  SDF_API
1073  void ClearCustomLayerData();
1074 
1075  /// Returns the expression variables dictionary authored on this layer.
1076  /// See \ref Sdf_Page_VariableExpressions for more details.
1077  SDF_API
1079 
1080  /// Sets the expression variables dictionary for this layer.
1081  SDF_API
1082  void SetExpressionVariables(const VtDictionary& expressionVars);
1083 
1084  /// Returns true if expression variables are authored on this layer.
1085  SDF_API
1086  bool HasExpressionVariables() const;
1087 
1088  /// Clears the expression variables dictionary authored on this layer.
1089  SDF_API
1090  void ClearExpressionVariables();
1091 
1092  /// @}
1093  /// \name Prims
1094  /// @{
1095 
1096  // Type for root prims view.
1098 
1099  /// Returns a vector of the layer's root prims
1100  SDF_API
1101  RootPrimsView GetRootPrims() const;
1102 
1103  /// Sets a new vector of root prims.
1104  /// You can re-order, insert and remove prims but cannot
1105  /// rename them this way. If any of the listed prims have
1106  /// an existing owner, they will be reparented.
1107  SDF_API
1108  void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims);
1109 
1110  /// Adds a new root prim at the given index.
1111  /// If the index is -1, the prim is inserted at the end.
1112  /// The layer will take ownership of the prim, via a TfRefPtr.
1113  /// Returns true if successful, false if failed (for example,
1114  /// due to a duplicate name).
1115  SDF_API
1116  bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index = -1);
1117 
1118  /// Remove a root prim.
1119  SDF_API
1120  void RemoveRootPrim(const SdfPrimSpecHandle &prim);
1121 
1122  /// Cause \p spec to be removed if it no longer affects the scene when the
1123  /// last change block is closed, or now if there are no change blocks.
1124  SDF_API
1125  void ScheduleRemoveIfInert(const SdfSpec& spec);
1126 
1127  /// Removes scene description that does not affect the scene in the
1128  /// layer namespace beginning with \p prim.
1129  ///
1130  /// Calling this method on a prim will only clean up prims with specifier
1131  /// 'over' that are not contributing any opinions. The \p prim will only
1132  /// be removed if all of its nameChildren are also inert. The hierarchy
1133  /// \p prim is defined in will be pruned up to the layer root for each
1134  /// successive inert parent that has specifier 'over'.
1135  ///
1136  /// note: PrimSpecs that contain any PropertySpecs, even PropertySpecs with
1137  /// required fields only (see PropertySpec::HasRequiredFieldsOnly)
1138  /// are not considered inert, and thus the prim won't be removed.
1139  SDF_API
1140  void RemovePrimIfInert(SdfPrimSpecHandle prim);
1141 
1142  /// Removes prop if it has only required fields (i.e. is not
1143  /// contributing any opinions to the scene other than property
1144  /// instantiation).
1145  ///
1146  /// The hierarchy \p prop is defined in will then be pruned up to the
1147  /// layer root for each successive inert parent.
1148  SDF_API
1149  void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop);
1150 
1151  /// Removes all scene description in this layer that does not affect the
1152  /// scene.
1153  ///
1154  /// This method walks the layer namespace hierarchy and removes any prims
1155  /// and that are not contributing any opinions.
1156  SDF_API
1158 
1159  /// Returns the list of prim names for this layer's reorder rootPrims
1160  /// statement.
1161  ///
1162  /// See SetRootPrimOrder() for more info.
1163  SDF_API
1165 
1166  /// Given a list of (possible sparse) prim names, authors a reorder
1167  /// rootPrims statement for this prim.
1168  ///
1169  /// This reorder statement can modify the order of root prims that have
1170  /// already been explicitly ordered with InsertRootPrim() or SetRootPrims();
1171  /// but only during composition. Therefore, GetRootPrims(),
1172  /// InsertRootPrim(), SetRootPrims(), etc. do not read, author, or pay any
1173  /// attention to this statement.
1174  SDF_API
1175  void SetRootPrimOrder(const std::vector<TfToken>& names);
1176 
1177  /// Adds a new root prim name in the root prim order.
1178  /// If the index is -1, the name is inserted at the end.
1179  SDF_API
1180  void InsertInRootPrimOrder(const TfToken &name, int index = -1);
1181 
1182  /// Removes a root prim name from the root prim order.
1183  SDF_API
1184  void RemoveFromRootPrimOrder(const TfToken & name);
1185 
1186  /// Removes a root prim name from the root prim order by index.
1187  SDF_API
1189 
1190  /// Reorders the given list of prim names according to the reorder rootPrims
1191  /// statement for this layer.
1192  ///
1193  /// This routine employs the standard list editing operations for ordered
1194  /// items in a ListEditor.
1195  SDF_API
1196  void ApplyRootPrimOrder(std::vector<TfToken> *vec) const;
1197 
1198  /// @}
1199  /// \name Sublayers
1200  /// @{
1201 
1202  /// Returns a proxy for this layer's sublayers.
1203  ///
1204  /// Sub-layers are the weaker layers directly included by this layer.
1205  /// They're in order from strongest to weakest and they're all weaker
1206  /// than this layer.
1207  ///
1208  /// Edits through the proxy changes the sublayers. If this layer does
1209  /// not have any sublayers the proxy is empty.
1210  ///
1211  /// Sub-layer paths are asset paths, and thus must contain valid asset path
1212  /// characters (UTF-8 without C0 and C1 controls). See SdfAssetPath for
1213  /// more details.
1214  SDF_API
1216 
1217  /// Sets the paths of the layer's sublayers.
1218  SDF_API
1219  void SetSubLayerPaths(const std::vector<std::string>& newPaths);
1220 
1221  /// Returns the number of sublayer paths (and offsets).
1222  SDF_API
1223  size_t GetNumSubLayerPaths() const;
1224 
1225  /// Inserts new sublayer path at the given index.
1226  ///
1227  /// The default index of -1 means to insert at the end.
1228  SDF_API
1229  void InsertSubLayerPath(const std::string& path, int index = -1);
1230 
1231  /// Removes sublayer path at the given index.
1232  SDF_API
1233  void RemoveSubLayerPath(int index);
1234 
1235  /// Returns the layer offsets for all the subLayer paths.
1236  SDF_API
1238 
1239  /// Returns the layer offset for the subLayer path at the given index.
1240  SDF_API
1242 
1243  /// Sets the layer offset for the subLayer path at the given index.
1244  SDF_API
1245  void SetSubLayerOffset(const SdfLayerOffset& offset, int index);
1246 
1247  /// @}
1248  /// \name Relocates
1249  /// @{
1250 
1251  /// Get the list of relocates specified in this layer's metadata.
1252  ///
1253  /// Each individual relocate in the list is specified as a pair of
1254  /// \c \SdfPath where the first is the source path of the relocate and the
1255  /// second is target path.
1256  ///
1257  /// Note that is NOT a proxy object and cannot be used to edit the field in
1258  /// place.
1259  SDF_API
1260  SdfRelocates GetRelocates() const;
1261 
1262  /// Set the entire list of namespace relocations specified on this layer to
1263  /// \p relocates.
1264  SDF_API
1265  void SetRelocates(const SdfRelocates& relocates);
1266 
1267  /// Returns true if this layer's metadata has any relocates opinion,
1268  /// including that there should be no relocates (i.e. an empty list). An
1269  /// empty list (no relocates) does not mean the same thing as a missing list
1270  /// (no opinion).
1271  SDF_API
1272  bool HasRelocates() const;
1273 
1274  /// Clears the layer relocates opinion in the layer's metadata.
1275  SDF_API
1276  void ClearRelocates();
1277 
1278  /// @}
1279 
1280  /// \name Detached Layers
1281  ///
1282  /// Detached layers are layers that are detached from the serialized
1283  /// data store and isolated from any external changes to that serialized
1284  /// data.
1285  ///
1286  /// File format plugins may produce layers that maintain a persistent
1287  /// connection to their serialized representation to read data on-demand.
1288  /// For example, a file format might set up layers to hold an open file
1289  /// handle and read attribute time samples from it only when requested, to
1290  /// avoid pulling in unnecessary data. However, there may be times when
1291  /// keeping this connection is undesirable. In the previous example, a
1292  /// crash might occur if some other process were to change the file on
1293  /// disk, or users might be prevented from overwriting the file at all
1294  /// which could interfere with workflow.
1295  ///
1296  /// To avoid these problems, the functions below may be used to specify
1297  /// layers that are to be detached from the original serialized data.
1298  ///
1299  /// @{
1300 
1301  /// \class DetachedLayerRules
1302  ///
1303  /// Object used to specify detached layers. Layers may be included or
1304  /// excluded from the detached layer set by specifying simple substring
1305  /// patterns for layer identifiers. For example, the following will
1306  /// include all layers in the detached layer set, except for those whose
1307  /// identifiers contain the substring "sim" or "geom":
1308  ///
1309  /// \code
1310  /// SdfLayer::SetDetachedLayerRules(
1311  /// SdfLayer::DetachedLayerRules()
1312  /// .IncludeAll();
1313  /// .Exclude({"sim", "geom"})
1314  /// );
1315  /// \endcode
1317  {
1318  public:
1319  /// A default constructed rules object Excludes all layers from
1320  /// the detached layer set.
1321  DetachedLayerRules() = default;
1322 
1323  /// Include all layers in the detached layer set.
1325  {
1326  _includeAll = true;
1327  _include.clear();
1328  return *this;
1329  }
1330 
1331  /// Include layers whose identifiers contain any of the strings in
1332  /// \p patterns in the detached layer set.
1333  SDF_API
1334  DetachedLayerRules& Include(const std::vector<std::string>& patterns);
1335 
1336  /// Exclude layers whose identifiers contain any of the strings in
1337  /// \p patterns from the detached layer set.
1338  SDF_API
1339  DetachedLayerRules& Exclude(const std::vector<std::string>& patterns);
1340 
1341  bool IncludedAll() const { return _includeAll; }
1342  const std::vector<std::string>& GetIncluded() const { return _include; }
1343  const std::vector<std::string>& GetExcluded() const { return _exclude; }
1344 
1345  /// Returns true if \p identifier is included in the detached layer set,
1346  /// false otherwise.
1347  ///
1348  /// \p identifier is included if it matches an include pattern (or the
1349  /// mask includes all identifiers) and it does not match any of the
1350  /// exclude patterns. Anonymous layer identifiers are always excluded
1351  /// from the mask.
1352  SDF_API
1353  bool IsIncluded(const std::string& identifier) const;
1354 
1355  private:
1356  friend class SdfLayer;
1357 
1358  std::vector<std::string> _include;
1359  std::vector<std::string> _exclude;
1360  bool _includeAll = false;
1361  };
1362 
1363  /// Sets the rules specifying detached layers.
1364  ///
1365  /// Newly-created or opened layers whose identifiers are included in
1366  /// \p rules will be opened as detached layers. Existing layers that are now
1367  /// included or no longer included will be reloaded. Any unsaved
1368  /// modifications to those layers will be lost.
1369  ///
1370  /// This function is not thread-safe. It may not be run concurrently with
1371  /// any other functions that open, close, or read from any layers.
1372  ///
1373  /// The detached layer rules are initially set to exclude all layers.
1374  /// This may be overridden by setting the environment variables
1375  /// SDF_LAYER_INCLUDE_DETACHED and SDF_LAYER_EXCLUDE_DETACHED to specify
1376  /// the initial set of include and exclude patterns in the rules. These
1377  /// variables can be set to a comma-delimited list of patterns.
1378  /// SDF_LAYER_INCLUDE_DETACHED may also be set to "*" to include
1379  /// all layers. Note that these environment variables only set the initial
1380  /// state of the detached layer rules; these values may be overwritten by
1381  /// subsequent calls to this function.
1382  ///
1383  /// See SdfLayer::DetachedLayerRules::IsIncluded for details on how the
1384  /// rules are applied to layer identifiers.
1385  SDF_API
1386  static void SetDetachedLayerRules(const DetachedLayerRules& mask);
1387 
1388  /// Returns the current rules for the detached layer set.
1389  SDF_API
1390  static const DetachedLayerRules& GetDetachedLayerRules();
1391 
1392  /// Returns whether the given layer identifier is included in the
1393  /// current rules for the detached layer set. This is equivalent to
1394  /// GetDetachedLayerRules().IsIncluded(identifier).
1395  SDF_API
1396  static bool IsIncludedByDetachedLayerRules(const std::string& identifier);
1397 
1398  /// @}
1399 
1400  /// \name Muting
1401  /// @{
1402 
1403  /// Returns the set of muted layer paths.
1404  SDF_API
1405  static std::set<std::string> GetMutedLayers();
1406 
1407  /// Returns \c true if the current layer is muted.
1408  SDF_API
1409  bool IsMuted() const;
1410 
1411  /// Returns \c true if the specified layer path is muted.
1412  SDF_API
1413  static bool IsMuted(const std::string &path);
1414 
1415  /// Mutes the current layer if \p muted is \c true, and unmutes it
1416  /// otherwise.
1417  SDF_API
1418  void SetMuted(bool muted);
1419 
1420  /// Add the specified path to the muted layers set.
1421  SDF_API
1422  static void AddToMutedLayers(const std::string &mutedPath);
1423 
1424  /// Remove the specified path from the muted layers set.
1425  SDF_API
1426  static void RemoveFromMutedLayers(const std::string &mutedPath);
1427 
1428  /// @}
1429  /// \name Lookup
1430  /// @{
1431 
1432  /// Returns the layer's pseudo-root prim.
1433  ///
1434  /// The layer's root prims are namespace children of the pseudo-root.
1435  /// The pseudo-root exists to make the namespace hierarchy a tree
1436  /// instead of a forest. This simplifies the implementation of
1437  /// some algorithms. Note that the layer's metadata is considered owned
1438  /// by the pseudo root spec.
1439  ///
1440  /// A layer always has a pseudo-root prim.
1441  SDF_API
1442  SdfPrimSpecHandle GetPseudoRoot() const;
1443 
1444  /// Returns the object at the given \p path.
1445  ///
1446  /// There is no distinction between an absolute and relative path
1447  /// at the SdLayer level.
1448  ///
1449  /// Returns \c NULL if there is no object at \p path.
1450  SDF_API
1451  SdfSpecHandle GetObjectAtPath(const SdfPath &path);
1452 
1453  /// Returns the prim at the given \p path.
1454  ///
1455  /// Returns \c NULL if there is no prim at \p path.
1456  /// This is simply a more specifically typed version of
1457  /// \c GetObjectAtPath().
1458  SDF_API
1459  SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path);
1460 
1461  /// Returns a property at the given \p path.
1462  ///
1463  /// Returns \c NULL if there is no property at \p path.
1464  /// This is simply a more specifically typed version of
1465  /// \c GetObjectAtPath().
1466  SDF_API
1467  SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path);
1468 
1469  /// Returns an attribute at the given \p path.
1470  ///
1471  /// Returns \c NULL if there is no attribute at \p path.
1472  /// This is simply a more specifically typed version of
1473  /// \c GetObjectAtPath().
1474  SDF_API
1475  SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path);
1476 
1477  /// Returns a relationship at the given \p path.
1478  ///
1479  /// Returns \c NULL if there is no relationship at \p path.
1480  /// This is simply a more specifically typed version of
1481  /// \c GetObjectAtPath().
1482  SDF_API
1483  SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path);
1484 
1485  /// @}
1486  /// \name Permissions
1487  /// @{
1488 
1489  /// Returns true if the caller is allowed to modify the layer and
1490  /// false otherwise. A layer may have to perform some action to acquire
1491  /// permission to be edited.
1492  SDF_API
1493  bool PermissionToEdit() const;
1494 
1495  /// Returns true if the caller is allowed to save the layer to its
1496  /// existing fileName and false otherwise.
1497  SDF_API
1498  bool PermissionToSave() const;
1499 
1500  /// Sets permission to edit.
1501  SDF_API
1502  void SetPermissionToEdit(bool allow);
1503 
1504  /// Sets permission to save.
1505  SDF_API
1506  void SetPermissionToSave(bool allow);
1507 
1508  /// @}
1509  /// \name Batch namespace editing
1510  /// @{
1511 
1512  /// Check if a batch of namespace edits will succeed. This returns
1513  /// \c SdfNamespaceEditDetail::Okay if they will succeed as a batch,
1514  /// \c SdfNamespaceEditDetail::Unbatched if the edits will succeed but
1515  /// will be applied unbatched, and \c SdfNamespaceEditDetail::Error
1516  /// if they will not succeed. No edits will be performed in any case.
1517  ///
1518  /// If \p details is not \c NULL and the method does not return \c Okay
1519  /// then details about the problems will be appended to \p details. A
1520  /// problem may cause the method to return early, so \p details may not
1521  /// list every problem.
1522  ///
1523  /// Note that Sdf does not track backpointers so it's unable to fix up
1524  /// targets/connections to namespace edited objects. Clients must fix
1525  /// those to prevent them from falling off. In addition, this method
1526  /// will report failure if any relational attribute with a target to
1527  /// a namespace edited object is subsequently edited (in the same
1528  /// batch). Clients should perform edits on relational attributes
1529  /// first.
1530  ///
1531  /// Clients may wish to report unbatch details to the user to confirm
1532  /// that the edits should be applied unbatched. This will give the
1533  /// user a chance to correct any problems that cause batching to fail
1534  /// and try again.
1535  SDF_API
1538  SdfNamespaceEditDetailVector* details = NULL) const;
1539 
1540  /// Performs a batch of namespace edits. Returns \c true on success
1541  /// and \c false on failure. On failure, no namespace edits will have
1542  /// occurred.
1543  SDF_API
1544  bool Apply(const SdfBatchNamespaceEdit&);
1545 
1546  /// @}
1547  /// \name Layer state
1548  /// @{
1549 
1550  /// Returns the state delegate used to manage this layer's authoring
1551  /// state.
1552  SDF_API
1553  SdfLayerStateDelegateBasePtr GetStateDelegate() const;
1554 
1555  /// Sets the state delegate used to manage this layer's authoring
1556  /// state. The 'dirty' state of this layer will be transferred to
1557  /// the new delegate.
1558  SDF_API
1559  void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr& delegate);
1560 
1561  /// Returns \c true if the layer is dirty, i.e. has changed from
1562  /// its persistent representation.
1563  SDF_API
1564  bool IsDirty() const;
1565 
1566  /// @}
1567 
1568  /// \name Time-sample API
1569  /// @{
1570  SDF_API
1571  std::set<double> ListAllTimeSamples() const;
1572 
1573  SDF_API
1574  std::set<double>
1575  ListTimeSamplesForPath(const SdfPath& path) const;
1576 
1577  SDF_API
1578  bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper);
1579 
1580  SDF_API
1581  size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
1582 
1583  SDF_API
1584  bool GetBracketingTimeSamplesForPath(const SdfPath& path,
1585  double time,
1586  double* tLower, double* tUpper) const;
1587 
1588  /// Returns the previous time sample authored just before the querying \p
1589  /// time.
1590  ///
1591  /// If there is no time sample authored just before \p time, this function
1592  /// returns false. Otherwise, it returns true and sets \p tPrevious to the
1593  /// time of the previous sample.
1594  SDF_API
1595  bool GetPreviousTimeSampleForPath(const SdfPath& path, double time,
1596  double* tPrevious) const;
1597 
1598  SDF_API
1599  bool QueryTimeSample(const SdfPath& path, double time,
1600  VtValue *value=NULL) const;
1601 
1602  SDF_API
1603  bool QueryTimeSample(const SdfPath& path, double time,
1604  SdfAbstractDataValue *value) const;
1605 
1606  template <class T>
1607  bool QueryTimeSample(const SdfPath& path, double time,
1608  T* data) const
1609  {
1610  if (!data) {
1611  return QueryTimeSample(path, time);
1612  }
1613 
1614  SdfAbstractDataTypedValue<T> outValue(data);
1615  const bool hasValue = QueryTimeSample(
1616  path, time, static_cast<SdfAbstractDataValue *>(&outValue));
1617 
1619  return hasValue && outValue.isValueBlock;
1620  }
1621 
1622  return hasValue && (!outValue.isValueBlock);
1623  }
1624 
1625  /// If there is a time sample authored at \p time, return its value's
1626  /// typeid(), otherwise return typeid(void).
1627  SDF_API
1628  const std::type_info &
1629  QueryTimeSampleTypeid(const SdfPath &path, double time) const;
1630 
1631  SDF_API
1632  void SetTimeSample(const SdfPath& path, double time,
1633  const VtValue & value);
1634 
1635  SDF_API
1636  void SetTimeSample(const SdfPath& path, double time,
1638 
1639  template <class T>
1640  void SetTimeSample(const SdfPath& path, double time,
1641  const T& value)
1642  {
1643  const SdfAbstractDataConstTypedValue<T> inValue(&value);
1644  const SdfAbstractDataConstValue& untypedInValue = inValue;
1645  return SetTimeSample(path, time, untypedInValue);
1646  }
1647 
1648  SDF_API
1649  void EraseTimeSample(const SdfPath& path, double time);
1650 
1651  /// @}
1652 
1653  // Debugging
1654  // @{
1655 
1656  SDF_API
1657  static void DumpLayerInfo();
1658 
1659  // Write this layer's SdfData to a file in a simple generic format.
1660  SDF_API
1661  bool WriteDataFile(const std::string &filename);
1662 
1663  // @}
1664 
1665  /// Returns a \ref SdfChangeList containing the minimal edits that would be
1666  /// needed to transform this layer to match the contents of the given
1667  /// \p layer parameter. If \p processPropertyFields is false, property
1668  /// fields will be ignored during the diff computation. Any differences in
1669  /// fields between properties with the same path in this layer and \p layer
1670  /// will not be captured in the returned SdfChangeList. This can, however,
1671  /// avoid potentially expensive data retrieval operations.
1672  SDF_API
1674  const SdfLayerHandle& layer,
1675  bool processPropertyFields = true) const;
1676 
1677 protected:
1678  // Private constructor -- use New(), FindOrCreate(), etc.
1679  // Precondition: _layerRegistryMutex must be locked.
1680  SdfLayer(const SdfFileFormatConstPtr& fileFormat,
1681  const std::string &identifier,
1682  const std::string &realPath = std::string(),
1683  const ArAssetInfo& assetInfo = ArAssetInfo(),
1685  bool validateAuthoring = false);
1686 
1687 private:
1688  // Create a new layer.
1689  // Precondition: _layerRegistryMutex must be locked.
1690  static SdfLayerRefPtr _CreateNew(
1691  SdfFileFormatConstPtr fileFormat,
1692  const std::string& identifier,
1693  const FileFormatArguments& args,
1694  bool saveLayer = true);
1695 
1696  static SdfLayerRefPtr _CreateNewWithFormat(
1697  const SdfFileFormatConstPtr &fileFormat,
1698  const std::string& identifier,
1699  const std::string& realPath,
1700  const ArAssetInfo& assetInfo = ArAssetInfo(),
1702 
1703  static SdfLayerRefPtr _CreateAnonymousWithFormat(
1704  const SdfFileFormatConstPtr &fileFormat,
1705  const std::string& tag,
1706  const FileFormatArguments& args);
1707 
1708  // Finish initializing this layer (which may have succeeded or not)
1709  // and publish the results to other threads by unlocking the mutex.
1710  // Sets _initializationWasSuccessful.
1711  void _FinishInitialization(bool success);
1712 
1713  // Layers retrieved from the layer registry may still be in the
1714  // process of having their contents initialized. Other threads
1715  // retrieving layers from the registry must wait until initialization
1716  // is complete, using this method.
1717  // Returns _initializationWasSuccessful.
1718  //
1719  // Callers *must* be holding an SdfLayerRefPtr to this layer to
1720  // ensure that it is not deleted out from under them, in
1721  // case initialization fails. (This method cannot acquire the
1722  // reference itself internally without being susceptible to a race.)
1723  bool _WaitForInitializationAndCheckIfSuccessful();
1724 
1725  // Returns whether or not this layer should post change
1726  // notification. This simply returns (!_GetIsLoading())
1727  bool _ShouldNotify() const;
1728 
1729  // This function keeps track of the last state of IsDirty() before
1730  // updating it. It returns false if the last saved dirty state is the
1731  // same than the current state. It returns true if the state differs and
1732  // will update the 'last dirty state' to the current state. So, after
1733  // returning true, it would return false for subsequent calls until the
1734  // IsDirty() state would change again...
1735  bool _UpdateLastDirtinessState() const;
1736 
1737  // Returns a handle to the spec at the given path if it exists and matches
1738  // type T.
1739  template <class T>
1740  SdfHandle<T> _GetSpecAtPath(const SdfPath& path);
1741 
1742  // Returns true if a spec can be retrieved at the given path, false
1743  // otherwise. This function will return the canonicalized path to the
1744  // spec as well as the spec type.
1745  bool _CanGetSpecAtPath(const SdfPath& path,
1746  SdfPath* canonicalPath, SdfSpecType* specType) const;
1747 
1748  /// Initialize layer internals that are based on it's path.
1749  /// This includes the asset path and show path the layer to be loaded
1750  /// reflects at the point of initialization.
1751  void _InitializeFromIdentifier(
1752  const std::string &identifier,
1753  const std::string &realPath = std::string(),
1754  const std::string &fileVersion = std::string(),
1755  const ArAssetInfo& assetInfo = ArAssetInfo());
1756 
1757  // Helper for computing the necessary information to lookup a layer
1758  // in the registry or open the layer.
1759  struct _FindOrOpenLayerInfo;
1760  static bool _ComputeInfoToFindOrOpenLayer(
1761  const std::string& identifier,
1763  _FindOrOpenLayerInfo* info,
1764  bool computeAssetInfo = false);
1765 
1766  // Open a layer, adding an entry to the registry and releasing
1767  // the registry lock.
1768  // Precondition: _layerRegistryMutex must be locked.
1769  template <class Lock>
1770  static SdfLayerRefPtr _OpenLayerAndUnlockRegistry(
1771  Lock &lock,
1772  const _FindOrOpenLayerInfo& info,
1773  bool metadataOnly);
1774 
1775  // Helper function for finding a layer with \p identifier and \p args.
1776  // \p lock must be unlocked initially and will be locked by this
1777  // function when needed. See docs for \p retryAsWriter argument on
1778  // _TryToFindLayer for details on the final state of the lock when
1779  // this function returns.
1780  template <class ScopedLock>
1781  static SdfLayerRefPtr
1782  _Find(const std::string &identifier,
1783  const FileFormatArguments &args,
1784  ScopedLock &lock, bool retryAsWriter);
1785 
1786  // Helper function to try to find the layer with \p identifier and
1787  // pre-resolved path \p resolvedPath in the registry. Caller must hold
1788  // registry \p lock for reading. If \p retryAsWriter is false, lock is
1789  // released upon return. Otherwise the lock is released upon return if a
1790  // layer is found successfully. If no layer is found then the lock is
1791  // upgraded to a writer lock upon return. Note that this upgrade may not be
1792  // atomic, but this function ensures that if upon return there does not
1793  // exist a matching layer in the registry.
1794  template <class ScopedLock>
1795  static SdfLayerRefPtr
1796  _TryToFindLayer(const std::string &identifier,
1797  const ArResolvedPath &resolvedPath,
1798  ScopedLock &lock, bool retryAsWriter);
1799 
1800  /// Returns true if the spec at the specified path has no effect on the
1801  /// scene.
1802  ///
1803  /// If ignoreChildren is true, this will ignore prim and property
1804  /// children of prim specs. Property specs are always considered to be
1805  /// non-inert unless they have only required fields and
1806  /// requiredFieldOnlyPropertiesareInert is set to false.
1807  bool _IsInert(const SdfPath &path, bool ignoreChildren,
1808  bool requiredFieldOnlyPropertiesAreInert = false) const;
1809 
1810  /// Return true if the entire subtree rooted at \a path does not affect the
1811  /// scene. For this purpose, property specs that have only required fields
1812  /// are considered inert.
1813  bool _IsInertSubtree(const SdfPath &path) const;
1814 
1815  /// Cause \p spec to be removed if it does not affect the scene. This
1816  /// removes any empty descendants before checking if \p spec itself is
1817  /// inert. Property specs are always considered non-inert, so this will
1818  /// remove them if they have only required fields (see
1819  /// PropertySpec::HasOnlyRequiredFields). This also removes inert ancestors.
1820  void _RemoveIfInert(const SdfSpec& spec);
1821 
1822  /// Performs a depth first search of the namespace hierarchy, beginning at
1823  /// \p prim, removing prims that do not affect the scene. The return value
1824  /// indicates whether the prim passed in is now inert as a result of this
1825  /// call, and can itself be removed.
1826  bool _RemoveInertDFS(SdfPrimSpecHandle prim);
1827 
1828  /// If \p prim is inert (has no affect on the scene), removes prim, then
1829  /// prunes inert parent prims back to the root.
1830  void _RemoveInertToRootmost(SdfPrimSpecHandle prim);
1831 
1832  /// Returns whether this layer is validating authoring operations.
1833  bool _ValidateAuthoring() const { return _validateAuthoring; }
1834 
1835  /// Returns the path used in the muted layers set.
1836  std::string _GetMutedPath() const;
1837 
1838  // If old and new asset path is given, rename all external prim
1839  // composition dependency referring to the old path.
1840  void _UpdatePrimCompositionDependencyPaths(
1841  const SdfPrimSpecHandle &parent,
1842  const std::string &oldLayerPath,
1843  const std::string &newLayerPath);
1844 
1845  // Set the clean state to the current state.
1846  void _MarkCurrentStateAsClean() const;
1847 
1848  // Return the field definition for \p fieldName if \p fieldName is a
1849  // required field for the spec type identified by \p path.
1850  inline SdfSchema::FieldDefinition const *
1851  _GetRequiredFieldDef(const SdfPath &path,
1852  const TfToken &fieldName,
1853  SdfSpecType specType = SdfSpecTypeUnknown) const;
1854 
1855  // Return the field definition for \p fieldName if \p fieldName is a
1856  // required field for \p specType subject to \p schema.
1857  static inline SdfSchema::FieldDefinition const *
1858  _GetRequiredFieldDef(const SdfSchemaBase &schema,
1859  const TfToken &fieldName,
1860  SdfSpecType specType);
1861 
1862  // Helper to list all fields on \p data at \p path subject to \p schema.
1863  static std::vector<TfToken>
1864  _ListFields(SdfSchemaBase const &schema,
1865  SdfAbstractData const &data, const SdfPath& path);
1866 
1867  // Helper for HasField for \p path in \p data subject to \p schema.
1868  static inline bool
1869  _HasField(const SdfSchemaBase &schema,
1870  const SdfAbstractData &data,
1871  const SdfPath& path,
1872  const TfToken& fieldName,
1873  VtValue *value);
1874 
1875  // Helper to get a field value for \p path in \p data subject to \p schema.
1876  static inline VtValue
1877  _GetField(const SdfSchemaBase &schema,
1878  const SdfAbstractData &data,
1879  const SdfPath& path,
1880  const TfToken& fieldName);
1881 
1882  // Set a value.
1883  template <class T>
1884  void _SetValue(const TfToken& key, T value);
1885 
1886  // Get a value.
1887  template <class T>
1888  T _GetValue(const TfToken& key) const;
1889 
1890  enum _ReloadResult { _ReloadFailed, _ReloadSucceeded, _ReloadSkipped };
1891  _ReloadResult _Reload(bool force);
1892 
1893  // Reads contents of asset specified by \p identifier with resolved
1894  // path \p resolvedPath into this layer.
1895  bool _Read(const std::string& identifier,
1896  const ArResolvedPath& resolvedPath,
1897  bool metadataOnly);
1898 
1899  // Saves this layer if it is dirty or the layer doesn't already exist
1900  // on disk. If \p force is true, the layer will be written out
1901  // regardless of those conditions.
1902  bool _Save(bool force) const;
1903 
1904  // A helper method used by Save and Export.
1905  // This method allows Save to specify the existing file format and Export
1906  // to use the format provided by the file extension in newFileName. If no
1907  // file format can be discovered from the file name, the existing file
1908  // format associated with the layer will be used in both cases. This allows
1909  // users to export and save to any file name, regardless of extension.
1910  bool _WriteToFile(const std::string& newFileName,
1911  const std::string& comment,
1912  SdfFileFormatConstPtr fileFormat,
1913  const FileFormatArguments& args) const;
1914 
1915  // Swap contents of _data and data. This operation does not register
1916  // inverses or emit change notification.
1917  void _SwapData(SdfAbstractDataRefPtr &data);
1918 
1919  // Set _data to \p newData and send coarse DidReplaceLayerContent
1920  // invalidation notice.
1921  void _AdoptData(const SdfAbstractDataRefPtr &newData);
1922 
1923  // Helper function which will process incoming data to this layer in a
1924  // generic way.
1925  // If \p processPropertyFields is false, this method will not
1926  // consider property spec fields. In some cases, this can avoid expensive
1927  // operations which would pull large amounts of data.
1928  template<typename DeleteSpecFunc, typename CreateSpecFunc,
1929  typename GetFieldValuesFunc, typename SetFieldFunc, typename ErrorFunc>
1930  void _ProcessIncomingData(const SdfAbstractDataPtr &newData,
1931  const SdfSchemaBase *newDataSchema,
1932  bool processPropertyFields,
1933  const DeleteSpecFunc &deleteSpecFunc,
1934  const CreateSpecFunc &createSpecFunc,
1935  const GetFieldValuesFunc &getFieldValuesFunc,
1936  const SetFieldFunc &setFieldFunc,
1937  const ErrorFunc &errorFunc) const;
1938 
1939  // Set _data to match data, calling other primitive setter methods to
1940  // provide fine-grained inverses and notification. If \p data might adhere
1941  // to a different schema than this layer's, pass a pointer to it as \p
1942  // newDataSchema. In this case, check to see if fields from \p data are
1943  // known to this layer's schema, and if not, omit them and issue a TfError
1944  // with SdfAuthoringErrorUnrecognizedFields, but continue to set all other
1945  // known fields.
1946  void _SetData(const SdfAbstractDataPtr &newData,
1947  const SdfSchemaBase *newDataSchema=nullptr);
1948 
1949  // Returns const handle to _data.
1950  SdfAbstractDataConstPtr _GetData() const;
1951 
1952  // Returns a new SdfAbstractData object for this layer.
1953  SdfAbstractDataRefPtr _CreateData() const;
1954 
1955  // Inverse primitive for setting a single field. The previous value for the
1956  // field may be given via \p oldValue. If \p oldValue is non-nullptr, the
1957  // VtValue it points to will be moved-from after the function completes. If
1958  // \p oldValue is nullptr, the old field value will be retrieved
1959  // automatically.
1960  template <class T>
1961  void _PrimSetField(const SdfPath& path,
1962  const TfToken& fieldName,
1963  const T& value,
1964  VtValue *oldValue = nullptr,
1965  bool useDelegate = true);
1966 
1967  // Inverse primitive for setting a single key in a dict-valued field. The
1968  // previous dictionary value for the field (*not* the individual entry) may
1969  // be supplied via \p oldValue. If \p oldValue is non-nullptr, the VtValue
1970  // it points to will be moved-from after the function completes. If \p
1971  // oldValue is nullptr, the old field value will be retrieved automatically.
1972  template <class T>
1973  void _PrimSetFieldDictValueByKey(const SdfPath& path,
1974  const TfToken& fieldName,
1975  const TfToken& keyPath,
1976  const T& value,
1977  VtValue *oldValue = nullptr,
1978  bool useDelegate = true);
1979 
1980  // Primitive for appending a child to the list of children.
1981  template <class T>
1982  void _PrimPushChild(const SdfPath& parentPath,
1983  const TfToken& fieldName,
1984  const T& value,
1985  bool useDelegate = true);
1986  template <class T>
1987  void _PrimPopChild(const SdfPath& parentPath,
1988  const TfToken& fieldName,
1989  bool useDelegate = true);
1990 
1991  // Move all the fields at all paths at or below \a oldPath to be
1992  // at a corresponding location at or below \a newPath. This does
1993  // not update the children fields of the parents of these paths.
1994  bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath);
1995 
1996  // Inverse primitive for moving a spec.
1997  void _PrimMoveSpec(const SdfPath &oldPath, const SdfPath &newPath,
1998  bool useDelegate = true);
1999 
2000  // Create a new spec of type \p specType at \p path.
2001  // Returns true if spec was successfully created, false otherwise.
2002  bool _CreateSpec(const SdfPath& path, SdfSpecType specType, bool inert);
2003 
2004  // Delete all the fields at or below the specified path. This does
2005  // not update the children field of the parent of \a path.
2006  bool _DeleteSpec(const SdfPath &path);
2007 
2008  // Inverse primitive for deleting a spec.
2009  void _PrimCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert,
2010  bool useDelegate = true);
2011 
2012  // Inverse primitive for deleting a spec.
2013  void _PrimDeleteSpec(const SdfPath &path, bool inert,
2014  bool useDelegate = true);
2015 
2016  // Inverse primitive for setting time samples.
2017  template <class T>
2018  void _PrimSetTimeSample(const SdfPath& path, double time,
2019  const T& value,
2020  bool useDelegate = true);
2021 
2022  // Helper method for Traverse. Visits the children of \a path using the
2023  // specified \a ChildPolicy.
2024  template <typename ChildPolicy>
2025  void _TraverseChildren(const SdfPath &path, const TraversalFunction &func);
2026 
2027 private:
2028  SdfLayerHandle _self;
2029 
2030  // File format and arguments for this layer.
2031  SdfFileFormatConstPtr _fileFormat;
2032  FileFormatArguments _fileFormatArgs;
2033 
2034  // Cached reference to the _fileFormat's schema -- we need access to this to
2035  // be as fast as possible since we look at it on every SetField(), for
2036  // example.
2037  const SdfSchemaBase &_schema;
2038 
2039  // Registry of Sdf Identities
2040  mutable Sdf_IdentityRegistry _idRegistry;
2041 
2042  // The underlying SdfData which stores all the data in the layer.
2043  SdfAbstractDataRefPtr _data;
2044 
2045  // The state delegate for this layer.
2046  SdfLayerStateDelegateBaseRefPtr _stateDelegate;
2047 
2048  // Dispatcher used in layer initialization, letting waiters participate in
2049  // loading instead of just busy-waiting.
2050  WorkDispatcher _initDispatcher;
2051 
2052  // Atomic variable protecting layer initialization -- the interval between
2053  // adding a layer to the layer registry and finishing the process of
2054  // initializing its contents, at which point we can truly publish the layer
2055  // for consumption by concurrent threads. We add the layer to the registry
2056  // before initialization completes so that other threads can discover and
2057  // wait for it to finish initializing.
2058  std::atomic<bool> _initializationComplete;
2059 
2060  // This is an optional<bool> that is only set once initialization
2061  // is complete, before _initializationComplete is set.
2062  std::optional<bool> _initializationWasSuccessful;
2063 
2064  // remembers the last 'IsDirty' state.
2065  mutable bool _lastDirtyState;
2066 
2067  // Asset information for this layer.
2068  std::unique_ptr<Sdf_AssetInfo> _assetInfo;
2069 
2070  // Modification timestamp of the backing file asset when last read.
2071  mutable VtValue _assetModificationTime;
2072 
2073  // All external asset dependencies, with their modification timestamps, of
2074  // the layer when last read.
2075  mutable VtDictionary _externalAssetModificationTimes;
2076 
2077  // Mutable revision number for cache invalidation.
2078  mutable size_t _mutedLayersRevisionCache;
2079 
2080  // Cache of whether or not this layer is muted. Only valid if
2081  // _mutedLayersRevisionCache is up-to-date with the global revision number.
2082  mutable bool _isMutedCache;
2083 
2084  // Layer permission bits.
2085  bool _permissionToEdit;
2086  bool _permissionToSave;
2087 
2088  // Whether layer edits are validated.
2089  bool _validateAuthoring;
2090 
2091  // Layer hints as of the most recent save operation.
2092  mutable SdfLayerHints _hints;
2093 
2094  // Allow access to _ValidateAuthoring() and _IsInert().
2095  friend class SdfSpec;
2096  friend class SdfPropertySpec;
2097  friend class SdfAttributeSpec;
2098 
2099  friend class Sdf_ChangeManager;
2100 
2101  // Allow access to _CreateSpec and _DeleteSpec and _MoveSpec
2102  template <class ChildPolicy> friend class Sdf_ChildrenUtils;
2103 
2104  // Give the file format access to our data. Limit breaking encapsulation
2105  // to the base SdFileFormat class so we don't have to friend every
2106  // implementation here.
2107  friend class SdfFileFormat;
2108 
2109  // Give layer state delegates access to our data as well as to
2110  // the various _Prim functions.
2112 };
2113 
2115 
2116 #endif // PXR_USD_SDF_LAYER_H
static SDF_API SdfLayerRefPtr FindOrOpen(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API void ClearColorConfiguration()
std::vector< SdfNamespaceEditDetail > SdfNamespaceEditDetailVector
A sequence of SdfNamespaceEditDetail.
SDF_API bool HasDefaultPrim()
SDF_API void SetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const VtValue &value)
Definition: layer.h:81
T GetFieldAs(const SdfPath &path, const TfToken &fieldName, const T &defaultValue=T()) const
Definition: layer.h:678
SDF_API SdfAssetPath GetColorConfiguration() const
SDF_API void EraseTimeSample(const SdfPath &path, double time)
const std::vector< std::string > & GetExcluded() const
Definition: layer.h:1343
DetachedLayerRules & IncludeAll()
Include all layers in the detached layer set.
Definition: layer.h:1324
Result
Validity of an edit.
GT_API const UT_StringHolder filename
SDF_API void SetSubLayerPaths(const std::vector< std::string > &newPaths)
Sets the paths of the layer's sublayers.
SDF_API bool WriteDataFile(const std::string &filename)
SDF_API void RemoveInertSceneDescription()
SDF_API bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index=-1)
SDF_API bool HasEndTimeCode() const
Returns true if the layer has an endTimeCode opinion.
SDF_API void SetComment(const std::string &comment)
Sets the comment string for this layer.
SDF_API VtDictionary GetCustomLayerData() const
SDF_API void SetFramePrecision(int framePrecision)
Sets the layer's frame precision.
SDF_API std::string ComputeAbsolutePath(const std::string &assetPath) const
SDF_API std::set< std::string > GetExternalReferences() const
SDF_API void EraseFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath)
bool HasFieldDictKey(const SdfPath &path, const TfToken &name, const TfToken &keyPath, T *value) const
Definition: layer.h:655
SDF_API void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop)
SDF_API void SetDocumentation(const std::string &documentation)
Sets the documentation string for this layer.
SDF_API void ClearFramesPerSecond()
Clear the framesPerSecond opinion.
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(SdfFileFormat)
static SDF_API SdfLayerRefPtr New(const SdfFileFormatConstPtr &fileFormat, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
static SDF_API bool ReloadLayers(const std::set< SdfLayerHandle > &layers, bool force=false)
SDF_API bool HasRelocates() const
SDF_API bool IsMuted() const
Returns true if the current layer is muted.
SDF_API void SetStartTimeCode(double startTimecode)
Sets the layer's start timeCode.
SDF_API bool ExportToString(std::string *result) const
GT_API const UT_StringHolder time
SDF_API const VtValue & GetAssetInfo() const
static SDF_API bool SplitIdentifier(const std::string &identifier, std::string *layerPath, FileFormatArguments *arguments)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
SDF_API bool HasStartTimeCode() const
Returns true if the layer has a startTimeCode opinion.
static SDF_API SdfLayerRefPtr FindOrOpenRelativeToLayer(const SdfLayerHandle &anchor, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API const std::string & GetAssetName() const
Returns the asset name associated with this layer.
SDF_API void SetDefaultPrim(const TfToken &name)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
std::map< std::string, std::string > FileFormatArguments
Definition: layer.h:107
SDF_API bool QueryTimeSample(const SdfPath &path, double time, VtValue *value=NULL) const
SDF_API void ClearSessionOwner()
SDF_API SdfNameOrderProxy GetRootPrimOrder() const
std::type_info const & GetFieldTypeid(const SdfPath &path, const TfToken &name) const
Definition: layer.h:631
SDF_API bool HasSpec(const SdfPath &path) const
Return whether a spec exists at path.
SDF_API SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path)
SDF_API void RemoveFromRootPrimOrderByIndex(int index)
Removes a root prim name from the root prim order by index.
SDF_API SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path)
SDF_API void SetPermissionToEdit(bool allow)
Sets permission to edit.
SDF_API void Traverse(const SdfPath &path, const TraversalFunction &func)
TF_DECLARE_WEAK_AND_REF_PTRS(SdfLayerStateDelegateBase)
SDF_API void ClearRelocates()
Clears the layer relocates opinion in the layer's metadata.
Definition: spec.h:32
SDF_API bool HasSessionOwner() const
Returns true if the layer has a session owner opinion.
friend class Sdf_ChangeManager
Definition: layer.h:2099
SDF_API SdfPrimSpecHandle GetPseudoRoot() const
SDF_API bool PermissionToEdit() const
std::set< SdfHandleTo< SdfLayer >::Handle > SdfLayerHandleSet
static SDF_API SdfLayerRefPtr CreateAnonymous(const std::string &tag=std::string(), const FileFormatArguments &args=FileFormatArguments())
SDF_API void SetSubLayerOffset(const SdfLayerOffset &offset, int index)
Sets the layer offset for the subLayer path at the given index.
SDF_API void ScheduleRemoveIfInert(const SdfSpec &spec)
SDF_API void SetRelocates(const SdfRelocates &relocates)
**But if you need a result
Definition: thread.h:622
std::function< void(const SdfPath &)> TraversalFunction
Definition: layer.h:764
static SDF_API std::string CreateIdentifier(const std::string &layerPath, const FileFormatArguments &arguments)
Joins the given layer path and arguments into an identifier.
SDF_API std::string GetDocumentation() const
SDF_API void SetPermissionToSave(bool allow)
Sets permission to save.
SDF_API bool Apply(const SdfBatchNamespaceEdit &)
SDF_API bool Import(const std::string &layerPath)
SDF_API const std::string & GetRepositoryPath() const
SDF_API SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path)
SDF_API void SetTimeCodesPerSecond(double timeCodesPerSecond)
Sets the layer's timeCodes per second.
static SDF_API std::set< std::string > GetMutedLayers()
Returns the set of muted layer paths.
SDF_API std::set< double > ListTimeSamplesForPath(const SdfPath &path) const
SDF_API SdfLayerOffset GetSubLayerOffset(int index) const
Returns the layer offset for the subLayer path at the given index.
SDF_API double GetTimeCodesPerSecond() const
SDF_API void SetColorConfiguration(const SdfAssetPath &colorConfiguration)
Sets the color configuration asset-path for this layer.
SDF_API std::string GetSessionOwner() const
static SDF_API bool IsIncludedByDetachedLayerRules(const std::string &identifier)
SDF_API SdfSpecType GetSpecType(const SdfPath &path) const
SDF_API void SetEndTimeCode(double endTimeCode)
Sets the layer's end timeCode.
SDF_API bool Reload(bool force=false)
SDF_API double GetStartTimeCode() const
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
SDF_API size_t GetNumSubLayerPaths() const
Returns the number of sublayer paths (and offsets).
SDF_API SdfLayerOffsetVector GetSubLayerOffsets() const
Returns the layer offsets for all the subLayer paths.
SDF_API const SdfFileFormatConstPtr & GetFileFormat() const
Returns the file format used by this layer.
SDF_API void ClearOwner()
Clear the owner opinion.
SDF_API const FileFormatArguments & GetFileFormatArguments() const
SDF_API SdfDataRefPtr GetMetadata() const
Returns the data from the absolute root path of this layer.
SDF_API void RemoveRootPrim(const SdfPrimSpecHandle &prim)
Remove a root prim.
static SDF_API SdfLayerRefPtr OpenAsAnonymous(const std::string &layerPath, bool metadataOnly=false, const std::string &tag=std::string())
SDF_API void ClearFramePrecision()
Clear the framePrecision opinion.
SDF_API void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr &delegate)
SDF_API void SetColorManagementSystem(const TfToken &cms)
std::vector< SdfLayerOffset > SdfLayerOffsetVector
Definition: layerOffset.h:168
Definition: token.h:70
SDF_API bool HasField(const SdfPath &path, const TfToken &fieldName, VtValue *value=NULL) const
SDF_API void SetSessionOwner(const std::string &owner)
GLintptr offset
Definition: glcorearb.h:665
SDF_API void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims)
SDF_API SdfPath GetDefaultPrimAsPath() const
SDF_API void SetCustomLayerData(const VtDictionary &value)
Sets the CustomLayerData dictionary associated with this layer.
SDF_API void EraseField(const SdfPath &path, const TfToken &fieldName)
Remove the field at path and fieldName, if one exists.
SDF_API std::set< std::string > GetCompositionAssetDependencies() const
SDF_API void ClearEndTimeCode()
Clear the endTimeCode opinion.
SDF_API bool HasCustomLayerData() const
Returns true if CustomLayerData is authored on the layer.
SDF_API bool UpdateExternalReference(const std::string &oldAssetPath, const std::string &newAssetPath=std::string())
SDF_API double GetFramesPerSecond() const
SDF_API void ClearDefaultPrim()
SDF_API void Clear()
static SDF_API std::string GetDisplayNameFromIdentifier(const std::string &identifier)
SDF_API VtValue GetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath) const
SDF_API bool ImportFromString(const std::string &string)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
SDF_API std::set< std::string > GetExternalAssetDependencies() const
const std::vector< std::string > & GetIncluded() const
Definition: layer.h:1342
GLint GLuint mask
Definition: glcorearb.h:124
SDF_API bool HasFramesPerSecond() const
Returns true if the layer has a frames per second opinion.
SdfPrimSpecView RootPrimsView
Returns a vector of the layer's root prims.
Definition: layer.h:1097
SDF_API void SetRootPrimOrder(const std::vector< TfToken > &names)
SDF_API bool Export(const std::string &filename, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const
SDF_API const std::type_info & QueryTimeSampleTypeid(const SdfPath &path, double time) const
SDF_API double GetEndTimeCode() const
SDF_API SdfLayerStateDelegateBasePtr GetStateDelegate() const
SDF_API DetachedLayerRules & Include(const std::vector< std::string > &patterns)
SDF_API void SetHasOwnedSubLayers(bool)
Sets whether the layer's sublayers are expected to have owners.
SDF_API const std::string & GetRealPath() const
SDF_API void ClearTimeCodesPerSecond()
Clear the timeCodesPerSecond opinion.
SDF_API void RemoveFromRootPrimOrder(const TfToken &name)
Removes a root prim name from the root prim order.
SDF_API TfToken GetColorManagementSystem() const
SDF_API bool HasTimeCodesPerSecond() const
Returns true if the layer has a timeCodesPerSecond opinion.
GLuint const GLchar * name
Definition: glcorearb.h:786
SDF_API void ClearExpressionVariables()
Clears the expression variables dictionary authored on this layer.
void SetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const T &val)
Definition: layer.h:731
Definition: path.h:280
SdfLayer & operator=(const SdfLayer &)=delete
bool IncludedAll() const
Definition: layer.h:1341
SDF_API bool StreamsData() const
SDF_API DetachedLayerRules & Exclude(const std::vector< std::string > &patterns)
SDF_API bool HasFieldDictKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, VtValue *value=NULL) const
SDF_API bool HasExpressionVariables() const
Returns true if expression variables are authored on this layer.
SDF_API bool GetBracketingTimeSamples(double time, double *tLower, double *tUpper)
SDF_API void SetFramesPerSecond(double framesPerSecond)
Sets the layer's frames per second.
SDF_API std::string GetDisplayName() const
SDF_API void UpdateAssetInfo()
SDF_API bool IsIncluded(const std::string &identifier) const
SDF_API bool UpdateCompositionAssetDependency(const std::string &oldAssetPath, const std::string &newAssetPath=std::string())
SDF_API const ArResolvedPath & GetResolvedPath() const
SdfLayer(const SdfLayer &)=delete
Noncopyable.
SDF_API SdfNamespaceEditDetail::Result CanApply(const SdfBatchNamespaceEdit &, SdfNamespaceEditDetailVector *details=NULL) const
static SDF_API void SetDetachedLayerRules(const DetachedLayerRules &mask)
SDF_API void InsertSubLayerPath(const std::string &path, int index=-1)
static SDF_API SdfLayerHandle FindRelativeToLayer(const SdfLayerHandle &anchor, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API SdfSpecHandle GetObjectAtPath(const SdfPath &path)
SDF_API bool GetPreviousTimeSampleForPath(const SdfPath &path, double time, double *tPrevious) const
#define SDF_API
Definition: api.h:23
SDF_API void SetIdentifier(const std::string &identifier)
SDF_API void SetExpressionVariables(const VtDictionary &expressionVars)
Sets the expression variables dictionary for this layer.
SDF_API bool IsAnonymous() const
Returns true if this layer is an anonymous layer.
bool HasField(const SdfPath &path, const TfToken &name, T *value) const
Definition: layer.h:611
GLenum func
Definition: glcorearb.h:783
SDF_API std::string GetFileExtension() const
SDF_API void InsertInRootPrimOrder(const TfToken &name, int index=-1)
SDF_API void RemoveSubLayerPath(int index)
Removes sublayer path at the given index.
SDF_API void SetField(const SdfPath &path, const TfToken &fieldName, const VtValue &value)
Set the value of the given path and fieldName.
SDF_API void TransferContent(const SdfLayerHandle &layer)
SIM_API const UT_StringHolder force
void SetField(const SdfPath &path, const TfToken &fieldName, const T &val)
Set the value of the given path and fieldName.
Definition: layer.h:702
bool QueryTimeSample(const SdfPath &path, double time, T *data) const
Definition: layer.h:1607
SDF_API bool HasColorManagementSystem() const
SDF_API VtDictionary GetExpressionVariables() const
SdfSpecType
Definition: types.h:71
SDF_API std::string GetOwner() const
Returns the layer's owner.
SDF_API void SetMuted(bool muted)
SDF_API void ClearCustomLayerData()
Clears out the CustomLayerData dictionary associated with this layer.
SDF_API bool PermissionToSave() const
static SDF_API TfToken ConvertDefaultPrimPathToToken(const SdfPath &primPath)
virtual SDF_API ~SdfLayer()
Destructor.
SDF_API bool HasColorConfiguration() const
GLuint index
Definition: glcorearb.h:786
SDF_API bool HasOwner() const
Returns true if the layer has an owner opinion.
SDF_API void SetTimeSample(const SdfPath &path, double time, const VtValue &value)
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
SDF_API bool IsDetached() const
SDF_API bool HasFramePrecision() const
Returns true if the layer has a frames precision opinion.
**If you just want to fire and args
Definition: thread.h:618
SDF_API int GetFramePrecision() const
Returns the layer's frame precision.
SDF_API void SetOwner(const std::string &owner)
Sets the layer's owner.
SDF_API const std::string & GetIdentifier() const
Returns the layer identifier.
SDF_API bool GetHasOwnedSubLayers() const
Returns true if the layer's sublayers are expected to have owners.
static SDF_API void RemoveFromMutedLayers(const std::string &mutedPath)
Remove the specified path from the muted layers set.
static SDF_API SdfPath ConvertDefaultPrimTokenToPath(const TfToken &defaultPrim)
SDF_API RootPrimsView GetRootPrims() const
Returns a vector of the layer's root prims.
static SDF_API void AddToMutedLayers(const std::string &mutedPath)
Add the specified path to the muted layers set.
SDF_API TfToken GetDefaultPrim() const
SDF_API SdfChangeList CreateDiff(const SdfLayerHandle &layer, bool processPropertyFields=true) const
SDF_API std::vector< TfToken > ListFields(const SdfPath &path) const
Return the names of all the fields that are set at path.
SDF_API SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path)
static SDF_API void DumpLayerInfo()
SDF_API size_t GetNumTimeSamplesForPath(const SdfPath &path) const
std::vector< SdfRelocate > SdfRelocates
A vector of relocation source path to target path pairs.
Definition: types.h:277
SDF_API const std::string & GetVersion() const
SDF_API SdfSubLayerProxy GetSubLayerPaths() const
SDF_API bool GetBracketingTimeSamplesForPath(const SdfPath &path, double time, double *tLower, double *tUpper) const
SDF_API void RemovePrimIfInert(SdfPrimSpecHandle prim)
static SDF_API const DetachedLayerRules & GetDetachedLayerRules()
Returns the current rules for the detached layer set.
static SDF_API SdfLayerRefPtr CreateNew(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API SdfLayerHints GetHints() const
static SDF_API SdfLayerHandleSet GetLoadedLayers()
Returns handles for all layers currently held by the layer registry.
SDF_API const SdfSchemaBase & GetSchema() const
SDF_API bool IsDirty() const
SDF_API void ApplyRootPrimOrder(std::vector< TfToken > *vec) const
SDF_API void ClearStartTimeCode()
Clear the startTimeCode opinion.
SDF_API void ClearColorManagementSystem()
Definition: value.h:89
SDF_API std::string GetComment() const
SDF_API bool Save(bool force=false) const
SDF_API VtValue GetField(const SdfPath &path, const TfToken &fieldName) const
static SDF_API bool IsAnonymousLayerIdentifier(const std::string &identifier)
Definition: format.h:1821
SDF_API std::set< double > ListAllTimeSamples() const
SDF_API bool IsEmpty() const
Returns whether this layer has no significant data.
SDF_API SdfRelocates GetRelocates() const
static SDF_API SdfLayerHandle Find(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
void SetTimeSample(const SdfPath &path, double time, const T &value)
Definition: layer.h:1640