This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
inMemoryAsset.h
1//
2// Copyright 2022 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_IN_MEMORY_ASSET_H
7#define PXR_USD_AR_IN_MEMORY_ASSET_H
8
9#include "pxr/pxr.h"
10#include "pxr/usd/ar/api.h"
11#include "pxr/usd/ar/asset.h"
12
13#include <cstdio>
14#include <memory>
15#include <utility>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
24 : public ArAsset
25{
26public:
32 AR_API
33 static std::shared_ptr<ArInMemoryAsset> FromAsset(
34 const ArAsset& srcAsset);
35
38 AR_API
39 static std::shared_ptr<ArInMemoryAsset> FromBuffer(
40 const std::shared_ptr<const char>& buffer,
41 size_t bufferSize);
42
45 AR_API
46 static std::shared_ptr<ArInMemoryAsset> FromBuffer(
47 std::shared_ptr<const char>&& buffer,
48 size_t bufferSize);
49
52 AR_API
54
56 AR_API
57 size_t GetSize() const override;
58
60 AR_API
61 std::shared_ptr<const char> GetBuffer() const override;
62
65 AR_API
66 size_t Read(void* buffer, size_t count, size_t offset) const override;
67
69 AR_API
70 std::pair<FILE*, size_t> GetFileUnsafe() const override;
71
74 AR_API
75 std::shared_ptr<ArAsset> GetDetachedAsset() const override;
76
77private:
78 struct PrivateCtorTag {};
79public:
80 // "Private" c'tor. Must actually be public for std::make_shared,
81 // but the PrivateCtorTag prevents other code from using this.
82 template <class BufferSharedPtr>
84 BufferSharedPtr&& buffer,
85 size_t bufferSize,
86 PrivateCtorTag);
87
88private:
89 std::shared_ptr<const char> _buffer;
90 size_t _bufferSize;
91};
92
93PXR_NAMESPACE_CLOSE_SCOPE
94
95#endif
Interface for accessing the contents of an asset.
Definition: asset.h:27
ArAsset implementation that stores asset content in a heap-allocated buffer managed by this object.
Definition: inMemoryAsset.h:25
AR_API std::shared_ptr< const char > GetBuffer() const override
Returns the buffer managed by this object.
AR_API size_t Read(void *buffer, size_t count, size_t offset) const override
Reads count bytes from the buffer held by this object at the given offset into buffer.
static AR_API std::shared_ptr< ArInMemoryAsset > FromBuffer(const std::shared_ptr< const char > &buffer, size_t bufferSize)
Constructs a new instance sharing ownership of the given buffer containing bufferSize bytes.
AR_API std::pair< FILE *, size_t > GetFileUnsafe() const override
Returns { nullptr, 0 } as this object is not associated with a file.
static AR_API std::shared_ptr< ArInMemoryAsset > FromAsset(const ArAsset &srcAsset)
Constructs a new instance containing the entire contents of srcAsset.
AR_API size_t GetSize() const override
Returns the size of the buffer managed by this object.
AR_API std::shared_ptr< ArAsset > GetDetachedAsset() const override
Returns a new ArInMemoryAsset instance that shares the same buffer as this object.
static AR_API std::shared_ptr< ArInMemoryAsset > FromBuffer(std::shared_ptr< const char > &&buffer, size_t bufferSize)
Constructs a new instance taking ownership of the given buffer containing bufferSize bytes.
AR_API ~ArInMemoryAsset()
Destructor.