summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-02-04 09:27:42 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-02-04 09:27:42 +0000
commitaaa78240ef7409f27bfadf3916d095eb0007bfa9 (patch)
tree7141af89a69c40a9beee5bc4ee60f320f9862b74 /src/include
parent4ec2152e21ddce9f873f6d1d4beb0b5b9bec3c41 (diff)
Rationalised the overloading of functions. Goodbye RegisterKeyedFunction,
hello Overloadable ! Now each subdirectory has one header file (in the include dir) which defines the overloadable functions. Macros are then applied to the header file to produce functions of the form CCTK_OverloadFoo(... (*func)(...)) to overload the function, and to create prototypes, dummy functions, and if statements which can be used to assign dummy (or other default) functions to any overloadable function which hasn't been assigned. The resulting functions have names of the form CCTK_Foo() As a byproduct of this the communication layer should work, 'though it's all dummy functions there at the moment, but at least you can call the functions. I've put OutputGH and OutputGroup in the IO layer, but can't remember precisely what we had decided as the canonical set of overloadable functions for IO. Tom git-svn-id: http://svn.cactuscode.org/flesh/trunk@206 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/include')
-rw-r--r--src/include/CactusCommFunctions.h16
-rw-r--r--src/include/CactusMainFunctions.h8
-rw-r--r--src/include/CommOverloadables.h70
-rw-r--r--src/include/IOOverloadables.h29
-rw-r--r--src/include/MainOverloadables.h28
-rw-r--r--src/include/OverloadMacros.h72
-rw-r--r--src/include/flesh.h6
7 files changed, 211 insertions, 18 deletions
diff --git a/src/include/CactusCommFunctions.h b/src/include/CactusCommFunctions.h
index 329fa9f8..3cabbfd3 100644
--- a/src/include/CactusCommFunctions.h
+++ b/src/include/CactusCommFunctions.h
@@ -12,23 +12,21 @@
#ifndef _CACTUSCOMMFUNCTIONS_H_
#define _CACTUSCOMMFUNCTIONS_H_
+#include <stdarg.h>
+
+#include "OverloadMacros.h"
+
#ifdef _cplusplus
extern "C" {
#endif
/* The functions. */
-extern cGH * (*SetupGH)(tFleshConfig *, int);
-extern int (*SetupGF)(cGH *, cGF *);
-
-extern int (*SyncAllFuncs)(cGH *);
-extern int (*SyncGroupFuncs)(cGH *, const char *group);
-extern int (*SyncOneFunc)(cGH*, int );
+#define OVERLOADABLE(name) OVERLOADABLE_PROTOTYPE(name)
-extern int (*ParallelInit)(tFleshConfig *);
-extern int (*ParallelFinalise)(tFleshConfig *);
+#include "CommOverloadables.h"
-extern int (*Reduce)(cGH *, int , int operation, void *result);
+#undef OVERLOADABLE(name)
#ifdef _cplusplus
}
diff --git a/src/include/CactusMainFunctions.h b/src/include/CactusMainFunctions.h
index 690c0984..de215593 100644
--- a/src/include/CactusMainFunctions.h
+++ b/src/include/CactusMainFunctions.h
@@ -10,17 +10,19 @@
#ifndef _CACTUSMAINFUNCTIONS_H_
#define _CACTUSMAINFUNCTIONS_H_
+#include "OverloadMacros.h"
+
/* Function prototypes */
#ifdef __cplusplus
extern "C" {
#endif
-extern int (*Initialise)(tFleshConfig *);
+#define OVERLOADABLE(name) OVERLOADABLE_PROTOTYPE(name)
-extern int (*Evolve)(tFleshConfig *);
+#include "MainOverloadables.h"
-extern int (*Shutdown)(tFleshConfig *);
+#undef OVERLOADABLE(name)
#ifdef __cplusplus
}
diff --git a/src/include/CommOverloadables.h b/src/include/CommOverloadables.h
new file mode 100644
index 00000000..7b6ead2d
--- /dev/null
+++ b/src/include/CommOverloadables.h
@@ -0,0 +1,70 @@
+ /*@@
+ @header CommOverloadables.h
+ @date Thu Feb 4 08:11:41 1999
+ @author Tom Goodale
+ @desc
+ The overloadable functions for the comm layer.
+ See OverloadMacros.h to see how to use these.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#ifdef ARGUMENTS
+#undef ARGUMENTS
+#endif
+
+#ifdef RETURN_TYPE
+#undef RETURN_TYPE
+#endif
+
+#define RETURN_TYPE int
+#define ARGUMENTS cGH *GH, const char *group
+OVERLOADABLE(SyncGroup)
+
+OVERLOADABLE(EnableGroupStorage)
+OVERLOADABLE(DisableGroupStorage)
+
+OVERLOADABLE(EnableGroupComm)
+OVERLOADABLE(DisableGroupComm)
+
+#undef ARGUMENTS
+#define ARGUMENTS cGH *GH
+OVERLOADABLE(Barrier)
+
+#undef ARGUMENTS
+#define ARGUMENTS cGH *GH, \
+ const char *operation, \
+ int n_infields, \
+ int n_outfields, \
+ int out_type, \
+ void **outarray, \
+ ...
+
+OVERLOADABLE(Reduce)
+
+#undef ARGUMENTS
+#define ARGUMENTS cGH *GH, \
+ const char *operation, \
+ int n_coords, \
+ int n_infields, \
+ int n_outfields, \
+ int n_points, \
+ int type, \
+ ...
+
+OVERLOADABLE(Interp)
+
+#undef ARGUMENTS
+#define ARGUMENTS cGH *GH
+OVERLOADABLE(ParallelInit)
+OVERLOADABLE(Exit)
+OVERLOADABLE(Abort)
+
+#undef ARGUMENTS
+#define ARGUMENTS tFleshConfig *config, int convergence_level
+#undef RETURN_TYPE
+#define RETURN_TYPE cGH *
+OVERLOADABLE(SetupGH)
+
+#undef ARGUMENTS
+#undef RETURN_TYPE
diff --git a/src/include/IOOverloadables.h b/src/include/IOOverloadables.h
new file mode 100644
index 00000000..1fd09782
--- /dev/null
+++ b/src/include/IOOverloadables.h
@@ -0,0 +1,29 @@
+ /*@@
+ @header IOOverloadables.h
+ @date Thu Feb 4 09:59:34 1999
+ @author Tom Goodale
+ @desc
+ The overloadable functions for the IO layer.
+ See OverloadMacros.h to see how to use these.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#ifdef ARGUMENTS
+#undef ARGUMENTS
+#endif
+
+#ifdef RETURN_TYPE
+#undef RETURN_TYPE
+#endif
+
+#define RETURN_TYPE int
+#define ARGUMENTS cGH *GH
+OVERLOADABLE(OutputGH)
+
+#undef ARGUMENTS
+#define ARGUMENTS cGH *GH, const char *group
+OVERLOADABLE(OutputGroup)
+
+#undef ARGUMENTS
+#undef RETURN_TYPE
diff --git a/src/include/MainOverloadables.h b/src/include/MainOverloadables.h
new file mode 100644
index 00000000..1848947c
--- /dev/null
+++ b/src/include/MainOverloadables.h
@@ -0,0 +1,28 @@
+ /*@@
+ @header MainOverloadables.h
+ @date Thu Feb 4 08:58:52 1999
+ @author Tom Goodale
+ @desc
+ The overloadable functions for the main layer.
+ See OverloadMacros.h to see how to use these.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#ifdef ARGUMENTS
+#undef ARGUMENTS
+#endif
+
+#ifdef RETURN_TYPE
+#undef RETURN_TYPE
+#endif
+
+#define RETURN_TYPE int
+#define ARGUMENTS tFleshConfig *
+
+OVERLOADABLE(Initialise)
+OVERLOADABLE(Evolve)
+OVERLOADABLE(Shutdown)
+
+#undef ARGUMENTS
+#undef RETURN_TYPE
diff --git a/src/include/OverloadMacros.h b/src/include/OverloadMacros.h
new file mode 100644
index 00000000..55018866
--- /dev/null
+++ b/src/include/OverloadMacros.h
@@ -0,0 +1,72 @@
+ /*@@
+ @header OverloadMacros.h
+ @date Thu Feb 4 08:02:29 1999
+ @author Tom Goodale
+ @desc
+ Macros used for the overload functions
+ @enddesc
+ @version $Header$
+ @@*/
+
+#ifndef _OVERLOADMACROS_H_
+#define _OVERLOADMACROS_H_
+
+/* These are a load of macros used to make overloadable functions.
+ *
+ * Basically define ARGUMENTS with the arguments of the function,
+ * and RETURN_TYPE as the return type
+ * then put lines of the form OVERLOADABLE(function)
+ * in a header file.
+ * Defining OVERLOADABLE(name) as OVERLOADABLE_<macro>(name)
+ * and then including the header will create functions, prototypes
+ * dummy functions or some checking code as required.
+ */
+
+/* This macro defines a global variable with the name of the function
+ * and a function which allows people to set its value.
+ */
+#define OVERLOADABLE_FUNCTION(name) \
+RETURN_TYPE (*CCTK_##name)(ARGUMENTS) = NULL; \
+int CCTK_Overload##name(RETURN_TYPE (*func)(ARGUMENTS)) \
+{ \
+ int return_code; \
+ if(CCTK_##name) \
+ { \
+ CCTK_##name = func; \
+ return_code = 1; \
+ } \
+ else \
+ { \
+ fprintf(stderr, \
+ "Warning: Attempted to overload function %s twice\n",\
+ #name); \
+ return_code = 0; \
+ } \
+ \
+ return return_code; \
+}
+
+/* This macro creates an extern declaration for an overloadable function */
+#define OVERLOADABLE_PROTOTYPE(name) \
+extern RETURN_TYPE (*CCTK_##name)(ARGUMENTS);
+
+/* This macro defines a dummy function */
+#define OVERLOADABLE_DUMMY(name) \
+RETURN_TYPE CCTK_Dummy##name(ARGUMENTS) \
+{ \
+ fprintf(stderr, "Dummy %s called.\n", #name); \
+ return 0; \
+}
+
+/* This macro defines the prototype for a dummy function. */
+#define OVERLOADABLE_DUMMYPROTOTYPE(name) \
+RETURN_TYPE CCTK_Dummy##name(ARGUMENTS);
+
+/* This macro defines a check line which will set the overloadable
+ * function to be the dummy if it hasn't been set.
+ */
+#define OVERLOADABLE_CHECK(name) \
+ if(!CCTK_##name) CCTK_##name = CCTK_Dummy##name;
+
+
+#endif
diff --git a/src/include/flesh.h b/src/include/flesh.h
index cdad508c..8a160d78 100644
--- a/src/include/flesh.h
+++ b/src/include/flesh.h
@@ -114,12 +114,6 @@ int InitialiseCactus(int *, char ***, tFleshConfig *);
int CCTK_SetParameter(const char *parameter, const char *value);
-extern int (*Initialise)(tFleshConfig *);
-
-extern int (*Evolve)(tFleshConfig *);
-
-extern int (*Shutdown)(tFleshConfig *);
-
int ShutdownCactus(tFleshConfig *);
int ProcessCommandLine(int *argc, char ***argv, tFleshConfig *ConfigData);