Bembel
 
Loading...
Searching...
No Matches
Logger.hpp
1// This file is part of Bembel, the higher order C++ boundary element library.
2//
3// Copyright (C) 2022 see <http://www.bembel.eu>
4//
5// It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz,
6// M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt,
7// Universitaet Basel, and Universita della Svizzera italiana, Lugano. This
8// source code is subject to the GNU General Public License version 3 and
9// provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further
10// information.
11#ifndef BEMBEL_SRC_IO_LOGGER_HPP_
12#define BEMBEL_SRC_IO_LOGGER_HPP_
13
14namespace Bembel {
15namespace IO {
16
28template <int N = 10>
29class Logger {
30 std::string _sep = " ";
31 std::fstream _file;
32 std::ios_base::openmode _mode = std::fstream::trunc;
33 std::string name_ = "default.log";
34
35 public:
36 Logger() {}
37 explicit Logger(std::string name) { name_ = name; }
38 Logger(std::string name, std::string sep) {
39 name_ = name;
40 _sep = sep;
41 }
42 Logger(std::string name, std::string sep, std::ios_base::openmode mode) {
43 name_ = name;
44 _sep = sep;
45 _mode = mode;
46 }
47 Logger(std::string name, std::ios_base::openmode mode) {
48 name_ = name;
49 _mode = mode;
50 }
51 explicit Logger(std::ios_base::openmode mode) { _mode = mode; }
52 template <typename T, typename... Args>
53 void term(T t, Args... arg) {
54 std::cout << std::setprecision(N - 4) << std::setw(N + _sep.size())
55 << std::left << t << _sep;
56 term(arg...);
57 }
58 template <typename T>
59 void term(T t) {
60 std::cout << std::setprecision(N - 4) << std::setw(N + _sep.size()) << t
61 << std::endl;
62 }
63 template <typename T, typename... Args>
64 void file(T t, Args... arg) {
65 if (!(_file.is_open())) {
66 _file.open(name_, std::fstream::out | std::fstream::trunc);
67 }
68 _file << std::setprecision(N - 4) << std::setw(N + _sep.size()) << std::left
69 << t << _sep;
70 file(arg...);
71 }
72 template <typename T>
73 void file(T t) {
74 if (!(_file.is_open())) {
75 _file.open(name_, std::fstream::out | std::fstream::trunc);
76 }
77 std::setprecision(N);
78 _file << std::setprecision(N - 4) << std::setw(N + _sep.size()) << std::left
79 << t << std::endl;
80 }
81 template <typename... Args>
82 void both(Args... arg) {
83 file(arg...);
84 term(arg...);
85 }
86 ~Logger() { _file.close(); }
87};
88} // namespace IO
89} // namespace Bembel
90#endif // BEMBEL_SRC_IO_LOGGER_HPP_
A simple class for producing output.
Definition Logger.hpp:29
Routines for the evalutation of pointwise errors.
constexpr int getFunctionSpaceOutputDimension()