Program Listing for File PcBufferReader.h

Program Listing for File PcBufferReader.h#

Return to documentation for file (src/buffer/PcBufferReader.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 PcBufferReader
{
  public:
    inline Result pop(element_t &elem)
    {
        return static_cast<T *>(this)->pop_impl(elem);
    }

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

    inline Result pop(std::span<element_t> &elem_span)
    {
        return pop_n(elem_span.data(), elem_span.size());
    }

    inline Result pop_n(element_t *elem_array, std::size_t count)
    {
        return static_cast<T *>(this)->pop_n_impl(elem_array, count);
    }

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

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

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

    inline std::size_t pop_all(element_t *elem_array = nullptr)
    {
        return static_cast<T *>(this)->pop_all_impl(elem_array);
    }
};

}; // namespace Coral