io: add more write wrappers

This commit is contained in:
Danny Robson 2015-10-20 21:04:14 +11:00
parent 003685ce2b
commit ba9a8f8b35
2 changed files with 19 additions and 0 deletions

3
io.hpp
View File

@ -82,6 +82,9 @@ namespace util {
template <typename T> template <typename T>
void write (const fd&, const T *restrict data, size_t count); void write (const fd&, const T *restrict data, size_t count);
template <typename T>
void write (const fd&, const T &data);
template <typename T> template <typename T>
void write (const fd&, const T *restrict first, const T *restrict last); void write (const fd&, const T *restrict first, const T *restrict last);

16
io.ipp
View File

@ -15,6 +15,22 @@ namespace util {
write (_fd, first, first + sizeof (T) * count); write (_fd, first, first + sizeof (T) * count);
} }
//-------------------------------------------------------------------------
template <typename T>
void
write (const fd &_fd, const T &data)
{
write (_fd, &data, 1);
}
//-------------------------------------------------------------------------
inline void
write (const fd &_fd, const void *_data, size_t _bytes)
{
auto data = reinterpret_cast<const uint8_t*> (_data);
write (_fd, data, data + _bytes);
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <typename T> template <typename T>
indented<T>::indented (const T &_data): indented<T>::indented (const T &_data):