ampsci
High-precision calculations for one- and two-valence atomic systems
IO::FRW Namespace Reference

Detailed Description

File read/write utilities: text parsing and binary I/O.

Low-level helpers for reading and writing text and binary files. Includes functions for parsing space- or line-separated input files (with comment stripping), reading (x, y) data, and variadic binary read/write for PoD types, vectors, and strings.

Warning
Many functions in this namespace are old and some are obsolete. Use sparingly and with caution – prefer higher-level IO interfaces where available.

Enumerations

enum  RoW { read , write }
 

Functions

std::pair< std::vector< double >, std::vector< double > > readFile_xy_PoV (const std::string &fname)
 Reads (x, y) pairs from a file; returns a pair of vectors {xs, ys}. Lines beginning with '#', '!', or '//' are skipped.
 
void removeBlockComments (std::string &input)
 Removes C-style block comments (/* ... *‍/) from a string in-place.
 
std::string removeCommentsAndSpaces (const std::string &input)
 Strips comments (#, !, //, /* *‍/), spaces, tabs, and quote characters. Lines are squashed together; semicolons are preserved as delimiters.
 
void open_binary (std::fstream &stream, const std::string &fname, RoW row)
 Opens a binary fstream for reading or writing according to row.
 
bool file_exists (const std::string &fileName)
 Returns true if the file at fileName exists and can be opened.
 
template<typename T , typename... Types>
void rw_binary (std::fstream &stream, RoW row, std::vector< T > &value, Types &...values)
 Function (variadic): reads/writes data from/to binary file. Works for trivial (PoD) types, and std::string only (but not checked) Overload for vectors.
 
template<typename T , typename... Types>
void rw_binary (std::fstream &stream, RoW row, T &value, Types &...values)
 Function (variadic): reads/writes data from/to binary file. Works for trivial (PoD) types, and std::string only (but not checked)
 
template<typename T >
void binary_rw (std::fstream &stream, T &value, RoW row)
 
template<typename T >
void binary_rw_vec (std::fstream &stream, std::vector< T > &value, RoW row)
 
void binary_str_rw (std::fstream &stream, std::string &value, RoW row)
 

Function Documentation

◆ readFile_xy_PoV()

std::pair< std::vector< double >, std::vector< double > > IO::FRW::readFile_xy_PoV ( const std::string &  fname)
inline

Reads (x, y) pairs from a file; returns a pair of vectors {xs, ys}. Lines beginning with '#', '!', or '//' are skipped.

◆ removeBlockComments()

void IO::FRW::removeBlockComments ( std::string &  input)
inline

Removes C-style block comments (/* ... *‍/) from a string in-place.

◆ removeCommentsAndSpaces()

std::string IO::FRW::removeCommentsAndSpaces ( const std::string &  input)
inline

Strips comments (#, !, //, /* *‍/), spaces, tabs, and quote characters. Lines are squashed together; semicolons are preserved as delimiters.

◆ open_binary()

void IO::FRW::open_binary ( std::fstream &  stream,
const std::string &  fname,
RoW  row 
)
inline

Opens a binary fstream for reading or writing according to row.

◆ file_exists()

bool IO::FRW::file_exists ( const std::string &  fileName)
inline

Returns true if the file at fileName exists and can be opened.

◆ rw_binary() [1/2]

template<typename T , typename... Types>
void IO::FRW::rw_binary ( std::fstream &  stream,
RoW  row,
std::vector< T > &  value,
Types &...  values 
)

Function (variadic): reads/writes data from/to binary file. Works for trivial (PoD) types, and std::string only (but not checked) Overload for vectors.

◆ rw_binary() [2/2]

template<typename T , typename... Types>
void IO::FRW::rw_binary ( std::fstream &  stream,
RoW  row,
T &  value,
Types &...  values 
)

Function (variadic): reads/writes data from/to binary file. Works for trivial (PoD) types, and std::string only (but not checked)