mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Input/Output Utilities

Various input/output utilities

Modules

 Working with strings
 
 File System Utilities
 
 ASCII I/O Utilities
 
 FITS Files
 
 binVector Binary File Format
 A simple binary file format for storing vectors of data on disk.
 

Functions

template<char space = ' ', bool flush = true, char eol = '\n', typename valT , typename... valTs>
void mx::ioutils::pout (valT value, const valTs &... values)
 A simple formatted output function. More...
 
template<typename T >
int mx::ioutils::readRawBinary (T *data, size_t szData, const std::string &fileName)
 Read an array of data from a file as raw binary. More...
 
template<typename T >
int mx::ioutils::writeRawBinary (const std::string &fileName, T *data, size_t szData)
 Write an array of data to file as raw binary. More...
 

Function Documentation

◆ pout()

template<char space = ' ', bool flush = true, char eol = '\n', typename valT , typename... valTs>
void mx::ioutils::pout ( valT  value,
const valTs &...  values 
)

A simple formatted output function.

This function writes its arguments, of any type and of any number, to stdout. By default, the arguments are separated by a space, the new line '\n' is written at the end, and the std::cout stream is flushed. These behaviors can be altered via template parameters.

Example:

std::string s="output:";
double d=2.567;
int i=3;
pout(s,d,i);

Note that the types of the values do not need to be specified as templated arguments. When run, this code results in

* $ output: 2.567 3
* $
* 

The behavior can be changed with template arguments like

pout<'\t', false, 0>(s,d,i);

which would use the tab instead of space, and neither flush nor print a newline at the end.

Template Parameters
spaceis the character to place between the values, by default this is space.
flushcontrols whether std::cout.flush() is called, by default it is true.
eolis the character to print at end of line, by default it is '\n'.
valTa type which can be output by std::cout
valTsa variadic list of additional types which can be output by std::cout
Parameters
[in]valuea value to print.
[in]valuesa variadic list of additional values. Any number of values can be specified, with any type handled by std::cout.

Definition at line 82 of file pout.hpp.

◆ readRawBinary()

template<typename T >
int mx::ioutils::readRawBinary ( T *  data,
size_t  szData,
const std::string &  fileName 
)

Read an array of data from a file as raw binary.

Here raw binary means no formatting or metadata.

Returns
0 on success
-1 on error
Parameters
[out]datathe data pointer
[in]szDatanumber of elements of sizeof(T) to read
[in]fileNamethe file to read from

Definition at line 50 of file rawBinary.hpp.

◆ writeRawBinary()

template<typename T >
int mx::ioutils::writeRawBinary ( const std::string &  fileName,
T *  data,
size_t  szData 
)

Write an array of data to file as raw binary.

Here raw binary means no formatting or metadata, just the bytes pointed to by the array are written to disk.

Returns
0 on success
-1 on error
Parameters
[in]fileNamethe file to write to
[in]datathe data pointer
[in]szDatanumber of elements of sizeof(T) to write

Definition at line 101 of file rawBinary.hpp.