HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filesystemAsset_v2.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 INCLUDE_AR_FILESYSTEM_ASSET
24 #error This file should not be included directly. Include filesystemAsset.h instead.
25 #endif
26 
27 #ifndef PXR_USD_AR_FILESYSTEM_ASSET_V2_H
28 #define PXR_USD_AR_FILESYSTEM_ASSET_V2_H
29 
30 /// \file ar/filesystemAsset_v2.h
31 
32 #include "pxr/pxr.h"
33 #include "pxr/usd/ar/api.h"
34 #include "pxr/usd/ar/asset.h"
35 #include "pxr/usd/ar/timestamp.h"
36 
37 #include <cstdio>
38 #include <memory>
39 #include <utility>
40 
42 
43 class ArResolvedPath;
44 
45 /// \class ArFilesystemAsset
46 ///
47 /// ArAsset implementation for asset represented by a file on a filesystem.
49  : public ArAsset
50 {
51 public:
52  /// Constructs a new ArFilesystemAsset for the file at \p resolvedPath.
53  /// Returns a null pointer if the file could not be opened.
54  AR_API
55  static std::shared_ptr<ArFilesystemAsset> Open(
56  const ArResolvedPath& resolvedPath);
57 
58  /// Returns an ArTimestamp holding the mtime of the file at \p resolvedPath.
59  /// Returns an invalid ArTimestamp if the mtime could not be retrieved.
60  AR_API
62  const ArResolvedPath& resolvedPath);
63 
64  /// Constructs an ArFilesystemAsset for the given \p file.
65  /// The ArFilesystemAsset object takes ownership of \p file and will
66  /// close the file handle on destruction.
67  AR_API
68  explicit ArFilesystemAsset(FILE* file);
69 
70  /// Closes the file owned by this object.
71  AR_API
73 
74  /// Returns the size of the file held by this object.
75  AR_API
76  virtual size_t GetSize() const override;
77 
78  /// Creates a read-only memory map for the file held by this object
79  /// and returns a pointer to the start of the mapped contents.
80  AR_API
81  virtual std::shared_ptr<const char> GetBuffer() const override;
82 
83  /// Reads \p count bytes from the file held by this object at the
84  /// given \p offset into \p buffer.
85  AR_API
86  virtual size_t Read(
87  void* buffer, size_t count, size_t offset) const override;
88 
89  /// Returns the FILE* handle this object was created with and an offset
90  /// of 0, since the asset's contents are located at the beginning of the
91  /// file.
92  AR_API
93  virtual std::pair<FILE*, size_t> GetFileUnsafe() const override;
94 
95 private:
96  FILE* _file;
97 };
98 
100 
101 #endif // PXR_USD_AR_FILESYSTEM_ASSET_V2_H
static AR_API std::shared_ptr< ArFilesystemAsset > Open(const ArResolvedPath &resolvedPath)
#define AR_API
Definition: api.h:40
Definition: core.h:760
virtual AR_API size_t GetSize() const override
Returns the size of the file held by this object.
virtual AR_API std::pair< FILE *, size_t > GetFileUnsafe() const override
AR_API ArFilesystemAsset(FILE *file)
GLint GLsizei count
Definition: glcorearb.h:405
static AR_API ArTimestamp GetModificationTimestamp(const ArResolvedPath &resolvedPath)
virtual AR_API size_t Read(void *buffer, size_t count, size_t offset) const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
virtual AR_API std::shared_ptr< const char > GetBuffer() const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
AR_API ~ArFilesystemAsset()
Closes the file owned by this object.
GLintptr offset
Definition: glcorearb.h:665