1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*@@
@header Ell_Register.h
@date
@author Gerd Lanferman
@desc
Registration routines for elliptic classes and solvers
@enddesc
@version $Header$
@@*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cctk.h"
#include "cctk_parameters.h"
#include "cctk_WarnLevel.h"
#include "EllBase.h"
#include "StoreNamedData.h"
static pNamedData *EqNameDB;
/* Ell_RegisterEq takes a routine ("function") and registers that routine
under the name "eqname" in the EqNameDB"
Application: Call Ell_Register with the routine that registers a solver
for a elliptic equation class. */
int Ell_RegisterEq(void *(function)(const char *, void*), const char *eqname)
{
DECLARE_CCTK_PARAMETERS
/* Register if function not already there with this name */
if (!GetNamedData(EqNameDB, eqname))
{
if (StoreNamedData(&EqNameDB, eqname, (void*)function)==0)
{
if CCTK_EQUALS(elliptic_verbose,"yes")
{
char *msg;
msg = (char *)malloc( (200+strlen(eqname))*sizeof(char) );
sprintf(msg,"Registered elliptic class: %s",eqname);
CCTK_INFO(msg);
free(msg);
}
}
else
{
char *msg;
msg = (char *)malloc( (200+strlen(eqname))*sizeof(char) );
sprintf(msg,"Failed to register elliptic class: %s",eqname);
CCTK_INFO(msg);
free(msg);
}
}
else
{
char *msg;
msg = (char *)malloc( (200+strlen(eqname))*sizeof(char) );
sprintf(msg,"Elliptic class %s already registered",eqname);
CCTK_INFO(msg);
free(msg);
}
}
/* Ell_RegisterSolver takes a routine ("function") and registers that
routine under the name "sname" with the database specified by "eqname".
So, how do we get to the database, after all it needs to be hardcoded
as pNamedData ? Well, we know its name and in Ell_RegisterEq we have
registered a function under the equation class name.
We now get that function and use that function to register the solver.
Sounds confusing, well it is. The advantage is, that somebody can come
up with a new equation class and can keep the database (the pNamedData
declaration) in his own routine and does not have to put it in a central
place. Amen*/
int Ell_RegisterSolver(void (*function),
const char *sname,
const char *eqname)
{
DECLARE_CCTK_PARAMETERS
int retval;
void (*fn)(void *, const char *);
fn = (void(*)(void (*function), const char *sname))
GetNamedData(EqNameDB, eqname);
if (fn)
{
fn(function,sname);
if CCTK_EQUALS(elliptic_verbose,"yes")
{
char *msg;
msg = (char *)malloc( (200+strlen(eqname)+strlen(sname))*sizeof(char) );
sprintf(msg,"Registered elliptic solver %s for %s",sname,eqname);
CCTK_INFO(msg);
free(msg);
}
retval = ELL_SUCCESS;
}
else
{
CCTK_WARN(0,"Cannot get function in EqName");
retval = ELL_NOCLASS;
}
return retval;
}
|