From fb71c8e935025d61787b4fcaf8f62385b0f305b3 Mon Sep 17 00:00:00 2001 From: eschnett Date: Mon, 9 Jul 2012 00:19:07 +0000 Subject: Use namespace instead of static declarations Use a namespace instead of static declarations, so that name resolution in the template works. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/NaNChecker/trunk@105 ff385933-4943-42dc-877b-ffc776028de6 --- src/NaNCheck.cc | 76 +++++++++++++++++++++++++++++++-------------------------- src/NaNCheck.h | 2 ++ 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/NaNCheck.cc b/src/NaNCheck.cc index d9eda83..90572be 100644 --- a/src/NaNCheck.cc +++ b/src/NaNCheck.cc @@ -6,14 +6,14 @@ Routines to check CCTK real and complex variables against Not-a-Number values. @enddesc - @version $Id: NaNCheck.c 101 2012-03-27 03:16:10Z rhaas $ + @version $Id$ @@*/ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "cctk.h" #include "cctk_WarnLevel.h" @@ -26,10 +26,10 @@ #include "NaNCheck.h" +using namespace std; + +namespace NaNChecker { -/* the rcsid and the macro to use it */ -static const char *rcsid = "$Header$"; -CCTK_FILEVERSION(CactusUtils_NaNChecker_NaNCheck_c) /******************************************************************** @@ -60,17 +60,17 @@ void CCTK_FCALL CCTK_FNAME (NaNChecker_SetVarsToNaN) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static void CheckForNaN (int vindex, const char *optstring, void *arg); -static void SetToNaN (int vindex, const char *optstring, void *arg); -static void PrintWarning (const char *error_type, - int verbose, - int linear_index, - int reflevel, - int cctk_iteration, - int fp_type, - const CCTK_REAL *const coords[], - const char *fullname, - const cGroupDynamicData *gdata); +void CheckForNaN (int vindex, const char *optstring, void *arg); +void SetToNaN (int vindex, const char *optstring, void *arg); +void PrintWarning (const char *error_type, + int verbose, + int linear_index, + int reflevel, + int cctk_iteration, + int fp_type, + const CCTK_REAL *const coords[], + const char *fullname, + const cGroupDynamicData *gdata); /******************************************************************** ******************** Internal Typedefs ************************ @@ -96,7 +96,7 @@ typedef struct /******************************************************************** ******************** Static Variables ************************ ********************************************************************/ -static int last_iteration_output = -1; +int last_iteration_output = -1; /*@@ @@ -138,7 +138,7 @@ void NaNChecker_ResetCounter (CCTK_ARGUMENTS) @vio in @endvar @@*/ -static t_nanchecker_info info; +t_nanchecker_info info; extern "C" void NaNChecker_NaNCheck_Prepare (CCTK_ARGUMENTS) { @@ -195,6 +195,8 @@ void NaNChecker_NaNCheck_Prepare (CCTK_ARGUMENTS) } #endif } + +extern "C" void NaNChecker_NaNCheck_Check (CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS; @@ -208,6 +210,8 @@ void NaNChecker_NaNCheck_Check (CCTK_ARGUMENTS) CCTK_TraverseString (check_vars, CheckForNaN, &info, CCTK_GROUP_OR_VAR); } + +extern "C" void NaNChecker_NaNCheck_Finish (CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS; @@ -584,15 +588,15 @@ void CCTK_FCALL CCTK_FNAME (NaNChecker_SetVarsToNaN) @vio in @endvar @@*/ -static void PrintWarning (const char *error_type, - int verbose, - int linear_index, - int reflevel, - int cctk_iteration, - int fp_type, - const CCTK_REAL *const coords[], - const char *fullname, - const cGroupDynamicData *gdata) +void PrintWarning (const char *error_type, + int verbose, + int linear_index, + int reflevel, + int cctk_iteration, + int fp_type, + const CCTK_REAL *const coords[], + const char *fullname, + const cGroupDynamicData *gdata) { int i; char *index_string, *coord_string; @@ -680,7 +684,7 @@ static void PrintWarning (const char *error_type, @vio in @endvar @@*/ -template static void +template void CHECK_DATA(const cctk_type *_data, int nelems, const CCTK_REAL *CarpetWeights, const t_nanchecker_info *info, CCTK_INT &nans_found, int reflevel, CCTK_INT cctk_iteration, int fp_type, const CCTK_REAL * const *coords, @@ -753,7 +757,7 @@ CHECK_DATA(const cctk_type *_data, int nelems, const CCTK_REAL *CarpetWeights, @vio in @endvar @@*/ -static void CheckForNaN (int vindex, const char *optstring, void *_info) +void CheckForNaN (int vindex, const char *optstring, void *_info) { t_nanchecker_info *info; int i, sum_handle; @@ -1007,7 +1011,7 @@ static void CheckForNaN (int vindex, const char *optstring, void *_info) @vio in @endvar @@*/ -static void SetToNaN (int vindex, const char *optstring, void *_info) +void SetToNaN (int vindex, const char *optstring, void *_info) { t_nanchecker_info *info; int i, timelevel, vtype, gindex, nelems; @@ -1106,6 +1110,7 @@ static void SetToNaN (int vindex, const char *optstring, void *_info) ******************** Schedule Wrappers *********************** ********************************************************************/ +extern "C" CCTK_INT NaNChecker_CheckVarsForNaN_Wrapper (CCTK_POINTER_TO_CONST const cctkGH_, CCTK_INT const report_max, @@ -1118,6 +1123,7 @@ NaNChecker_CheckVarsForNaN_Wrapper (CCTK_POINTER_TO_CONST const cctkGH_, vars, check_for, action_if_found); } +extern "C" CCTK_INT NaNChecker_SetVarsToNaN_Wrapper (CCTK_POINTER_TO_CONST const cctkGH_, CCTK_STRING const vars) @@ -1125,3 +1131,5 @@ NaNChecker_SetVarsToNaN_Wrapper (CCTK_POINTER_TO_CONST const cctkGH_, return NaNChecker_SetVarsToNaN ((cGH const *) cctkGH_, vars); } + +} // end namespace NaNChecker diff --git a/src/NaNCheck.h b/src/NaNCheck.h index bdf6649..134f1e5 100644 --- a/src/NaNCheck.h +++ b/src/NaNCheck.h @@ -13,6 +13,7 @@ #define NANCHECKER_NANCHECK_H 1 #ifdef __cplusplus +namespace NaNChecker { extern "C" { #endif @@ -28,6 +29,7 @@ int NaNChecker_SetVarsToNaN (const cGH *GH, #ifdef __cplusplus } +} // end namespace NaNChecker #endif #endif /* NANCHECKER_NANCHECK_H */ -- cgit v1.2.3