Commit 3b439adb authored by thomas.forbriger's avatar thomas.forbriger
Browse files

tsxx [WP][!!!]: re-organize headers

- place error handling in separate compilation unit
- place type definitions in separate header file
- provide input/output operators
- use debug code of libtsxx
parent 1346dc38
......@@ -38,7 +38,7 @@
#include <tsxx/anyfilter.h>
#include <tsxx/filter.h>
#include <tsxx/seifeclass.h>
#include <tfxx/misc.h>
#include <tsxx/debug.h>
namespace ts {
......@@ -47,7 +47,7 @@ namespace ts {
Tfilterhandle make_any_filter(const std::string& s,
const bool& debug)
{
TFXX_debug(debug, "make_any_filter", "process " + s );
TSXX_debug(debug, "make_any_filter", "process " + s );
tfxx::error::Exception::dont_report_on_construct();
typedef Tfilterhandle Tfh;
Tfh fh(new Noop());
......@@ -60,11 +60,11 @@ namespace ts {
}
catch (UnknownFilterException) {
hot=true;
TFXX_debug(debug, "make_any_filter",
TSXX_debug(debug, "make_any_filter",
"caught unknown filter exception from my own" );
}
catch (Exception e) {
TFXX_debug(debug, "make_any_filter",
TSXX_debug(debug, "make_any_filter",
"caught other exception from my own" );
tfxx::error::Exception::report_on_construct();
e.report();
......@@ -79,11 +79,11 @@ namespace ts {
}
catch (UnknownFilterException) {
hot=true;
TFXX_debug(debug, "make_any_filter",
TSXX_debug(debug, "make_any_filter",
"caught unknown filter exception from seife" );
}
catch (Exception e) {
TFXX_debug(debug, "make_any_filter",
TSXX_debug(debug, "make_any_filter",
"caught other exception from seife" );
tfxx::error::Exception::report_on_construct();
e.report();
......@@ -91,7 +91,7 @@ namespace ts {
}
}
if (hot) {
TFXX_debug(debug, "make_any_filter",
TSXX_debug(debug, "make_any_filter",
"still hot after seife and my own" );
tfxx::error::Exception::report_on_construct();
TSXX_UnknownFilterAbort("ts::filter::make_any_filter", s);
......
......@@ -39,6 +39,8 @@
#define TSXX_DEBUG_H_VERSION \
"TSXX_DEBUG_H V1.0 "
#include<iostream>
/*! \brief produce debug output
* \ingroup group_util
*
......
/*! \file dttimeseries.h
* \brief time series with basic sampling interval header (prototypes)
*
* ----------------------------------------------------------------------------
*
* \author Thomas Forbriger
* \date 22/11/2016
*
* time series with basic sampling interval header (prototypes)
*
* Copyright (c) 2016 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ----
*
* REVISIONS and CHANGES
* - 22/11/2016 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TSXX_DTTIMESERIES_H_VERSION
#define TSXX_DTTIMESERIES_H_VERSION \
"TSXX_DTTIMESERIES_H V1.0"
#include<tsxx/tsxx.h>
namespace ts {
/*----------------------------------------------------------------------*/
// generic version
/*! \brief simple header
*
* Adding a sampling interval to a series qualifies it to represent a time
* series. That's the bare minimum required to make a time series.
*/
template<class T>
struct DTHeader {
typedef T Tvalue;
DTHeader(const Tvalue& sdt): dt(sdt) { }
//! sampling interval
Tvalue dt;
}; // DTHeader
//! double precision version of simple time series
typedef ts::TimeSeries<aff::Series<double>, DTHeader<double> > TDtimeseries;
//! single precision version of simple time series
typedef ts::TimeSeries<aff::Series<float>, DTHeader<float> > TStimeseries;
} // namespace ts
#endif // TSXX_DTTIMESERIES_H_VERSION (includeguard)
/* ----- END OF dttimeseries.h ----- */
/*! \file error.cc
* \brief error handling for libtsxx (implementation)
*
* ----------------------------------------------------------------------------
*
* \author Thomas Forbriger
* \date 22/11/2016
*
* error handling for libtsxx (implementation)
*
* Copyright (c) 2016 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ----
*
* REVISIONS and CHANGES
* - 22/11/2016 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TSXX_ERROR_CC_VERSION \
"TSXX_ERROR_CC V1.0"
#include <iostream>
#include <tsxx/error.h>
using std::cerr;
using std::endl;
namespace ts {
namespace error {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
//! construct from nothing
Exception::Exception():
Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
}
//! report
void Exception::report() const
{
base_report();
}
//! report
void Exception::base_report() const
{
cerr << "Exception report:" << endl;
if (Mmessage==NULL)
{
cerr << " No message" << endl;
}
else
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=NULL)
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=NULL)
{
cerr << " by condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
}
}
} // namespace error
} // namespace ts
/* ----- END OF error.cc ----- */
/*! \file error.h
* \brief error handling for libtsxx (prototypes)
*
* ----------------------------------------------------------------------------
*
* \author Thomas Forbriger
* \date 22/11/2016
*
* error handling for libtsxx (prototypes)
*
* Copyright (c) 2016 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ----
*
* REVISIONS and CHANGES
* - 22/11/2016 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TSXX_ERROR_H_VERSION
#define TSXX_ERROR_H_VERSION \
"TSXX_ERROR_H V1.0"
/*----------------------------------------------------------------------*/
// assertions
namespace ts {
namespace error {
/*! \brief Base class for exceptions
*
* This is an exception base class. It holds some information about the
* reason for throwing the exception. The information is printed to cerr
* through function report(). This function may be overloaded by a derived
* type. But its functionality is still accessible through base_report().
*
* The standard behaviour is to print ou the message during object
* initialization. If you don't like this, call dont_report_on_construct().
*
* \ingroup group_error
* \sa TSXX_Xassert
*/
class Exception
{
public:
//! Creates exception with no explaning comments
Exception();
//! Creates an exception with an explanation message
Exception(const char* message);
//! Creates an exception with message and failed assertion
Exception(const char* message,
const char* condition);
//! Create with message, failed assertion, and code position
Exception(const char* message,
const char* file,
const int& line,
const char* condition);
//! Create with message and code position
Exception(const char* message,
const char* file,
const int& line);
//! provide virtual destructor
virtual ~Exception() { }
//! Screen report
virtual void report() const;
//! Issue a screen report on construction of exception
static void report_on_construct();
//! Issue NO screen report on construction of exception
static void dont_report_on_construct();
private:
//! Screen report
void base_report() const;
//! Shall we print to cerr at construction time?
static bool Mreport_on_construct;
//! pointer to message string
const char* Mmessage;
//! pointer to file name string
const char* Mfile;
//! pointer to line number in source file
const int& Mline;
//! pointer to assertion condition text string
const char* Mcondition;
}; // class exception
} // namespace error
} // namespace ts
/*======================================================================*/
//
// preprocessor macros
// ===================
/*! \brief Check an assertion and report by throwing an exception
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param E exception class to throw
*/
#define TSXX_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*
*/
#define TSXX_assert(C,M) TSXX_Xassert( C , M , ts::error::Exception )
/*! \brief Abort and give a message
*
* \ingroup group_error
* \param M message of type char*
* \param E exception class to throw
*/
#define TSXX_abort(M) \
throw( ts::error::Exception ( M , __FILE__, __LINE__ ))
#endif // TSXX_ERROR_H_VERSION (includeguard)
/* ----- END OF error.h ----- */
......@@ -69,7 +69,8 @@
#include <aff/functions/absmax.h>
#include <aff/seriesoperators.h>
#include <aff/subarray.h>
#include <tfxx/misc.h>
#include <tsxx/error.h>
#include <tsxx/debug.h>
namespace ts {
......@@ -403,13 +404,13 @@ namespace ts {
const bool& debug)
{
std::replace(s.begin(),s.end(),',',' ');
TFXX_debug(debug, "make_filter", "process " + s );
TSXX_debug(debug, "make_filter", "process " + s );
typedef Tfilterhandle Tfh;
Tfh fh(new Noop());
std::string ID;
std::istringstream is(s);
is >> ID;
TFXX_debug(debug, "make_filter", " filter ID is " + ID );
TSXX_debug(debug, "make_filter", " filter ID is " + ID );
Tvalue v;
int n, n2, n3;
if (ID=="tre") {
......@@ -428,7 +429,7 @@ namespace ts {
fh=Tfh(new Scale(v));
} else if (ID=="add") {
is >> v;
TFXX_debug(debug, "make_filter", " filter is: Add(" << v << ")" );
TSXX_debug(debug, "make_filter", " filter is: Add(" << v << ")" );
fh=Tfh(new Add(v));
} else if (ID=="fbl") {
is >> n >> n2 >> n3;
......@@ -456,7 +457,7 @@ namespace ts {
is >> v;
fh=Tfh(new Normalize(v));
} else {
TFXX_debug(debug, "make_filter", " filter ID " + ID + " is unknown" );
TSXX_debug(debug, "make_filter", " filter ID " + ID + " is unknown" );
TSXX_UnknownFilterAbort("ts::filter::make_filter", ID.c_str());
}
return(fh);
......
......@@ -37,7 +37,7 @@
#include <iostream>
#include <tsxx/filterbase.h>
#include <tfxx/misc.h>
#include <tsxx/debug.h>
namespace ts {
......@@ -49,12 +49,12 @@ namespace ts {
Tfilterlist::const_iterator i=this->Tfilterlist::begin();
while (i!=this->Tfilterlist::end())
{
TFXX_debug(debug, "FilterCollection::operator()",
TSXX_debug(debug, "FilterCollection::operator()",
"apply filter" );
(*i)->operator()(s, debug);
++i;
}
TFXX_debug(debug, "FilterCollection::operator()",
TSXX_debug(debug, "FilterCollection::operator()",
"applied all filters" );
return s;
}
......
......@@ -41,7 +41,7 @@
#include<list>
#include<string>
#include<tsxx/tsxx.h>
#include<tsxx/dttimeseries.h>
#include<tfxx/handle.h>
#include<tfxx/error.h>
......
......@@ -42,6 +42,7 @@
#include<string>
#include<aff/series.h>
#include<aff/iterator.h>
#include<tsxx/error.h>
namespace ts {
......
......@@ -40,6 +40,8 @@
"TF_IPO_H V1.1"
#include<tsxx/tsxx.h>
#include<tsxx/error.h>
#include<tsxx/wid2timeseries.h>
namespace ts {
......
......@@ -42,6 +42,7 @@
#include <tsxx/tsxx.h>
#include <tsxx/debug.h>
#include <tsxx/ovtaper.h>
#include <tsxx/error.h>
namespace ts {
......
......@@ -40,8 +40,10 @@
"TSXX_OVTAPER_H V1.0 "
#include <iostream>
#include <list>
#include <tsxx/tsxx.h>
#include <tsxx/tapers.h>
#include <tsxx/dttimeseries.h>
namespace ts {
......
......@@ -40,6 +40,7 @@
//#include <iostream>
#include <tsxx/tapers.h>
#include <tsxx/tsxx.h>
#include <tsxx/error.h>
//#include <tsxx/debug.h>
#include <cmath>
......
......@@ -29,99 +29,11 @@
* REVISIONS and CHANGES
* - 19/12/2003 V1.0 Thomas Forbriger
* - 13/07/2005 V1.1 added exception
* - 22/11/2016 V1.2 move error handling code to error.cc
*
* ============================================================================
*/
#define TF_TSXX_CC_VERSION \
"TF_TSXX_CC V1.1"
#include <iostream>
#include <tsxx/tsxx.h>
using std::cerr;
using std::endl;
namespace ts {
namespace error {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
//! construct from nothing
Exception::Exception():
Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
}
//! report
void Exception::report() const
{
base_report();
}
//! report
void Exception::base_report() const
{
cerr << "Exception report:" << endl;
if (Mmessage==NULL)
{
cerr << " No message" << endl;
}
else
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=NULL)
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=NULL)
{
cerr << " by condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
}
}
} // namespace error
} // namespace ts
"TF_TSXX_CC V1.2"