docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C++ API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Buffer.h
Go to the documentation of this file.
1
///
2
/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3
/// A license is required for commercial use. https://ultralig.ht
4
///
5
#pragma once
6
#include <
Ultralight/Defines.h
>
7
#include <
Ultralight/RefPtr.h
>
8
9
namespace
ultralight
{
10
11
///
12
/// Function signature for a user-defined destruction callback to optionally be called when Buffer
13
/// is destroyed. Users can use this to deallocate any data associated with the Buffer.
14
///
15
/// @param user_data Pointer to user-defined user-data (this will be the same value as what was
16
/// passed to Buffer::Create, if any)
17
///
18
/// @param data Pointer to raw Buffer data.
19
///
20
typedef
void (*
DestroyBufferCallback
)(
void
* user_data,
void
* data);
21
22
///
23
/// A fixed-size container for raw byte data.
24
///
25
/// This class is used to represent raw data buffers in Ultralight. It intelligently manages the
26
/// lifetime of the data and can optionally call a user-supplied callback to deallocate the data
27
/// when the Buffer is destroyed.
28
///
29
class
UExport
Buffer
:
public
RefCounted
{
30
public
:
31
///
32
/// Create a Buffer from existing, user-owned data without any copies. An optional, user-supplied
33
/// callback will be called to deallocate data upon destruction.
34
///
35
/// @param data A pointer to the data.
36
///
37
/// @param size Size of the data in bytes.
38
///
39
/// @param user_data Optional user data that will be passed to destruction_callback
40
/// when the returned Buffer is destroyed.
41
///
42
/// @param destruction_callback Optional callback that will be called upon destruction. Pass a
43
/// null pointer if you don't want to be informed of destruction.
44
///
45
///
46
/// @return A ref-counted Buffer object that wraps the existing data.
47
///
48
static
RefPtr<Buffer>
Create
(
void
*
data
,
size_t
size
,
void
*
user_data
,
49
DestroyBufferCallback
destruction_callback);
50
51
///
52
/// Create a Buffer from existing data, a deep copy of data will be made.
53
///
54
static
RefPtr<Buffer>
CreateFromCopy
(
const
void
*
data
,
size_t
size
);
55
56
///
57
/// Get a pointer to the raw byte data.
58
///
59
virtual
void
*
data
() = 0;
60
61
///
62
/// Get the size in bytes.
63
///
64
virtual
size_t
size
()
const
= 0;
65
66
///
67
/// Get the user data associated with this Buffer, if any.
68
///
69
virtual
void
*
user_data
() = 0;
70
71
///
72
/// Check whether this Buffer owns its own data (Buffer was created via CreateFromCopy).
73
/// If this is false, Buffer will call the user-supplied destruction callback to deallocate data
74
/// when this Buffer instance is destroyed.
75
///
76
virtual
bool
owns_data
()
const
= 0;
77
78
protected
:
79
Buffer
();
80
virtual
~Buffer
();
81
Buffer
(
const
Buffer
&);
82
void
operator=
(
const
Buffer
&);
83
};
84
85
}
// namespace ultralight
UExport
#define UExport
Definition
Exports.h:22
RefPtr.h
Defines.h
ultralight::Buffer::Buffer
Buffer(const Buffer &)
ultralight::Buffer::user_data
virtual void * user_data()=0
Get the user data associated with this Buffer, if any.
ultralight::Buffer::Buffer
Buffer()
ultralight::Buffer::owns_data
virtual bool owns_data() const =0
Check whether this Buffer owns its own data (Buffer was created via CreateFromCopy).
ultralight::Buffer::Create
static RefPtr< Buffer > Create(void *data, size_t size, void *user_data, DestroyBufferCallback destruction_callback)
Create a Buffer from existing, user-owned data without any copies.
ultralight::Buffer::operator=
void operator=(const Buffer &)
ultralight::Buffer::size
virtual size_t size() const =0
Get the size in bytes.
ultralight::Buffer::data
virtual void * data()=0
Get a pointer to the raw byte data.
ultralight::Buffer::~Buffer
virtual ~Buffer()
ultralight::Buffer::CreateFromCopy
static RefPtr< Buffer > CreateFromCopy(const void *data, size_t size)
Create a Buffer from existing data, a deep copy of data will be made.
ultralight::RefCounted
Interface for all ref-counted objects that will be managed using the RefPtr<> smart pointer.
Definition
RefPtr.h:49
ultralight::RefPtr
A nullable smart pointer.
Definition
RefPtr.h:126
ultralight
Root namespace for every public Ultralight type, function, and enumeration.
ultralight::DestroyBufferCallback
void(*) DestroyBufferCallback(void *user_data, void *data)
Function signature for a user-defined destruction callback to optionally be called when Buffer is des...
Definition
Buffer.h:20
Ultralight
Buffer.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4