HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
asset.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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 //
24 #ifndef PXR_USD_AR_ASSET_H
25 #define PXR_USD_AR_ASSET_H
26 
27 /// \file ar/asset.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/ar/ar.h"
31 #include "pxr/usd/ar/api.h"
32 
33 #include <cstdio>
34 #include <memory>
35 #include <utility>
36 
38 
39 /// \class ArAsset
40 ///
41 /// Interface for accessing the contents of an asset.
42 ///
43 /// \see ArResolver::OpenAsset for how to retrieve instances of this object.
44 class ArAsset {
45 public:
46  AR_API
47  virtual ~ArAsset();
48 
49  ArAsset(const ArAsset&) = delete;
50  ArAsset& operator=(const ArAsset&) = delete;
51 
52  /// Returns size of the asset.
53  AR_API
54  virtual size_t GetSize() const = 0;
55 
56  /// Returns a pointer to a buffer with the contents of the asset,
57  /// with size given by GetSize(). Returns an invalid std::shared_ptr
58  /// if the contents could not be retrieved.
59  ///
60  /// The data in the returned buffer must remain valid while there are
61  /// outstanding copies of the returned std::shared_ptr. Note that the
62  /// deleter stored in the std::shared_ptr may contain additional data
63  /// needed to maintain the buffer's validity.
64  AR_API
65  virtual std::shared_ptr<const char> GetBuffer() const = 0;
66 
67  /// Read \p count bytes at \p offset from the beginning of the asset
68  /// into \p buffer. Returns number of bytes read, or 0 on error.
69  ///
70  /// Implementers should range-check calls and return zero for out-of-bounds
71  /// reads.
72  AR_API
73  virtual size_t Read(void* buffer, size_t count, size_t offset) const = 0;
74 
75  /// Returns a read-only FILE* handle and offset for this asset if
76  /// available, or (nullptr, 0) otherwise.
77  ///
78  /// The returned handle must remain valid for the lifetime of this
79  /// ArAsset object. The returned offset is the offset from the beginning
80  /// of the FILE* where the asset's contents begins.
81  ///
82  /// This function is marked unsafe because the handle may wind up
83  /// being used in multiple threads depending on the underlying
84  /// resolver implementation. For instance, a resolver may cache
85  /// and return ArAsset objects with the same FILE* to multiple
86  /// threads.
87  ///
88  /// Clients MUST NOT use this handle with functions that cannot be
89  /// called concurrently on the same file descriptor, e.g. read,
90  /// fread, fseek, etc. See ArchPRead for a function that can be used
91  /// to read data from this handle safely.
92  AR_API
93  virtual std::pair<FILE*, size_t> GetFileUnsafe() const = 0;
94 
95  /// Returns an ArAsset with the contents of this asset detached from
96  /// from this asset's serialized data. External changes to the serialized
97  /// data must not have any effect on the ArAsset returned by this function.
98  ///
99  /// The default implementation returns a new instance of an ArInMemoryAsset
100  /// that reads the entire contents of this asset into a heap-allocated
101  /// buffer.
102  AR_API
103  virtual std::shared_ptr<ArAsset> GetDetachedAsset() const;
104 
105 protected:
106  AR_API
107  ArAsset();
108 };
109 
111 
112 #endif // PXR_USD_AR_ASSET_H
ArAsset & operator=(const ArAsset &)=delete
virtual AR_API std::shared_ptr< ArAsset > GetDetachedAsset() const
Definition: asset.h:44
virtual AR_API std::shared_ptr< const char > GetBuffer() const =0
virtual AR_API size_t GetSize() const =0
Returns size of the asset.
#define AR_API
Definition: api.h:40
virtual AR_API size_t Read(void *buffer, size_t count, size_t offset) const =0
GLintptr offset
Definition: glcorearb.h:665
Definition: core.h:760
virtual AR_API ~ArAsset()
AR_API ArAsset()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual AR_API std::pair< FILE *, size_t > GetFileUnsafe() const =0
GLint GLsizei count
Definition: glcorearb.h:405