aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjthorn <jthorn@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e>2003-03-17 11:17:14 +0000
committerjthorn <jthorn@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e>2003-03-17 11:17:14 +0000
commitc476443ffe5ada5e7af7c7b3d9271e5622f0f6e5 (patch)
tree2e0b8ab877c1afeebccbd2fd2d6f12b0cf64b843 /src
parent357693d0fcc12b93dea5746c7e28257ef2af93b6 (diff)
add many const qualifiers to tell humans and compilers that
these functions won't try to modify state names etc, also that looking at a state won't modify the gridfn (without the const qualifiers, C++ code can't use these functions on const data) git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/SpaceMask/trunk@26 a491c6a4-70bf-4b89-8b36-d6c0cb1f094e
Diffstat (limited to 'src')
-rw-r--r--src/MaskUtils.c74
-rw-r--r--src/SpaceMask.h21
2 files changed, 53 insertions, 42 deletions
diff --git a/src/MaskUtils.c b/src/MaskUtils.c
index 9dd064d..29a280a 100644
--- a/src/MaskUtils.c
+++ b/src/MaskUtils.c
@@ -23,22 +23,26 @@ CCTK_FILEVERSION(CACTUSEINSTEIN_SPACEMASK_MaskUtils_c);
SpaceMask_Registry* spacemask_registry = NULL;
-/* Prototypes */
-int SpaceMask_get_bit_nbr(int nstates);
-CCTK_INT SpaceMask_get_free_bits(int nbits);
-CCTK_INT* SpaceMask_determine_state_mask(CCTK_INT allocated_bits, int nstates);
-SpaceMask_State* SpaceMask_setup_new_state(CCTK_INT state_mask, char* name);
-SpaceMask_Type* SpaceMask_setup_new_type(CCTK_INT new_bits, char* type_name,
- int nstates, char** state_list,
- CCTK_INT* state_mask);
-void SpaceMask_append_type_to_registry(SpaceMask_Type* new_type);
-int SpaceMask_RegisterType(char* type_name, int nstates, char** state_list);
-int SpaceMask_AppendStatesToType(char* type_name, int nstates, char** state_list);
-CCTK_INT SpaceMask_GetTypeBits(char* type_name);
-CCTK_INT SpaceMask_GetStateBits(char* type_name, char* state_name);
-void SpaceMask_SetState(CCTK_INT* mask, int point, char* type_name, char* state);
-int SpaceMask_CheckState(CCTK_INT* mask, int point, char* type_name, char* state);
-
+/* prototypes for functions local to this file */
+static
+ int SpaceMask_get_bit_nbr(int nstates);
+static
+ CCTK_INT SpaceMask_get_free_bits(int nbits);
+static
+ CCTK_INT* SpaceMask_determine_state_mask(CCTK_INT allocated_bits,
+ int nstates);
+static
+ SpaceMask_State* SpaceMask_setup_new_state(CCTK_INT state_mask,
+ const char* name);
+static
+ SpaceMask_Type*
+ SpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name,
+ int nstates, const char* const state_list[],
+ const CCTK_INT state_mask[]);
+static
+ void SpaceMask_append_type_to_registry(SpaceMask_Type* new_type);
+
+/* prototypes for Fortran wrapper functions defined in this file */
void CCTK_FCALL CCTK_FNAME(SpaceMask_GetTypeBits)(CCTK_INT* type_bits,
ONE_FORTSTRING_ARG);
void CCTK_FCALL CCTK_FNAME(SpaceMask_GetStateBits)(CCTK_INT* state_bits,
@@ -59,7 +63,7 @@ void CCTK_FCALL CCTK_FNAME(SpaceMask_CheckState)(int* retval,
Cheesy divide-by-two method, maybe something else is quicker.
@enddesc
@@*/
-
+static
int
SpaceMask_get_bit_nbr(int nstates)
{
@@ -85,7 +89,7 @@ SpaceMask_get_bit_nbr(int nstates)
to satisfy the request, stop with an error.
@enddesc
@@*/
-
+static
CCTK_INT
SpaceMask_get_free_bits(int nbits)
{
@@ -133,7 +137,7 @@ SpaceMask_get_free_bits(int nbits)
non-zero (active) bits.
@enddesc
@@*/
-
+static
CCTK_INT*
SpaceMask_determine_state_mask(CCTK_INT allocated_bits, int nstates)
{
@@ -178,9 +182,9 @@ SpaceMask_determine_state_mask(CCTK_INT allocated_bits, int nstates)
a bit mask.
@enddesc
@@*/
-
+static
SpaceMask_State*
-SpaceMask_setup_new_state(CCTK_INT state_mask, char* name)
+SpaceMask_setup_new_state(CCTK_INT state_mask, const char* name)
{
SpaceMask_State* new_state;
@@ -202,11 +206,11 @@ SpaceMask_setup_new_state(CCTK_INT state_mask, char* name)
the requested states.
@enddesc
@@*/
-
+static
SpaceMask_Type*
-SpaceMask_setup_new_type(CCTK_INT new_bits, char* type_name,
- int nstates, char** state_list,
- CCTK_INT* state_mask)
+SpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name,
+ int nstates, const char* const state_list[],
+ const CCTK_INT state_mask[])
{
SpaceMask_Type* new_type;
int j;
@@ -232,7 +236,7 @@ SpaceMask_setup_new_type(CCTK_INT new_bits, char* type_name,
Adds a new type to the spacemask_registry.
@enddesc
@@*/
-
+static
void
SpaceMask_append_type_to_registry(SpaceMask_Type* new_type)
{
@@ -274,7 +278,8 @@ SpaceMask_append_type_to_registry(SpaceMask_Type* new_type)
@@*/
int
-SpaceMask_RegisterType(char* type_name, int nstates, char** state_list)
+SpaceMask_RegisterType(const char* type_name, int nstates,
+ const char* const state_list[])
{
SpaceMask_Type* new_type;
CCTK_INT new_bits;
@@ -306,14 +311,15 @@ SpaceMask_RegisterType(char* type_name, int nstates, char** state_list)
@@*/
int
-SpaceMask_AppendStatesToType(char* type_name, int nstates, char** state_list)
+SpaceMask_AppendStatesToType(const char* type_name, int nstates,
+ const char* const state_list[])
{
CCTK_INT new_bits;
CCTK_INT allocated_bits;
CCTK_INT* state_mask;
SpaceMask_Type* old_type;
SpaceMask_Type* new_type;
- char** new_state_list;
+ const char** new_state_list;
int i;
int j;
int old_type_idx;
@@ -346,7 +352,7 @@ SpaceMask_AppendStatesToType(char* type_name, int nstates, char** state_list)
state_mask = SpaceMask_determine_state_mask(allocated_bits, total_nstates);
- new_state_list = (char**) malloc (total_nstates*sizeof(char*));
+ new_state_list = (const char**) malloc (total_nstates*sizeof(char*));
i = 0;
for (j=0; j<old_type->nstates; ++j, ++i)
@@ -375,7 +381,7 @@ SpaceMask_AppendStatesToType(char* type_name, int nstates, char** state_list)
@@*/
CCTK_INT
-SpaceMask_GetTypeBits(char* type_name)
+SpaceMask_GetTypeBits(const char* type_name)
{
int i;
@@ -401,7 +407,7 @@ SpaceMask_GetTypeBits(char* type_name)
@@*/
CCTK_INT
-SpaceMask_GetStateBits(char* type_name, char* state_name)
+SpaceMask_GetStateBits(const char* type_name, const char* state_name)
{
SpaceMask_Type* type;
int i, j;
@@ -436,7 +442,7 @@ SpaceMask_GetStateBits(char* type_name, char* state_name)
@@*/
void
-SpaceMask_SetState(CCTK_INT* mask, int point, char* type_name, char* state)
+SpaceMask_SetState(CCTK_INT* mask, int point, const char* type_name, const char* state)
{
CCTK_INT type_bits;
CCTK_INT state_bits;
@@ -458,7 +464,7 @@ SpaceMask_SetState(CCTK_INT* mask, int point, char* type_name, char* state)
@@*/
int
-SpaceMask_CheckState(CCTK_INT* mask, int point, char* type_name, char* state)
+SpaceMask_CheckState(const CCTK_INT* mask, int point, const char* type_name, const char* state)
{
CCTK_INT type_bits;
CCTK_INT state_bits;
diff --git a/src/SpaceMask.h b/src/SpaceMask.h
index 143574a..b98cb30 100644
--- a/src/SpaceMask.h
+++ b/src/SpaceMask.h
@@ -23,12 +23,17 @@ extern "C"
{
#endif
-int SpaceMask_RegisterType(char*, int, char**);
-int SpaceMask_AppendStatesToType(char*, int, char**);
-void SpaceMask_SetState(CCTK_INT*, int, char*, char*);
-int SpaceMask_CheckState(CCTK_INT*, int, char*, char*);
-CCTK_INT SpaceMask_GetTypeBits(char*);
-CCTK_INT SpaceMask_GetStateBits(char*, char*);
+/* publicly visible routines */
+int SpaceMask_RegisterType(const char* type_name, int nstates,
+ const char* const state_list[]);
+int SpaceMask_AppendStatesToType(const char* type_name, int nstates,
+ const char* const state_list[]);
+CCTK_INT SpaceMask_GetTypeBits(const char* type_name);
+CCTK_INT SpaceMask_GetStateBits(const char* type_name, const char* state_name);
+void SpaceMask_SetState(CCTK_INT* mask, int point,
+ const char* type_name, const char* state);
+int SpaceMask_CheckState(const CCTK_INT* mask, int point,
+ const char* type_name, const char* state);
#ifdef __cplusplus
}
@@ -44,13 +49,13 @@ CCTK_INT SpaceMask_GetStateBits(char*, char*);
typedef struct
{
- char* name;
+ const char* name;
CCTK_INT bitmask;
} SpaceMask_State;
typedef struct
{
- char* name;
+ const char* name;
int nstates;
CCTK_INT bitmask;
SpaceMask_State** state_list;