Program Listing for File PcBufferWriter.h

Program Listing for File PcBufferWriter.h#

Return to documentation for file (src/buffer/PcBufferWriter.h)

#pragma once

/* toolchain */
#include <array>
#include <cstdint>
#include <span>

/* internal */
#include "../result.h"

namespace Coral
{

template <class T, typename element_t = std::byte> class PcBufferWriter
{
  public:
    inline Result push(const element_t &elem, bool drop = false)
    {
        return static_cast<T *>(this)->push_impl(elem, drop);
    }

    inline void push_blocking(const element_t &elem)
    {
        static_cast<T *>(this)->push_blocking_impl(elem);
    }

    template <std::size_t N>
    inline Result push(const std::array<element_t, N> &elem_array,
                       bool drop = false)
    {
        return push_n(elem_array.data(), elem_array.size(), drop);
    }

    inline Result push(const std::span<element_t> &elem_span,
                       bool drop = false)
    {
        return push_n(elem_span.data(), elem_span.size(), drop);
    }

    inline Result push_n(const element_t *elem_array, std::size_t count,
                         bool drop = false)
    {
        return static_cast<T *>(this)->push_n_impl(elem_array, count, drop);
    }

    template <std::size_t N>
    inline std::size_t try_push_n(const std::array<element_t, N> &elem_array)
    {
        return try_push_n(elem_array.data(), elem_array.size());
    }

    inline std::size_t try_push_n(const std::span<element_t> &elem_span)
    {
        return try_push_n(elem_span.data(), elem_span.size());
    }

    inline std::size_t try_push_n(const element_t *elem_array,
                                  std::size_t count)
    {
        return static_cast<T *>(this)->try_push_n_impl(elem_array, count);
    }

    template <std::size_t N>
    inline void push_n_blocking(const std::array<element_t, N> &elem_array)
    {
        push_n_blocking(elem_array.data(), elem_array.size());
    }

    inline void push_n_blocking(const std::span<element_t> &elem_span)
    {
        push_n_blocking(elem_span.data(), elem_span.size());
    }

    inline void push_n_blocking(const element_t *elem_array, std::size_t count)
    {
        static_cast<T *>(this)->push_n_blocking_impl(elem_array, count);
    }
};

}; // namespace Coral