Doxygen Source Code Documentation
niml_registry.c File Reference
#include "niml_private.h"
Go to the source code of this file.
Data Structures | |
struct | registry_entry |
Defines | |
#define | INLINE |
#define | NIREG_PRIVATE_MALLOC (1<<0) |
#define | NIREG_isprivate(rr) (((rr)->flags & NIREG_PRIVATE_MALLOC) != 0) |
#define | NIREG_free(rr) |
Functions | |
INLINE void | vpt_to_char (void *vpt, char *cpt) |
INLINE void * | char_to_vpt (char *cpt) |
void | init_registry (void) |
void * | NI_registry_malloc (char *idcode, char *name, size_t len) |
void * | NI_registry_add (char *idcode, char *name, void *vpt) |
void * | NI_registry_realloc (void *vpt, size_t newlen) |
void * | NI_registry_replace (void *vpt, void *vpt_new) |
void | NI_registry_free (void *vpt) |
void * | NI_registry_idcode_to_ptr (char *idcode) |
size_t | NI_registry_idcode_to_len (char *idcode) |
size_t | NI_registry_ptr_to_len (void *vpt) |
char * | NI_registry_idcode_to_name (char *idcode) |
char * | NI_registry_ptr_to_idcode (void *vpt) |
char * | NI_registry_ptr_to_name (void *vpt) |
void | NI_registry_idcode_altername (char *idcode, char *newname) |
void | NI_registry_ptr_altername (void *vpt, char *newname) |
Variables | |
Htable * | registry_htable_idc = NULL |
Htable * | registry_htable_ipt = NULL |
Define Documentation
|
Definition at line 7 of file niml_registry.c. Referenced by char_to_vpt(), and vpt_to_char(). |
|
Value: do{ if( !NIREG_isprivate(rr) ) free( (rr)->vpt ) ; \ free((void *)(rr)->name) ; \ free((void *)(rr)) ; \ } while(0) Definition at line 31 of file niml_registry.c. Referenced by NI_registry_free(). |
|
Definition at line 28 of file niml_registry.c. Referenced by NI_registry_realloc(), and NI_registry_replace(). |
|
Definition at line 25 of file niml_registry.c. Referenced by NI_registry_add(), and NI_registry_replace(). |
Function Documentation
|
Convert string representation to a pointer; this is the inverse function to vpt_to_char(). Definition at line 55 of file niml_registry.c. References INLINE.
00056 { 00057 void *vpt=NULL ; 00058 if( cpt == NULL ) return NULL ; 00059 sscanf(cpt,"%p",&vpt) ; 00060 return vpt ; 00061 } |
|
Create the (empty) underlying hash tables for indexing the list of registry elements. Definition at line 67 of file niml_registry.c. References new_Htable(). Referenced by NI_registry_add(), and NI_registry_malloc().
00068 { 00069 if( registry_htable_ipt == NULL ){ 00070 registry_htable_idc = new_Htable(131) ; 00071 registry_htable_ipt = new_Htable(131) ; 00072 } 00073 return ; 00074 } |
|
Associate a given pointer (non-NULL) with idcode and name string.
Definition at line 138 of file niml_registry.c. References addto_Htable(), calloc, findin_Htable(), registry_entry::flags, registry_entry::idc, init_registry(), registry_entry::ipt, registry_entry::name, name, NI_strncpy(), NIREG_PRIVATE_MALLOC, registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00139 { 00140 void *xpt ; 00141 registry_entry *rent ; /* pay this or be evicted */ 00142 00143 init_registry() ; /* setup empty hash tables, if needed */ 00144 00145 if( idcode == NULL || *idcode == '\0' || vpt == NULL ) return NULL ; 00146 00147 /* check to see if already have this idcode */ 00148 00149 xpt = findin_Htable( idcode , registry_htable_idc ) ; 00150 if( xpt != NULL ) return NULL ; /* bad */ 00151 00152 /* make the registry entry for this doohicky */ 00153 00154 rent = calloc(1,sizeof(registry_entry)) ; 00155 NI_strncpy( rent->idc , idcode , 32 ) ; /* copy idcode */ 00156 rent->vpt = vpt ; /* copy data pointer */ 00157 rent->vlen = 0 ; /* set length */ 00158 vpt_to_char( vpt , rent->ipt ) ; /* string version of data pointer */ 00159 if( name == NULL ) name = "\0" ; 00160 rent->name = strdup(name) ; /* copy name */ 00161 rent->flags = NIREG_PRIVATE_MALLOC ; /* init flags */ 00162 00163 /* and index this new registry entry under the idcode and the pointer */ 00164 00165 addto_Htable( rent->idc , (void *)rent , registry_htable_idc ) ; 00166 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ; 00167 00168 return vpt ; /* give the user the pointer he asked for */ 00169 } |
|
Definition at line 256 of file niml_registry.c. References findin_Htable(), registry_entry::idc, registry_entry::ipt, NIREG_free, removefrom_Htable(), and vpt_to_char().
00257 { 00258 char ipt[32] ; 00259 registry_entry *rent ; 00260 00261 if( vpt == NULL || registry_htable_ipt == NULL ) return ; 00262 00263 /* look for the pointer in the index */ 00264 00265 vpt_to_char( vpt , ipt ) ; 00266 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00267 if( rent == NULL ) return ; /* stupid users must be punished somehow */ 00268 00269 removefrom_Htable( rent->ipt , registry_htable_ipt ) ; 00270 removefrom_Htable( rent->idc , registry_htable_idc ) ; 00271 NIREG_free( rent ) ; 00272 return ; 00273 } |
|
Given an idcode, modify the name string that goes with it. Definition at line 373 of file niml_registry.c. References findin_Htable(), free, and registry_entry::name.
00374 { 00375 registry_entry *rent ; 00376 00377 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ; 00378 if( rent == NULL ) return ; 00379 free((void *)rent->name) ; 00380 if( newname == NULL ) newname = "\0" ; 00381 rent->name = strdup(newname) ; 00382 return ; 00383 } |
|
Given an idcode, get the data length that goes with it. Note that 0 is returned if the data ptr was setup with len=0 OR* if the idcode can't be found in the registry. --------------------------------------------------------------------- Definition at line 293 of file niml_registry.c. References findin_Htable(), and registry_entry::vlen.
00294 { 00295 registry_entry *rent ; 00296 00297 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ; 00298 if( rent == NULL ) return 0 ; 00299 return rent->vlen ; 00300 } |
|
Given an idcode, get the name string that went with it. This is the pointer into the internal registry_entry struct, so don't modify it! --------------------------------------------------------------------- Definition at line 327 of file niml_registry.c. References findin_Htable(), and registry_entry::name.
00328 { 00329 registry_entry *rent ; 00330 00331 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ; 00332 if( rent == NULL ) return NULL ; 00333 return rent->name ; 00334 } |
|
Given an idcode, get the data pointer that goes with it. Definition at line 278 of file niml_registry.c. References findin_Htable(), and registry_entry::vpt.
00279 { 00280 registry_entry *rent ; 00281 00282 rent = (registry_entry *) findin_Htable( idcode , registry_htable_idc ) ; 00283 if( rent == NULL ) return NULL ; 00284 return rent->vpt ; 00285 } |
|
Allocate memory with calloc(), and associate it with a given idcode and name string.
Definition at line 87 of file niml_registry.c. References addto_Htable(), calloc, findin_Htable(), registry_entry::flags, registry_entry::idc, init_registry(), registry_entry::ipt, registry_entry::name, name, NI_strncpy(), registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00088 { 00089 void *vpt ; 00090 int lll ; 00091 registry_entry *rent ; /* pay this or be evicted */ 00092 00093 init_registry() ; /* setup empty hash tables, if needed */ 00094 00095 if( idcode == NULL || *idcode == '\0' ) return NULL ; 00096 00097 /* check to see if already have this idcode */ 00098 00099 vpt = findin_Htable( idcode , registry_htable_idc ) ; 00100 if( vpt != NULL ) return NULL ; /* bad */ 00101 00102 /* allocate space for result of this function */ 00103 00104 lll = (len == 0) ? 4 : len ; 00105 vpt = calloc(1,lll) ; 00106 if( vpt == NULL ) return NULL ; /* bad */ 00107 00108 if( len == 0 ){ char *cpt=(char *)vpt; *cpt = '\0'; } 00109 00110 /* make the registry entry for this doohicky */ 00111 00112 rent = calloc(1,sizeof(registry_entry)) ; 00113 NI_strncpy( rent->idc , idcode , 32 ) ; /* copy idcode */ 00114 rent->vpt = vpt ; /* copy data pointer */ 00115 rent->vlen = len ; /* save length */ 00116 vpt_to_char( vpt , rent->ipt ) ; /* string version of data pointer */ 00117 if( name == NULL ) name = "\0" ; 00118 rent->name = strdup(name) ; /* copy name */ 00119 rent->flags = 0 ; /* init flags */ 00120 00121 /* and index this new registry entry under the idcode and the pointer */ 00122 00123 addto_Htable( rent->idc , (void *)rent , registry_htable_idc ) ; 00124 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ; 00125 00126 return vpt ; /* give the user the pointer he asked for */ 00127 } |
|
Given a data pointer, alter the name string that goes with it. Definition at line 388 of file niml_registry.c. References findin_Htable(), free, registry_entry::name, and vpt_to_char().
00389 { 00390 char ipt[32] ; 00391 registry_entry *rent ; 00392 00393 if( vpt == NULL || registry_htable_ipt == NULL ) return ; 00394 00395 vpt_to_char( vpt , ipt ) ; 00396 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00397 if( rent == NULL ) return ; 00398 free((void *)rent->name) ; 00399 if( newname == NULL ) newname = "\0" ; 00400 rent->name = strdup(newname) ; 00401 return ; 00402 } |
|
Given a data pointer, return a pointer to the idcode that corresponds. Don't modify this! --------------------------------------------------------------------- Definition at line 341 of file niml_registry.c. References findin_Htable(), registry_entry::idc, and vpt_to_char().
00342 { 00343 char ipt[32] ; 00344 registry_entry *rent ; 00345 00346 if( vpt == NULL || registry_htable_ipt == NULL ) return ; 00347 00348 vpt_to_char( vpt , ipt ) ; 00349 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00350 if( rent == NULL ) return ; 00351 return rent->idc ; 00352 } |
|
Given a data pointer, get the data length that goes with it. Note that 0 is returned if the data ptr was setup with len=0 OR* if the data ptr can't be found in the registry. --------------------------------------------------------------------- Definition at line 308 of file niml_registry.c. References findin_Htable(), registry_entry::vlen, and vpt_to_char().
00309 { 00310 char ipt[32] ; 00311 registry_entry *rent ; 00312 00313 if( vpt == NULL || registry_htable_ipt == NULL ) return ; 00314 00315 vpt_to_char( vpt , ipt ) ; 00316 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00317 if( rent == NULL ) return 0 ; 00318 return rent->vlen ; 00319 } |
|
Given a data pointer, get the name string that corresponds. Definition at line 357 of file niml_registry.c. References findin_Htable(), registry_entry::name, and vpt_to_char().
00358 { 00359 char ipt[32] ; 00360 registry_entry *rent ; 00361 00362 if( vpt == NULL || registry_htable_ipt == NULL ) return ; 00363 00364 vpt_to_char( vpt , ipt ) ; 00365 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00366 if( rent == NULL ) return ; 00367 return rent->name ; 00368 } |
|
Like realloc(), but also updates the indexes.
Definition at line 182 of file niml_registry.c. References addto_Htable(), findin_Htable(), registry_entry::ipt, NIREG_isprivate, realloc, removefrom_Htable(), registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00183 { 00184 char ipt[32] ; 00185 void *vpt_new ; 00186 int lll ; 00187 registry_entry *rent ; 00188 00189 if( vpt == NULL || registry_htable_ipt == NULL ) return NULL ; 00190 00191 /* look up the pointer in the index */ 00192 00193 vpt_to_char( vpt , ipt ) ; 00194 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00195 if( rent == NULL ) return NULL ; /* not found!? */ 00196 if( NIREG_isprivate(rent) ) return NULL ; /* bad user */ 00197 00198 lll = (newlen == 0) ? 4 : newlen ; 00199 vpt_new = realloc( vpt , lll ) ; /* get new allocation */ 00200 if( vpt_new == NULL ) return NULL ; /* bad */ 00201 if( vpt_new == vpt ) return vpt ; /* no change! */ 00202 00203 /* remove the pointer-based entry from the index, 00204 then make a new pointer index */ 00205 00206 removefrom_Htable( ipt , registry_htable_ipt ) ; 00207 00208 rent->vpt = vpt_new ; 00209 rent->vlen = newlen ; 00210 vpt_to_char( vpt , rent->ipt ) ; 00211 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ; 00212 00213 return vpt_new ; /* give back the new pointer */ 00214 } |
|
For something added with NI_registry_add(), lets you replace the pointer with some other pointer. --------------------------------------------------------------------- Definition at line 221 of file niml_registry.c. References addto_Htable(), findin_Htable(), registry_entry::flags, free, registry_entry::ipt, NIREG_isprivate, NIREG_PRIVATE_MALLOC, removefrom_Htable(), registry_entry::vlen, registry_entry::vpt, and vpt_to_char().
00222 { 00223 char ipt[32] ; 00224 registry_entry *rent ; 00225 00226 if( vpt == NULL || vpt_new == NULL || 00227 registry_htable_ipt == NULL ) return NULL ; 00228 00229 if( vpt == vpt_new ) return vpt ; 00230 00231 /* look up the pointer in the index */ 00232 00233 vpt_to_char( vpt , ipt ) ; 00234 rent = (registry_entry *) findin_Htable( ipt , registry_htable_ipt ) ; 00235 if( rent == NULL ) return NULL ; /* not found!? */ 00236 00237 if( !NIREG_isprivate(rent) ) free((void *)vpt) ; 00238 00239 /* remove the pointer-based entry from the index, 00240 then make a new pointer index */ 00241 00242 removefrom_Htable( ipt , registry_htable_ipt ) ; 00243 00244 rent->vpt = vpt_new ; 00245 rent->vlen = 0 ; /* len is unknown here */ 00246 vpt_to_char( vpt , rent->ipt ) ; 00247 addto_Htable( rent->ipt , (void *)rent , registry_htable_ipt ) ; 00248 rent->flags = NIREG_PRIVATE_MALLOC ; 00249 00250 return vpt_new ; /* give back the new pointer */ 00251 } |
|
Convert pointer to a string representation. Definition at line 46 of file niml_registry.c. References INLINE. Referenced by NI_registry_add(), NI_registry_free(), NI_registry_malloc(), NI_registry_ptr_altername(), NI_registry_ptr_to_idcode(), NI_registry_ptr_to_len(), NI_registry_ptr_to_name(), NI_registry_realloc(), and NI_registry_replace().
00047 {
00048 sprintf( cpt , "%p" , vpt ) ;
00049 }
|
Variable Documentation
|
Definition at line 40 of file niml_registry.c. |
|
Definition at line 41 of file niml_registry.c. |