ABLATE Source Documentation  0.12.33
log.hpp
1 #ifndef ABLATELIBRARY_LOG_HPP
2 #define ABLATELIBRARY_LOG_HPP
3 
4 #include <petsc.h>
5 #include <memory>
6 #include <ostream>
7 #include <vector>
8 
9 namespace ablate::monitors::logs {
10 class Log {
11  private:
12  bool initialized = false;
13 
17  class DefaultOutBuffer : public std::streambuf {
18  private:
19  Log& log;
20 
21  protected:
22  int_type overflow(int_type c) override {
23  if (c != EOF) {
24  log.Printf("%c", static_cast<char>(c));
25  }
26  return c;
27  }
28 
29  public:
30  DefaultOutBuffer(Log& log) : log(log) {}
31  };
32 
33  // store pointer for an ostream
34  std::unique_ptr<std::ostream> ostream;
35 
36  // store the pointer for a stream buffer
37  std::unique_ptr<DefaultOutBuffer> ostreambuf;
38 
39  public:
40  virtual ~Log();
41 
42  // each log must support the print command
43  virtual void Printf(const char*, ...) = 0;
44  virtual void Print(const char* value) { Printf(value); }
45  virtual void Print(const char* name, std::size_t num, const double*, const char* format = nullptr);
46  virtual void Initialize(MPI_Comm comm = MPI_COMM_SELF) { initialized = true; }
47 
48  // built in support calls
49  void Print(const char* name, const std::vector<double>& values, const char* format = nullptr);
50 
51  // determine if the log has been initialized
52  inline const bool& Initialized() const { return initialized; }
53 
58  virtual std::ostream& GetStream();
59 };
60 } // namespace ablate::monitors::logs
61 
62 #endif // ABLATELIBRARY_LOG_HPP
Definition: log.hpp:10
virtual std::ostream & GetStream()
Definition: log.cpp:35