HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filesystemAsset.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_ASSET_H
7 #define PXR_USD_AR_FILESYSTEM_ASSET_H
8 
9 /// \file ar/filesystemAsset.h
10 
11 #include "pxr/pxr.h"
12 #include "pxr/usd/ar/api.h"
13 #include "pxr/usd/ar/asset.h"
14 #include "pxr/usd/ar/timestamp.h"
15 
16 #include <cstdio>
17 #include <memory>
18 #include <utility>
19 
21 
22 class ArResolvedPath;
23 
24 /// \class ArFilesystemAsset
25 ///
26 /// ArAsset implementation for asset represented by a file on a filesystem.
28  : public ArAsset
29 {
30 public:
31  /// Constructs a new ArFilesystemAsset for the file at \p resolvedPath.
32  /// Returns a null pointer if the file could not be opened.
33  AR_API
34  static std::shared_ptr<ArFilesystemAsset> Open(
35  const ArResolvedPath& resolvedPath);
36 
37  /// Returns an ArTimestamp holding the mtime of the file at \p resolvedPath.
38  /// Returns an invalid ArTimestamp if the mtime could not be retrieved.
39  AR_API
41  const ArResolvedPath& resolvedPath);
42 
43  /// Constructs an ArFilesystemAsset for the given \p file.
44  /// The ArFilesystemAsset object takes ownership of \p file and will
45  /// close the file handle on destruction.
46  AR_API
47  explicit ArFilesystemAsset(FILE* file);
48 
49  /// Closes the file owned by this object.
50  AR_API
52 
53  /// Returns the size of the file held by this object.
54  AR_API
55  virtual size_t GetSize() const override;
56 
57  /// Creates a read-only memory map for the file held by this object
58  /// and returns a pointer to the start of the mapped contents.
59  AR_API
60  virtual std::shared_ptr<const char> GetBuffer() const override;
61 
62  /// Reads \p count bytes from the file held by this object at the
63  /// given \p offset into \p buffer.
64  AR_API
65  virtual size_t Read(
66  void* buffer, size_t count, size_t offset) const override;
67 
68  /// Returns the FILE* handle this object was created with and an offset
69  /// of 0, since the asset's contents are located at the beginning of the
70  /// file.
71  AR_API
72  virtual std::pair<FILE*, size_t> GetFileUnsafe() const override;
73 
74 private:
75  FILE* _file;
76 };
77 
79 
80 #endif // PXR_USD_AR_FILESYSTEM_ASSET_H
Definition: asset.h:27
static AR_API std::shared_ptr< ArFilesystemAsset > Open(const ArResolvedPath &resolvedPath)
#define AR_API
Definition: api.h:23
GLuint buffer
Definition: glcorearb.h:660
GLintptr offset
Definition: glcorearb.h:665
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)
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:1425
virtual AR_API std::shared_ptr< const char > GetBuffer() const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
AR_API ~ArFilesystemAsset()
Closes the file owned by this object.
GLint GLsizei count
Definition: glcorearb.h:405