Commit ae04d551 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libdatrwxx [WP][API]: make use of new multi-line feature

Multiline messages can be passed to the reporting functions and exceptions.
Asserting and warning macros are adjusted accordingly. The locations where
they are used are similarly adjusted.

We no longer distinguish between reports which output only a single-line
message (argument M to macros) and such reports, which use output operators to
report additional values (argument V to macros). The string passed by M now
may contain newline characters as well as argument M may contain an expression
which makes use of stream output operators to print values of variables.
parent 2276eecc
......@@ -28,15 +28,18 @@
*
*
* REVISIONS and CHANGES
* - 18/10/2011 V1.0 Thomas Forbriger
* - 18/10/2011 V1.0 Thomas Forbriger (thof)
* - 12/06/2012 V1.1 settraceheader must not be called before actual
* number of samples ist set
* correction in skipseries()
* - 08/07/2016 V1.2 thof:
* - make correct use of new DATRW_report_assert
* - make correct use of new DATRW_nonfatal_assert
*
* ============================================================================
*/
#define DATRW_IASCIISTREAM_CC_VERSION \
"DATRW_IASCIISTREAM_CC V1.0 "
"DATRW_IASCIISTREAM_CC V1.2"
#include<iomanip>
#include<vector>
......@@ -255,7 +258,7 @@ namespace datrw {
if (key.length()==0)
{
DATRW_report_assert(key.length()>0,
"keyword is missing in header line",
"keyword is missing in header line\n" <<
"input line: " << Mcurrentline << "\n" <<
"key: " << key);
}
......@@ -268,7 +271,7 @@ namespace datrw {
// was not recognoized
DATRW_nonfatal_assert(Mnonfatal,
false,
"iasciistream: header key not recognized",
"iasciistream: header key not recognized\n"
"input line: " << Mcurrentline << "\n" <<
"key: " << key);
}
......@@ -378,7 +381,7 @@ namespace datrw {
DATRW_nonfatal_assert(nonfatal,
(i==n),
"readsamples (ASCII): "
"found less samples than expected",
"found less samples than expected\n"
"expected: " << n << " " <<
"found: " << i);
}
......
......@@ -31,11 +31,12 @@
* - 11/04/2006 V1.0 Thomas Forbriger
* - 01/04/2011 V1.1 do not clear Mhassrce upon writing the file header
* - 07/06/2011 V1.2 promise constness of series samples
* - 08/07/2016 V1.3 make correct use of new DATRW_report_assert
*
* ============================================================================
*/
#define DATRW_DATWRITE_CC_VERSION \
"DATRW_DATWRITE_CC V1.2"
"DATRW_DATWRITE_CC V1.3"
#include<fstream>
#include <datrwxx/datwrite.h>
......@@ -103,11 +104,11 @@ namespace datrw {
if (Mheaderflushed)
{
DATRW_report_assert(this->handlestracefree(),
"file format cannot handle trace FREE data",
"file format cannot handle trace FREE data\n" <<
"FREE data will be dropped silently");
} else {
DATRW_report_assert(this->handlesfilefree(),
"file format cannot handle file FREE data",
"file format cannot handle file FREE data\n" <<
"FREE data will be dropped silently");
}
Mfreeset=true;
......@@ -128,7 +129,7 @@ namespace datrw {
void odatstream::setinfo(const sff::INFO& info)
{
DATRW_report_assert(this->handlesinfo(),
"file format cannot handle INFO data",
"file format cannot handle INFO data\n"
"INFO data will be dropped silently");
Minfoset=true;
Minfo=info;
......@@ -139,7 +140,7 @@ namespace datrw {
void odatstream::setsrce(const sff::SRCE& srce)
{
DATRW_report_assert(this->handlessrce(),
"file format cannot handle SRCE data",
"file format cannot handle SRCE data\n"
"SRCE data will be dropped silently");
Msrceset=true;
Msrce=srce;
......
......@@ -36,8 +36,10 @@
* - 05/07/2016 V1.5 thof: operate with string containers rather than
* with pointer to character arrays
* - 07/07/2016 V1.6 thof: move class exception to separate header
* - 08/07/2016 V1.7 thof: move report functions to separate compilation
* unit
* - 08/07/2016 V1.7 thof:
* - move report functions to separate compilation unit
* - create multiline messages
* - remove specific multiline macros
*
* ============================================================================
*/
......@@ -46,9 +48,10 @@
#ifndef DATRW_ERROR_H_VERSION
#define DATRW_ERROR_H_VERSION \
"DATRW_ERROR_H V1.7"
"DATRW_ERROR_H V1.8"
#include <iostream>
#include <sstream>
#include <datrwxx/report.h>
#include <datrwxx/exception.h>
......@@ -64,28 +67,17 @@
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param M message (may use output operators;
* possibly containing newline characters)
* \param E exception class to throw
*/
#define DATRW_Xassert(C,M,E) \
if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
/*! \brief Check an assertion and report by throwing an exception.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
* \param E exception class to throw
*/
#define DATRW_XRassert(C,M,V,E) \
if (!(C)) { \
std::cerr << std::endl; \
std::cerr << "* violation of " << #C << std::endl; \
std::cerr << "* comment: " << V << std::endl; \
std::cerr.flush(); \
throw( E ( M , __FILE__, __LINE__, #C )); \
{ \
std::ostringstream oss; \
oss << M; \
throw( E ( oss.str() , __FILE__, __LINE__, #C )); \
} \
}
/*! \brief Check an assertion and report by throwing an exception.
......@@ -96,16 +88,6 @@
*/
#define DATRW_assert(C,M) DATRW_Xassert( C , M , datrw::Exception )
/*! \brief Check an assertion and report by throwing an exception.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define DATRW_Rassert(C,M,V) DATRW_XRassert( C , M , V , datrw::Exception )
/*! \brief Abort and give a message.
*
* \ingroup group_error
......@@ -122,17 +104,17 @@
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
* \param M message (may use output operators;
* possibly containing newline characters)
*/
#define DATRW_report_assert(C,M,V) \
#define DATRW_report_assert(C,M) \
if (!(C)) { \
datrw::util::report_violation(datrw::util::Fnonfatal, \
M, __FILE__, __LINE__, #C); \
std::cerr << "* comment: " << V << std::endl; \
std::cerr << std::endl; \
std::cerr.flush(); \
{ \
std::ostringstream oss; \
oss << M; \
datrw::util::report_violation(datrw::util::Fnonfatal, \
oss.str(), __FILE__, __LINE__, #C); \
} \
}
/*! \brief Macro to distinguish between fatal and non fatal assertions.
......@@ -140,25 +122,26 @@
* \ingroup group_error
* \param F true for non fatal behaviour
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
* \param M message (may use output operators;
* possibly containing newline characters)
*/
#define DATRW_nonfatal_assert(F,C,M,V) \
if (F) { DATRW_report_assert(C,M,V) } else { DATRW_Rassert(C,M,V) }
#define DATRW_nonfatal_assert(F,C,M) \
if (F) { DATRW_report_assert(C,M) } else { DATRW_assert(C,M) }
/*! \brief Report a warning.
*
* \ingroup group_error
* \param N name of function
* \param M any values that should be output (comment)
* a sequence of values and output operators
* \param M message (may use output operators;
* possibly containing newline characters)
*/
#define DATRW_warning(N,M) \
std::cerr << "WARNING (" << N << ", " \
<< __FILE__ << " line #" << __LINE__ << "):" << std::endl \
<< " " << M << std::endl; \
std::cerr.flush();
{ \
std::ostringstream oss; \
oss << "in function " << N << "\n" << M; \
datrw::util::report_violation(datrw::util::Fwarning, \
oss.str(), __FILE__, __LINE__, ""); \
}
#endif // DATRW_ERROR_H_VERSION (includeguard)
......
......@@ -32,6 +32,7 @@
* - 21/01/2012 V1.1 provide online help output support class
* - 05/07/2016 V1.2 thof: provide output operator for line indentation
* with modifier help
* - 08/07/2016 V1.3 make correct use of new DATRW_report_assert
*
* ============================================================================
*/
......@@ -40,7 +41,7 @@
#ifndef DATRW_FORMATMODIFIER_H_VERSION
#define DATRW_FORMATMODIFIER_H_VERSION \
"DATRW_FORMATMODIFIER_H V1.2"
"DATRW_FORMATMODIFIER_H V1.3"
#include <string>
#include <sstream>
......@@ -61,7 +62,7 @@
*/
#define DATRW_expect_no_modifier(F,M) \
DATRW_report_assert(M.length()<1, \
"no format modifier should be passed!", \
"no format modifier should be passed!\n" << \
"format " << anyID( F ) \
<< " is not expected to handle format modifiers\n" \
<< "any modifiers are silently ignored!");
......
......@@ -37,11 +37,13 @@
* V1.2 thof
* - disable check for number of frames, if number of
* frames is guessed
* - 08/07/2016 V1.3 thof:
* - make correct use of new DATRW_nonfatal_assert
*
* ============================================================================
*/
#define DATRW_MSEEDREAD_MSEEDRECORD_READ_CC_VERSION \
"DATRW_MSEEDREAD_MSEEDRECORD_READ_CC V1.2"
"DATRW_MSEEDREAD_MSEEDRECORD_READ_CC V1.3"
#include <string>
#include <cstring>
......@@ -240,7 +242,7 @@ namespace datrw {
|| (!Mchecks.nsamples.fatal),
(isample==nsamples),
"ERROR (reading MiniSEED record): "
"missing samples",
"missing samples\n"
"isample=" << isample << " nsamples=" <<
nsamples);
}
......@@ -266,7 +268,7 @@ namespace datrw {
|| (!Mchecks.data.fatal),
(Mdata(isample-1)==xn),
"ERROR (reading MiniSEED record): "
"data is corrupt",
"data is corrupt\n"
"Mdata(isample-1)=" << Mdata(isample-1)
<< " xn=" << xn
<< " isample=" << isample);
......@@ -289,7 +291,7 @@ namespace datrw {
|| (!Mchecks.nframes.fatal),
(iframe==nframes),
"ERROR (reading MiniSEED record): "
"inconsistent frame count",
"inconsistent frame count\n"
"number of frames (" << iframe << ") " <<
"differs from expected number ("
<< nframes << ")");
......
......@@ -86,6 +86,7 @@ namespace datrw {
pos+=len;
} // while (posend!=std::string::npos)
} // if (message.empty())
cerr.flush();
} // void report_violation(...)
/*----------------------------------------------------------------------*/
......
......@@ -28,11 +28,12 @@
*
* REVISIONS and CHANGES
* - 30/11/2010 V1.0 Thomas Forbriger
* - 08/07/2016 V1.1 make correct use of new DATRW_report_assert
*
* ============================================================================
*/
#define DATRW_OSEIFESTREAM_CC_VERSION \
"DATRW_OSEIFESTREAM_CC V1.0 "
"DATRW_OSEIFESTREAM_CC V1.1"
#include <datrwxx/seife.h>
#include <datrwxx/seifeio.h>
......@@ -93,7 +94,7 @@ namespace datrw {
void oseifestream::writetraceheader(const unsigned int& n)
{
DATRW_report_assert(!this->Mtracewritten,
"WARNING in (oseifestream::writetraceheader):",
"WARNING in (oseifestream::writetraceheader):\n"
"More than one trace will be written to the same "
"seife file!\n"
"seife format only supports single trace files.\n");
......
......@@ -58,11 +58,12 @@
* - 26/01/2012 V1.5 bug fix: ScalCoo::set(const double&):
* initial scale value must equal one
* see ticket:168
* - 08/07/2016 V1.6 make correct use of new DATRW_report_assert
*
* ============================================================================
*/
#define DATRW_SUCOMANAGER_CC_VERSION \
"DATRW_SUCOMANAGER_CC V1.5"
"DATRW_SUCOMANAGER_CC V1.6"
#include <cmath>
#include <climits>
......@@ -189,7 +190,7 @@ namespace datrw {
<< " truncationerror: " << truncationerror);
DATRW_report_assert(truncationerror<0.001,
"WARNING (ScalCoo::set) "
"truncation error > 0.1%",
"truncation error > 0.1%\n"
"coordinate value "
<< helper::MyOutputFormat() << value
<< " will be truncated!"
......@@ -251,7 +252,7 @@ namespace datrw {
}
DATRW_report_assert(vcmp==this->coo,
"WARNING ScalCoo::scaletopower will truncate "
"coordinate value",
"coordinate value\n"
"value was "
<< helper::MyOutputFormat() << this->coo <<
" value will be " << vcmp);
......@@ -501,7 +502,7 @@ namespace datrw {
* set to 0, we have to deal with this value
*/
DATRW_report_assert(s != 0,
"WARNING (ScalCoo::set): incorrect scale",
"WARNING (ScalCoo::set): incorrect scale\n"
"value: " << s << "; will be set to 1");
DATRW_assert(!((strict) && (s==0)),
"Violation of SeismicUn*x format definition!");
......@@ -519,7 +520,7 @@ namespace datrw {
* being larger than 1 and smaller than 10
*/
DATRW_report_assert(((sabs < 10) && (s != 1)),
"WARNING (ScalCoo::set): non-standard scale",
"WARNING (ScalCoo::set): non-standard scale\n"
"value: " << s);
DATRW_assert(!strict,
"Violation of SeismicUn*x format definition!");
......
......@@ -32,8 +32,10 @@
* - 22/01/2012 V1.2
* - indicate ultrasonic data
* - renamed absdelay -> absdelrt
* - 23/01/2012 V1.2
* - 23/01/2012 V1.3
* - added member data Mdt and some comments
* - 08/07/2016 V1.4
* - make exception argument types match base class
*
* ============================================================================
*/
......@@ -42,7 +44,7 @@
#ifndef DATRW_SUHEADER_H_VERSION
#define DATRW_SUHEADER_H_VERSION \
"DATRW_SUHEADER_H V1.3"
"DATRW_SUHEADER_H V1.4"
#include<iostream>
#include<datrwxx/suformat.h>
......@@ -104,10 +106,10 @@ namespace datrw {
{
public:
//! Create with message, failed assertion, and code position
SUReadException(const char* message,
const char* file,
SUReadException(const std::string message,
const std::string file,
const int& line,
const char* condition)
const std::string condition)
: ::datrw::Exception(message, file, line, condition) { }
//! provide explicit virtual destructor
virtual ~SUReadException() { }
......
......@@ -43,6 +43,9 @@
* now suppresses a notice-message which otherwise
* would be output to the terminal in cases of
* duplicate time stamps
* - 08/07/2016 V1.4 thof:
* - make correct use of new DATRW_report_assert
* - make correct use of new DATRW_nonfatal_assert
*
* ============================================================================
* A statement of Volker König at ThiesClima regarding the duplicate entries
......@@ -58,7 +61,7 @@
* ============================================================================
*/
#define DATRW_THIESDL1FILE_CC_VERSION \
"DATRW_THIESDL1FILE_CC V1.3"
"DATRW_THIESDL1FILE_CC V1.4"
#include <datrwxx/thiesdl1file.h>
#include <datrwxx/thiesdl1line.h>
......@@ -184,7 +187,7 @@ namespace datrw {
found.creation,
"ERROR: could not extract full header data");
DATRW_report_assert(line == retval.expectedinitialdataline,
"initial data line is not matsching",
"initial data line is not matsching"
"\n expected: "
<< retval.expectedinitialdataline <<
"\n found: "
......@@ -246,7 +249,7 @@ namespace datrw {
Mheader.earliestdate;
DATRW_nonfatal_assert(!Mbetolerantagainstwrongtime,
fileduration<libtime::TRelativeTime(5),
"Duration of file is larger than 5 days!",
"Duration of file is larger than 5 days!\n"
"earlist sample: "
<< Mheader.earliestdate.timestring()
<< "\n"
......
......@@ -30,11 +30,12 @@
* REVISIONS and CHANGES
* - 16/09/2009 V1.0 Thomas Forbriger
* - 02/12/2011 V1.1 prepared for input stream modifiers
* - 08/07/2016 V1.2 make correct use of new DATRW_report_assert
*
* ============================================================================
*/
#define DATRW_TSOFTDATA_CC_VERSION \
"DATRW_TSOFTDATA_CC V1.1"
"DATRW_TSOFTDATA_CC V1.2"
#include <datrwxx/error.h>
#include <datrwxx/tsoftdata.h>
......@@ -125,7 +126,7 @@ namespace datrw {
std::istringstream iss(Mline);
iss >> year >> month >> day >> hour >> minute >> second;
DATRW_report_assert(iss.good(),
"read beyond end of data line when reading date and time", line);
"read beyond end of data line when reading date and time" << line);
DATRW_assert(iss.good(), "empty data line or read beyond end of file");
Mtime=libtime::TAbsoluteTime(year,month,day,hour,minute,second);
double sample;
......@@ -264,7 +265,7 @@ namespace datrw {
else
{
DATRW_report_assert(insequence,
"WARNING (Channeldata::push_sample): TSOFT reading",
"WARNING (Channeldata::push_sample): TSOFT reading\n"
"User requested to bridge data entries labelled with time: "
<< rc.bridgetime.timestring() << "\n"
<< "This time label is present in the first entry of the"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment