2026-04-09 17:43:58 +02:00
|
|
|
#ifndef TYPES_HPP
|
|
|
|
|
#define TYPES_HPP
|
|
|
|
|
|
2026-04-10 15:05:29 +02:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdint>
|
2026-04-09 17:43:58 +02:00
|
|
|
|
|
|
|
|
/// A pointer to a contiguous sequence of elements with a known length.
|
|
|
|
|
///
|
|
|
|
|
/// # Parameters
|
|
|
|
|
///
|
|
|
|
|
/// - `T`: The element type. Use `const T` for immutable data.
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct Slice {
|
|
|
|
|
/// Pointer to the first element.
|
|
|
|
|
T* data;
|
|
|
|
|
/// Number of elements.
|
|
|
|
|
size_t size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Mutable byte buffer.
|
|
|
|
|
using Bytes = Slice<uint8_t>;
|
|
|
|
|
|
|
|
|
|
/// Immutable byte buffer.
|
|
|
|
|
using ConstBytes = Slice<const uint8_t>;
|
|
|
|
|
|
2026-04-10 15:05:29 +02:00
|
|
|
namespace status {
|
|
|
|
|
/// Represents the outcome of an operation.
|
|
|
|
|
enum StatusCode {
|
|
|
|
|
Ok = 0,
|
|
|
|
|
DynError = 1,
|
|
|
|
|
InvalidInput = 2,
|
|
|
|
|
OutOfMemory = 3,
|
|
|
|
|
};
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 15:05:29 +02:00
|
|
|
inline bool is_ok(const StatusCode code) {
|
|
|
|
|
return code == Ok;
|
2026-04-10 12:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-10 15:05:29 +02:00
|
|
|
inline bool is_error(const StatusCode code) {
|
|
|
|
|
return !is_ok(code);
|
|
|
|
|
}
|
2026-04-10 12:15:33 +02:00
|
|
|
|
|
|
|
|
/// A status code with an optional human-readable description.
|
|
|
|
|
struct Status {
|
|
|
|
|
StatusCode code;
|
2026-04-10 15:05:29 +02:00
|
|
|
const char* message;
|
2026-04-10 12:15:33 +02:00
|
|
|
};
|
|
|
|
|
|
2026-04-10 15:05:29 +02:00
|
|
|
inline Status from_code(const StatusCode code) { return Status { code, nullptr }; }
|
|
|
|
|
inline Status ok() { return from_code(Ok); }
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 15:05:29 +02:00
|
|
|
inline bool is_ok(const Status status) { return is_ok(status.code); }
|
|
|
|
|
inline bool is_error(const Status status) { return is_error(status.code); }
|
2026-04-10 12:15:33 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 17:43:58 +02:00
|
|
|
#endif // TYPES_HPP
|