pair.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*!
  2. Temelia - Pair implementation source file.
  3. Copyright (C) 2008, 2009 Ceata (http://ceata.org/proiecte/temelia).
  4. @author Dascalu Laurentiu
  5. This program is free software; you can redistribute it and
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 3
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #include "include/pair.h"
  18. #include "include/common.h"
  19. #include <stdlib.h>
  20. // Pair of key and value.
  21. struct _pair_t
  22. {
  23. /*! key */
  24. void *key;
  25. /*! value */
  26. void *value;
  27. };
  28. pair_t pair_new(void *key, void *value)
  29. {
  30. pair_t pair;
  31. pair = (struct _pair_t *) _new(sizeof(struct _pair_t));
  32. _ASSERT(pair, ==, NULL, NULL_POINTER, NULL);
  33. pair->key = key;
  34. pair->value = value;
  35. return pair;
  36. }
  37. void pair_delete(pair_t pair)
  38. {
  39. _ASSERT(pair, ==, NULL, NULL_POINTER,);
  40. pair->key = pair->value = NULL;
  41. _delete(pair);
  42. }
  43. void pair_set_key(pair_t pair, void *key)
  44. {
  45. _ASSERT(pair, ==, NULL, NULL_POINTER,);
  46. pair->key = key;
  47. }
  48. void pair_set_value(pair_t pair, void *value)
  49. {
  50. _ASSERT(pair, ==, NULL, NULL_POINTER,);
  51. pair->value = value;
  52. }
  53. void *pair_get_key(pair_t pair)
  54. {
  55. _ASSERT(pair, ==, NULL, NULL_POINTER, NULL);
  56. return pair->key;
  57. }
  58. void *pair_get_value(pair_t pair)
  59. {
  60. _ASSERT(pair, ==, NULL, NULL_POINTER, NULL);
  61. return pair->value;
  62. }