xdrindex.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*!
  2. \file lib/db/dbmi_base/xdrindex.c
  3. \brief DBMI Library (base) - external data representation (index)
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek, Brad Douglas, Markus Neteler
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/dbmi.h>
  11. #include "macros.h"
  12. /*!
  13. \brief Send index
  14. \param index
  15. \return
  16. */
  17. int db__send_index(dbIndex * index)
  18. {
  19. int i;
  20. DB_SEND_STRING(&index->indexName);
  21. DB_SEND_STRING(&index->tableName);
  22. DB_SEND_CHAR(index->unique);
  23. DB_SEND_INT(index->numColumns);
  24. for (i = 0; i < index->numColumns; i++) {
  25. DB_SEND_STRING(&index->columnNames[i]);
  26. }
  27. return DB_OK;
  28. }
  29. /*!
  30. \brief Send index array
  31. \param list
  32. \param count
  33. \return
  34. */
  35. int db__send_index_array(dbIndex * list, int count)
  36. {
  37. int i;
  38. DB_SEND_INT(count);
  39. for (i = 0; i < count; i++) {
  40. DB_SEND_INDEX(&list[i]);
  41. }
  42. return DB_OK;
  43. }
  44. /*!
  45. \brief Receive index
  46. \param index
  47. \return
  48. */
  49. int db__recv_index(dbIndex * index)
  50. {
  51. int i, ncols;
  52. db_init_index(index);
  53. DB_RECV_STRING(&index->indexName);
  54. DB_RECV_STRING(&index->tableName);
  55. DB_RECV_CHAR(&index->unique);
  56. DB_RECV_INT(&ncols);
  57. if (db_alloc_index_columns(index, ncols) != DB_OK)
  58. return db_get_error_code();
  59. for (i = 0; i < ncols; i++) {
  60. DB_RECV_STRING(&index->columnNames[i]);
  61. }
  62. return DB_OK;
  63. }
  64. /*!
  65. \brief Receive index array
  66. \param list
  67. \param count
  68. */
  69. int db__recv_index_array(dbIndex ** list, int *count)
  70. {
  71. int i;
  72. DB_RECV_INT(count);
  73. *list = db_alloc_index_array(*count);
  74. if (*list == NULL)
  75. return db_get_error_code();
  76. for (i = 0; i < *count; i++) {
  77. DB_RECV_INDEX(&((*list)[i]));
  78. }
  79. return DB_OK;
  80. }