Avara3D 0.2.0
C++ API reference
Buffer.h
1//
2// Buffer.h
3// avara3d
4//
5// Created by Morgan Davis on 9/5/18.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_BUFFER_H
10#define AVARA3D_BUFFER_H
11
12#include <filesystem>
13#include <memory>
14#include <vector>
15
16namespace a3d {
17
23 class Buffer {
24
25 public:
26 // [Public Lifecycle Functions]
27
33 explicit Buffer(const std::filesystem::path& path);
34
36 explicit Buffer(const std::vector<std::byte>& buf);
37
39 Buffer(const std::byte* buf, std::size_t size);
40
42 explicit Buffer(std::size_t size);
43
44 Buffer(const Buffer& other);
45 Buffer& operator=(const Buffer& other);
46
47 Buffer(Buffer&& other) noexcept;
48 Buffer& operator=(Buffer&& other) noexcept;
49
50 ~Buffer();
51
52 // [Public Member Functions]
53
55 std::byte* data() const;
56
58 std::size_t size() const;
59
61 std::byte* operator*() const;
62
68 std::byte operator[](std::size_t idx) const;
69
70 private:
71 // [Private Member Variables]
72
73 std::unique_ptr<std::byte[]> _data;
74 std::size_t _size;
75 };
76
77}
78
79#endif // AVARA3D_BUFFER_H
Container for a contiguous byte buffer.
Definition: Buffer.h:23
Buffer(const std::filesystem::path &path)
Reads the complete contents of path into a Buffer.
std::byte operator[](std::size_t idx) const
Returns the byte at idx without bounds checking.
std::byte * data() const
Returns a mutable pointer to the owned bytes, or nullptr when the Buffer is empty.
std::size_t size() const
Returns the buffer size in bytes.
Buffer(const std::vector< std::byte > &buf)
Creates a Buffer by copying the bytes in buf.
Buffer(const std::byte *buf, std::size_t size)
Creates a Buffer containing size bytes copied from buf.
Buffer(std::size_t size)
Creates a Buffer with storage for size bytes.
std::byte * operator*() const
Returns a mutable pointer to the owned bytes, equivalent to data().