diff options
author | pollney <pollney@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e> | 2003-05-26 07:28:49 +0000 |
---|---|---|
committer | pollney <pollney@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e> | 2003-05-26 07:28:49 +0000 |
commit | 22b8b80801ec209e4e3006e6be2de62e1f90a7ce (patch) | |
tree | da0920f8f667789022132f5487269c953a331098 /src | |
parent | 0481cfb5f8b8f4fa31ae5aeecb9b636053c2c904 (diff) |
Added SpaceMask_GetMaskBitsList() function, which returns an ordered
list of all the bitmasks associated with each state of a given type.
Also allowed for passing a NULL as the list of state names on registry,
in which case the mask states are allocated but not named.
These additions make it easier to allocate a mask bitfield of a size
that might only be known at runtime.
More routines for working with mask states as integers might be useful
in the future.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/SpaceMask/trunk@31 a491c6a4-70bf-4b89-8b36-d6c0cb1f094e
Diffstat (limited to 'src')
-rw-r--r-- | src/MaskUtils.c | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/src/MaskUtils.c b/src/MaskUtils.c index 784f5b0..1394267 100644 --- a/src/MaskUtils.c +++ b/src/MaskUtils.c @@ -229,9 +229,19 @@ SpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name, new_type->state_list = (SpaceMask_State**) malloc (nstates*sizeof(SpaceMask_State*)); - for (j=0; j<nstates; ++j) - new_type->state_list[j] = SpaceMask_setup_new_state(state_mask[j], - state_list[j]); + if (state_list==NULL) + { + for (j=0; j<nstates; ++j) + new_type->state_list[j] = SpaceMask_setup_new_state(state_mask[j], + NULL); + } + else + { + for (j=0; j<nstates; ++j) + new_type->state_list[j] = SpaceMask_setup_new_state(state_mask[j], + state_list[j]); + } + return new_type; } @@ -292,7 +302,7 @@ SpaceMask_RegisterType(const char* type_name, int nstates, CCTK_INT new_bits; CCTK_INT* state_mask; int bit_nbr; - + bit_nbr = SpaceMask_get_bit_nbr(nstates); new_bits = SpaceMask_get_free_bits(bit_nbr); @@ -454,6 +464,46 @@ SpaceMask_GetStateBits(const char* type_name, const char* state_name) } /*@@ + @routine SpaceMask_GetStateBitsList + @author Denis Pollney + @date 25 May 2003 + @desc + Returns a list of all of the state masks allocated + for a given type. The number of elements in the list + is equal to the number of states of the type. + If the type name is not recognised, NULL is returned. + @enddesc +@@*/ + +CCTK_INT* +SpaceMask_GetStateBitsList(const char* type_name) +{ + SpaceMask_Type* type; + CCTK_INT* state_bits_list; + int i, j; + + for (i=0; i<spacemask_registry->ntypes; ++i) + { + if (!strcmp(spacemask_registry->type_list[i]->name, type_name)) + { + type = spacemask_registry->type_list[i]; + state_bits_list = (CCTK_INT*) + malloc (sizeof(CCTK_INT)*(type->nstates)); + + for (j=0; j<type->nstates; ++j) + state_bits_list[j] = type->state_list[j]->bitmask; + + return state_bits_list; + } + } + + CCTK_VInfo (CCTK_THORNSTRING, + "Requested type \"%s\" could not be found\n", type_name); + + return NULL; +} + +/*@@ @routine SpaceMask_SetState @author Denis Pollney @date 15 October 2002 @@ -484,7 +534,7 @@ SpaceMask_SetState(CCTK_INT* mask, int point, const char* type_name, const char* @enddesc @@*/ -int +CCTK_INT SpaceMask_CheckState(const CCTK_INT* mask, int point, const char* type_name, const char* state) { CCTK_INT type_bits; @@ -496,6 +546,7 @@ SpaceMask_CheckState(const CCTK_INT* mask, int point, const char* type_name, con return SpaceMask_CheckStateBits(mask, point, type_bits, state_bits); } + /******************************************************************** ********************* Fortran Wrappers *************************** ********************************************************************/ |