48 lines
1.2 KiB
C++
Raw Normal View History

2025-02-20 05:32:33 -05:00
// Copyright 2025 xensik. All rights reserved.
2024-02-27 01:34:37 -05:00
//
// Use of this source code is governed by a GNU GPLv3 license
// that can be found in the LICENSE file.
#pragma once
namespace xsk::utils
{
2025-02-20 05:32:33 -05:00
struct writer
2024-02-27 01:34:37 -05:00
{
using ptr = std::unique_ptr<writer>;
2025-02-20 05:32:33 -05:00
using error = std::runtime_error;
2024-02-27 01:34:37 -05:00
private:
2025-02-20 05:32:33 -05:00
static constexpr usize default_size = 0x100000;
2024-02-27 01:34:37 -05:00
u8* data_;
2025-02-20 05:32:33 -05:00
usize size_;
usize pos_ = 0;
2024-02-27 01:34:37 -05:00
bool swap_;
public:
2025-02-20 05:32:33 -05:00
writer(writer const&) = delete;
writer(writer&&) = delete;
auto operator=(writer const&) -> writer& = delete;
auto operator=(writer&&) -> writer& = delete;
explicit writer(bool swap = false);
writer(usize size, bool swap = false);
2024-02-27 01:34:37 -05:00
~writer();
auto clear() -> void;
template <typename T>
auto write(T data) -> void;
2025-02-20 05:32:33 -05:00
auto write_i24(i32 data) -> void;
2024-02-27 01:34:37 -05:00
auto write_string(std::string const& data) -> void;
auto write_cstr(std::string const& data) -> void;
2025-02-20 05:32:33 -05:00
auto is_avail() const -> bool;
auto seek(usize size) -> void;
auto seek_neg(usize size) -> void;
auto align(usize size) -> usize;
auto data() const -> u8 const*;
auto size() const -> usize;
auto pos() const -> usize;
auto pos(usize pos) -> void;
2024-02-27 01:34:37 -05:00
};
} // namespace xsk::utils