2016-02-26 13:36:01 +11:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* Copyright:
|
|
|
|
* 2014-2015, Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
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
|
2016-10-02 15:50:13 +11:00
|
|
|
write (const posix::fd &_fd, const T &data)
|
2015-07-02 16:34:17 +10:00
|
|
|
{
|
2015-10-29 10:48:54 +11:00
|
|
|
write (_fd, &data, sizeof (T));
|
2015-07-02 16:34:17 +10:00
|
|
|
}
|
|
|
|
|
2015-10-29 10:48:54 +11:00
|
|
|
|
2015-10-20 21:04:14 +11:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void
|
2016-10-02 15:50:13 +11:00
|
|
|
write (const posix::fd &_fd, const T *restrict first, const T *restrict last)
|
2015-10-20 21:04:14 +11:00
|
|
|
{
|
2015-10-29 10:48:54 +11:00
|
|
|
write (_fd, first, (last - first) * sizeof (T));
|
2015-10-20 21:04:14 +11:00
|
|
|
}
|
|
|
|
|
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
|
|
|
//-------------------------------------------------------------------------
|
2014-08-01 20:43:51 +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
|
|
|
}
|