DATRW++ library: seismic data I/O with multiple formats
report.cc
Go to the documentation of this file.
1 /*! \file report.cc
2  * \brief report errors and warnings (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 08/07/2016
8  *
9  * report errors and warnings (implementation)
10  *
11  * Copyright (c) 2016 by Thomas Forbriger (BFO Schiltach)
12  *
13  *
14  * ----
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 
28  * ----
29  *
30  * REVISIONS and CHANGES
31  * - 08/07/2016 V1.0 Thomas Forbriger
32  *
33  * ============================================================================
34  */
35 #define DATRW_REPORT_CC_VERSION \
36  "DATRW_REPORT_CC V1.0"
37 
38 #include <datrwxx/report.h>
39 #include <iostream>
40 #include <datrwxx/error.h>
41 #include <datrwxx/aalibdatrwxx.h>
42 #include <datrwxx/util.h>
43 
44 using std::cerr;
45 using std::endl;
46 
47 namespace datrw {
48 
49  namespace util {
50 
51  //! report violation of assertion
52  void report_violation(const Ereport& t,
53  const std::string& message,
54  const std::string& file,
55  const int& line,
56  const std::string& condition)
57  {
58  if (t==Fnonfatal)
59  {
60  cerr << "ERROR (non-fatal)";
61  }
62  else if (t==Fwarning)
63  {
64  cerr << "WARNING";
65  }
66  else
67  {
68  cerr << "ERROR";
69  }
70 
71  cerr << " reported by " << datrw::libversion << "!" << endl;
72  cerr << "| A problem occured while "
73  "reading or writing time series data" << endl;
74  if (!condition.empty())
75  {
76  cerr << "| the following condition is violated:" << endl
77  << "| \"" << condition << "\"" << endl;
78  }
79  if (!file.empty())
80  {
81  cerr << "| in \"" << file << "\" at line #" << line << endl;
82  }
83  if (message.empty())
84  {
85  cerr << "| no further comment is provided." << endl;
86  }
87  else
88  {
89  const std::string delimiter("\n");
90  std::string::size_type posend=0, pos=0;
91  std::string::size_type len=0;
92  while (posend!=std::string::npos)
93  {
94  posend=message.find(delimiter, pos);
95  len=posend-pos;
96  cerr << "* ";
97  cerr << message.substr(pos, len) << endl;
98  if (posend!=std::string::npos) { len+=delimiter.length(); }
99  pos+=len;
100  } // while (posend!=std::string::npos)
101  } // if (message.empty())
102  if (t==Ffatal)
103  {
104  cerr << "This error is fatal. The program probably will abort..."
105  << endl;
106  }
107  cerr.flush();
108  } // void report_violation(...)
109 
110  /*----------------------------------------------------------------------*/
111 
112  //! report deprecated function
113  void report_deprecated(const std::string& function,
114  const std::string& reason)
115  {
116  cerr << "WARNING: program uses deprecated function" << endl;
117  cerr << " \"" << function << "\"" << endl;
118  cerr << " from " << datrw::libversion << endl;
119  cerr << " This function should no longer be used because\n"
120  << " " << reason << endl;
121  cerr << " Please report this issue at "
122  "http://git.scc.kit.edu/Seitosh/Seitosh"
123  << endl;
124  }
125 
126  } // namespce util
127 
128 } // namespace datrw
129 
130 /* ----- END OF report.cc ----- */
void report_deprecated(const std::string &function, const std::string &reason)
report deprecated function
Definition: report.cc:113
a fatal error; processing wil abort as a consequence
Definition: report.h:58
Ereport
report categories
Definition: report.h:52
libdatrwxx version string (prototypes)
exception class declaration for libdatrwxx (prototypes)
just a warning; processing can proceeed
Definition: report.h:54
const char *const libversion
Version string.
Definition: aalibdatrwxx.cc:18
Root namespace of library.
Definition: aalibdatrwxx.cc:16
utilities used by more than one type of data reader (prototypes)
an error, but non-fatal; processing will proceed
Definition: report.h:56
void report_violation(const Ereport &t, const std::string &message, const std::string &file, const int &line, const std::string &condition)
report violation of assertion
Definition: report.cc:52
report errors and warnings (prototypes)