diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-04 09:27:42 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-04 09:27:42 +0000 |
commit | aaa78240ef7409f27bfadf3916d095eb0007bfa9 (patch) | |
tree | 7141af89a69c40a9beee5bc4ee60f320f9862b74 /src/include/OverloadMacros.h | |
parent | 4ec2152e21ddce9f873f6d1d4beb0b5b9bec3c41 (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/OverloadMacros.h')
-rw-r--r-- | src/include/OverloadMacros.h | 72 |
1 files changed, 72 insertions, 0 deletions
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 |