SSAGES  0.1
A MetaDynamics Package
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 
35 namespace SSAGES
36 {
38  class BuildException : public std::runtime_error
39  {
40  private:
41  std::vector<std::string> errors_;
42  public:
44 
47  BuildException(std::vector<std::string> errors) :
48  std::runtime_error("Object build error"), errors_(errors)
49  {
50  }
51 
53 
56  virtual const char* what() const throw()
57  {
58  std::ostringstream msg("");
59 
60  msg << runtime_error::what() << ": "
61  << "See errors for details.";
62 
63  return msg.str().c_str();
64  }
65 
67 
70  std::vector<std::string> GetErrors()
71  {
72  return errors_;
73  }
74  };
75 
77 
81  inline void PrintBoldNotice(const std::string& notice, int msgw)
82  {
83  std::cout << std::setw(msgw + 8) << std::left << "\033[1m" + notice + "\033[0m";
84  }
85 
87 
94  inline int DumpErrorsToConsole(const std::vector<std::string>& msgs, int notw)
95  {
96  std::cout << std::setw(notw) << std::right << "\033[1;31mError(s)! See below.\033[0m\n";
97  for(auto& msg : msgs)
98  std::cout << " * " << msg << "\n";
99  return -1;
100  }
101 
103 
108  inline void DumpNoticesToConsole(const std::vector<std::string>& msgs, std::string prefix, int notw)
109  {
110  std::cout << std::setw(notw) << std::right << "\033[32mOK!\033[0m\n";
111  if(msgs.size() == 0)
112  return;
113 
114  for(auto& msg : msgs)
115  std::cout << prefix << " * " << msg << "\n";
116  }
117 }
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.
void PrintBoldNotice(const std::string &notice, int msgw)
Print out Notice in bold text.
virtual const char * what() const
Get generic error message.