MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtlib_validate_id

Function gmtlib_validate_id

src/gmt_api.c:8228–8281  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

8226
8227/*! . */
8228int gmtlib_validate_id (struct GMTAPI_CTRL *API, int family, int object_ID, int direction, int module_input) {
8229 /* Checks to see if the given object_ID is listed and of the right direction. If so
8230 * we return the item number; otherwise return GMT_NOTSET and set API->error to the error code.
8231 * Note: int arguments MAY be GMT_NOTSET, hence we use signed ints. If object_ID == GMT_NOTSET
8232 * then we only look for DATASETS. Note: module_input controls if we are being very specific
8233 * about the type of input resource. There are module inputs and option inputs. We have:
8234 * module_input = GMT_NOTSET [-1]: Do not use the resource's module_input status in determining the next ID.
8235 * module_input = GMTAPI_OPTION_INPUT [0]: Only validate resources with module_input = false.
8236 * module_input = GMTAPI_MODULE_INPUT [1]: Only validate resources with module_input = true.
8237 * Finally, since we allow vectors and matrices to masquerade as DATASETs we check for this and
8238 * re-baptize such objects to become GMT_IS_DATASETs. */
8239 unsigned int i;
8240 int item;
8241 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
8242
8243 API->error = GMT_NOERROR;
8244
8245 /* Search for the object in the active list. However, if object_ID == GMT_NOTSET we pick the first in that direction */
8246
8247 for (i = 0, item = GMT_NOTSET; item == GMT_NOTSET && i < API->n_objects; i++) {
8248 S_obj = API->object[i]; /* Shorthand only */
8249 if (!S_obj) continue; /* Empty object, skip */
8250 if (direction != GMT_NOTSET && (int)S_obj->direction != direction) continue; /* Not the requested direction */
8251 if (direction == GMT_IN && S_obj->status != GMT_IS_UNUSED && object_ID == GMT_NOTSET) continue; /* Already used this input object once */
8252 /* Preliminary checks passed, no look at family */
8253 //if (!(family == GMT_NOTSET || (int)S_obj->family == family)) { /* Not the required data type; check for exceptions... */
8254 if (family != GMT_NOTSET) { /* Was specific about the family. */
8255 if (family == GMT_IS_GRID && S_obj->actual_family == GMT_IS_MATRIX && S_obj->family != GMT_IS_DATASET)
8256 S_obj->family = GMT_IS_GRID; /* Matrix masquerading as grids is valid. Change the family here. */
8257 else if (family == GMT_IS_DATASET && (S_obj->actual_family == GMT_IS_VECTOR || S_obj->actual_family == GMT_IS_MATRIX) && !(S_obj->family == GMT_IS_GRID || S_obj->family == GMT_IS_IMAGE))
8258 S_obj->family = GMT_IS_DATASET; /* Vectors or Matrix masquerading as dataset are valid. Change their family here. */
8259 else if (family != (int)S_obj->family) /* We don't like your kind */
8260 continue;
8261 }
8262 if (object_ID == GMT_NOTSET && (int)S_obj->direction == direction) item = i; /* Pick the first object with the specified direction */
8263 if (object_ID == GMT_NOTSET && !(S_obj->family == GMT_IS_DATASET)) continue; /* Must be data/text-set */
8264 else if (direction == GMT_NOTSET && (int)S_obj->ID == object_ID) item = i; /* Pick the requested object regardless of direction */
8265 else if ((int)S_obj->ID == object_ID) item = i; /* Pick the requested object */
8266 if (item != GMT_NOTSET && direction == GMT_IN && module_input != GMT_NOTSET) { /* Must check that object's module_input status matches */
8267 bool status = (module_input == GMTAPI_MODULE_INPUT) ? true : false;
8268 if (status != S_obj->module_input) item = GMT_NOTSET; /* Not the right type of input resource */
8269 }
8270 }
8271 if (item == GMT_NOTSET) return_value (API, GMT_NOT_A_VALID_ID, GMT_NOTSET); /* No such object found */
8272
8273 /* OK, we found the object; is it the right kind (input or output)? */
8274 if (direction != GMT_NOTSET && (int)(API->object[item]->direction) != direction) {
8275 /* Passing an input object but it is listed as output, or vice versa */
8276 if (direction == GMT_IN) return_value (API, GMT_NOT_INPUT_OBJECT, GMT_NOTSET);
8277 if (direction == GMT_OUT) return_value (API, GMT_NOT_OUTPUT_OBJECT, GMT_NOTSET);
8278 }
8279 /* Here we have been successful in finding the right object */
8280 return (item);
8281}
8282
8283/*! . */
8284int gmtlib_unregister_io (struct GMTAPI_CTRL *API, int object_ID, unsigned int direction) {

Callers 15

gmtapi_retrieve_dataFunction · 0.85
gmtapi_memory_registeredFunction · 0.85
gmtapi_import_paletteFunction · 0.85
gmtapi_export_paletteFunction · 0.85
gmtapi_import_postscriptFunction · 0.85
gmtapi_export_postscriptFunction · 0.85
gmtapi_import_datasetFunction · 0.85
gmtapi_export_datasetFunction · 0.85
gmtapi_import_imageFunction · 0.85
gmtapi_export_imageFunction · 0.85
gmtapi_import_gridFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected