Pixie16 Analysis Software Suite
Analysis code for processing of .ldf files
Messenger.hpp
Go to the documentation of this file.
1 
6 #ifndef MESSENGER_HPP
7 #define MESSENGER_HPP
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <fstream>
12 #include <string>
13 #include <sstream>
14 #include <vector>
15 
16 #include "Exceptions.hpp"
17 
19 class Messenger {
20  public:
22  Messenger () {
23  file_ = false;
24  out_ = &std::cout;
25  }
26 
29  Messenger (const std::string& name) {
30  file_ = true;
31  fout_.open(name.c_str());
32  if (!fout_.good()) {
33  std::string msg =
34  "Messenger::Messenger: Could not open file " + name;
35  throw IOException(msg);
36  }
37  out_ = &fout_;
38  }
39 
42  void start(std::string msg) {
43  if (!endline_)
44  *out_ << std::endl;
45 
46  *out_ << std::setfill('.') << std::setw(66)
47  << std::left << msg;
48  endline_ = false;
49  }
50 
56  void detail(std::string msg, short level = 0, std::string symbol = "*");
57 
61  void warning(std::string msg, short level = 0);
62 
65  void run_message(std::string msg);
66 
68  void done() {
69  *out_ << std::setfill(' ');
70  if (endline_) {
71  *out_ << std::right << std::setw(72);
72  }
73  *out_ << "[Done]" << std::endl;
74  endline_ = true;
75  }
76 
78  void fail() {
79  *out_ << std::setfill(' ');
80  if (endline_) {
81  *out_ << std::right << std::setw(72);
82  }
83  *out_ << "[FAIL]" << std::endl;
84  endline_ = true;
85  }
86 
89  if (file_)
90  fout_.close();
91  }
92 
93  private:
94  std::ostream* out_;
95  std::ofstream fout_;
96  bool file_;
97  static bool endline_;
98 };
99 #endif
void fail()
Definition: Messenger.hpp:78
void start(std::string msg)
Definition: Messenger.hpp:42
bool file_
true if the file is opened
Definition: Messenger.hpp:96
Class to handle errors occurring during the execution of the code.
Messenger(const std::string &name)
Definition: Messenger.hpp:29
void run_message(std::string msg)
Messenger()
Definition: Messenger.hpp:22
~Messenger()
Definition: Messenger.hpp:88
std::ofstream fout_
the output file stream
Definition: Messenger.hpp:95
Read/write exception for all file operation related tasks.
Definition: Exceptions.hpp:68
void done()
Definition: Messenger.hpp:68
static bool endline_
true if we have an endline
Definition: Messenger.hpp:97
This class outputs nicely formatted messages during configuration loading.
Definition: Messenger.hpp:19
void detail(std::string msg, short level=0, std::string symbol="*")
void warning(std::string msg, short level=0)
std::ostream * out_
the output stream
Definition: Messenger.hpp:94