SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
DriverException.h
1 
26 #pragma once
27 
28 #include <vector>
29 #include <iostream>
30 #include <exception>
31 #include <stdexcept>
32 #include <sstream>
33 #include <iomanip>
34 #include <unistd.h>
35 
36 namespace SSAGES
37 {
39  class BuildException : public std::runtime_error
40  {
41  private:
42  std::vector<std::string> errors_;
43  public:
45 
48  BuildException(std::vector<std::string> errors) :
49  std::runtime_error("Object build error"), errors_(errors)
50  {
51  }
52 
54 
57  virtual const char* what() const throw()
58  {
59  std::ostringstream msg("");
60 
61  msg << runtime_error::what() << ": "
62  << "See errors for details.";
63 
64  return msg.str().c_str();
65  }
66 
68 
71  std::vector<std::string> GetErrors()
72  {
73  return errors_;
74  }
75  };
76 
78 
82  inline void PrintBoldNotice(const std::string& notice, int msgw)
83  {
84  if(isatty(fileno(stdout)))
85  {
86  std::cout << std::setw(msgw + 8) << std::left << "\033[1m" + notice + "\033[0m";
87  }
88  else
89  {
90  std::cout << std::setw(msgw + 8) << std::left << notice;
91  }
92  }
93 
95 
102  inline int DumpErrorsToConsole(const std::vector<std::string>& msgs, int notw)
103  {
104  if(isatty(fileno(stdout)))
105  {
106  std::cout << std::setw(notw) << std::right << "\033[1;31mError(s)! See below.\033[0m\n";
107  }
108  else
109  {
110  std::cout << std::setw(notw) << std::right << "Error(s)! See below.\n";
111  }
112  for(auto& msg : msgs)
113  std::cout << " * " << msg << "\n";
114  return -1;
115  }
116 
118 
123  inline void DumpNoticesToConsole(const std::vector<std::string>& msgs, std::string prefix, int notw)
124  {
125  if(isatty(fileno(stdout)))
126  {
127  std::cout << std::setw(notw) << std::right << "\033[32mOK!\033[0m\n";
128  }
129  else
130  {
131  std::cout << std::setw(notw) << std::right << "OK!\n";
132  }
133  if(msgs.size() == 0)
134  return;
135 
136  for(auto& msg : msgs)
137  std::cout << prefix << " * " << msg << "\n";
138  }
139 }
std::vector< std::string > errors_
Error message.
BuildException(std::vector< std::string > errors)
Constructor.
STL namespace.
Exception to be thrown when building the Driver fails.
std::vector< std::string > GetErrors()
Get specific error message.
int DumpErrorsToConsole(const std::vector< std::string > &msgs, int notw)
Print a list of errors.
void DumpNoticesToConsole(const std::vector< std::string > &msgs, std::string prefix, int notw)
Print a list of notices.
virtual const char * what() const
Get generic error message.
void PrintBoldNotice(const std::string &notice, int msgw)
Print out Notice in bold text.