Skip to content

Commit

Permalink
More consistent naming of stream I/O template functions
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomofiorin committed Sep 15, 2023
1 parent 3eaa89c commit 7011be3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
13 changes: 7 additions & 6 deletions src/colvarbias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void raise_error_rewind(IST &is, SPT start_pos, std::string const &bias_type,
}


template <typename IST> IST & colvarbias::read_state_from_stream(IST &is)
template <typename IST> IST & colvarbias::read_state_template_(IST &is)
{
auto const start_pos = is.tellg();

Expand Down Expand Up @@ -603,13 +603,13 @@ template <typename IST> IST & colvarbias::read_state_from_stream(IST &is)

std::istream &colvarbias::read_state(std::istream &is)
{
return read_state_from_stream<std::istream>(is);
return read_state_template_<std::istream>(is);
}


cvm::memory_stream &colvarbias::read_state(cvm::memory_stream &is)
{
return read_state_from_stream<cvm::memory_stream>(is);
return read_state_template_<cvm::memory_stream>(is);
}


Expand Down Expand Up @@ -699,7 +699,8 @@ cvm::memory_stream &colvarbias::write_state_data_key(cvm::memory_stream &os, std
}


template <typename IST> IST &colvarbias::read_state_data_key_template(IST &is, std::string const &key)
template <typename IST>
IST &colvarbias::read_state_data_key_template_(IST &is, std::string const &key)
{
auto const start_pos = is.tellg();
std::string key_in;
Expand All @@ -718,13 +719,13 @@ template <typename IST> IST &colvarbias::read_state_data_key_template(IST &is, s

std::istream & colvarbias::read_state_data_key(std::istream &is, std::string const &key)
{
return read_state_data_key_template<std::istream>(is, key);
return read_state_data_key_template_<std::istream>(is, key);
}


cvm::memory_stream & colvarbias::read_state_data_key(cvm::memory_stream &is, std::string const &key)
{
return read_state_data_key_template<cvm::memory_stream>(is, key);
return read_state_data_key_template_<cvm::memory_stream>(is, key);
}


Expand Down
4 changes: 2 additions & 2 deletions src/colvarbias.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class colvarbias
/// Read a keyword header for a data sequence from a stream
/// \param[in,out] Input stream
/// \param[in] Keyword labeling the header block; an error will be raised if not matching
template <typename IST> IST &read_state_data_key_template(IST &is, std::string const &key);
template <typename IST> IST &read_state_data_key_template_(IST &is, std::string const &key);

public:

Expand All @@ -198,7 +198,7 @@ class colvarbias
private:

/// Generic stream reading function (formatted and not)
template <typename IST> IST & read_state_from_stream(IST &is);
template <typename IST> IST & read_state_template_(IST &is);

public:

Expand Down
12 changes: 6 additions & 6 deletions src/colvarbias_abf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ int colvarbias_abf::read_gradients_samples()
}


template <typename OST> OST & colvarbias_abf::write_to_stream(OST &os)
template <typename OST> OST & colvarbias_abf::write_state_data_template_(OST &os)
{
auto flags = os.flags();

Expand Down Expand Up @@ -770,17 +770,17 @@ template <typename OST> OST & colvarbias_abf::write_to_stream(OST &os)

std::ostream & colvarbias_abf::write_state_data(std::ostream& os)
{
return write_to_stream<std::ostream>(os);
return write_state_data_template_<std::ostream>(os);
}


cvm::memory_stream & colvarbias_abf::write_state_data(cvm::memory_stream& os)
{
return write_to_stream<cvm::memory_stream>(os);
return write_state_data_template_<cvm::memory_stream>(os);
}


template <typename IST> IST &colvarbias_abf::read_from_stream(IST &is)
template <typename IST> IST &colvarbias_abf::read_state_data_template_(IST &is)
{
if ( input_prefix.size() > 0 ) {
cvm::error("ERROR: cannot provide both inputPrefix and a colvars state file.\n", COLVARS_INPUT_ERROR);
Expand Down Expand Up @@ -827,13 +827,13 @@ template <typename IST> IST &colvarbias_abf::read_from_stream(IST &is)

std::istream & colvarbias_abf::read_state_data(std::istream& is)
{
return read_from_stream<std::istream>(is);
return read_state_data_template_<std::istream>(is);
}


cvm::memory_stream & colvarbias_abf::read_state_data(cvm::memory_stream& is)
{
return read_from_stream<cvm::memory_stream>(is);
return read_state_data_template_<cvm::memory_stream>(is);
}


Expand Down
4 changes: 2 additions & 2 deletions src/colvarbias_abf.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ class colvarbias_abf : public colvarbias {
private:

/// Generic stream writing function (formatted and not)
template <typename OST> OST &write_to_stream(OST &os);
template <typename OST> OST &write_state_data_template_(OST &os);

/// Generic stream readingx function (formatted and not)
template <typename IST> IST &read_from_stream(IST &is);
template <typename IST> IST &read_state_data_template_(IST &is);

public:

Expand Down
12 changes: 6 additions & 6 deletions src/colvargrid_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "colvars_memstream.h"


template <class T, class IST> IST &read_restart_template(colvar_grid<T> &g, IST &is)
template <class T, class IST> IST &read_restart_template_(colvar_grid<T> &g, IST &is)
{
auto const start_pos = is.tellg();
std::string conf;
Expand All @@ -43,13 +43,13 @@ template <class T, class IST> IST &read_restart_template(colvar_grid<T> &g, IST

template <class T> std::istream &colvar_grid<T>::read_restart(std::istream &is)
{
return read_restart_template<T, std::istream>(*this, is);
return read_restart_template_<T, std::istream>(*this, is);
}


template <class T> cvm::memory_stream &colvar_grid<T>::read_restart(cvm::memory_stream &is)
{
return read_restart_template<T, cvm::memory_stream>(*this, is);
return read_restart_template_<T, cvm::memory_stream>(*this, is);
}


Expand All @@ -69,7 +69,7 @@ template <class T> cvm::memory_stream &colvar_grid<T>::write_restart(cvm::memory
}


template <class T, class IST> IST &read_raw_template(colvar_grid<T> &g, IST &is)
template <class T, class IST> IST &read_raw_template_(colvar_grid<T> &g, IST &is)
{
auto const start_pos = is.tellg();

Expand Down Expand Up @@ -99,13 +99,13 @@ template <class T, class IST> IST &read_raw_template(colvar_grid<T> &g, IST &is)

template <class T> std::istream &colvar_grid<T>::read_raw(std::istream &is)
{
return read_raw_template<T, std::istream>(*this, is);
return read_raw_template_<T, std::istream>(*this, is);
}


template <class T> cvm::memory_stream &colvar_grid<T>::read_raw(cvm::memory_stream &is)
{
return read_raw_template<T, cvm::memory_stream>(*this, is);
return read_raw_template_<T, cvm::memory_stream>(*this, is);
}


Expand Down
12 changes: 6 additions & 6 deletions src/colvarvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ int colvarvalue::from_simple_string(std::string const &s)
}


template <typename OST> void colvarvalue::write_to_stream(OST &os) const
template <typename OST> void colvarvalue::write_to_stream_template_(OST &os) const
{
switch (type()) {
case colvarvalue::type_scalar:
Expand Down Expand Up @@ -751,14 +751,14 @@ template <typename OST> void colvarvalue::write_to_stream(OST &os) const

std::ostream & operator << (std::ostream &os, colvarvalue const &x)
{
x.write_to_stream<std::ostream>(os);
x.write_to_stream_template_<std::ostream>(os);
return os;
}


cvm::memory_stream & operator << (cvm::memory_stream &os, colvarvalue const &x)
{
x.write_to_stream<cvm::memory_stream>(os);
x.write_to_stream_template_<cvm::memory_stream>(os);
return os;
}

Expand All @@ -773,7 +773,7 @@ std::ostream & operator << (std::ostream &os, std::vector<colvarvalue> const &v)
}


template <typename IST> void colvarvalue::read_from_stream(IST &is)
template <typename IST> void colvarvalue::read_from_stream_template_(IST &is)
{
if (type() == colvarvalue::type_notset) {
cvm::error("Trying to read from a stream a colvarvalue, "
Expand Down Expand Up @@ -811,14 +811,14 @@ template <typename IST> void colvarvalue::read_from_stream(IST &is)

std::istream & operator >> (std::istream &is, colvarvalue &x)
{
x.read_from_stream<std::istream>(is);
x.read_from_stream_template_<std::istream>(is);
return is;
}


cvm::memory_stream & operator >> (cvm::memory_stream &is, colvarvalue &x)
{
x.read_from_stream<cvm::memory_stream>(is);
x.read_from_stream_template_<cvm::memory_stream>(is);
return is;
}

Expand Down
11 changes: 9 additions & 2 deletions src/colvarvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,25 @@ class colvarvalue {
/// Undefined operation
void undef_op() const;

private:

/// Generic stream writing function (formatted and not)
template <typename OST> void write_to_stream(OST &os) const;
template <typename OST> void write_to_stream_template_(OST &os) const;

public:

/// Formatted output operator
friend std::ostream & operator << (std::ostream &os, colvarvalue const &x);

/// Unformatted output operator
friend cvm::memory_stream & operator << (cvm::memory_stream &os, colvarvalue const &x);

private:

/// Generic stream reading function (formatted and not)
template <typename IST> void read_from_stream(IST &is);
template <typename IST> void read_from_stream_template_(IST &is);

public:

/// Formatted input operator
friend std::istream & operator >> (std::istream &is, colvarvalue &x);
Expand Down

0 comments on commit 7011be3

Please sign in to comment.