#include <stdlib.h>
#include "string.h"
#include "anamod.h"
Go to the source code of this file.
Data Structures | |
struct | IntArray_ |
struct | StringArray_ |
struct | AnalysisItemArray_ |
struct | AnalysisDataTypeArray_ |
Defines | |
#define | NALLOC 70 |
Functions | |
PetscErrorCode | CreateIntArray (const char *name, int size, IntArray *array) |
PetscErrorCode | DeleteIntArray (IntArray array) |
PetscErrorCode | IntArrayAdd (IntArray array, int val, int *idx) |
PetscErrorCode | IntArraySetAt (IntArray array, int idx, int val) |
PetscErrorCode | IntArrayTryGetAt (IntArray array, int idx, int *val, PetscTruth *has) |
PetscErrorCode | IntArrayGetAt (IntArray array, int idx, int *val) |
PetscErrorCode | CreateStringArray (const char *name, int size, StringArray *array) |
PetscErrorCode | DeleteStringArray (StringArray array) |
PetscErrorCode | StringArrayAdd (StringArray array, char *val, int *idx) |
PetscErrorCode | StringArrayGetFill (StringArray array, int *idx) |
PetscErrorCode | StringArraySetAt (StringArray array, int idx, char *val) |
PetscErrorCode | StringArrayTryGetAt (StringArray array, int idx, char **val, PetscTruth *has) |
PetscErrorCode | StringArrayGetAt (StringArray array, int idx, char **val) |
PetscErrorCode | CreateAnalysisItemArray (char *name, int size, AnalysisItemArray *array) |
PetscErrorCode | DeleteAnalysisItemArray (AnalysisItemArray array) |
PetscErrorCode | AnalysisItemArrayAdd (AnalysisItemArray array, AnalysisItem val, int *idx) |
PetscErrorCode | AnalysisItemArraySetAt (AnalysisItemArray array, int idx, AnalysisItem val) |
PetscErrorCode | AnalysisItemArrayTryGetAt (AnalysisItemArray array, int idx, AnalysisItem *val, PetscTruth *has) |
PetscErrorCode | AnalysisItemArrayGetAt (AnalysisItemArray array, int idx, AnalysisItem *val) |
PetscErrorCode | CreateAnalysisDataTypeArray (char *name, int size, AnalysisDataTypeArray *array) |
PetscErrorCode | DeleteAnalysisDataTypeArray (AnalysisDataTypeArray array) |
PetscErrorCode | AnalysisDataTypeArrayAdd (AnalysisDataTypeArray array, AnalysisDataType val, int *idx) |
PetscErrorCode | AnalysisDataTypeArraySetAt (AnalysisDataTypeArray array, int idx, AnalysisDataType val) |
PetscErrorCode | AnalysisDataTypeArrayTryGetAt (AnalysisDataTypeArray array, int idx, AnalysisDataType *val, PetscTruth *has) |
PetscErrorCode | AnalysisDataTypeArrayGetAt (AnalysisDataTypeArray array, int idx, AnalysisDataType *val) |
#define NALLOC 70 |
Definition at line 5 of file anamodutils.c.
Referenced by CreateAnalysisDataTypeArray(), CreateAnalysisItemArray(), CreateIntArray(), and CreateStringArray().
PetscErrorCode AnalysisDataTypeArrayAdd | ( | AnalysisDataTypeArray | array, | |
AnalysisDataType | val, | |||
int * | idx | |||
) |
Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.
Definition at line 370 of file anamodutils.c.
References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::fill, and AnalysisDataTypeArray_::has.
00371 { 00372 int ins; 00373 PetscFunctionBegin; 00374 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space"); 00375 ins = array->fill++; 00376 array->data[ins] = val; 00377 array->has[ins] = PETSC_TRUE; 00378 PetscFunctionReturn(0); 00379 }
PetscErrorCode AnalysisDataTypeArrayGetAt | ( | AnalysisDataTypeArray | array, | |
int | idx, | |||
AnalysisDataType * | val | |||
) |
As AnalysisDataTypeArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.
Definition at line 422 of file anamodutils.c.
References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, and AnalysisDataTypeArray_::has.
00423 { 00424 PetscFunctionBegin; 00425 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00426 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx); 00427 *val = array->data[idx]; 00428 PetscFunctionReturn(0); 00429 }
PetscErrorCode AnalysisDataTypeArraySetAt | ( | AnalysisDataTypeArray | array, | |
int | idx, | |||
AnalysisDataType | val | |||
) |
Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.
Definition at line 386 of file anamodutils.c.
References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::fill, and AnalysisDataTypeArray_::has.
Referenced by InstantiateFeatureSet().
00387 { 00388 PetscFunctionBegin; 00389 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00390 array->data[idx] = val; array->has[idx] = PETSC_TRUE; 00391 if (idx>array->fill) array->fill = idx; 00392 PetscFunctionReturn(0); 00393 }
PetscErrorCode AnalysisDataTypeArrayTryGetAt | ( | AnalysisDataTypeArray | array, | |
int | idx, | |||
AnalysisDataType * | val, | |||
PetscTruth * | has | |||
) |
Retrieve data from a given index.
Arguments:
array
: the AnalysisDataTypeArray objectidx
: the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reportedval
(output) : the value retrieved. This argument is allowed to be null.has
(output) : true if a value was stored at this index. This argument is allowed to be null. Definition at line 408 of file anamodutils.c.
References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, and AnalysisDataTypeArray_::has.
00409 { 00410 PetscFunctionBegin; 00411 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00412 if (has) *has = (PetscTruth)array->has[idx]; 00413 if (array->has[idx] && val) *val = array->data[idx]; 00414 PetscFunctionReturn(0); 00415 }
PetscErrorCode AnalysisItemArrayAdd | ( | AnalysisItemArray | array, | |
AnalysisItem | val, | |||
int * | idx | |||
) |
Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.
Definition at line 266 of file anamodutils.c.
References AnalysisItemArray_::alloc, AnalysisItemArray_::data, AnalysisItemArray_::fill, and AnalysisItemArray_::has.
00267 { 00268 int ins; 00269 PetscFunctionBegin; 00270 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space"); 00271 ins = array->fill++; 00272 array->data[ins] = val; 00273 array->has[ins] = PETSC_TRUE; 00274 PetscFunctionReturn(0); 00275 }
PetscErrorCode AnalysisItemArrayGetAt | ( | AnalysisItemArray | array, | |
int | idx, | |||
AnalysisItem * | val | |||
) |
As AnalysisItemArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.
Definition at line 318 of file anamodutils.c.
References AnalysisItemArray_::alloc, AnalysisItemArray_::data, and AnalysisItemArray_::has.
00319 { 00320 PetscFunctionBegin; 00321 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00322 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx); 00323 *val = array->data[idx]; 00324 PetscFunctionReturn(0); 00325 }
PetscErrorCode AnalysisItemArraySetAt | ( | AnalysisItemArray | array, | |
int | idx, | |||
AnalysisItem | val | |||
) |
Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.
Definition at line 282 of file anamodutils.c.
References AnalysisItemArray_::alloc, AnalysisItemArray_::data, AnalysisItemArray_::fill, and AnalysisItemArray_::has.
Referenced by InstantiateFeatureSet().
00283 { 00284 PetscFunctionBegin; 00285 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00286 array->data[idx] = val; array->has[idx] = PETSC_TRUE; 00287 if (idx>array->fill) array->fill = idx; 00288 PetscFunctionReturn(0); 00289 }
PetscErrorCode AnalysisItemArrayTryGetAt | ( | AnalysisItemArray | array, | |
int | idx, | |||
AnalysisItem * | val, | |||
PetscTruth * | has | |||
) |
Retrieve data from a given index.
Arguments:
array
: the AnalysisItemArray objectidx
: the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reportedval
(output) : the value retrieved. This argument is allowed to be null.has
(output) : true if a value was stored at this index. This argument is allowed to be null. Definition at line 304 of file anamodutils.c.
References AnalysisItemArray_::alloc, AnalysisItemArray_::data, and AnalysisItemArray_::has.
Referenced by GetFeatureValue().
00305 { 00306 PetscFunctionBegin; 00307 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00308 if (has) *has = (PetscTruth)array->has[idx]; 00309 if (array->has[idx] && val) *val = array->data[idx]; 00310 PetscFunctionReturn(0); 00311 }
PetscErrorCode CreateAnalysisDataTypeArray | ( | char * | name, | |
int | size, | |||
AnalysisDataTypeArray * | array | |||
) |
Definition at line 336 of file anamodutils.c.
References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::fill, AnalysisDataTypeArray_::has, NALLOC, and AnalysisDataTypeArray_::name.
Referenced by NewFeatureValues().
00337 { 00338 AnalysisDataTypeArray anew; PetscErrorCode ierr; 00339 PetscFunctionBegin; 00340 ierr = PetscMalloc(sizeof(struct AnalysisDataTypeArray_),&anew); CHKERRQ(ierr); 00341 ierr = PetscMemzero(anew,sizeof(struct AnalysisDataTypeArray_)); CHKERRQ(ierr); 00342 if (name) anew->name = strdup(name); 00343 anew->fill = 0; anew->alloc = NALLOC; 00344 ierr = PetscMalloc(anew->alloc*sizeof(PetscTruth),&(anew->has)); CHKERRQ(ierr); 00345 ierr = PetscMemzero(anew->has,anew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr); 00346 ierr = PetscMalloc(anew->alloc*sizeof(AnalysisDataType),&(anew->data)); CHKERRQ(ierr); 00347 ierr = PetscMemzero(anew->data,anew->alloc*sizeof(AnalysisDataType)); CHKERRQ(ierr); 00348 *array = anew; 00349 PetscFunctionReturn(0); 00350 }
PetscErrorCode CreateAnalysisItemArray | ( | char * | name, | |
int | size, | |||
AnalysisItemArray * | array | |||
) |
Definition at line 232 of file anamodutils.c.
References AnalysisItemArray_::alloc, AnalysisItemArray_::data, AnalysisItemArray_::fill, AnalysisItemArray_::has, NALLOC, and AnalysisItemArray_::name.
Referenced by NewFeatureValues().
00233 { 00234 AnalysisItemArray anew; PetscErrorCode ierr; 00235 PetscFunctionBegin; 00236 ierr = PetscMalloc(sizeof(struct AnalysisItemArray_),&anew); CHKERRQ(ierr); 00237 ierr = PetscMemzero(anew,sizeof(struct AnalysisItemArray_)); CHKERRQ(ierr); 00238 if (name) anew->name = strdup(name); 00239 anew->fill = 0; anew->alloc = NALLOC; 00240 ierr = PetscMalloc(anew->alloc*sizeof(PetscTruth),&(anew->has)); CHKERRQ(ierr); 00241 ierr = PetscMemzero(anew->has,anew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr); 00242 ierr = PetscMalloc(anew->alloc*sizeof(AnalysisItem),&(anew->data)); CHKERRQ(ierr); 00243 ierr = PetscMemzero(anew->data,anew->alloc*sizeof(AnalysisItem)); CHKERRQ(ierr); 00244 *array = anew; 00245 PetscFunctionReturn(0); 00246 }
PetscErrorCode CreateIntArray | ( | const char * | name, | |
int | size, | |||
IntArray * | array | |||
) |
Definition at line 13 of file anamodutils.c.
References IntArray_::alloc, IntArray_::data, IntArray_::fill, IntArray_::has, NALLOC, and IntArray_::name.
Referenced by NewFeatureSet().
00014 { 00015 IntArray inew; PetscErrorCode ierr; 00016 PetscFunctionBegin; 00017 ierr = PetscMalloc(sizeof(struct IntArray_),&inew); CHKERRQ(ierr); 00018 ierr = PetscMemzero(inew,sizeof(struct IntArray_)); CHKERRQ(ierr); 00019 if (name) inew->name = strdup(name); 00020 inew->fill = 0; inew->alloc = NALLOC; 00021 ierr = PetscMalloc(inew->alloc*sizeof(PetscTruth),&(inew->has)); CHKERRQ(ierr); 00022 ierr = PetscMemzero(inew->has,inew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr); 00023 ierr = PetscMalloc(inew->alloc*sizeof(int),&(inew->data)); CHKERRQ(ierr); 00024 ierr = PetscMemzero(inew->data,inew->alloc*sizeof(int)); CHKERRQ(ierr); 00025 *array = inew; 00026 PetscFunctionReturn(0); 00027 }
PetscErrorCode CreateStringArray | ( | const char * | name, | |
int | size, | |||
StringArray * | array | |||
) |
Definition at line 117 of file anamodutils.c.
References StringArray_::alloc, StringArray_::data, StringArray_::fill, StringArray_::has, NALLOC, and StringArray_::name.
Referenced by NewFeatureSet().
00118 { 00119 StringArray snew; PetscErrorCode ierr; 00120 PetscFunctionBegin; 00121 ierr = PetscMalloc(sizeof(struct StringArray_),&snew); CHKERRQ(ierr); 00122 ierr = PetscMemzero(snew,sizeof(struct StringArray_)); CHKERRQ(ierr); 00123 if (name) snew->name = strdup(name); 00124 snew->fill = 0; snew->alloc = NALLOC; 00125 ierr = PetscMalloc(snew->alloc*sizeof(PetscTruth),&(snew->has)); CHKERRQ(ierr); 00126 ierr = PetscMemzero(snew->has,snew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr); 00127 ierr = PetscMalloc(snew->alloc*sizeof(char*),&(snew->data)); CHKERRQ(ierr); 00128 ierr = PetscMemzero(snew->data,snew->alloc*sizeof(char*)); CHKERRQ(ierr); 00129 *array = snew; 00130 PetscFunctionReturn(0); 00131 }
PetscErrorCode DeleteAnalysisDataTypeArray | ( | AnalysisDataTypeArray | array | ) |
Definition at line 354 of file anamodutils.c.
References AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::has, and AnalysisDataTypeArray_::name.
Referenced by DeleteFeatureValues().
00355 { 00356 PetscErrorCode ierr; 00357 PetscFunctionBegin; 00358 ierr = PetscFree(array->data); CHKERRQ(ierr); 00359 ierr = PetscFree(array->has); CHKERRQ(ierr); 00360 if (array->name) free(array->name); 00361 ierr = PetscFree(array); CHKERRQ(ierr); 00362 PetscFunctionReturn(0); 00363 }
PetscErrorCode DeleteAnalysisItemArray | ( | AnalysisItemArray | array | ) |
Definition at line 250 of file anamodutils.c.
References AnalysisItemArray_::data, AnalysisItemArray_::has, and AnalysisItemArray_::name.
Referenced by DeleteFeatureValues().
00251 { 00252 PetscErrorCode ierr; 00253 PetscFunctionBegin; 00254 ierr = PetscFree(array->data); CHKERRQ(ierr); 00255 ierr = PetscFree(array->has); CHKERRQ(ierr); 00256 if (array->name) free(array->name); 00257 ierr = PetscFree(array); CHKERRQ(ierr); 00258 PetscFunctionReturn(0); 00259 }
PetscErrorCode DeleteIntArray | ( | IntArray | array | ) |
Definition at line 31 of file anamodutils.c.
References IntArray_::data, IntArray_::has, and IntArray_::name.
Referenced by DeleteFeatureSet().
00032 { 00033 PetscErrorCode ierr; 00034 PetscFunctionBegin; 00035 ierr = PetscFree(array->data); CHKERRQ(ierr); 00036 ierr = PetscFree(array->has); CHKERRQ(ierr); 00037 if (array->name) free(array->name); 00038 ierr = PetscFree(array); CHKERRQ(ierr); 00039 PetscFunctionReturn(0); 00040 }
PetscErrorCode DeleteStringArray | ( | StringArray | array | ) |
Definition at line 135 of file anamodutils.c.
References StringArray_::data, StringArray_::fill, StringArray_::has, and StringArray_::name.
Referenced by DeleteFeatureSet().
00136 { 00137 int i; PetscErrorCode ierr; 00138 PetscFunctionBegin; 00139 for (i=0; i<array->fill; i++) 00140 if (array->has[i]) free(array->data[i]); 00141 ierr = PetscFree(array->data); CHKERRQ(ierr); 00142 ierr = PetscFree(array->has); CHKERRQ(ierr); 00143 if (array->name) free(array->name); 00144 ierr = PetscFree(array); CHKERRQ(ierr); 00145 PetscFunctionReturn(0); 00146 }
PetscErrorCode IntArrayAdd | ( | IntArray | array, | |
int | val, | |||
int * | idx | |||
) |
Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.
Definition at line 47 of file anamodutils.c.
References IntArray_::alloc, IntArray_::data, IntArray_::fill, and IntArray_::has.
00048 { 00049 int ins; 00050 PetscFunctionBegin; 00051 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space"); 00052 ins = array->fill++; 00053 array->data[ins] = val; 00054 array->has[ins] = PETSC_TRUE; 00055 PetscFunctionReturn(0); 00056 }
PetscErrorCode IntArrayGetAt | ( | IntArray | array, | |
int | idx, | |||
int * | val | |||
) |
As IntArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.
Definition at line 99 of file anamodutils.c.
References IntArray_::alloc, IntArray_::data, and IntArray_::has.
00100 { 00101 PetscFunctionBegin; 00102 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00103 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx); 00104 *val = array->data[idx]; 00105 PetscFunctionReturn(0); 00106 }
PetscErrorCode IntArraySetAt | ( | IntArray | array, | |
int | idx, | |||
int | val | |||
) |
Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.
Definition at line 63 of file anamodutils.c.
References IntArray_::alloc, IntArray_::data, IntArray_::fill, and IntArray_::has.
00064 { 00065 PetscFunctionBegin; 00066 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00067 array->data[idx] = val; array->has[idx] = PETSC_TRUE; 00068 if (idx>array->fill) array->fill = idx; 00069 PetscFunctionReturn(0); 00070 }
PetscErrorCode IntArrayTryGetAt | ( | IntArray | array, | |
int | idx, | |||
int * | val, | |||
PetscTruth * | has | |||
) |
Retrieve data from a given index.
Arguments:
array
: the IntArray objectidx
: the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reportedval
(output) : the value retrieved. This argument is allowed to be null.has
(output) : true if a value was stored at this index. This argument is allowed to be null. Definition at line 85 of file anamodutils.c.
References IntArray_::alloc, IntArray_::data, and IntArray_::has.
00086 { 00087 PetscFunctionBegin; 00088 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00089 if (has) *has = array->has[idx]; 00090 if (array->has[idx] && val) *val = array->data[idx]; 00091 PetscFunctionReturn(0); 00092 }
PetscErrorCode StringArrayAdd | ( | StringArray | array, | |
char * | val, | |||
int * | idx | |||
) |
Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.
Definition at line 153 of file anamodutils.c.
References StringArray_::alloc, StringArray_::data, StringArray_::fill, and StringArray_::has.
Referenced by AddToFeatureSet().
00154 { 00155 int ins; 00156 PetscFunctionBegin; 00157 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space"); 00158 ins = array->fill++; 00159 array->data[ins] = strdup(val); 00160 array->has[ins] = PETSC_TRUE; 00161 PetscFunctionReturn(0); 00162 }
PetscErrorCode StringArrayGetAt | ( | StringArray | array, | |
int | idx, | |||
char ** | val | |||
) |
As StringArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.
Definition at line 214 of file anamodutils.c.
References StringArray_::alloc, StringArray_::data, and StringArray_::has.
Referenced by InstantiateFeatureSet().
00215 { 00216 PetscFunctionBegin; 00217 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00218 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx); 00219 *val = array->data[idx]; 00220 PetscFunctionReturn(0); 00221 }
PetscErrorCode StringArrayGetFill | ( | StringArray | array, | |
int * | idx | |||
) |
Definition at line 166 of file anamodutils.c.
References StringArray_::fill.
Referenced by InstantiateFeatureSet().
00167 { 00168 PetscFunctionBegin; 00169 *idx = array->fill; 00170 PetscFunctionReturn(0); 00171 }
PetscErrorCode StringArraySetAt | ( | StringArray | array, | |
int | idx, | |||
char * | val | |||
) |
Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.
Definition at line 178 of file anamodutils.c.
References StringArray_::alloc, StringArray_::data, StringArray_::fill, and StringArray_::has.
00179 { 00180 PetscFunctionBegin; 00181 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00182 array->data[idx] = strdup(val); array->has[idx] = PETSC_TRUE; 00183 if (idx>array->fill) array->fill = idx; 00184 PetscFunctionReturn(0); 00185 }
PetscErrorCode StringArrayTryGetAt | ( | StringArray | array, | |
int | idx, | |||
char ** | val, | |||
PetscTruth * | has | |||
) |
Retrieve data from a given index.
Arguments:
array
: the StringArray objectidx
: the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reportedval
(output) : the value retrieved. This argument is allowed to be null.has
(output) : true if a value was stored at this index. This argument is allowed to be null. Definition at line 200 of file anamodutils.c.
References StringArray_::alloc, StringArray_::data, and StringArray_::has.
00201 { 00202 PetscFunctionBegin; 00203 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx); 00204 if (has) *has = array->has[idx]; 00205 if (array->has[idx] && val) *val = array->data[idx]; 00206 PetscFunctionReturn(0); 00207 }