SSAGES  0.9.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 #include <string.h>
36 
37 namespace SSAGES
38 {
40  class BuildException : public std::runtime_error
41  {
42  private:
43  std::vector<std::string> errors_;
44  public:
46 
49  BuildException(std::vector<std::string> errors) :
50  std::runtime_error("Object build error"), errors_(errors)
51  {
52  }
53 
55 
58  virtual const char* what() const throw()
59  {
60  std::ostringstream msg("");
61 
62  msg << runtime_error::what() << ": "
63  << "See errors for details.";
64 
65  return strdup(msg.str().c_str());
66  }
67 
69 
72  std::vector<std::string> GetErrors()
73  {
74  return errors_;
75  }
76  };
77 
79 
83  inline void PrintBoldNotice(const std::string& notice, int msgw)
84  {
85  if(isatty(fileno(stdout)))
86  {
87  std::cout << std::setw(msgw + 8) << std::left << "\033[1m" + notice + "\033[0m";
88  }
89  else
90  {
91  std::cout << std::setw(msgw + 8) << std::left << notice;
92  }
93  }
94 
96 
103  inline int DumpErrorsToConsole(const std::vector<std::string>& msgs, int notw)
104  {
105  if(isatty(fileno(stdout)))
106  {
107  std::cout << std::setw(notw) << std::right << "\033[1;31mError(s)! See below.\033[0m\n";
108  }
109  else
110  {
111  std::cout << std::setw(notw) << std::right << "Error(s)! See below.\n";
112  }
113  for(auto& msg : msgs)
114  std::cout << " * " << msg << "\n";
115  return -1;
116  }
117 
119 
124  inline void DumpNoticesToConsole(const std::vector<std::string>& msgs, std::string prefix, int notw)
125  {
126  if(isatty(fileno(stdout)))
127  {
128  std::cout << std::setw(notw) << std::right << "\033[32mOK!\033[0m\n";
129  }
130  else
131  {
132  std::cout << std::setw(notw) << std::right << "OK!\n";
133  }
134  if(msgs.size() == 0)
135  return;
136 
137  for(auto& msg : msgs)
138  std::cout << prefix << " * " << msg << "\n";
139  }
140 }
Exception to be thrown when building the Driver fails.
std::vector< std::string > GetErrors()
Get specific error message.
std::vector< std::string > errors_
Error message.
virtual const char * what() const
Get generic error message.
BuildException(std::vector< std::string > errors)
Constructor.
void PrintBoldNotice(const std::string &notice, int msgw)
Print out Notice in bold text.
void DumpNoticesToConsole(const std::vector< std::string > &msgs, std::string prefix, int notw)
Print a list of notices.
int DumpErrorsToConsole(const std::vector< std::string > &msgs, int notw)
Print a list of errors.