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. ...@@ -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 class, I do not check the key values and prefer the simple and straight
forward way of implementation. 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 \date 10.05.2011
*/ */
......
...@@ -38,16 +38,40 @@ ...@@ -38,16 +38,40 @@
#define STFINV_STFINVBASE_CC_CVSID \ #define STFINV_STFINVBASE_CC_CVSID \
"$Id$" "$Id$"
#include <sstream>
#include <cmath>
#include <stfinv/stfinvbase.h> #include <stfinv/stfinvbase.h>
namespace stfinv { 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 void STFBaseEngine::checkconsistency() const
{ {
STFINV_abort("consistency check not yet implemented");
const int& n=Mstf.sampling.n; const int& n=Mstf.sampling.n;
const double& dt=Mstf.sampling.dt; const double& dt=Mstf.sampling.dt;
const double tolerance=1.e-4; 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 { ...@@ -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, 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() } // std::string STFBaseEngine::parameter()
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
......
...@@ -122,12 +122,7 @@ namespace stfinv { ...@@ -122,12 +122,7 @@ namespace stfinv {
*/ */
STFBaseEngine(const stfinv::Tvectoroftriples& triples, STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf, const stfinv::Waveform& stf,
const std::string& parameters) const std::string& parameters);
: Mtriples(triples), Mstf(stf)
{
this->checkconsistency();
this->parseparameters(parameters);
}
public: public:
//! \brief abstract base requires virtual destructor //! \brief abstract base requires virtual destructor
virtual ~STFBaseEngine() { } virtual ~STFBaseEngine() { }
...@@ -141,21 +136,33 @@ namespace stfinv { ...@@ -141,21 +136,33 @@ namespace stfinv {
//! \brief return the value of a parameters //! \brief return the value of a parameters
std::string parameter(const std::string& key, std::string parameter(const std::string& key,
const std::string& defvalue="false") const; const std::string& defvalue="false") const;
//! \brief check is parameter was set by user
bool parameterisset(const std::string& key) const;
private: private:
//! \brief parse parameters in Mparameters //! \brief parse parameters in Mparameters
void parseparameters(std::string parameters); void parseparameters(std::string parameters);
//! \brief Check consistency of data members. //! \brief Check consistency of data members.
void checkconsistency() const; void checkconsistency() const;
// member data
// -----------
protected: protected:
// protected members are accessed directly from derived classes // protected members are accessed directly from derived classes
//! \brief Waveform triples. //! \brief Waveform triples.
stfinv::Tvectoroftriples Mtriples; stfinv::Tvectoroftriples Mtriples;
//! \brief Source time function. //! \brief Source time function.
stfinv::Waveform Mstf; stfinv::Waveform Mstf;
//! \brief debug level
int Mdebug;
//! \brief verbose level
int Mverbose;
private: private:
//! \brief Parameter map /*! \brief Parameter map
stfinv::tools::Tparamap Mparamap; * \note must be declared mutable, since std::map does not provide a
* const read function.
*/
mutable stfinv::tools::Tparamap Mparamap;
}; // class STFBaseEngine }; // class STFBaseEngine
} // namespace stfinv } // 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