Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
cvm::memory_stream Class Reference

Public Member Functions

 memory_stream (size_t max_length=(static_cast< size_t >(1L)<< 36))
 
 memory_stream (size_t n, unsigned char const *buf)
 Set up a stream based on an external input buffer.
 
 memory_stream (std::vector< unsigned char > &buf)
 Set up a stream based on an external output buffer.
 
size_t length () const
 Length of the buffer.
 
unsigned char * output_buffer ()
 Output buffer.
 
unsigned char * output_location ()
 Next location to write to.
 
unsigned char const * input_buffer () const
 Input buffer.
 
unsigned char const * input_location () const
 Next location to read from.
 
 operator bool () const
 Cast operator to be used to test for errors.
 
template<typename T >
void write_object (T const &t)
 Write a simple object to the output buffer.
 
template<typename T >
void write_vector (std::vector< T > const &t)
 Write a vector of simple objects to the output buffer.
 
template<typename T >
void read_object (T &t)
 Read a simple object from the buffer.
 
template<typename T >
void read_vector (std::vector< T > &t)
 Read a vector of simple objects from the buffer.
 
size_t tellg () const
 Report the current position in the buffer.
 
memory_streamseekg (size_t pos)
 Report the current position in the buffer.
 
void setf (decltype(std::ios::fmtflags(0)), decltype(std::ios::floatfield))
 Ignore formatting operators.
 
void flags (decltype(std::ios::fmtflags(0)))
 Ignore formatting operators.
 
decltype(std::ios::fmtflags(0)) flags () const
 Get the current formatting flags (i.e. none because this stream is unformatted)
 
std::ios::iostate rdstate () const
 Get the error code.
 
void setstate (std::ios::iostate new_state)
 Set the error code.
 
void clear ()
 Clear the error code.
 
template<>
void write_object (std::string const &t)
 
template<>
void write_object (colvarvalue const &t)
 
template<>
void write_object (cvm::vector1d< cvm::real > const &t)
 
template<>
void read_object (std::string &t)
 
template<>
void read_object (colvarvalue &t)
 
template<>
void read_object (cvm::vector1d< cvm::real > &t)
 

Protected Member Functions

bool expand_output_buffer (size_t add_bytes)
 Add the requester number of bytes to the array capacity; return false if buffer is external.
 
void incr_write_pos (size_t c)
 Move the buffer position past the data just written.
 
void begin_reading ()
 Begin an attempt to read an object; assume EOF unless there is space remaining.
 
void done_reading ()
 Mark the reading attempt succesful.
 
void incr_read_pos (size_t c)
 Move the buffer position past the data just read.
 
bool has_remaining (size_t c)
 

Protected Attributes

std::vector< unsigned char > * external_output_buffer_ = nullptr
 External output buffer.
 
unsigned char const * external_input_buffer_ = nullptr
 External input buffer.
 
std::vector< unsigned char > internal_buffer_
 Internal buffer (may server for both input and output)
 
size_t data_length_ = 0L
 Length of the data buffer (either internal or external)
 
size_t const max_length_
 Largest allowed capacity of the data buffer.
 
std::ios::iostate state_ = std::ios::goodbit
 Error status.
 
size_t read_pos_ = 0L
 Current position when reading from the buffer.
 

Friends

template<typename T >
memory_streamoperator<< (memory_stream &os, T const &t)
 Wrapper to write_object()
 
template<typename T >
memory_streamoperator<< (memory_stream &os, std::vector< T > const &t)
 Wrapper to write_vector()
 
template<typename T >
memory_streamoperator>> (memory_stream &is, T &t)
 Wrapper to read_object()
 
template<typename T >
memory_streamoperator>> (memory_stream &is, std::vector< T > &t)
 Wrapper to read_vector()
 

Constructor & Destructor Documentation

◆ memory_stream()

cvm::memory_stream::memory_stream ( size_t  max_length = (static_cast<size_t>(1L) << 36))
inline

Set up an empty stream with an internal buffer, suitable for writing to

Parameters
max_lengthMaximum allowed capacity (default is 64 GiB)

Member Function Documentation

◆ has_remaining()

bool cvm::memory_stream::has_remaining ( size_t  c)
inlineprotected

Check that the buffer contains enough bytes to read as the argument says, set error otherwise


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