pflib v3.0.0-rc1-29-g3a901ac
Pretty Fine HGCROC Interaction Library
|
Writing a raw data file. More...
#include <Writer.h>
Public Member Functions | |
Writer () | |
default constructor | |
void | open (const std::string &file_name) |
Open a file with this writer. | |
Writer (const std::string &file_name) | |
Open the input file name upon construction of this writer. | |
~Writer ()=default | |
destructor, close the input file stream | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
Writer & | write (const WordType *w, std::size_t num) |
Write a certain number of words from the input array to the output file stream. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
Writer & | operator<< (const WordType &w) |
Write a single integral-type word to the output file stream. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
Writer & | operator<< (const std::vector< WordType > &vec) |
Write out a vector of integral-type objects. | |
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true> | |
Writer & | operator<< (const ObjectType &o) |
Write out a class object. | |
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true> | |
Writer & | operator<< (const std::vector< ObjectType > &vec) |
Write out a vector fo class objects. | |
bool | operator! () const |
Check if writer is in a fail state. | |
operator bool () const | |
Check if writer is in a good/bad state. | |
Private Attributes | |
std::ofstream | file_ |
file stream we are writing to | |
Writing a raw data file.
We wrap a basic std::ifstream in order to make the writing of specific-width words easier for ourselves.
|
inline |
default constructor
make sure we don't skip "whitespace"
|
inline |
Open the input file name upon construction of this writer.
[in] | file_name | name of file to open |
|
inline |
Open a file with this writer.
We open the file stream in output, binary mode.
[in] | file_name | name of file to open |
|
inline |
Check if writer is in a good/bad state.
Uses std::ofstream::fail to check on stream.
|
inline |
Check if writer is in a fail state.
Uses std::ofstream::fail to check on stream.
|
inline |
Write out a class object.
We assume that the input class object has a specific method defined.
Writer& write(Writer&) const;
With this method defined, then the class can be streamed out through this object.
in] ObjectType class-type to write out
[in] | o | object to write out |
|
inline |
Write out a vector fo class objects.
We make the same assumptions as when streaming out a single class object. We leave early if any write action changes the file to a fail state.
in] ObjectType class-type inside vector to write out
[in] | vec | vector of objects to write out |
|
inline |
Write out a vector of integral-type objects.
This is a short-cut in order to help speed up writing.
in] WordType integral-type to write out
[in] | vec | vector of integral words to write out |
|
inline |
Write a single integral-type word to the output file stream.
in] WordType integral-type to write out
[in] | w | single word to write out |
|
inline |
Write a certain number of words from the input array to the output file stream.
This method is only enabled for integral types so we can safely reinterpret the underlying data as an array of characters.
in] WordType integral-type to write out
[in] | w | pointer to array of words to write |
[in] | num | number of words in array |