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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 #ifndef PXR_USD_AR_FILESYSTEM_WRITABLE_ASSET_H
24 #define PXR_USD_AR_FILESYSTEM_WRITABLE_ASSET_H
25 
26 /// \file ar/filesystemWritableAsset.h
27 
28 #include "pxr/pxr.h"
29 #include "pxr/usd/ar/api.h"
30 #include "pxr/usd/ar/resolver.h"
32 
34 
36 
37 /// \class ArFilesystemWritableAsset
38 ///
39 /// ArWritableAsset implementation for asset represented by a file on a
40 /// filesystem.
41 ///
42 /// This implementation uses TfSafeOutputFile; in the case where the asset
43 /// has been opened for replacement, data will be written to a temporary
44 /// file which will be renamed over the destination file when this object
45 /// is destroyed. See documentation for TfSafeOutputFile for more details.
47  : public ArWritableAsset
48 {
49 public:
50  /// Constructs a new ArFilesystemWritableAsset for the file at
51  /// \p resolvedPath with the given \p writeMode. Returns a null pointer
52  /// if the file could not be opened.
53  AR_API
54  static std::shared_ptr<ArFilesystemWritableAsset> Create(
55  const ArResolvedPath& resolvedPath,
56  ArResolver::WriteMode writeMode);
57 
58  /// Constructs an ArFilesystemWritableAsset for the given \p file.
59  /// The ArFilesystemWritableAsset takes ownership of \p file.
60  AR_API
62 
63  AR_API
65 
66  /// Closes the file owned by this asset. If the TfSafeOutputFile was
67  /// opened for replacement, the temporary file that was being written
68  /// to be will be renamed over the destination file.
69  AR_API
70  virtual bool Close() override;
71 
72  /// Writes \p count bytes from \p buffer at \p offset from the beginning
73  /// of the file held by this object. Returns number of bytes written, or
74  /// 0 on error.
75  AR_API
76  virtual size_t Write(
77  const void* buffer, size_t count, size_t offset) override;
78 
79 private:
80  TfSafeOutputFile _file;
81 };
82 
84 
85 #endif
static AR_API std::shared_ptr< ArFilesystemWritableAsset > Create(const ArResolvedPath &resolvedPath, ArResolver::WriteMode writeMode)
#define AR_API
Definition: api.h:40
AR_API ArFilesystemWritableAsset(TfSafeOutputFile &&file)
GLintptr offset
Definition: glcorearb.h:665
Definition: core.h:760
virtual AR_API bool Close() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
WriteMode
Enumeration of write modes for OpenAssetForWrite.
Definition: resolver.h:311
virtual AR_API ~ArFilesystemWritableAsset()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GLint GLsizei count
Definition: glcorearb.h:405
virtual AR_API size_t Write(const void *buffer, size_t count, size_t offset) override