0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

ircd::buffer: Deconflict buffers templates in separate namespace.

This commit is contained in:
Jason Volk 2018-09-13 03:22:21 -07:00
parent 09529ae311
commit 994916b7eb

View file

@ -77,13 +77,16 @@ namespace ircd::buffer
void reverse(const mutable_buffer &buf); void reverse(const mutable_buffer &buf);
void zero(const mutable_buffer &buf); void zero(const mutable_buffer &buf);
// Convenience copy to std stream
template<class it> std::ostream &operator<<(std::ostream &s, const buffer<it> &buffer);
}
namespace ircd::buffer::buffers
{
// Iterable of buffers tools // Iterable of buffers tools
template<template<class> class I, class T> size_t size(const I<T> &buffers); template<template<class> class I, class T> size_t size(const I<T> &buffers);
template<template<class> class I, class T> size_t copy(const mutable_buffer &, const I<T> &buffer); template<template<class> class I, class T> size_t copy(const mutable_buffer &, const I<T> &buffer);
template<template<class> class I, class T> size_t consume(I<T> &buffers, const size_t &bytes); template<template<class> class I, class T> size_t consume(I<T> &buffers, const size_t &bytes);
// Convenience copy to std stream
template<class it> std::ostream &operator<<(std::ostream &s, const buffer<it> &buffer);
template<template<class> class I, class T> std::ostream &operator<<(std::ostream &s, const I<T> &buffers); template<template<class> class I, class T> std::ostream &operator<<(std::ostream &s, const I<T> &buffers);
} }
@ -123,7 +126,7 @@ template<template<class>
class buffers, class buffers,
class T> class T>
std::ostream & std::ostream &
ircd::buffer::operator<<(std::ostream &s, const buffers<T> &b) ircd::buffer::buffers::operator<<(std::ostream &s, const buffers<T> &b)
{ {
using it = typename T::iterator; using it = typename T::iterator;
@ -140,14 +143,16 @@ template<template<class>
class buffers, class buffers,
class T> class T>
size_t size_t
ircd::buffer::consume(buffers<T> &b, ircd::buffer::buffers::consume(buffers<T> &b,
const size_t &bytes) const size_t &bytes)
{ {
ssize_t remain(bytes); ssize_t remain(bytes);
for(auto it(std::begin(b)); it != std::end(b) && remain > 0; ++it) for(auto it(std::begin(b)); it != std::end(b) && remain > 0; ++it)
{ {
using buffer = typename buffers<T>::value_type; using buffer = typename buffers<T>::value_type;
using iterator = typename buffer::iterator; using iterator = typename buffer::iterator;
using ircd::buffer::size;
using ircd::buffer::consume;
buffer &b(const_cast<buffer &>(*it)); buffer &b(const_cast<buffer &>(*it));
const ssize_t bsz(size(b)); const ssize_t bsz(size(b));
@ -164,10 +169,12 @@ template<template<class>
class buffers, class buffers,
class T> class T>
size_t size_t
ircd::buffer::copy(const mutable_buffer &dest, ircd::buffer::buffers::copy(const mutable_buffer &dest,
const buffers<T> &b) const buffers<T> &b)
{ {
using it = typename T::iterator; using it = typename T::iterator;
using ircd::buffer::copy;
using ircd::buffer::size;
size_t ret(0); size_t ret(0);
for(const buffer<it> &b : b) for(const buffer<it> &b : b)
@ -180,9 +187,10 @@ template<template<class>
class buffers, class buffers,
class T> class T>
size_t size_t
ircd::buffer::size(const buffers<T> &b) ircd::buffer::buffers::size(const buffers<T> &b)
{ {
using it = typename T::iterator; using it = typename T::iterator;
using ircd::buffer::size;
return std::accumulate(std::begin(b), std::end(b), size_t(0), [] return std::accumulate(std::begin(b), std::end(b), size_t(0), []
(auto ret, const buffer<it> &b) (auto ret, const buffer<it> &b)