Skip to content
Snippets Groups Projects
Commit a5f26f8f authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Split func.*, new files fbase.cpp, fregistry.*.

NFunctions -> SFuncRegistry (singleton class instead of namespace;
not sure this is a good idea).
parent abb29121
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ curve.cpp
dualplot.cpp
edif.cpp
expr.cpp
fbase.cpp
file_in.cpp
file_out.cpp
fit.cpp
......@@ -56,6 +57,7 @@ expr.hpp
file_in.hpp
file_out.hpp
fit.hpp
fregistry.hpp
func.hpp
geni.hpp
import.hpp
......
......@@ -11,6 +11,7 @@
#include <cstring>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <cstdio>
......@@ -24,7 +25,7 @@
#include "mem.hpp"
#include "edif.hpp"
#include "import.hpp"
#include "func.hpp"
#include "fregistry.hpp"
#include "geni.hpp"
#include "dualplot.hpp"
#include "opr.hpp"
......@@ -88,7 +89,7 @@ bool fridaCommand( string cmd )
;
} else if (cmd == "hf") {
NFunctions::display_functions();
GFuncRegistry->display_functions();
} else if (cmd == "hg") {
NGeni::display_genis();
} else if (cmd == "hi") {
......
This diff is collapsed.
//**************************************************************************************************
//* FRIDA: fast reliable interactive data analysis
//* (C) Joachim Wuttke 2001-
//* http://apps.jcns.fz-juelich.de/frida
//**************************************************************************************************
//! \file fregistry.hpp
//! \brief Registration of CFunc's.
// Low-level function types.
typedef int (*func_i_i) (int);
typedef int (*func_i_d) (double);
typedef double (*func_d_i) (int);
typedef double (*func_d_d) (double);
typedef void (*func_e_e) (double&,double&, double,double);
typedef int (*func_i_ii) (int, int);
typedef int (*func_i_id) (int, double);
typedef int (*func_i_di) (double, int);
typedef int (*func_i_dd) (double, double);
typedef double (*func_d_ii) (int, int);
typedef double (*func_d_id) (int, double);
typedef double (*func_d_di) (double, int);
typedef double (*func_d_dd) (double, double);
typedef void (*func_e_dd) (double&,double&, double, double);
typedef void (*func_e_ee) (double&,double&, double,double, double,double);
typedef int (*func_i_iii) (int, int, int);
typedef double (*func_d_iid) (int, int, double);
typedef double (*func_d_idi) (int, double, int);
typedef double (*func_d_idd) (int, double, double);
typedef double (*func_d_ddd) (double, double, double);
typedef void (*func_e_eee) (double&,double&, double,double, double,double, double,double);
//! A singleton class, holding a collection of CFunc's.
class SFuncRegistry { // public (short) interface
private:
SFuncRegistry() {};
SFuncRegistry(SFuncRegistry const&); //! To prevent copying; don't implement.
void operator=(SFuncRegistry const&); //! To prevent copying; don't implement.
map<string,class CFunc*> FMap; //! unsorted hash, for expression evaluation
vector<const class CFunc*> FList; //! sorted array, for help text
void register_fct_template(
const char* _tag, const char* _outtype, const char* _intypes, void* _f );
public:
static SFuncRegistry& getInstance()
{ static SFuncRegistry instance; //! Instantiated on first use.
return instance; }
const class CFunc* find( string nam ) const;
const class CFunc* find_or_fail( string nam ) const;
void display_functions() const;
void register_fct_meta(
const char* _tag, int _narg, const char* _explanation, int _precedence=0 );
void register_fct_i_i( const char* _tag, func_i_i _f )
{ register_fct_template( _tag, "i", "i", (void*)_f ); }
void register_fct_i_d( const char* _tag, func_i_d _f )
{ register_fct_template( _tag, "i", "d", (void*)_f ); }
void register_fct_d_i( const char* _tag, func_d_i _f )
{ register_fct_template( _tag, "d", "i", (void*)_f ); }
void register_fct_d_d( const char* _tag, func_d_d _f )
{ register_fct_template( _tag, "d", "d", (void*)_f ); }
void register_fct_e_e( const char* _tag, func_e_e _f )
{ register_fct_template( _tag, "e", "e", (void*)_f ); }
void register_fct_i_ii( const char* _tag, func_i_ii _f )
{ register_fct_template( _tag, "i", "ii", (void*)_f ); }
void register_fct_i_id( const char* _tag, func_i_id _f )
{ register_fct_template( _tag, "i", "id", (void*)_f ); }
void register_fct_i_di( const char* _tag, func_i_di _f )
{ register_fct_template( _tag, "i", "di", (void*)_f ); }
void register_fct_i_dd( const char* _tag, func_i_dd _f )
{ register_fct_template( _tag, "i", "dd", (void*)_f ); }
void register_fct_d_ii( const char* _tag, func_d_ii _f )
{ register_fct_template( _tag, "d", "ii", (void*)_f ); }
void register_fct_d_dd( const char* _tag, func_d_dd _f )
{ register_fct_template( _tag, "d", "dd", (void*)_f ); }
void register_fct_e_dd( const char* _tag, func_e_dd _f )
{ register_fct_template( _tag, "e", "dd", (void*)_f ); }
void register_fct_e_ee( const char* _tag, func_e_ee _f )
{ register_fct_template( _tag, "e", "ee", (void*)_f ); }
void register_fct_i_iii( const char* _tag, func_i_iii _f )
{ register_fct_template( _tag, "i", "iii", (void*)_f ); }
void register_fct_d_iid( const char* _tag, func_d_iid _f )
{ register_fct_template( _tag, "d", "iid", (void*)_f ); }
void register_fct_d_idi( const char* _tag, func_d_idi _f )
{ register_fct_template( _tag, "d", "idi", (void*)_f ); }
void register_fct_d_idd( const char* _tag, func_d_idd _f )
{ register_fct_template( _tag, "d", "idd", (void*)_f ); }
void register_fct_d_ddd( const char* _tag, func_d_ddd _f )
{ register_fct_template( _tag, "d", "ddd", (void*)_f ); }
void register_fct_e_eee( const char* _tag, func_e_eee _f )
{ register_fct_template( _tag, "e", "eee", (void*)_f ); }
};
//! The one global instance of SFuncRegistry.
extern SFuncRegistry* GFuncRegistry;
This diff is collapsed.
......@@ -5,33 +5,7 @@
//**************************************************************************************************
//! \file func.hpp
//! \brief Collection NFunctions of function wrappers CFunc.
// Low-level function types.
typedef int (*func_i_i) (int);
typedef int (*func_i_d) (double);
typedef double (*func_d_i) (int);
typedef double (*func_d_d) (double);
typedef void (*func_e_e) (double&,double&, double,double);
typedef int (*func_i_ii) (int, int);
typedef int (*func_i_id) (int, double);
typedef int (*func_i_di) (double, int);
typedef int (*func_i_dd) (double, double);
typedef double (*func_d_ii) (int, int);
typedef double (*func_d_id) (int, double);
typedef double (*func_d_di) (double, int);
typedef double (*func_d_dd) (double, double);
typedef void (*func_e_dd) (double&,double&, double, double);
typedef void (*func_e_ee) (double&,double&, double,double, double,double);
typedef int (*func_i_iii) (int, int, int);
typedef double (*func_d_iid) (int, int, double);
typedef double (*func_d_idi) (int, double, int);
typedef double (*func_d_idd) (int, double, double);
typedef double (*func_d_ddd) (double, double, double);
typedef void (*func_e_eee) (double&,double&, double,double, double,double, double,double);
//! \brief Function wrapper classes CTypedFunc and CFunc.
//! A wrapper holding a function with given input and output types.
......@@ -61,12 +35,3 @@ class CFunc {
class CCoord coord( class CCoord *co1, class CCoord *co2 ) const;
class CCoord coord( class CCoord *co1, class CCoord *co2, class CCoord *co3 ) const;
};
//! Collection of function wrappers CFunc
namespace NFunctions { // public (short) interface
void initialize();
const CFunc* find( string nam );
const CFunc* find_or_fail( string nam );
void display_functions();
}
......@@ -8,6 +8,7 @@
//! \brief Nodes within expression trees, inheriting from virtual base CNode.
#include <map>
#include <algorithm>
#include <iostream>
......@@ -17,6 +18,7 @@
#include "slice.hpp"
#include "reg.hpp"
#include "func.hpp"
#include "fregistry.hpp"
#include "geni.hpp"
#include "integrate.hpp"
#include "var.hpp"
......
//**************************************************************************************************
//* FRIDA: fast reliable interactive data analysis
//* (C) Joachim Wuttke 2001-
//* http://apps.jcns.fz-juelich.de/frida
//**************************************************************************************************
//! \file fregistry.hpp
//! \brief Registration of CFunc's.
//! A singleton class, holding a collection of CFunc's.
class SFunctions { // public (short) interface
private:
SFunctions(SFunctions const&); //! To prevent copying; don't implement.
void operator=(SFunctions const&); //! To prevent copying; don't implement.
public:
static SFunctions& getInstance()
{ static SFunctions instance; //! Instantiated on first use.
return instance; }
map<string,CFunc*> FMap; //! unsorted hash, for expression evaluation
vector<const CFunc*> FList; //! sorted array, for help text
const CFunc* find( string nam );
const CFunc* find_or_fail( string nam );
void display_functions();
void register_fct_template(
const char* _tag, const char* _outtype, const char* _intypes, void* _f );
void register_fct_meta(
const char* _tag, int _narg, const char* _explanation, int _precedence=0 );
void register_fct_i_i( const char* _tag, func_i_i _f )
{ register_fct_template( _tag, "i", "i", (void*)_f ); }
void register_fct_i_d( const char* _tag, func_i_d _f )
{ register_fct_template( _tag, "i", "d", (void*)_f ); }
void register_fct_d_i( const char* _tag, func_d_i _f )
{ register_fct_template( _tag, "d", "i", (void*)_f ); }
void register_fct_d_d( const char* _tag, func_d_d _f )
{ register_fct_template( _tag, "d", "d", (void*)_f ); }
void register_fct_e_e( const char* _tag, func_e_e _f )
{ register_fct_template( _tag, "e", "e", (void*)_f ); }
void register_fct_i_ii( const char* _tag, func_i_ii _f )
{ register_fct_template( _tag, "i", "ii", (void*)_f ); }
void register_fct_i_id( const char* _tag, func_i_id _f )
{ register_fct_template( _tag, "i", "id", (void*)_f ); }
void register_fct_i_di( const char* _tag, func_i_di _f )
{ register_fct_template( _tag, "i", "di", (void*)_f ); }
void register_fct_i_dd( const char* _tag, func_i_dd _f )
{ register_fct_template( _tag, "i", "dd", (void*)_f ); }
void register_fct_d_ii( const char* _tag, func_d_ii _f )
{ register_fct_template( _tag, "d", "ii", (void*)_f ); }
void register_fct_d_dd( const char* _tag, func_d_dd _f )
{ register_fct_template( _tag, "d", "dd", (void*)_f ); }
void register_fct_e_dd( const char* _tag, func_e_dd _f )
{ register_fct_template( _tag, "e", "dd", (void*)_f ); }
void register_fct_e_ee( const char* _tag, func_e_ee _f )
{ register_fct_template( _tag, "e", "ee", (void*)_f ); }
void register_fct_i_iii( const char* _tag, func_i_iii _f )
{ register_fct_template( _tag, "i", "iii", (void*)_f ); }
void register_fct_d_iid( const char* _tag, func_d_iid _f )
{ register_fct_template( _tag, "d", "iid", (void*)_f ); }
void register_fct_d_idi( const char* _tag, func_d_idi _f )
{ register_fct_template( _tag, "d", "idi", (void*)_f ); }
void register_fct_d_idd( const char* _tag, func_d_idd _f )
{ register_fct_template( _tag, "d", "idd", (void*)_f ); }
void register_fct_d_ddd( const char* _tag, func_d_ddd _f )
{ register_fct_template( _tag, "d", "ddd", (void*)_f ); }
void register_fct_e_eee( const char* _tag, func_e_eee _f )
{ register_fct_template( _tag, "e", "eee", (void*)_f ); }
}
......@@ -12,6 +12,7 @@
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <gsl/gsl_errno.h>
......@@ -25,13 +26,19 @@
#include "defs.hpp"
#include "olf.hpp"
#include "mem.hpp"
#include "func.hpp"
#include "fregistry.hpp"
#include "geni.hpp"
#include "integrate.hpp"
#include "dualplot.hpp"
#include "commands.hpp"
#include "calc.hpp"
// Declarations.
void fbase_initialize(); // implemented in fbase.cpp; no .hpp file
// Initializiations.
SFuncRegistry* GFuncRegistry = &(SFuncRegistry::getInstance());
using namespace std;
......@@ -96,7 +103,7 @@ CFrida::CFrida()
NReadln::initialize(); // command-line dialog (readline and history)
NPloWin::initialize(); // plot windows
gsl_set_error_handler( my_gsl_error_handler );
NFunctions::initialize();
fbase_initialize();
NGeni::initialize();
NCvin::initialize();
......
......@@ -15,12 +15,14 @@
%{
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <../trivia/string_convs.hpp>
#include <boost/shared_ptr.hpp>
using namespace std;
#include "ptr.hpp"
#include "func.hpp"
#include "fregistry.hpp"
#include "geni.hpp"
#include "integrate.hpp"
#include "reg.hpp"
......@@ -110,7 +112,7 @@ e {
"resol" { return DIRAC; }
{ID} {
if ( const CFunc* f1 = NFunctions::find(xaxtext) ) {
if ( const CFunc* f1 = GFuncRegistry->find(xaxtext) ) {
xaxlval->p = (void*) f1;
return FNCT;
}
......
......@@ -9,10 +9,12 @@
%{
#include <string>
#include <map>
#include <vector>
#include "defs.hpp"
#include "ptr.hpp"
#include "func.hpp"
#include "fregistry.hpp"
#include "var.hpp"
#include "obj.hpp"
#include "expr.hpp"
......@@ -41,11 +43,11 @@ int xaxerror( PNode* T, const char*);
int xaxlex(YYSTYPE *xaxlval); // created by lex.l
#define MONFUNC(op,v1) \
PNode( new CNodeFun1(NFunctions::find_or_fail(op),v1.t ) )
PNode( new CNodeFun1(GFuncRegistry->find_or_fail(op),v1.t ) )
#define BINFUNC(op,v1,v2) \
PNode( new CNodeFun2(NFunctions::find_or_fail(op),v1.t,v2.t ) )
PNode( new CNodeFun2(GFuncRegistry->find_or_fail(op),v1.t,v2.t ) )
#define TERFUNC(op,v1,v2,v3) \
PNode( new CNodeFun3(NFunctions::find_or_fail(op),v1.t,v2.t,v3.t) )
PNode( new CNodeFun3(GFuncRegistry->find_or_fail(op),v1.t,v2.t,v3.t) )
%}
%parse-param{ PNode* T }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment