1#ifndef PACKING_UTILITY_WRITER_H_
2#define PACKING_UTILITY_WRITER_H_
35 void open(
const std::string& file_name) {
36 file_.open(file_name, std::ios::out | std::ios::binary);
61 template <
typename WordType,
62 std::enable_if_t<std::is_integral<WordType>::value,
bool> =
true>
64 file_.
write(
reinterpret_cast<const char*
>(w),
sizeof(WordType) * num);
77 template <
typename WordType,
78 std::enable_if_t<std::is_integral<WordType>::value,
bool> =
true>
92 template <
typename WordType,
93 std::enable_if_t<std::is_integral<WordType>::value,
bool> =
true>
95 return write(vec.data(), vec.size());
112 template <
typename ObjectType,
113 std::enable_if_t<std::is_class<ObjectType>::value,
bool> =
true>
115 return o.
write(*
this);
128 template <
typename ObjectType,
129 std::enable_if_t<std::is_class<ObjectType>::value,
bool> =
true>
131 for (
auto const& o : vec)
132 if (!o.write(*
this))
return *
this;
152 operator bool()
const {
return !
file_.fail(); }
Writer()
default constructor
Writer & operator<<(const ObjectType &o)
Write out a class object.
Writer & write(const WordType *w, std::size_t num)
Write a certain number of words from the input array to the output file stream.
~Writer()=default
destructor, close the input file stream
Writer & operator<<(const std::vector< ObjectType > &vec)
Write out a vector fo class objects.
Writer & operator<<(const WordType &w)
Write a single integral-type word to the output file stream.
Writer(const std::string &file_name)
Open the input file name upon construction of this writer.
Writer & operator<<(const std::vector< WordType > &vec)
Write out a vector of integral-type objects.
std::ofstream file_
file stream we are writing to
void open(const std::string &file_name)
Open a file with this writer.
bool operator!() const
Check if writer is in a fail state.