libcruft-util/io.ipp

58 lines
1.5 KiB
Plaintext
Raw Normal View History

2014-06-29 22:49:26 +10:00
#ifdef __UTIL_IO_IPP
#error "multiple inclusions"
#else
#define __UTIL__IO_IPP
#endif
namespace util {
2015-07-02 16:34:17 +10:00
//-------------------------------------------------------------------------
template <typename T>
void
write (const fd &_fd, const T *restrict data, size_t count)
{
auto first = reinterpret_cast<const char*> (data);
write (_fd, first, first + sizeof (T) * count);
}
2015-10-20 21:04:14 +11:00
//-------------------------------------------------------------------------
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);
}
2015-07-02 16:34:17 +10:00
//-------------------------------------------------------------------------
2014-06-29 22:49:26 +10:00
template <typename T>
indented<T>::indented (const T &_data):
data (_data)
{ ; }
2015-07-02 16:34:17 +10:00
//-------------------------------------------------------------------------
2014-06-29 22:49:26 +10:00
template <typename T>
indented<T>
make_indented (const T &_data) {
return indented<T> (_data);
}
2015-07-02 16:34:17 +10:00
//-------------------------------------------------------------------------
template <typename T>
std::ostream&
operator<< (std::ostream &os, const util::indented<T> &&v) {
util::indenter raii (os);
os << v.data;
return os;
}
2014-06-29 22:49:26 +10:00
}