HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filesystemWritableAsset.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 #ifndef PXR_USD_AR_FILESYSTEM_WRITABLE_ASSET_H
7 #define PXR_USD_AR_FILESYSTEM_WRITABLE_ASSET_H
8 
9 /// \file ar/filesystemWritableAsset.h
10 
11 #include "pxr/pxr.h"
12 #include "pxr/usd/ar/api.h"
13 #include "pxr/usd/ar/resolver.h"
15 
17 
19 
20 /// \class ArFilesystemWritableAsset
21 ///
22 /// ArWritableAsset implementation for asset represented by a file on a
23 /// filesystem.
24 ///
25 /// This implementation uses TfSafeOutputFile; in the case where the asset
26 /// has been opened for replacement, data will be written to a temporary
27 /// file which will be renamed over the destination file when this object
28 /// is destroyed. See documentation for TfSafeOutputFile for more details.
30  : public ArWritableAsset
31 {
32 public:
33  /// Constructs a new ArFilesystemWritableAsset for the file at
34  /// \p resolvedPath with the given \p writeMode. Returns a null pointer
35  /// if the file could not be opened.
36  AR_API
37  static std::shared_ptr<ArFilesystemWritableAsset> Create(
38  const ArResolvedPath& resolvedPath,
39  ArResolver::WriteMode writeMode);
40 
41  /// Constructs an ArFilesystemWritableAsset for the given \p file.
42  /// The ArFilesystemWritableAsset takes ownership of \p file.
43  AR_API
45 
46  AR_API
48 
49  /// Closes the file owned by this asset. If the TfSafeOutputFile was
50  /// opened for replacement, the temporary file that was being written
51  /// to be will be renamed over the destination file.
52  AR_API
53  virtual bool Close() override;
54 
55  /// Writes \p count bytes from \p buffer at \p offset from the beginning
56  /// of the file held by this object. Returns number of bytes written, or
57  /// 0 on error.
58  AR_API
59  virtual size_t Write(
60  const void* buffer, size_t count, size_t offset) override;
61 
62 private:
63  TfSafeOutputFile _file;
64 };
65 
67 
68 #endif
static AR_API std::shared_ptr< ArFilesystemWritableAsset > Create(const ArResolvedPath &resolvedPath, ArResolver::WriteMode writeMode)
#define AR_API
Definition: api.h:23
GLuint buffer
Definition: glcorearb.h:660
AR_API ArFilesystemWritableAsset(TfSafeOutputFile &&file)
GLintptr offset
Definition: glcorearb.h:665
virtual AR_API bool Close() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
WriteMode
Enumeration of write modes for OpenAssetForWrite.
Definition: resolver.h:294
virtual AR_API ~ArFilesystemWritableAsset()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GLint GLsizei count
Definition: glcorearb.h:405
virtual AR_API size_t Write(const void *buffer, size_t count, size_t offset) override