11#ifndef UTILS_UTIL_IO_H
12#define UTILS_UTIL_IO_H
67 std::string
str()
const {
return d_oss.str(); }
70 operator std::string()
const {
return d_oss.str(); }
83 std::string tabS =
"";
84 for (
int i = 0; i < nt; i++)
98 std::ostringstream oss;
109template <
class T>
inline std::string
printStr(
const std::vector<T> &list,
113 std::ostringstream oss;
116 for (
auto l : list) {
119 if (i != list.size())
127template <>
inline std::string
printStr(
const std::vector<util::Point> &list,
131 std::ostringstream oss;
134 for (
auto l : list) {
135 oss <<
"(" << l[0] <<
", " << l[1] <<
", " << l[2] <<
")";
137 if (i != list.size())
150 template <
typename T,
typename U>
inline std::string
printStr(
const std::map<T, U> &map,
154 std::ostringstream oss;
156 for (
const auto &l : map) {
157 oss <<
"{" << l.first <<
" : " << l.second <<
"}";
158 if (std::next(&l) != map.cend())
191inline std::string
printStr(
const std::vector<std::vector<T>> &list,
195 std::ostringstream oss;
198 for (
auto l : list) {
200 for (
size_t k = 0; k < l.size(); k++) {
202 if (k < l.size() - 1)
208 if (i != list.size())
217template <
class T>
inline void print(
const std::vector<std::vector<T>> &list,
231inline std::string
printBoxStr(
const std::pair<util::Point, util::Point>
234 std::ostringstream oss;
235 oss << tabS <<
"Corner point 1 = " << box.first.printStr(nt, 0) << std::endl;
236 oss << tabS <<
"Corner point 2 = " << box.second.printStr(nt, 0) << std::endl;
247inline void printBox(
const std::pair<util::Point, util::Point> &box,
256inline std::string
printBoxStr(
const std::pair<std::vector<double>, std::vector<double>> &box,
259 std::ostringstream oss;
260 oss << tabS <<
"Corner point 1 = (" << printStr<double>(box.first, 0)
262 oss << tabS <<
"Corner point 2 = (" << printStr<double>(box.second, 0)
271inline void printBox(
const std::pair<std::vector<double>, std::vector<double>> &box,
291void log(std::ostringstream &oss,
bool screen_out =
false,
301void log(
const std::string &str,
bool screen_out =
false,
307bool logEnabled(
int priority,
bool check_condition =
true,
308 int override_priority = -1);
313void log(
int priority,
const std::string &str,
bool check_condition =
true,
314 int override_priority = -1,
bool screen_out =
false);
316void log(
int priority, std::ostringstream &oss,
bool check_condition =
true,
317 int override_priority = -1,
bool screen_out =
false);
329 return path.substr(path.find_last_of(delims) + 1);
341 typename std::string::size_type
const p(filename.find_last_of(
'.'));
342 return p > 0 && p != std::string::npos ? filename.substr(0, p) : filename;
353 typename std::string::size_type
const p(filename.find_last_of(
'.'));
356 return p > 0 && p != std::string::npos ? filename.substr(p+1) :
"";
369 std::string f = filename;
371 f = f +
"." + filename_ext;
374 if (f_ext != filename_ext) {
375 throw std::runtime_error(
377 <<
"checkAndCreateNewFilename(): Argument filename = "
378 << filename <<
" has extension = "
379 << f_ext <<
" which does not match expected extension = "
380 << filename_ext << std::endl);
394 std::ifstream pFile(filename);
395 return pFile.peek() == std::ifstream::traits_type::eof();
405 return pFile.peek() == std::ifstream::traits_type::eof();
Collects a message with stream syntax for use in an exception.
Msg & operator<<(std::ostream &(*manip)(std::ostream &))
Appends a stream manipulator such as std::endl.
std::ostringstream d_oss
Message under construction.
Msg & operator<<(const T &v)
Appends a value to the message.
std::string str() const
The message built so far.
bool logEnabled(int priority, bool check_condition=true, int override_priority=-1)
True if a message at this priority would be logged (uses LoggerDeck::d_debugLevel)
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
std::string getTabS(int nt)
Returns tab spaces of a given size.
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
const int print_default_tab
Default value of tab used in outputting formatted information.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
const int logger_default_debug_lvl
Default debug level for logger.
std::string getExtensionFromFile(std::string const &filename)
Get extension from the filename.
void initLogger(int debug_level=logger_default_debug_lvl, std::string filename="")
Initializes the logger.
bool isFileEmpty(std::string filename)
Check if file is empty or null.
std::string checkAndCreateNewFilename(std::string const &filename, std::string filename_ext)
Check for extension and if possible create new filename from a given filename and a given extension.
void printBox(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted string for output.
std::string removeExtensionFromFile(std::string const &filename)
Remove extension from the filename Source - https://stackoverflow.com/a/24386991.
void log(std::ostringstream &oss, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
Global method to log the message.
const int print_default_mpi_rank
Default mpi rank in printing information.
std::string getFilenameFromPath(std::string const &path, std::string const &delims="/\\")
Get filename removing path from the string Source - https://stackoverflow.com/a/24386991.
int mpiRank()
get rank (id) of this processor
Collection of methods useful in simulation.