Commit 759835e6 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

STFBaseEngine implemented

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 3927
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent f395b064
......@@ -219,6 +219,11 @@ time series samples as passed to ::initstfinvengine() become invalid.
class, I do not check the key values and prefer the simple and straight
forward way of implementation.
The handling of stfinv::STFBaseEngine::Mparamap is entirely encapsulated in
the base class.
For this reason it should be possible to implement parameter keyword checks
in the future is desired with relatively small effort.
\date 10.05.2011
*/
......
......@@ -38,16 +38,40 @@
#define STFINV_STFINVBASE_CC_CVSID \
"$Id$"
#include <sstream>
#include <cmath>
#include <stfinv/stfinvbase.h>
namespace stfinv {
STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
: Mtriples(triples), Mstf(stf)
{
this->checkconsistency();
this->parseparameters(parameters);
std::istringstream is(this->parameter("DEBUG","0"));
is >> Mdebug;
Mverbose=(this->parameter("verbose","false")=="true");
} // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
/*----------------------------------------------------------------------*/
void STFBaseEngine::checkconsistency() const
{
STFINV_abort("consistency check not yet implemented");
const int& n=Mstf.sampling.n;
const double& dt=Mstf.sampling.dt;
const double tolerance=1.e-4;
stfinv::Tvectoroftriples::const_iterator I=Mtriples.begin();
while (I!=Mtriples.end())
{
CTripleHeader header=I->header;
STFINV_assert(header.sampling.n==n,
"inconsistent number of samples");
STFINV_assert(std::abs(1.-header.sampling.dt/dt)<tolerance,
"inconsistent values of sampling interval");
} // while (I!=Mtriples.end())
}
/*----------------------------------------------------------------------*/
......@@ -79,10 +103,37 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
//! \brief return the value of a parameters
/*! \brief check is parameter was set
*
* \param key parameter key
* \return true, if parameter was set by user
*/
bool STFBaseEngine::parameterisset(const std::string& key) const
{
return (Mparamap.count(key)>0);
} // bool STFBaseEngine::parameter(const std::string& key) const
/*----------------------------------------------------------------------*/
/*! \brief return the value of a parameters
*
* \param key parameter key
* \param defvalue default value to be used is not set externally
* \return parameter value or default value if key is not present.
*/
std::string STFBaseEngine::parameter(const std::string& key,
const std::string& defvalue="false") const
const std::string& defvalue) const
{
std::string retval;
if (this->parameterisset(key))
{
retval=Mparamap[key];
}
else
{
retval=defvalue;
}
return retval;
} // std::string STFBaseEngine::parameter()
/*----------------------------------------------------------------------*/
......
......@@ -122,12 +122,7 @@ namespace stfinv {
*/
STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
: Mtriples(triples), Mstf(stf)
{
this->checkconsistency();
this->parseparameters(parameters);
}
const std::string& parameters);
public:
//! \brief abstract base requires virtual destructor
virtual ~STFBaseEngine() { }
......@@ -141,21 +136,33 @@ namespace stfinv {
//! \brief return the value of a parameters
std::string parameter(const std::string& key,
const std::string& defvalue="false") const;
//! \brief check is parameter was set by user
bool parameterisset(const std::string& key) const;
private:
//! \brief parse parameters in Mparameters
void parseparameters(std::string parameters);
//! \brief Check consistency of data members.
void checkconsistency() const;
// member data
// -----------
protected:
// protected members are accessed directly from derived classes
//! \brief Waveform triples.
stfinv::Tvectoroftriples Mtriples;
//! \brief Source time function.
stfinv::Waveform Mstf;
//! \brief debug level
int Mdebug;
//! \brief verbose level
int Mverbose;
private:
//! \brief Parameter map
stfinv::tools::Tparamap Mparamap;
/*! \brief Parameter map
* \note must be declared mutable, since std::map does not provide a
* const read function.
*/
mutable stfinv::tools::Tparamap Mparamap;
}; // class STFBaseEngine
} // namespace stfinv
......
Markdown is supported
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