aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--doc/documentation.tex40
-rw-r--r--src/MaskUtils.c74
-rw-r--r--src/SpaceMask.h21
3 files changed, 76 insertions, 59 deletions
diff --git a/doc/documentation.tex b/doc/documentation.tex
index b754047..28df841 100644
--- a/doc/documentation.tex
+++ b/doc/documentation.tex
@@ -75,9 +75,10 @@ Bits of the mask are allocated to a new type using the function:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
-int SpaceMask\_RegisterType(char* \emph{type\_name}, int \emph{nstates},
- char** \emph{state\_list})
-}
+int SpaceMask\_RegisterType(const char* \emph{type\_name},
+ \\\hspace*{10mm}
+ int \emph{nstates}, const char* const \emph{state\_list}[])
+}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
\item[\emph{type\_name}] The name of the new type to be registered;
@@ -95,9 +96,10 @@ states can be added to an already allocated type using the function:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
- int SpaceMask\_AppendStatesToType(char* \emph{type\_name},
- int \emph{nstates}, char** \emph{state\_list})
-}
+int SpaceMask\_AppendStatesToType(const char* \emph{type\_name},
+ \\\hspace*{10mm}
+ int \emph{nstates}, const char* const \emph{state\_list}[])
+}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
\item[\emph{type\_name}] The name of an already registered type;
@@ -118,8 +120,9 @@ The state of the mask at a given point is set using the function:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
void SpaceMask\_SetState(CCTK\_INT* \emph{mask}, int \emph{point},
- char* \emph{type\_name}, char* \emph{state})
-}
+ \\\hspace*{10mm}
+ const char* \emph{type\_name}, const char* \emph{state})
+}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
\item[\emph{mask}] A pointer to the mask grid function;
@@ -134,9 +137,10 @@ The state of the mask at a given point can be checked using:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
-int SpaceMask\_CheckState(CCTK\_INT* \emph{mask}, int \emph{point},
- char* \emph{type\_name}, char* \emph{state})
-}
+int SpaceMask\_CheckState(const CCTK\_INT* \emph{mask}, int \emph{point},
+ \\\hspace*{10mm}
+ const char* \emph{type\_name}, const char* \emph{state})
+}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
\item[\emph{mask}] A pointer to the mask grid function;
@@ -161,7 +165,7 @@ states need to be obtained using the following functions:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
-CCTK\_INT SpaceMask\_GetTypeBits(char* \emph{type\_name})
+CCTK\_INT SpaceMask\_GetTypeBits(const char* \emph{type\_name})
}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
@@ -172,8 +176,8 @@ CCTK\_INT SpaceMask\_GetTypeBits(char* \emph{type\_name})
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
-CCTK\_INT SpaceMask\_GetStateBits(char* \emph{type\_name},
- char* \emph{state\_name})
+CCTK\_INT SpaceMask\_GetStateBits(const char* \emph{type\_name},
+ const char* \emph{state\_name})
}
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
@@ -195,7 +199,8 @@ of the mask by direct bitwise operations:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
void SpaceMask\_SetStateBits(CCTK\_INT* \emph{mask}, int \emph{point},
- CCTK\_INT \emph{type\_bits},\\\hspace*{10mm} CCTK\_INT \emph{state\_bits})
+ \\\hspace*{10mm}
+ CCTK\_INT \emph{type\_bits}, CCTK\_INT \emph{state\_bits})
}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
@@ -211,8 +216,9 @@ void SpaceMask\_SetStateBits(CCTK\_INT* \emph{mask}, int \emph{point},
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
-int SpaceMask\_CheckStateBits(CCTK\_INT* \emph{mask}, int \emph{point},
- CCTK\_INT \emph{type\_bits},\\\hspace*{10mm} CCTK\_INT \emph{state\_bits})
+int SpaceMask\_CheckStateBits(const CCTK\_INT* \emph{mask}, int \emph{point},
+ \\\hspace*{10mm}
+ CCTK\_INT \emph{type\_bits}, CCTK\_INT \emph{state\_bits})
}\\
\hspace*{10mm}\parbox{\linewidth}{
\begin{description}
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;