1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
|
/* $Id: pildictionary.c,v 1.1.1.1 2008-10-21 09:10:13 cizzo Exp $
*
* This file is part of the VIMOS pipeline library
* Copyright (C) 2000-2004 European Southern Observatory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* $Author: cizzo $
* $Date: 2008-10-21 09:10:13 $
* $Revision: 1.1.1.1 $
* $Name: not supported by cvs2svn $
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "pildictionary.h"
/**
* @defgroup pilDictionary pilDictionary
*
* The module @b pilDictionary provides functions to create, destroy and
* maintain and a dictionary.
*
* @note
* The current implementation is based on the @b kazlib dictionary
* implementation. Not all services defined there are available through
* this interface.
*/
/**@{*/
/**
* @brief
* Create a new dictionary node.
*
* @param data Pointer to the node data.
*
* @return The function returns the pointer to the newly created node if no
* error occurs, otherwise the return value is @c NULL.
*
* The function allocates the memory for a dictionary node and initializes
* the node's fields. The data field of the node is initialized to the
* pointer @em data.
*/
PilDictNode *newPilDictNode(void *data)
{
return dnode_create(data);
}
/**
* @brief
* Destroys a dictionary node.
*
* @param node Pointer to an existing dictionary node.
*
* @return Nothing.
*
* The function destroys an existing dictionary node object.
*/
void deletePilDictNode(PilDictNode *node)
{
dnode_destroy(node);
return;
}
/**
* @brief
* Get the keyword of a dictionary node.
*
* @param node Pointer to a dictionary node.
*
* @return The pointer to the node's keyword is returned.
*
* The function returns a pointer to the keyword data of the node @em node.
*
* @see pilDictGetData(), pilDictPutData()
*/
const void *pilDictGetKey(PilDictNode *node)
{
return dnode_getkey(node);
}
/**
* @brief
* Get the user data of a dictionary node.
*
* @param node Pointer to a dictionary node.
*
* @return The pointer to the node's user data is returned.
*
* The function returns a pointer to the user supplied data of the node
* @em node.
*
* @see pilDictGetData(), pilDictPutData()
*/
void *pilDictGetData(PilDictNode *node)
{
return dnode_get(node);
}
/**
* @brief
* Set the user data of a dictionary node.
*
* @param node Pointer to a dictionary node.
* @param data Pointer to the user data object.
*
* @return Nothing.
*
* The function associates the user data object @em data to the dictionary
* node @em node.
*
* @see pilDictGetKey(), pilDictGetData()
*/
void pilDictPutData(PilDictNode *node, void *data)
{
dnode_put(node, data);
return;
}
/**
* @brief
* Create a new dictionary.
*
* @param capacity Maximum number of allowed dictionary entries.
* @param cmp Comparator function used for keyword comparision.
*
* @return Returns the pointer to the newly created dictionary if no error
* occurs, otherwise the return value is @c NULL.
*
* The function creates a new dictionary with the given maximum number
* of possible dictionary nodes and installs the provided comparator
* function in the dictionary.
*/
PilDictionary *newPilDictionary(PilDictCapacity capacity,
PilDictComparator cmp)
{
return dict_create(capacity, cmp);
}
/**
* @brief
* Destroys a dictionary object.
*
* @param dict Pointer to an existing dictionary.
*
* @return Nothing.
*
* The function destroys an existing dictionary object. The dictionary
* must be empty.
*
* @see pilDictClear()
*/
void deletePilDictionary(PilDictionary *dict)
{
dict_destroy(dict);
return;
}
/**
* @brief
* Configure a dictionary for duplicate entries.
*
* @param dict Pointer to an existing dictionary.
*
* @return Nothing.
*
* The function configures the dictionary @em dict so that multiple entries
* may have the same keyword.
*/
void pilDictAllowDuplicates(PilDictionary *dict)
{
dict_allow_dupes(dict);
return;
}
/**
* @brief
* Installs the dictionary allocator and deallocator functions.
*
* @param dict Pointer to an existing dictionary object.
* @param allocator Allocator function.
* @param deallocator Deallocator function.
* @param context Dictionary context.
*
* @return Nothing.
*
* The function replaces the default allocator and deallocator functions
* of the dictionary @em dict used for the creation and destruction of
* dictionary nodes by two user supplied functions @em allocator and
* @em deallocator of the type @c pilDictAllocator and @c pilDictDeallocator
* respectively. The allocator and deallocator can only be changed for empty
* dictionaries and both functions have to be replaced simultaneously. A
* dictionary context @em context may be provided.
*/
void pilDictSetAllocator(PilDictionary *dict,
PilDictAllocator allocator,
PilDictDeallocator deallocator, void *context)
{
dict_set_allocator(dict, allocator, deallocator, context);
return;
}
/**
* @brief
* Verify dictionary integrity.
*
* @param dict Pointer to an existing dictionary.
*
* @return The function returns 1 if the dictionary could be verified, if the
* dictionary is corrupted the return value is 0.
*
* The structure of the dictionary @em dict is verified. The function checks
* only for a limited set of possible corruptions. A return value of 1 does
* not necessarily imply that the directory structure is not corrupt.
*
* @note
* The function is provided for debugging purposes only and should be
* placed in assert statements.
*/
int pilDictVerify(PilDictionary *dict)
{
return dict_verify(dict);
}
/**
* @brief
* Check if a dictionary is empty.
*
* @param dict Pointer to an existing dictionary.
*
* @return The return value is different from 0 if the dictionary is empty,
* if it is not empty 0 is returned.
*
* The function checks if the dictionary @em dict is empty.
*
* @see pilDictIsFull()
*/
int pilDictIsEmpty(PilDictionary *dict)
{
return dict_isempty(dict);
}
/**
* @brief
* Check if a dictionary is full.
*
* @param dict Pointer to an existing dictionary.
*
* @return The return value is different from 0 if the dictionary is full,
* if it is not full 0 is returned.
*
* The function checks if the dictionary @em dict is full, i.e. if the
* number of dictionary nodes equals the dictionary's capacity.
*
* @see pilDictIsEmpty()
*/
int pilDictIsFull(PilDictionary *dict)
{
return dict_isfull(dict);
}
/**
* @brief
* Report the current number of dictionary nodes.
*
* @param dict Pointer to an existing dictionary.
*
* @return The function returns the number of dictionary nodes.
*
* The function reports the number of dictionary nodes in the dictionary
* @em dict.
*/
PilDictCapacity pilDictCapacity(PilDictionary *dict)
{
return dict_count(dict);
}
/**
* @brief
* Lookup a dictionary entry.
*
* @param dict Pointer to an existing dictionary.
* @param keyword Keyword string to be searched in the dictionary.
*
* @return Pointer to the dictionary node if the entry was found, otherwise
* @c NULL is returned.
*
* The function locates a dictionary node in the dictionary @em dict
* associated to the key @em keyword. If such a node is not found a
* @c NULL pointer is returned.
*
* @see pilDictInsert(), pilDictErase(), pilDictRemove()
*/
PilDictNode *pilDictLookup(PilDictionary *dict, const void *keyword)
{
return dict_lookup(dict, keyword);
}
/**
* @brief
* Check if a node is contained in a dictionary.
*
* @param dict Pointer to an existing dictionary.
* @param node Dictionary node to be checked.
*
* @return The return value is 1, if the node is found in the dictionary,
* otherwise 0 is returned.
*
* The function checks is the dictionary node @em node is a member of the
* dictionary @em dict.
*
* @see pilDictLookup()
*/
int pilDictContains(PilDictionary *dict, PilDictNode *node)
{
return dict_contains(dict, node);
}
/**
* @brief
* Insert a new entry into a dictionary.
*
* @param dict Pointer to an existing dictionary.
* @param keyword String to be used as node keyword.
* @param data Pointer to user data.
*
* @return The function returns 1 if the node insertion was successful,
* otherwise the return value is 0.
*
* The function allocates a new dictionary node using the dictionary's
* allocator function and initializes the newly created node with
* the reference to the user supplied data @em data. The node is then
* inserted into the dictionary @em dict using the key @em keyword.
*
* @note
* Only the reference to the keyword data is stored in the dictionary.
*
* @see pilDictInsertNode(), pilDictLookup(), pilDictErase(), pilDictRemove()
*/
int pilDictInsert(PilDictionary *dict, const void *keyword, void *data)
{
return dict_alloc_insert(dict, keyword, data);
}
/**
* @brief
* Insert an already existing dictionary node into a dictionary.
*
* @param dict Pointer to an existing dictionary.
* @param node Pointer to an existing dictionary node.
* @param keyword String to be used as the node keyword.
*
* @return Nothing
*
* The function inserts an already created dictionary node @em node in the
* dictionary @em dict using the dictionary key @em keyword. The data field
* of the node is not changed.
*
* @note
* Only the reference to the keyword data is stored in the dictionary.
*
* @see pilDictInsert()
*/
void pilDictInsertNode(PilDictionary *dict, PilDictNode *node,
const void *keyword)
{
dict_insert(dict, node, keyword);
return;
}
/**
* @brief
* Remove a node from a dictionary.
*
* @param dict Pointer to an existing dictionary.
* @param node Pointer to the dictionary node that should be removed.
*
* @return The removed dictionary node.
*
* The function removes the dictionary node @em node from the dictionary
* @em dict. The removed node is returned.
*
* @see pilDictLookup(), pilDictInsert(), pilDictErase()
*/
PilDictNode *pilDictRemove(PilDictionary *dict, PilDictNode *node)
{
return dict_delete(dict, node);
}
/**
* @brief
* Remove and delete a dictionary node.
*
* @param dict Pointer to an existing dictionary.
* @param node Pointer to the dictionary node that should be removed.
*
* @return Nothing.
*
* The function removes the dictionary node @em node from the dictionary
* @em dict. The node itself is destroyed using the dictionary's deallocator
* function.
*
* @note
* Since the default deallocator does not know anything about the user
* supplied data referenced by the node, it cannot deallocate the
* user data. This might result in a memory leak if no appropriate
* allocator and deallocator functions were installed!
*
* @see pilDictLookup(), pilDictInsert(), pilDictRemove()
*/
void pilDictErase(PilDictionary *dict, PilDictNode *node)
{
dict_delete_free(dict, node);
return;
}
/**
* @brief
* Deletes a dictionary and all its nodes.
*
* @param dict Pointer to an existing dictionary.
*
* @return Nothing.
*
* The function deletes all existing dictionary nodes in the dictionary
* @em dict. Each dictionary node is removed from the dictionary and deleted
* using the dictionary's deallocater function.
*
* @note
* Since the default deallocator does not know anything about the user
* supplied data referenced by a node, it cannot deallocate the
* user data. This might result in a memory leak if no appropriate
* allocator and deallocator functions were installed!
*
* @see pilDictDelete(), deletePilDictionary(), pilDictSetAllocator()
*/
void pilDictClear(PilDictionary *dict)
{
dict_free_nodes(dict);
return;
}
/**
* @brief
* Get the first node in a dictionary.
*
* @param dict Pointer to an existing dictionary.
*
* @return The function returns a pointer to the first node in the
* dictionary, if the dictionary is empty a @c NULL pointer is returned.
*
* The function looks for the first dictionary node in the dictionary
* @em dict, i.e. the node having the lowest dictionary keyword.
*
* @see pilDictEnd()
*/
PilDictNode *pilDictBegin(PilDictionary *dict)
{
return dict_first(dict);
}
/**
* @brief
* Get the last node in a dictionary.
*
* @param dict Pointer to an existing dictionary.
*
* @return The function returns a pointer to the last node in the
* dictionary, if the dictionary is empty a @c NULL pointer is returned.
*
* The function looks for the last dictionary node in the dictionary
* @em dict, i.e. the node having the highest dictionary keyword.
*
* @see pilDictBegin()
*/
PilDictNode *pilDictEnd(PilDictionary *dict)
{
return dict_last(dict);
}
/**
* @brief
* Get the next node in a dictionary.
*
* @param dict Pointer to an existing dictionary.
* @param node Pointer to a dictionary node.
*
* @return The function returns a pointer to the next node in the
* dictionary, if there is no next node a @c NULL pointer is returned.
*
* The function returns a pointer to the sucessor of the node @em node in
* the dictionary @em dict.
*
* @see pilDictPrev()
*/
PilDictNode *pilDictNext(PilDictionary *dict, PilDictNode *node)
{
return dict_next(dict, node);
}
/**
* @brief
* Get the previous node in a dictionary.
*
* @param dict Pointer to an existing dictionary.
* @param node Pointer to a dictionary node.
*
* @return The function returns a pointer to the previous node in the
* dictionary, if there is no previous node a @c NULL pointer is returned.
*
* The function returns a pointer to the predecessor of the node @em node
* in the dictionary @em dict.
*
* @see pilDictNext()
*/
PilDictNode *pilDictPrev(PilDictionary *dict, PilDictNode *node)
{
return dict_prev(dict, node);
}
/**@}*/
|