Changeset 12289
- Timestamp:
- Mar 6, 2007, 4:50:15 PM (19 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 12 edited
-
psArguments.c (modified) (5 diffs)
-
psArray.c (modified) (13 diffs)
-
psHash.c (modified) (17 diffs)
-
psHash.h (modified) (3 diffs)
-
psList.c (modified) (22 diffs)
-
psList.h (modified) (5 diffs)
-
psLookupTable.h (modified) (5 diffs)
-
psMetadata.c (modified) (2 diffs)
-
psMetadataConfig.c (modified) (12 diffs)
-
psMetadataItemParse.c (modified) (10 diffs)
-
psPixels.c (modified) (14 diffs)
-
psPixels.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psArguments.c
r11686 r12289 7 7 * @author David Robbins, MHPCC 8 8 * 9 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-0 2-07 23:52:54$9 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-03-07 02:50:15 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 41 41 PS_ASSERT_PTR_NON_NULL(argv, 2); 42 42 PS_ASSERT_PTR_NON_NULL(argc, 2); 43 PS_ASSERT_INT_POSITIVE(*argc, 2); 43 44 int argnum = 0; // Argument number 44 45 … … 96 97 const char *arg) 97 98 { 99 PS_ASSERT_INT_POSITIVE(argc, 0); 98 100 PS_ASSERT_PTR_NON_NULL(argv, 0); 99 PS_ASSERT_PTR_NON_NULL(arg, 0); 100 if (strlen(arg) == 0) 101 return 0; 101 PS_ASSERT_STRING_NON_EMPTY(arg, 0); 102 102 103 for (int i = 1; i < argc; i++) { 103 104 if (!strcmp(argv[i], arg)) … … 113 114 char **argv) 114 115 { 116 PS_ASSERT_INT_POSITIVE(argnum, false); 117 PS_ASSERT_PTR_NON_NULL(argc, false); 118 PS_ASSERT_INT_LESS_THAN(argnum, *argc, false); 115 119 PS_ASSERT_PTR_NON_NULL(argv, false); 116 PS_ASSERT_PTR_NON_NULL(argc, false); 117 if (argnum > 0) { 118 (*argc)--; 119 for (int i = argnum; i < *argc; i++) { 120 argv[i] = argv[i+1]; 121 } 122 argv[*argc] = NULL; 123 } else { 124 return false; 125 } 120 121 (*argc)--; 122 for (int i = argnum; i < *argc; i++) { 123 argv[i] = argv[i+1]; 124 } 125 argv[*argc] = NULL; 126 126 127 127 return true; … … 174 174 char **argv) 175 175 { 176 PS_ASSERT_PTR_NON_NULL(arguments, false); 176 PS_ASSERT_METADATA_NON_NULL(arguments, false); 177 PS_ASSERT_PTR_NON_NULL(argc, false); 178 PS_ASSERT_INT_POSITIVE(*argc, false); 177 179 PS_ASSERT_PTR_NON_NULL(argv, false); 178 PS_ASSERT_PTR_NON_NULL(argc, false); 179 if (*argc < 1) 180 return false; 180 181 181 // We need to do a bit of mucking around in order to preserve the arguments metadata until the last 182 182 // minute --- if there is a bad argument, we need to return the old "arguments", since they contain -
trunk/psLib/src/types/psArray.c
r12171 r12289 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.6 0$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-03-0 2 02:34:45 $11 * @version $Revision: 1.61 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-03-07 02:50:15 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 33 33 #include "psAssert.h" 34 34 35 35 #define DEFAULT_ARRAY_ADD 10 // Default number to add to an array when not specified 36 36 37 37 /***************************************************************************** … … 112 112 long nalloc) 113 113 { 114 PS_ASSERT_ARRAY_NON_NULL(in, NULL); 114 115 if (nalloc < 0) { 115 116 psError(PS_ERR_BAD_PARAMETER_VALUE, true, … … 117 118 return in; 118 119 } 119 if (in == NULL) { 120 psError(PS_ERR_BAD_PARAMETER_NULL,true, 121 _("psArrayRealloc must be given a non-NULL psArray to resize.")); 122 return NULL; 123 } else if (in->nalloc != nalloc) { // No need to realloc to same size 120 121 if (in->nalloc != nalloc) { // No need to realloc to same size 124 122 if (nalloc < in->n) { 125 for ( psS32i = nalloc; i < in->n; i++) { // For reduction in vector size123 for (long i = nalloc; i < in->n; i++) { // For reduction in vector size 126 124 psFree(in->data[i]); 127 125 } … … 145 143 { 146 144 if (array == NULL) { 147 int d = (delta > 0) ? delta : 10; // as spec'ed in SDRS.145 long d = (delta > 0) ? delta : DEFAULT_ARRAY_ADD; 148 146 array = psArrayAlloc(d); 149 147 array->n = 0; … … 154 152 if (n >= array->nalloc) { 155 153 // array needs to be expanded to make room for more elements 156 int d = (delta > 0) ? delta : 10; // as spec'ed in SDRS.154 long d = (delta > 0) ? delta : DEFAULT_ARRAY_ADD; 157 155 array = psArrayRealloc(array, n+d); 158 156 } … … 168 166 const psPtr data) 169 167 { 168 PS_ASSERT_ARRAY_NON_NULL(array, false); 169 PS_ASSERT_PTR_NON_NULL(data, false); 170 170 171 bool success = false; 171 172 if (array == NULL) { 173 psError(PS_ERR_BAD_PARAMETER_NULL, true, 174 _("Specified psArray can not be NULL.")); 175 return false; 176 } 177 178 psS32 n = array->n; 179 psPtr* psArrData = array->data; 180 for (psS32 i = n-1; i >= 0; i--) { 181 if (psArrData[i] == data) { 182 memmove(&array->data[i],&array->data[i+1],(n-i-1)*sizeof(psPtr)); 183 psFree(data); // free the removed item (see Bug #449) 172 long n = array->n; 173 psPtr *arrayData = array->data; 174 for (long i = n-1; i >= 0; i--) { 175 if (arrayData[i] == data) { 176 memmove(&arrayData[i],&arrayData[i+1],(n-i-1)*sizeof(psPtr)); 177 psFree(data); // Free the removed item 184 178 n--; 185 179 success = true; … … 194 188 long index) 195 189 { 196 PS_ASSERT_PTR_NON_NULL(array, false); 197 190 PS_ASSERT_ARRAY_NON_NULL(array, false); 198 191 if (index < 0 || index >= array->n) { 199 192 psError(PS_ERR_BAD_PARAMETER_NULL, true, 200 _(" index > then the numberof elements in the array."));193 _("Specified index outside the range of elements in the array.")); 201 194 return false; 202 195 } … … 228 221 psComparePtrFunc func) 229 222 { 230 if (array == NULL) { 231 return NULL; 232 } 233 223 PS_ASSERT_ARRAY_NON_NULL(array, NULL); 234 224 qsort(array->data, array->n, sizeof(psPtr), (int (*)(const void* , const void*))func); 235 236 225 return array; 237 226 } … … 242 231 psPtr data) ///< the value to set it to 243 232 { 244 if (array == NULL) 245 { 246 psError(PS_ERR_BAD_PARAMETER_NULL, true, 247 _("Specified psArray can not be NULL.")); 248 return false; 249 } 233 PS_ASSERT_ARRAY_NON_NULL(array, false); 250 234 251 235 if (position > array->n) … … 257 241 } 258 242 259 if (position < 0) 243 if (position < 0) { 260 244 position += array->n; 261 if (position < 0)262 {245 } 246 if (position < 0) { 263 247 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position. Negative number too large\n"); 264 248 return false; 265 249 } 266 250 267 if (position == array->n) 268 { 251 if (position == array->n) { 269 252 if (position >= array->nalloc) { 270 253 psError(PS_ERR_BAD_PARAMETER_NULL, true, … … 285 268 long position ) 286 269 { 287 if (array == NULL) { 288 psError(PS_ERR_BAD_PARAMETER_NULL, true, 289 _("Specified psArray can not be NULL.")); 290 return NULL; 291 } 270 PS_ASSERT_ARRAY_NON_NULL(array, NULL); 292 271 293 272 if (position >= array->n) { … … 308 287 long psArrayLength(const psArray *array) 309 288 { 310 if ( !psMemCheckArray((psArray*)array) ) { 311 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 312 "Error: Specified array is not a valid psArray \n"); 313 return -1; 314 } 289 PS_ASSERT_ARRAY_NON_NULL(array, -1); 315 290 return (array->n); 316 291 } -
trunk/psLib/src/types/psHash.c
r11709 r12289 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2007-0 2-08 21:44:00$14 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2007-03-07 02:50:15 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 38 38 static psHashBucket* hashBucketAlloc(const char *key, psPtr data, psHashBucket* next); 39 39 static void hashBucketFree(psHashBucket* bucket); 40 static psPtr doHashWork(psHash* table, const char *key, psPtr data, bool remove 41 ); 40 static psPtr doHashWork(psHash* table, const char *key, psPtr data, bool remove); 42 41 static void hashFree(psHash* table); 43 42 … … 52 51 psList* psHashKeyList(const psHash* hash) 53 52 { 54 PS_ASSERT_ PTR_NON_NULL(hash, NULL);55 psS32 i = 0; // Loop index variable 53 PS_ASSERT_HASH_NON_NULL(hash, NULL); 54 56 55 psList* myLinkList = NULL; // The output data structure 57 56 psHashBucket* ptr = NULL; // Used to step thru linked list. … … 62 61 // Loop through every bucket in the hash table. If that bucket is not 63 62 // NULL, then add the bucket's key to the linked list. 64 for ( i = 0; i < hash->n; i++) {63 for (long i = 0; i < hash->n; i++) { 65 64 if (hash->buckets[i] != NULL) { 66 65 // Since a bucket contains a linked list of keys/data, we must … … 93 92 psHashBucket* next) 94 93 { 94 assert(key && strlen(key) > 0); 95 95 96 // Allocate memory for the new hash bucket. 96 97 psHashBucket* bucket = psAlloc(sizeof(psHashBucket)); … … 142 143 long nalloc) // initial number of buckets 143 144 { 144 if (nalloc < 0) 145 { 145 if (nalloc < 0) { 146 146 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 147 147 "Can't allocate a psHash of negative size."); 148 148 return NULL; 149 149 } 150 psS32 i = 0; // loop index variable151 150 152 151 // Create the new hash table. … … 162 161 163 162 // Initialize all buckets to NULL. 164 for (i = 0; i < nalloc; i++) 165 { 163 for (long i = 0; i < nalloc; i++) { 166 164 table->buckets[i] = NULL; 167 165 } … … 183 181 table. It loops through each bucket, and calls hashBucketFree() on that 184 182 bucket. 185 183 186 184 Inputs: 187 185 table: a hash table … … 191 189 static void hashFree(psHash* table) 192 190 { 193 psS32 i = 0; // Loop index variable.194 195 191 // Loop through each bucket in the hash table. If that bucket is not 196 192 // NULL, then free the bucket via a function call to hashBucketFree(); 197 for (i = 0; i < table->n; i++) { 198 193 for (long i = 0; i < table->n; i++) { 199 194 // A bucket is composed of a linked list of buckets. 200 195 while (table->buckets[i] != NULL) { … … 223 218 Return: 224 219 NONE 225 220 226 221 NOTE: consider removing this private function and simply putting the code 227 222 into the psHashInsert(), psHashLookup(), and psHashRemove(). Why? Because … … 234 229 ) 235 230 { 236 psS64 hash = 1; // This will contain an integer value 237 238 // "hashed" from the key. 239 char *tmpchar = NULL; // Used in computing the hash function. 240 psHashBucket* ptr = NULL; // Used to retrieve the hash bucket. 241 psHashBucket* optr = NULL; // "original pointer": used to step 242 243 // thru the linked list for a bucket. 244 245 // The following condition should never be true, since this is a private 246 // function, but I'm checking it anyway since future coders might change 247 // the way this procedure is called. 248 /* if ((table == NULL) || (key == NULL)) { 249 psError(PS_ERR_BAD_PARAMETER_NULL, true, 250 _("Input key can not be NULL.")); 251 return NULL; 252 } 253 */ 254 // NOTE: This is the originally supplied hash function. 255 // for (psS32 i = 0, len = strlen(key); i < len; i++) { 256 // hash = (hash << 1) ^ key[i]; 257 // } 258 // hash &= (table->n - 1); 231 assert(table); 232 assert(table->n > 0); 233 assert(key && strlen(key) > 0); 259 234 260 235 // This hash algorithm is from Sedgewick. NOTE: must reread to ensure that 261 236 // the size of the hash table is not required to be a prime number. 262 if (table->n <= 0) 263 return NULL; 264 tmpchar = (char *)key; 237 char *tmpchar = (char *)key; // Used in computing the hash function. 238 long hash; // The hash value 265 239 for (hash = 0; *tmpchar != '\0'; tmpchar++) { 266 240 hash = (64 * hash + *tmpchar) % (table->n); 267 241 } 268 269 // NOTE: This should not be necessary, but for now, I'm checking bounds 270 // anyway. 271 /* if ((hash < 0) || (hash >= table->n)) { 272 psError(PS_ERR_UNKNOWN, true, 273 "Internal hash function out of range (%" PRId64 ")", hash); 274 } 275 */ 242 assert(hash >= 0 && hash < table->n); 243 276 244 // ptr will have the correct hash bucket. 277 ptr = table->buckets[hash]; 245 psHashBucket *ptr = table->buckets[hash]; // Used to retrieve the hash bucket. 246 psHashBucket* optr = NULL; // "original pointer": used to step thru the linked list for a bucket. 278 247 279 248 // We know the correct hash bucket, now we need to know what to do. … … 281 250 // or a remove operation on the hash table. 282 251 283 if (data == NULL) { 284 if (remove 285 ) { 252 if (data) { 253 if (remove) { 286 254 // We search through the linked list for this bucket in 287 255 // the hash table and look for an entry for this key. … … 368 336 psPtr data) 369 337 { 370 PS_ASSERT_ PTR_NON_NULL(hash, false);371 PS_ASSERT_ PTR_NON_NULL(key, false);338 PS_ASSERT_HASH_NON_NULL(hash, false); 339 PS_ASSERT_STRING_NON_EMPTY(key, false); 372 340 PS_ASSERT_PTR_NON_NULL(data, false); 373 341 … … 379 347 looks up the specified key in the hash table and returns the data associated 380 348 with that key. 381 349 382 350 Inputs: 383 351 table: a hash table … … 389 357 const char *key) // key to lookup 390 358 { 391 PS_ASSERT_ PTR_NON_NULL(hash, NULL);392 PS_ASSERT_ PTR_NON_NULL(key, NULL);359 PS_ASSERT_HASH_NON_NULL(hash, NULL); 360 PS_ASSERT_STRING_NON_EMPTY(key, NULL); 393 361 394 362 return doHashWork((psPtr)hash, key, NULL, false); … … 407 375 const char *key) 408 376 { 409 PS_ASSERT_ PTR_NON_NULL(hash, false);410 PS_ASSERT_ PTR_NON_NULL(key, false);377 PS_ASSERT_HASH_NON_NULL(hash, false); 378 PS_ASSERT_STRING_NON_EMPTY(key, false); 411 379 412 380 psPtr data = NULL; … … 425 393 psArray* psHashToArray(const psHash* hash) 426 394 { 427 PS_ASSERT_PTR_NON_NULL(hash, NULL); 428 429 // first, let's just count the number of data elements to know what size 430 // psArray we need to allocate. 395 PS_ASSERT_HASH_NON_NULL(hash, NULL); 396 397 // first, let's just count the number of data elements to know what size psArray we need to allocate. 431 398 int nElements = 0; 432 399 int nbucket = hash->n; 433 // XXX: If we do psArrayAlloc(0) here and use psArrayAdd(result, 1, tmpBucket->data)434 // we can eliminate the 2nd for loop below.400 // XXX: If we do psArrayAlloc(0) here and use psArrayAdd(result, 1, tmpBucket->data) 401 // we can eliminate the 2nd for loop below. 435 402 for (int i = 0; i < nbucket; i++) { 436 403 psHashBucket* tmpBucket = hash->buckets[i]; -
trunk/psLib/src/types/psHash.h
r11709 r12289 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2007-0 2-08 21:44:00$13 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2007-03-07 02:50:15 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 45 45 } 46 46 psHash; 47 48 47 49 48 /** Checks the type of a particular pointer. … … 114 113 115 114 115 #define PS_ASSERT_HASH_NON_NULL(NAME, RVAL) \ 116 if (!(NAME) || !(NAME)->buckets || (NAME)->n <= 0) { \ 117 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 118 "Error: Hash %s or one of its components is NULL.", \ 119 #NAME); \ 120 return RVAL; \ 121 } 122 116 123 /// @} End of DataContainer Functions 117 124 #endif // #ifndef PS_HASH_H -
trunk/psLib/src/types/psList.c
r11705 r12289 7 7 * @author Joshua Hoblitt, University of Hawaii 8 8 * 9 * @version $Revision: 1.6 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-0 2-08 04:35:35 $9 * @version $Revision: 1.62 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-03-07 02:50:15 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 84 84 static bool listIteratorRemove(psListIterator* iterator) 85 85 { 86 if (iterator == NULL || iterator->cursor == NULL) { 86 assert(iterator); 87 if (iterator->cursor == NULL) { 87 88 return false; 88 89 } … … 159 160 bool mutable) 160 161 { 161 if (list == NULL) { 162 psError(PS_ERR_BAD_PARAMETER_NULL, true, 163 _("Specified list is NULL.")); 164 return false; 165 } 162 PS_ASSERT_LIST_NON_NULL(list, NULL); 163 166 164 psListIterator* iter = p_psAlloc(file, lineno, func, sizeof(psListIterator)); 167 168 165 psMemSetDeallocator(iter, (psFreeFunc) listIteratorFree); 169 166 … … 180 177 psMemDecrRefCounter(iter); 181 178 182 if (! psListIteratorSet(iter,location)) {179 if (!psListIteratorSet(iter,location)) { 183 180 psFree(iter); 184 181 return NULL; … … 191 188 long location) 192 189 { 193 if (iterator == NULL || iterator->list == NULL) { 194 return false; 195 } 190 PS_ASSERT_LIST_ITERATOR_NON_NULL(iterator, false); 196 191 197 192 psList* list = iterator->list; … … 260 255 psPtr data) 261 256 { 262 263 if (list == NULL) { 264 psError(PS_ERR_BAD_PARAMETER_NULL, true, 265 _("Specified psList reference is NULL.")); 266 return false; 267 } 268 269 if (data == NULL) { 270 psError(PS_ERR_BAD_PARAMETER_NULL, true, 271 _("Specified data item is NULL.")); 272 return false; 273 } 257 PS_ASSERT_LIST_NON_NULL(list, false); 258 PS_ASSERT_PTR_NON_NULL(data, false); 274 259 275 260 if (location > 0 && location >= (int)list->n) { … … 297 282 void* data) 298 283 { 299 if (data == NULL) { 300 psError(PS_ERR_BAD_PARAMETER_NULL, true, 301 _("Specified data item is NULL.")); 302 return false; 303 } 304 305 if (iterator == NULL) { 306 psError(PS_ERR_BAD_PARAMETER_NULL, true, 307 _("Specified iterator is NULL.")); 308 return false; 309 } 284 PS_ASSERT_LIST_ITERATOR_NON_NULL(iterator, false); 285 PS_ASSERT_PTR_NON_NULL(data, false); 310 286 311 287 // Check if the list pointed by the iterator can be changed … … 318 294 psListElem* cursor = iterator->cursor; 319 295 psList* list = iterator->list; 320 321 if (cursor == NULL && list->head != NULL) {322 psError(PS_ERR_BAD_PARAMETER_VALUE, true,323 _("Specified iterator is not valid."));324 return false;325 }326 296 327 297 psListElem* elem = psAlloc(sizeof(psListElem)); … … 348 318 list->n++; 349 319 350 //XXX: The following is unreachable. cursor can't == list->tail unless cursor->next == NULL.351 // in which case list->tail will be set to elem. (list->tail = elem;)352 /* if (cursor == list->tail) {353 list->tail = elem;354 }355 */356 320 psArray* iterators = list->iterators; 357 321 int index = iterator->index; … … 369 333 void* data) 370 334 { 371 if (data == NULL) { 372 psError(PS_ERR_BAD_PARAMETER_NULL, true, 373 _("Specified data item is NULL.")); 374 return false; 375 } 376 377 if (iterator == NULL) { 378 psError(PS_ERR_BAD_PARAMETER_NULL, true, 379 _("Specified iterator is NULL.")); 380 return false; 381 } 335 PS_ASSERT_LIST_ITERATOR_NON_NULL(iterator, false); 336 PS_ASSERT_PTR_NON_NULL(data, false); 382 337 383 338 // Check if the list pointed by the iterator can be changed … … 390 345 psListElem* cursor = iterator->cursor; 391 346 psList* list = iterator->list; 392 393 if (cursor == NULL && list->head != NULL) {394 psError(PS_ERR_BAD_PARAMETER_VALUE, true,395 _("Specified iterator is not valid."));396 return false;397 }398 399 347 psListElem* elem = psAlloc(sizeof(psListElem)); 400 348 … … 420 368 list->n++; 421 369 422 //XXX: The following is unreachable. cursor can't == list->head unless cursor->prev == NULL.423 // in which case list->head will be set to elem. (list->tail = elem;)424 /* if (cursor == list->head) {425 list->head = elem;426 }427 */428 370 psArray* iterators = list->iterators; 429 371 int index = iterator->index; … … 441 383 long location) 442 384 { 443 if (list == NULL) { 444 psError(PS_ERR_BAD_PARAMETER_NULL, true, 445 _("Specified psList reference is NULL.")); 446 return false; 447 } 385 PS_ASSERT_LIST_NON_NULL(list, false); 448 386 449 387 // move ourselves to the given position … … 459 397 psPtr data) 460 398 { 461 if (list == NULL) { 462 psError(PS_ERR_BAD_PARAMETER_NULL, true, 463 _("Specified psList reference is NULL.")); 464 return false; 465 } 466 467 if (data == NULL) { 468 psError(PS_ERR_BAD_PARAMETER_NULL, true, 469 _("Specified data item is NULL.")); 470 return false; 471 } 399 PS_ASSERT_LIST_NON_NULL(list, false); 400 PS_ASSERT_PTR_NON_NULL(data, false); 472 401 473 402 psListElem* elem = list->head; … … 493 422 long location) 494 423 { 495 if (list == NULL) { 496 psError(PS_ERR_BAD_PARAMETER_NULL, true, 497 _("Specified psList reference is NULL.")); 498 return NULL; 499 } 500 501 if (list->head == NULL) { // list empty? 502 psError(PS_ERR_BAD_PARAMETER_NULL, true, 503 _("Specified psList reference is empty.")); 504 return NULL; 505 } 424 PS_ASSERT_LIST_NON_NULL(list, NULL); 506 425 507 426 psListIterator* iterator = list->iterators->data[0]; … … 522 441 psPtr psListGetAndIncrement(psListIterator* iterator) 523 442 { 524 if (iterator == NULL ) { 525 return NULL; 526 } 443 PS_ASSERT_LIST_ITERATOR_NON_NULL(iterator, NULL); 444 527 445 if (( iterator->cursor == NULL) && (iterator->offEnd)) { 528 446 return NULL; … … 547 465 psPtr psListGetAndDecrement(psListIterator* iterator) 548 466 { 549 if (iterator == NULL ) { 550 return NULL; 551 } 467 PS_ASSERT_LIST_ITERATOR_NON_NULL(iterator, NULL); 468 552 469 if ((iterator->cursor == NULL) && (!iterator->offEnd)) { 553 470 return NULL; … … 573 490 psArray* psListToArray(const psList* list) 574 491 { 575 PS_ASSERT_ PTR_NON_NULL(list, NULL);492 PS_ASSERT_LIST_NON_NULL(list, NULL); 576 493 577 494 long n = list->n; … … 579 496 580 497 psListElem *ptr = list->head; 581 for ( psS32i = 0; i < n; i++) {498 for (long i = 0; i < n; i++) { 582 499 arr->data[i] = psMemIncrRefCounter(ptr->data); 583 500 ptr = ptr->next; … … 589 506 psList* psArrayToList(const psArray* array) 590 507 { 591 psU32 n; 592 psList* list; // list of elements 593 594 if (array == NULL) { 595 return NULL; 596 } 597 598 list = psListAlloc(NULL); 599 n = array->n; 600 for (psS32 i = 0; i < n; i++) { 508 PS_ASSERT_ARRAY_NON_NULL(array, NULL); 509 510 psList *list = psListAlloc(NULL); // list of elements 511 for (long i = 0; i < array->n; i++) { 601 512 psListAdd(list, PS_LIST_TAIL, array->data[i]); 602 513 } 603 604 514 return list; 605 515 } … … 608 518 psComparePtrFunc func) 609 519 { 610 psArray* arr; 611 612 if (list == NULL) { 613 return NULL; 614 } 615 if (func == NULL) { 616 psError(PS_ERR_BAD_PARAMETER_NULL, true, 617 _("Specified psComparePtrFunc is NULL.")); 618 return list; 619 } 520 PS_ASSERT_LIST_NON_NULL(list, NULL); 521 PS_ASSERT_PTR_NON_NULL(func, NULL); 522 620 523 // convert to indexable vector for use by qsort. 621 arr = psListToArray(list);622 psArray *iterators = psMemIncrRefCounter(list->iterators);524 psArray *arr = psListToArray(list); 525 psArray *iterators = psMemIncrRefCounter(list->iterators); 623 526 psFree(list); 624 527 … … 641 544 long psListLength(const psList *list) 642 545 { 643 if ( !psMemCheckList((psList*)list) ) { 644 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 645 "Error: Specified list is not a valid psList \n"); 646 return -1; 647 } 648 return (list->n); 649 } 650 651 546 PS_ASSERT_LIST_NON_NULL(list, -1); 547 return list->n; 548 } 549 550 -
trunk/psLib/src/types/psList.h
r11705 r12289 5 5 * @author Robert Daniel DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.4 0$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 2-08 04:35:35 $7 * @version $Revision: 1.41 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-03-07 02:50:15 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 34 34 35 35 /** Doubly-linked list element */ 36 typedef struct psListElem 37 { 36 typedef struct psListElem { 38 37 struct psListElem* prev; ///< previous link in list 39 38 struct psListElem* next; ///< next link in list 40 39 psPtr data; ///< real data item 41 } 42 psListElem; 40 } psListElem; 43 41 44 42 … … 48 46 * @see psListAlloc 49 47 */ 50 typedef struct 51 { 48 typedef struct { 52 49 long n; ///< number of elements on list 53 50 psListElem* head; ///< first element on list (may be NULL) … … 58 55 ///< others are user-level iterators created by psListIteratorAlloc. 59 56 void *lock; ///< Optional lock for thread safety 60 } 61 psList; 57 } psList; 62 58 63 59 … … 279 275 280 276 277 #define PS_ASSERT_LIST_NON_NULL(NAME, RVAL) \ 278 if (!(NAME) || !(NAME)->iterators || (NAME)->n <= 0) { \ 279 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 280 "Error: List %s or one of its components is NULL.", \ 281 #NAME); \ 282 return RVAL; \ 283 } 284 285 #define PS_ASSERT_LIST_ITERATOR_NON_NULL(NAME, RVAL) \ 286 if (!(NAME) || !(NAME)->list || !(NAME)->list->iterators || (NAME)->list->n <= 0 || \ 287 (!(NAME)->cursor && (NAME)->list->head) || (NAME)->index <= 0) { \ 288 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 289 "Error: List iterator %s or one of its components is NULL.", \ 290 #NAME); \ 291 return RVAL; \ 292 } 293 294 281 295 /// @} End of DataContainer Functions 282 296 #endif // #ifndef PS_LIST_H -
trunk/psLib/src/types/psLookupTable.h
r11710 r12289 6 6 * @author Ross Harman, MHPCC 7 7 * 8 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 2-08 21:57:02$8 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-03-07 02:50:15 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 #include "psArray.h" 23 23 #include "psLogMsg.h" 24 24 #include "psString.h" 25 25 26 26 /** Lookup table structure … … 29 29 * 30 30 */ 31 typedef struct 32 { 33 const char *filename; ///< Name of file with table 34 const char *format; ///< scanf-like format string for file 31 typedef struct { 32 psString filename; ///< Name of file with table 33 psString format; ///< scanf-like format string for file 35 34 long indexCol; ///< Column of the index vector (starting at zero) 36 35 psVector *index; ///< Vector of independent index values … … 38 37 const double validFrom; ///< Lower bound for rable read 39 38 const double validTo; ///< Upper bound for table read 39 } psLookupTable; 40 41 #define PS_ASSERT_LOOKUPTABLE_NON_NULL(NAME, RVAL) \ 42 if (!(NAME) || !(NAME)->filename || strlen((NAME)->filename) == 0 || \ 43 !(NAME)->format || strlen((NAME)->format) == 0 || (NAME)->index < 0) { \ 44 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 45 "Error: Lookup table %s or one of its components is NULL.", \ 46 #NAME); \ 47 return RVAL; \ 40 48 } 41 psLookupTable;42 43 49 44 50 /** Lookup table lookup status and error conditions … … 135 141 const char *func, ///< Function name of caller 136 142 psLookupTable *table, ///< Lookup table into which to import 137 const psArray *vectors,///< Array of vectors143 psArray *vectors, ///< Array of vectors 138 144 long indexCol ///< Index of the index vector in the array of vectors 139 145 ); -
trunk/psLib/src/types/psMetadata.c
r12283 r12289 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.15 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2007-03-0 6 21:58:47$14 * @version $Revision: 1.154 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2007-03-07 02:50:15 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1159 1159 { 1160 1160 PS_ASSERT_METADATA_NON_NULL(md, NULL); 1161 1162 psList *list = psListAlloc(NULL); // List with the keys 1163 psMetadataIterator *iter = psMetadataIteratorAlloc(md, PS_LIST_HEAD, false); 1164 psMetadataItem *item; // Item from iteration 1165 while ((item = psMetadataGetAndIncrement(iter))) { 1166 psListAdd(list, PS_LIST_TAIL, item->name); 1167 } 1168 return list; 1161 return psHashKeyList(md->hash); 1169 1162 } 1170 1163 -
trunk/psLib/src/types/psMetadataConfig.c
r11668 r12289 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.12 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 2-06 21:36:09$12 * @version $Revision: 1.129 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-03-07 02:50:15 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 449 449 450 450 PS_ASSERT_PTR_NON_NULL(fd, false); 451 PS_ASSERT_ PTR_NON_NULL(format, false);452 PS_ASSERT_ PTR_NON_NULL(item, false);451 PS_ASSERT_STRING_NON_EMPTY(format, false); 452 PS_ASSERT_METADATA_ITEM_NON_NULL(item, false); 453 453 454 454 type = item->type; … … 1152 1152 psMetadataFlags flags) 1153 1153 { 1154 PS_ASSERT_ PTR_NON_NULL(keyName, false);1155 PS_ASSERT_ PTR_NON_NULL(levelArray, false);1154 PS_ASSERT_STRING_NON_EMPTY(keyName, false); 1155 PS_ASSERT_ARRAY_NON_NULL(levelArray, false); 1156 1156 PS_ASSERT_PTR_NON_NULL(linePtr, false); 1157 1157 … … 1182 1182 psMetadataFlags flags) 1183 1183 { 1184 PS_ASSERT_ PTR_NON_NULL(keyName, false);1185 PS_ASSERT_ PTR_NON_NULL(levelArray, false);1184 PS_ASSERT_STRING_NON_EMPTY(keyName, false); 1185 PS_ASSERT_ARRAY_NON_NULL(levelArray, false); 1186 1186 PS_ASSERT_PTR_NON_NULL(linePtr, false); 1187 1187 … … 1247 1247 psMetadataFlags flags) 1248 1248 { 1249 PS_ASSERT_ PTR_NON_NULL(keyName, false);1250 PS_ASSERT_ PTR_NON_NULL(levelArray, false);1249 PS_ASSERT_STRING_NON_EMPTY(keyName, false); 1250 PS_ASSERT_ARRAY_NON_NULL(levelArray, false); 1251 1251 PS_ASSERT_PTR_NON_NULL(linePtr, false); 1252 1252 … … 1274 1274 { 1275 1275 // Check for NULL file name 1276 PS_ASSERT_ PTR_NON_NULL(filename, NULL);1276 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 1277 1277 1278 1278 // Attempt to open specified file … … 1357 1357 bool allocedMD = false; 1358 1358 1359 PS_ASSERT_ PTR_NON_NULL(str, NULL);1359 PS_ASSERT_STRING_NON_EMPTY(str, NULL); 1360 1360 1361 1361 // Initialise nFail, if provided … … 1430 1430 psString psMetadataConfigFormat(psMetadata *md) 1431 1431 { 1432 PS_ASSERT_ PTR_NON_NULL(md, NULL);1432 PS_ASSERT_METADATA_NON_NULL(md, NULL); 1433 1433 1434 1434 psString format = NULL; … … 1465 1465 static psString formatMetadataItem(psMetadataItem *item) 1466 1466 { 1467 PS_ASSERT_ PTR_NON_NULL(item, NULL);1467 PS_ASSERT_METADATA_ITEM_NON_NULL(item, NULL); 1468 1468 1469 1469 psString content = NULL; … … 1698 1698 static psArray *p_psMetadataKeyArray(psMetadata *md) 1699 1699 { 1700 PS_ASSERT_ PTR_NON_NULL(md, NULL);1700 PS_ASSERT_METADATA_NON_NULL(md, NULL); 1701 1701 1702 1702 psArray *keys = psArrayAllocEmpty(psListLength(md->list)); … … 1732 1732 const char *filename) 1733 1733 { 1734 PS_ASSERT_ PTR_NON_NULL(md, NULL);1735 PS_ASSERT_ PTR_NON_NULL(filename, NULL);1734 PS_ASSERT_METADATA_NON_NULL(md, NULL); 1735 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 1736 1736 FILE *file; 1737 1737 if ( !(file = fopen(filename, "w")) ) { … … 1760 1760 psMetadata *md) 1761 1761 { 1762 PS_ASSERT_ PTR_NON_NULL(md, false);1762 PS_ASSERT_METADATA_NON_NULL(md, false); 1763 1763 PS_ASSERT_PTR_NON_NULL(stream, false); 1764 1764 if (fprintf(stream, "\n") <= 0) { -
trunk/psLib/src/types/psMetadataItemParse.c
r11686 r12289 41 41 ) 42 42 { 43 PS_ASSERT_ PTR_NON_NULL(item, false);43 PS_ASSERT_METADATA_ITEM_NON_NULL(item, false); 44 44 45 45 switch (item->type) { … … 71 71 ) 72 72 { 73 PS_ASSERT_ PTR_NON_NULL(item, NAN);73 PS_ASSERT_METADATA_ITEM_NON_NULL(item, NAN); 74 74 75 75 switch (item->type) { … … 94 94 ) 95 95 { 96 PS_ASSERT_ PTR_NON_NULL(item, NAN);96 PS_ASSERT_METADATA_ITEM_NON_NULL(item, NAN); 97 97 98 98 switch (item->type) { … … 117 117 ) 118 118 { 119 PS_ASSERT_ PTR_NON_NULL(item, 0);119 PS_ASSERT_METADATA_ITEM_NON_NULL(item, 0); 120 120 121 121 switch (item->type) { … … 140 140 ) 141 141 { 142 PS_ASSERT_ PTR_NON_NULL(item, 0);142 PS_ASSERT_METADATA_ITEM_NON_NULL(item, 0); 143 143 144 144 switch (item->type) { … … 163 163 ) 164 164 { 165 PS_ASSERT_ PTR_NON_NULL(item, 0);165 PS_ASSERT_METADATA_ITEM_NON_NULL(item, 0); 166 166 167 167 switch (item->type) { … … 186 186 ) 187 187 { 188 PS_ASSERT_ PTR_NON_NULL(item, 0);188 PS_ASSERT_METADATA_ITEM_NON_NULL(item, 0); 189 189 190 190 switch (item->type) { … … 209 209 ) 210 210 { 211 PS_ASSERT_ PTR_NON_NULL(item, 0);211 PS_ASSERT_METADATA_ITEM_NON_NULL(item, 0); 212 212 213 213 switch (item->type) { … … 232 232 ) 233 233 { 234 PS_ASSERT_ PTR_NON_NULL(item, 0);234 PS_ASSERT_METADATA_ITEM_NON_NULL(item, 0); 235 235 236 236 switch (item->type) { … … 261 261 ) 262 262 { 263 PS_ASSERT_ PTR_NON_NULL(item, NULL);263 PS_ASSERT_METADATA_ITEM_NON_NULL(item, NULL); 264 264 265 265 switch (item->type) { -
trunk/psLib/src/types/psPixels.c
r11707 r12289 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.3 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-0 2-08 21:29:50$9 * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-03-07 02:50:15 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 25 #include "psError.h" 26 26 27 #define PIXELS_DEFAULT_ADD 10 // Default number to add, if not specified 27 28 28 29 typedef int(*qsortCompareFcn)(const void *, const void *); … … 30 31 static void pixelsFree(psPixels* pixels) 31 32 { 33 assert(pixels); 32 34 psFree(pixels->data); 33 35 } … … 118 120 { 119 121 if (growth < 1) { 120 growth = 10;122 growth = PIXELS_DEFAULT_ADD; 121 123 } 122 124 … … 141 143 const psPixels* pixels) 142 144 { 143 if (pixels == NULL) { 144 psError(PS_ERR_BAD_PARAMETER_NULL,true,_("Input psPixels can not be NULL.")); 145 psFree(out); 146 return NULL; 147 } 145 PS_ASSERT_PIXELS_NON_NULL(pixels, NULL); 148 146 149 147 out = p_psPixelsRealloc(file, lineno, func, out, pixels->n); 150 151 148 memcpy(out->data,pixels->data, pixels->n*sizeof(psPixelCoord)); 152 149 out->n = pixels->n; … … 160 157 psMaskType maskVal) 161 158 { 162 // check that the input pixel vector is valid 163 if (pixels == NULL) { 164 psError(PS_ERR_BAD_PARAMETER_NULL, true, 165 _("Input psPixels can not be NULL.")); 166 psFree(out); 167 return NULL; 168 } 169 psPixelCoord* data = pixels->data; 170 if (data == NULL) { 171 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 172 _("Input psPixels contains no data.")); 173 psFree(out); 174 return NULL; 175 } 159 PS_ASSERT_PIXELS_NON_NULL(pixels, NULL); 176 160 177 161 float x0 = region.x0; … … 224 208 psMaskType** outData = out->data.PS_TYPE_MASK_DATA; 225 209 for (int p = 0; p < length; p++) { 226 float x = data[p].x;227 float y = data[p].y;210 float x = pixels->data[p].x; 211 float y = pixels->data[p].y; 228 212 // pixel in region? 229 213 if (x >= x0 && x <= x1 && y >= y0 && y <= y1) { … … 239 223 psMaskType maskVal) 240 224 { 241 if (mask == NULL) { 242 psError(PS_ERR_BAD_PARAMETER_NULL, true, 243 _("Specified mask can not be NULL.")); 244 psFree(out); 245 return NULL; 246 } 247 if (mask->type.type != PS_TYPE_MASK) { 248 char* typeStr; 249 PS_TYPE_NAME(typeStr,mask->type.type); 250 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 251 _("Specified mask's type, %s, is invalid. Should be PS_TYPE_MASK."), 252 typeStr); 253 psFree(out); 254 return NULL; 255 } 225 PS_ASSERT_IMAGE_NON_NULL(mask, NULL); 226 PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL); 227 256 228 int numRows = mask->numRows; 257 229 int numCols = mask->numCols; … … 302 274 const psPixels *pixels) 303 275 { 304 if (pixels == NULL) { 305 psError(PS_ERR_BAD_PARAMETER_NULL, true, 306 _("Input psPixels can not be NULL.")); 307 psFree(out); 308 return NULL; 309 } 276 PS_ASSERT_PIXELS_NON_NULL(pixels, NULL); 310 277 311 278 long pixelsN = pixels->n; … … 343 310 } 344 311 345 bool p_psPixelsPrint (FILE *fd, 346 psPixels* pixels, 347 const char *name) 348 { 312 bool p_psPixelsPrint(FILE *fd, 313 psPixels* pixels, 314 const char *name) 315 { 316 PS_ASSERT_PIXELS_NON_NULL(pixels, false); 317 349 318 if (fd == NULL) { 350 319 fd = stdout; … … 361 330 } 362 331 363 if (pixels == NULL) {364 fprintf(fd,"NULL\n\n");365 return true;366 }367 368 332 long n = pixels->n; 369 333 psPixelCoord* data = pixels->data; … … 385 349 psPixelCoord value) 386 350 { 387 if (pixels == NULL) { 388 psError(PS_ERR_BAD_PARAMETER_NULL, true, _("Input psPixels can not be NULL.")); 351 PS_ASSERT_PIXELS_NON_NULL(pixels, false); 352 353 if (position < 0) { 354 position += pixels->n; 355 } 356 if (position < 0 || position > pixels->n) { 357 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position: %ld\n", position); 389 358 return false; 390 }391 if (position > pixels->n) {392 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position. Number too large\n");393 return false;394 }395 if(position < 0) {396 position += pixels->n;397 }398 if(position < 0) {399 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position. Negative number too large\n");400 return false;401 }402 if (position == pixels->n) {403 if (position >= pixels->nalloc) {404 psError(PS_ERR_BAD_PARAMETER_NULL, true,405 "Specified position, %ld, is greater than n+1 of the pixels, %ld.",406 position, pixels->nalloc);407 return false;408 }409 pixels->n++;410 359 } 411 360 pixels->data[position].x = value.x; … … 421 370 if (pixels == NULL) { 422 371 psError(PS_ERR_BAD_PARAMETER_NULL, true, _("Input psPixels can not be NULL.")); 423 out.x = NAN; //XXX: should be NAN when changed to float424 out.y = NAN; //XXX: should be NAN when changed to float372 out.x = NAN; 373 out.y = NAN; 425 374 return out; 375 } 376 if (position < 0) { 377 position += pixels->n; 426 378 } 427 379 if (position >= pixels->n) { 428 380 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position. Number too large\n"); 429 out.x = NAN; //XXX: should be NAN when changed to float430 out.y = NAN; //XXX: should be NAN when changed to float381 out.x = NAN; 382 out.y = NAN; 431 383 return out; 432 }433 if (position < 0) {434 position += pixels->n;435 384 } 436 385 if (position < 0) { 437 386 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position. Negative number too large\n"); 438 out.x = NAN; //XXX: should be NAN when changed to float439 out.y = NAN; //XXX: should be NAN when changed to float387 out.x = NAN; 388 out.y = NAN; 440 389 return out; 441 390 } … … 447 396 long psPixelsLength(const psPixels *pixels) 448 397 { 449 if ( !psMemCheckPixels((psPixels*)pixels) ) { 450 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 451 "Error: Specified pixels is not a valid psPixels \n"); 452 return -1; 453 } 454 return (pixels->n); 455 } 456 398 PS_ASSERT_PIXELS_NON_NULL(pixels, -1); 399 return pixels->n; 400 } 401 -
trunk/psLib/src/types/psPixels.h
r11707 r12289 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 2-08 21:29:50$8 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-03-07 02:50:15 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 49 49 psPixels; 50 50 51 #define PS_ASSERT_PIXELS_NON_NULL(NAME, RVAL) \ 52 if (!(NAME) || !(NAME)->data || (NAME)->n < 0 || (NAME)->nalloc < 0) { \ 53 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 54 "Error: Pixels %s or one of its components is NULL.", \ 55 #NAME); \ 56 return RVAL; \ 57 } 58 51 59 #define P_PSPIXELS_SET_NALLOC(pix,n) *(long*)&pix->nalloc = n 52 60
Note:
See TracChangeset
for help on using the changeset viewer.
