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

separate C and C++ clearly; C++ classes need not know abount C structs

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: 3914
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent d80da42b
......@@ -42,4 +42,24 @@ $Id$
*/
/*======================================================================*/
/*! \brief C interface to libstfinv
*
* \defgroup cinterface C interface (API) to libstfinv
*
* When using libstfinv from a C program, the first step is to initialize the
* engine by calling ::initstfinvengine(). The engine will keep references to
* the memory locations where time series samples are stored. You can update
* the content of these locations as you like, e.g. by storing a new set of
* synthetic seismograms therein. Upon each call to ::runstfinvengine() a new
* source time function wavelet will be derived and stored at its place in
* memory. At the same time the synthetic waveforms are convolved with the
* source time function and stored at the memory location reserved for the
* convolved synthetics. It is good style to call ::freestfinvengine() when
* you have finished. This will remove the engine from memory. This call
* should at least be issued when the pointers to the memory locations for
* time series samples as passed to ::initstfinvengine() become invalid.
*/
// ----- END OF README -----
/*! \file stfinv.c
/*! \file stfinv.cc
* \brief C API to library (implementation)
*
* ----------------------------------------------------------------------------
......@@ -39,5 +39,57 @@
"$Id$"
#include <stfinv/stfinv.h>
#include <stfinv/error.h>
#include <stfinv/stfinvany.h>
/* ----- END OF stfinv.c ----- */
/*! \brief Internals of C API.
*
* The C language API uses some internal data structures to keep engines.
*
* \defgroup capiinternal Internals of C API
* \sa cinterface
*/
namespace stfinv {
/*! \brief Namespace for internal data structures of the C API.
* \ingroup capiinternal
*/
namespace capi {
/*! \brief Pointer to engine to work with.
* \ingroup capiinternal
*/
stfinv::STFEngine* Pengine=0;
} // namespace capi
} // namespace stfinv
/*======================================================================*/
void initstfinvengine(struct CTriples triples,
struct CWaveform stf,
char* parameters)
{
STFINV_abort("initstfinvengine(): not yet implemented");
freestfinvengine();
} // void initstfinvengine
/*----------------------------------------------------------------------*/
void runstfinvengine()
{
STFINV_assert(stfinv::capi::Pengine != 0,
"runstfinvengine(): engine is not initialized!");
stfinv::capi::Pengine->run();
} // void runstfinvengine()
/*----------------------------------------------------------------------*/
void freestfinvengine()
{
if (stfinv::capi::Pengine != 0) { delete stfinv::capi::Pengine; }
} // void freestfinvengine()
/* ----- END OF stfinv.cc ----- */
......@@ -44,20 +44,16 @@
#include <stfinv/waveformheader.h>
/*! \brief Value type of samples.
*/
typedef float Tvalue;
/*----------------------------------------------------------------------*/
/*! \brief A struct to store the time series for a waveform triple.
*
* \ingroup cinterface
*/
struct WaveformTriple {
struct CWaveformTriple {
/*! \brief The header is expected to be the same for all three time series.
* In particular the number of samples must be appropriate for the memory
* allocated for all three time series arrays.
*/
struct TripleHeader header;
struct CTripleHeader header;
/*! \brief Time series of recorded data.
*/
Tvalue* data;
......@@ -70,35 +66,62 @@ struct WaveformTriple {
* time function as a result of a call to the library functions.
*/
Tvalue* convolvedsynthetics;
}; // struct WaveformTriple
}; // struct CWaveformTriple
/*----------------------------------------------------------------------*/
/*! \brief A struct to store a single waveform.
* This will be used to pass the source time function.
*
* \ingroup cinterface
*/
struct Waveform {
struct CWaveform {
/*! \brief Temporal sampling.
*/
struct WaveformHeader sampling;
struct CWaveformHeader sampling;
/*! \brief Time series of waveform.
*/
Tvalue* series;
}; // struct Waveform
}; // struct CWaveform
/*----------------------------------------------------------------------*/
/*! \brief Array of waveform triples.
* This is used to pass data for a complete profile.
*
* \ingroup cinterface
*/
struct Triples {
struct CTriples {
/*! \brief Number of triples in the array.
*/
int n;
/*! \brief Pointer to array of waveform tripples.
*/
struct WaveformTriple* triples;
}; // struct Triples
struct CWaveformTriple* triples;
}; // struct CTriples
/*======================================================================*/
// function interface to libstfinv
/*! \brief Initialize the engine.
*
* \ingroup cinterface
*/
void initstfinvengine(struct CTriples triples,
struct CWaveform stf,
char* parameters);
/*! \brief Run the engine.
*
* \ingroup cinterface
*/
void runstfinvengine();
/*! \brief Free the engine.
*
* \ingroup cinterface
*/
void freestfinvengine();
#endif // STFINV_STFINV__H_VERSION (includeguard)
......
......@@ -49,23 +49,15 @@ namespace stfinv {
/*! \brief Class to access any engine in the library
*
* The interface of this class is identical to the interface defined by the
* abstract base class stfinv::STFBaseEngine except for a constructor which
* accepts the C structs and the fact that the first prefix (up to the first
* colon) in the parameter string is understood to identify the selected
* engine.
* abstract base class stfinv::STFBaseEngine except that the first prefix
* (up to the first colon) in the parameter string is understood to identify
* the selected engine.
*/
class STFEngine {
public:
//! \brief Constructor.
STFEngine(const stfinv::Tlistoftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
{ this->create(triples, stf, parameters); }
/*! \brief Constructor.
* This type is needed for the C interface
*/
STFEngine(const Triples& triples,
const Waveform& stf,
const std::string& parameters);
//! \brief Destructor must remove engine.
~STFEngine();
......@@ -74,10 +66,6 @@ namespace stfinv {
//! \brief Start engine and return source time function.
stfinv::Waveform run() { return(Mengine->run()); }
private:
//! \brief Function to actually create the engine.
void create(const stfinv::Tlistoftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters);
//! \brief Pointer to actual engine.
stfinv::STFBaseEngine* Mengine;
}; // class STFEngine
......
......@@ -42,7 +42,7 @@
#define STFINV_STFINVBASE_H_CVSID \
"$Id$"
#include<stfinv/stfinv.h>
#include<stfinv/waveformheader.h>
#include<stfinv/error.h>
#include<aff/series.h>
#include<list>
......@@ -62,7 +62,7 @@ namespace stfinv {
* In particular the number of samples must be appropriate for the memory
* allocated for all three time series arrays.
*/
TripleHeader header;
CTripleHeader header;
/*! \brief Time series of recorded data.
*/
Tseries data;
......@@ -85,7 +85,7 @@ namespace stfinv {
class Waveform {
/*! \brief Temporal sampling
*/
WaveformHeader sampling;
CWaveformHeader sampling;
/*! \brief Time series of waveform.
*/
Tseries series;
......@@ -113,7 +113,7 @@ namespace stfinv {
STFBaseEngine(const stfinv::Tlistoftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
:Mtriples(triples), Mstf(stf), Mparameters(parameters)
: Mtriples(triples), Mstf(stf), Mparameters(parameters)
{
this->checkconsistency();
}
......
......@@ -46,22 +46,34 @@
extern "C" {
#endif
/*! \brief Value type of samples.
*
* \ingroup cinterface
*/
typedef float Tvalue;
/*----------------------------------------------------------------------*/
/*! \brief Structure to hold header information for a time series array
*
* \ingroup cinterface
*/
struct WaveformHeader {
struct CWaveformHeader {
/*! \brief Sampling interval in seconds.
*/
double dt;
/*! \brief Number of samples in time series array.
*/
int n;
}; // struct WaveformHeader
}; // struct CWaveformHeader
/*----------------------------------------------------------------------*/
/*! \brief Structure to hold header information for a triple of waveforms
*
* \ingroup cinterface
*/
struct TripleHeader {
struct CTripleHeader {
/*! \brief Source coordinates in meters.
*
* - \c sx: x-coordinate
......@@ -78,8 +90,8 @@ extern "C" {
double rx, ry, rz;
/*! \brief Temporal sampling of all three waveforms.
*/
struct WaveformHeader sampling;
}; // struct TripleHeader
struct CWaveformHeader sampling;
}; // struct CTripleHeader
#ifdef __cplusplus
} // extern "C"
......
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