12#include "akreon/linalg/assert.hpp"
13#include "akreon/linalg/linalg.hpp"
29 constexpr std::size_t
size()
const {
return pos; }
31 constexpr const char*
c_str()
const {
return out; }
34 if (
out !=
nullptr &&
cap > 0)
out[0] =
'\0';
41 template <
typename...
Args>
43 AK_ASSERT(
out !=
nullptr &&
"FixedBufferWriter requires non-null output");
44 if (
out ==
nullptr ||
cap == 0)
return false;
59 const auto n =
static_cast<std::size_t
>(
bytes);
72template <std::
size_t N>
79template <linalg::Field T, std::
size_t N>
82 if (!w.
append(
"["))
return false;
83 const std::size_t
used = (size < N) ? size : N;
84 for (std::size_t
i = 0;
i <
used; ++
i) {
85 if (!w.
format((
i + 1 ==
used) ?
"%g" :
"%g, ",
static_cast<double>(
v[
i])))
91template <linalg::VectorContainer Vec>
93 if (!w.
append(
"["))
return false;
94 constexpr std::size_t N = linalg::vector_dim_v<Vec>;
95 for (std::size_t
i = 0;
i < N; ++
i) {
96 if (!w.
format((
i + 1 == N) ?
"%g" :
"%g, ",
static_cast<double>(
v(
i))))
102template <linalg::MatrixContainer Mat>
104 if (!w.
append(
"["))
return false;
105 constexpr std::size_t
Rows = linalg::mat_rows_v<Mat>;
106 constexpr std::size_t
Cols = linalg::mat_cols_v<Mat>;
107 for (std::size_t
i = 0;
i <
Rows; ++
i) {
108 if (!w.
append(
"["))
return false;
109 for (std::size_t
j = 0;
j <
Cols; ++
j) {
111 static_cast<double>(M(
i,
j))))
114 if (!w.
append((
i + 1 ==
Rows) ?
"]" :
"],"))
return false;
119template <linalg::VectorContainer Vec>
128template <linalg::MatrixContainer Mat>
bool append_vector(FixedBufferWriter &w, const Vec &v)
bool append_array_slice(FixedBufferWriter &w, const std::array< T, N > &v, std::size_t size)
FixedBufferWriter make_writer(char(&out)[N])
std::size_t vector_to_cstr(const Vec &v, char *out, std::size_t out_size)
std::size_t matrix_to_cstr(const Mat &M, char *out, std::size_t out_size)
bool append_matrix(FixedBufferWriter &w, const Mat &M)
constexpr std::size_t dom_size_v
Small no-heap append-only writer for debug formatting.
constexpr bool ok() const
bool append(const char *text)
bool format(const char *fmt, Args... args)
constexpr std::size_t size() const
constexpr const char * c_str() const