pflib v3.0.0-rc1-29-g3a901ac
Pretty Fine HGCROC Interaction Library
All Classes Namespaces Files Functions Variables Typedefs Pages
pflib::packing::Writer Class Reference

Writing a raw data file. More...

#include <Writer.h>

Collaboration diagram for pflib::packing::Writer:
[legend]

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>
Writerwrite (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>
Writeroperator<< (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>
Writeroperator<< (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>
Writeroperator<< (const ObjectType &o)
 Write out a class object.
 
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true>
Writeroperator<< (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
 

Detailed Description

Writing a raw data file.

We wrap a basic std::ifstream in order to make the writing of specific-width words easier for ourselves.

Constructor & Destructor Documentation

◆ Writer() [1/2]

pflib::packing::Writer::Writer ( )
inline

default constructor

make sure we don't skip "whitespace"

◆ Writer() [2/2]

pflib::packing::Writer::Writer ( const std::string & file_name)
inline

Open the input file name upon construction of this writer.

Parameters
[in]file_namename of file to open

Member Function Documentation

◆ open()

void pflib::packing::Writer::open ( const std::string & file_name)
inline

Open a file with this writer.

We open the file stream in output, binary mode.

Parameters
[in]file_namename of file to open

◆ operator bool()

pflib::packing::Writer::operator bool ( ) const
inline

Check if writer is in a good/bad state.

Uses std::ofstream::fail to check on stream.

Returns
true if stream is in good state

◆ operator!()

bool pflib::packing::Writer::operator! ( ) const
inline

Check if writer is in a fail state.

Uses std::ofstream::fail to check on stream.

Returns
true if stream is in fail state

◆ operator<<() [1/4]

template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true>
Writer & pflib::packing::Writer::operator<< ( const ObjectType & o)
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.

Template Parameters

in] ObjectType class-type to write out

Parameters
[in]oobject to write out
Returns
*this

◆ operator<<() [2/4]

template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true>
Writer & pflib::packing::Writer::operator<< ( const std::vector< ObjectType > & vec)
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.

Template Parameters

in] ObjectType class-type inside vector to write out

Parameters
[in]vecvector of objects to write out
Returns
*this

◆ operator<<() [3/4]

template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true>
Writer & pflib::packing::Writer::operator<< ( const std::vector< WordType > & vec)
inline

Write out a vector of integral-type objects.

This is a short-cut in order to help speed up writing.

Template Parameters

in] WordType integral-type to write out

Parameters
[in]vecvector of integral words to write out
Returns
*this

◆ operator<<() [4/4]

template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true>
Writer & pflib::packing::Writer::operator<< ( const WordType & w)
inline

Write a single integral-type word to the output file stream.

See also
write
Template Parameters

in] WordType integral-type to write out

Parameters
[in]wsingle word to write out
Returns
*this

◆ write()

template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true>
Writer & pflib::packing::Writer::write ( const WordType * w,
std::size_t num )
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.

Template Parameters

in] WordType integral-type to write out

Parameters
[in]wpointer to array of words to write
[in]numnumber of words in array
Returns
*this

The documentation for this class was generated from the following file: