filesystemAsset.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_ASSET_H
24 #define PXR_USD_AR_FILESYSTEM_ASSET_H
25 
27 
28 #include "pxr/pxr.h"
29 #include "pxr/usd/ar/api.h"
30 #include "pxr/usd/ar/asset.h"
31 #include "pxr/usd/ar/timestamp.h"
32 
33 #include <cstdio>
34 #include <memory>
35 #include <utility>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 class ArResolvedPath;
40 
45  : public ArAsset
46 {
47 public:
50  AR_API
51  static std::shared_ptr<ArFilesystemAsset> Open(
52  const ArResolvedPath& resolvedPath);
53 
56  AR_API
58  const ArResolvedPath& resolvedPath);
59 
63  AR_API
64  explicit ArFilesystemAsset(FILE* file);
65 
67  AR_API
69 
71  AR_API
72  virtual size_t GetSize() const override;
73 
76  AR_API
77  virtual std::shared_ptr<const char> GetBuffer() const override;
78 
81  AR_API
82  virtual size_t Read(
83  void* buffer, size_t count, size_t offset) const override;
84 
88  AR_API
89  virtual std::pair<FILE*, size_t> GetFileUnsafe() const override;
90 
91 private:
92  FILE* _file;
93 };
94 
95 PXR_NAMESPACE_CLOSE_SCOPE
96 
97 #endif // PXR_USD_AR_FILESYSTEM_ASSET_H
virtual AR_API std::shared_ptr< const char > GetBuffer() const override
Creates a read-only memory map for the file held by this object and returns a pointer to the start of...
Represents a timestamp for an asset.
Definition: timestamp.h:42
virtual AR_API std::pair< FILE *, size_t > GetFileUnsafe() const override
Returns the FILE* handle this object was created with and an offset of 0, since the asset's contents ...
Interface for accessing the contents of an asset.
Definition: asset.h:44
AR_API ~ArFilesystemAsset()
Closes the file owned by this object.
ArAsset implementation for asset represented by a file on a filesystem.
static AR_API std::shared_ptr< ArFilesystemAsset > Open(const ArResolvedPath &resolvedPath)
Constructs a new ArFilesystemAsset for the file at resolvedPath.
Represents a resolved asset path.
Definition: resolvedPath.h:39
AR_API ArFilesystemAsset(FILE *file)
Constructs an ArFilesystemAsset for the given file.
virtual AR_API size_t GetSize() const override
Returns the size of the file held by this object.
static AR_API ArTimestamp GetModificationTimestamp(const ArResolvedPath &resolvedPath)
Returns an ArTimestamp holding the mtime of the file at resolvedPath.
virtual AR_API size_t Read(void *buffer, size_t count, size_t offset) const override
Reads count bytes from the file held by this object at the given offset into buffer.