File Writer¶
These functions make writing data to file nice and easy
Initialiser¶
-
inline void
JSL::initialiseFile(const std::string &filename)¶ Creates a blank file at the specified location, overwriting any other file at the given location
- Parameters:
filename – The file which the system will attempt to open
String Writer¶
-
inline void
JSL::writeStringToFile(const std::string &filename, const std::string &content)¶ Opens the provided file and appends the provided string to the file, before closing it. If the file does not exist, it creates it.
- Parameters:
filename – The target file location
content – The desired string to be appended to the file (accepts control characters)
Vector Writer¶
-
template<class
T>
inline voidJSL::writeVectorToFile(const std::string &filename, const std::vector<T> &contentVector, const std::string &delimiter, bool includeTerminalLineBreak)¶ As with writeStringToFile, but accepts a vector of templated entities. The writing loops over the vector and writes them one at a time, separated by the delimiter object
- Parameters:
filename – The target file location
contentVector – A vector of templated objects to be written to file
delimiter – The character(s) to be written after every entry of contentVector except the final entry
includeTerminalLineBreak – If true, appends a linebreak character at the end of the vector. Useful for sequentially writing rows of data to file.
-
template<typename
T, typename ...Ts>
inline voidJSL::writeMultiVectorToFile(const std::string &filename, const std::string &delimiter, const std::vector<T> &v1, const std::vector<Ts>&... vecs)¶ As with writeVectorToFile, but accepts arbitrary vectors of templated entities. The writing loops over the length of the vectors (which must all be the same length), and writes them sequentially, separated by the delimiter, and a linebreak at the end of each row - i.e v1[0], v2[0], v3[0], … (linebreak) v1[1], v2[1], … etc.
- Parameters:
filename – The target file location
delimiter – The character(s) to be written after every individual vecs entry except the final entry on each row, which is a linebreak.
v1 – The first vector to be written to file
vecs – A variadic template for any number (including 0) of additional vectors, of any type (said type must have support for the streaming operator, <<). All vecs must be the same length
Matrix Writer¶
-
template<class
T>
inline voidJSL::writeMatrixToFile(const std::string &filename, const std::vector<std::vector<T>> contentMatrix, const std::string &columnDelimiter, const std::string &rowDelimiter)¶ As with writeStringToFile and writeVectorToFile, but accepts a vector<vector> of templated entities. The writing loops over the outer vector (the rows), and then at each step, the inner vectors(the columns). Writing them one at a time, separated by the delimiter objects. Objects need not be square matrices to be successfully written.
- Parameters:
filename – The target file location
contentMatrix – A vector<vector> of templated objects to be written to file
columnDelimiter – The character(s) to be written after every individual entry except the final entry in each row
rowRelimiter – The character(s) to be written at the end of each row including the final row. This will probably be a linebreak!