TF++, Miscellaneous classes and modules in C++:
error.cc
Go to the documentation of this file.
1 
36 #define TF_ERROR_CC_VERSION \
37  "TF_ERROR_CC V1.1"
38 
39 #include <iostream>
40 #include <tfxx/error.h>
41 
42 using std::cerr;
43 using std::endl;
44 
45 namespace tfxx {
46 namespace error {
47 
50  std::stack<bool> Exception::Mprevious_report_state;
51 
54  Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
55  { if (this->report_on_construct_is_true()) { base_report(); } }
56 
58  Exception::Exception(const char* message):
59  Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
60  { if (this->report_on_construct_is_true()) { base_report(); } }
61 
63  Exception::Exception(const char* message,
64  const char* condition):
65  Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
66  { if (this->report_on_construct_is_true()) { base_report(); } }
67 
69  Exception::Exception(const char* message,
70  const char* file,
71  const int& line):
72  Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
73  { if (this->report_on_construct_is_true()) { base_report(); } }
74 
76  Exception::Exception(const char* message,
77  const char* file,
78  const int& line,
79  const char* condition):
80  Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
81  { if (this->report_on_construct_is_true()) { base_report(); } }
82 
85  {
88  }
89 
92  {
95  }
96 
99  {
100  if (!Mprevious_report_state.empty())
101  {
104  }
105  }
106 
108  void Exception::report() const
109  {
110  base_report();
111  }
112 
115  {
116  std::cout.flush();
117  cerr << "Exception report:" << endl;
118  if (Mmessage==NULL)
119  {
120  cerr << " No message" << endl;
121  }
122  else
123  {
124  cerr << " message: " << Mmessage << endl;
125  }
126  if (Mfile!=NULL)
127  {
128  cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
129  }
130  if (Mcondition!=NULL)
131  {
132  cerr << " by test condition:" << endl
133  << " \"" << Mcondition << "\"" << endl;
134  }
135  cerr.flush();
136  }
137 
138  /*----------------------------------------------------------------------*/
139 
141  void report_violation(const char* message,
142  const char* file,
143  const int& line,
144  const char* condition)
145  {
146  std::cerr << std::endl;
147  std::cerr << "VIOLATION of condition: " << condition << std::endl;
148  std::cerr << "* in " << file << " at line " << line << std::endl;
149  std::cerr << "* message: " << message << std::endl;
150  }
151 
152  /*----------------------------------------------------------------------*/
153 
155  void report_deprecated(const char* function,
156  const char* reason)
157  {
158  std::cerr << "WARNING: program uses deprecated function in libtfxx\n"
159  << "* " << function << std::endl;
160  std::cerr << "* This function should no longer be used because\n"
161  << "* " << reason << std::endl;
162  std::cerr << "* Please place a ticket at "
163  "http://git.scc.kit.edu:Seitosh/Seitosh"
164  << std::endl;
165  }
166 
167 } // namespace error
168 } // namespace tfxx
169 
170 /* ----- END OF error.cc ----- */
static void restore_report_state()
Restore previous report state.
Definition: error.cc:98
void report_deprecated(const char *function, const char *reason)
report deprecated function
Definition: error.cc:155
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:91
bool report_on_construct_is_true() const
Definition: error.h:108
static bool Mreport_on_construct
Shall we print to cerr at construction time?
Definition: error.h:114
const char * Mfile
pointer to file name string
Definition: error.h:118
int Mline
pointer to line number in source file
Definition: error.h:120
static std::stack< bool > Mprevious_report_state
a place to store previous report state
Definition: error.h:124
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: error.cc:84
const char * Mcondition
pointer to assertion condition text string
Definition: error.h:122
const char * Mmessage
pointer to message string
Definition: error.h:116
virtual void report() const
Screen report.
Definition: error.cc:108
Exception()
Creates exception with no explaning comments.
Definition: error.cc:53
void report_violation(const char *message, const char *file, const int &line, const char *condition)
report violation of assertion
Definition: error.cc:141
Namespace containing all code of library libtfxx.
void base_report() const
Screen report.
Definition: error.cc:114