oo_WRITE_BINARY.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* oo_WRITE_BINARY.h
  2. *
  3. * Copyright (C) 1994-2009,2011-2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "oo_undef.h"
  19. #define oo_SIMPLE(type, storage, x) \
  20. binput##storage (our x, f);
  21. #define oo_SET(type, storage, x, setType) \
  22. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  23. binput##storage (our x [_i], f); \
  24. }
  25. #define oo_VECTOR(type, storage, x, min, max) \
  26. { \
  27. integer _min = (min), _max = (max); \
  28. if (our x) { \
  29. NUMvector_writeBinary_##storage (our x, _min, _max, f); \
  30. } \
  31. }
  32. #define oo_ANYVEC(type, storage, x, sizeExpression) \
  33. { \
  34. integer _size = (sizeExpression); \
  35. Melder_assert (our x.size == _size); \
  36. if (our x.at) { \
  37. NUMvector_writeBinary_##storage (our x.at, 1, _size, f); \
  38. } \
  39. }
  40. #define oo_MATRIX(type, storage, x, row1, row2, col1, col2) \
  41. { \
  42. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  43. if (our x) { \
  44. NUMmatrix_writeBinary_##storage (our x, _row1, _row2, _col1, _col2, f); \
  45. } \
  46. }
  47. #define oo_ANYMAT(type, storage, x, nrowExpression, ncolExpression) \
  48. { \
  49. integer _nrow = (nrowExpression), _ncol = (ncolExpression); \
  50. Melder_assert (our x.nrow == _nrow && our x.ncol == _ncol); \
  51. if (our x.at) { \
  52. NUMmatrix_writeBinary_##storage (our x.at, 1, _nrow, 1, _ncol, f); \
  53. } \
  54. }
  55. #define oo_ENUMx(kType, storage, x) \
  56. binput##storage ((int) our x, f);
  57. //#define oo_ENUMx_SET(kType, storage, x, setType) \
  58. // for (int _i = 0; _i <= setType::MAX; _i ++) { \
  59. // binput##storage ((int) our x [_i], f); \
  60. // }
  61. //#define oo_ENUMx_VECTOR(kType, storage, x, min, max) \
  62. // { \
  63. // integer _min = (min), _max = (max); \
  64. // if (our x) { \
  65. // NUMvector_writeBinary_##storage ((int) our x, _min, _max, f); \
  66. // } \
  67. // {
  68. #define oo_STRINGx(storage,x) \
  69. binput##storage (our x.get(), f);
  70. #define oo_STRINGx_SET(storage, x, setType) \
  71. for (int _i = 0; _i <= setType::MAX; _i ++) { \
  72. binput##storage (our x [_i].get(), f); \
  73. }
  74. #define oo_STRINGx_VECTOR(storage, x, n) \
  75. { \
  76. integer _size = (n); \
  77. Melder_assert (_size == our x.size); \
  78. for (integer _i = 1; _i <= _size; _i ++) \
  79. binput##storage (our x [_i].get(), f); { \
  80. } \
  81. }
  82. #define oo_STRUCT(Type, x) \
  83. our x. writeBinary (f);
  84. #define oo_STRUCT_SET(Type, x, setType) \
  85. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  86. our x [_i]. writeBinary (f); \
  87. }
  88. #define oo_STRUCT_VECTOR_FROM(Type, x, min, max) \
  89. { \
  90. integer _min = (min), _max = (max); \
  91. for (integer _i = _min; _i <= _max; _i ++) { \
  92. our x [_i]. writeBinary (f); \
  93. } \
  94. }
  95. #define oo_STRUCT_MATRIX_FROM(Type, x, row1, row2, col1, col2) \
  96. { \
  97. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  98. for (integer _irow = _row1; _irow <= _row2; _irow ++) { \
  99. for (integer _icol = _col1; _icol <= _col2; _icol ++) { \
  100. our x [_irow] [_icol]. writeBinary (f); \
  101. } \
  102. } \
  103. }
  104. #define oo_OBJECT(Class, version, x) \
  105. binputex ((bool) our x, f); \
  106. if (our x) { \
  107. Data_writeBinary (our x.get(), f); \
  108. }
  109. #define oo_COLLECTION_OF(Class, x, ItemClass, version) \
  110. binputinteger32BE (our x.size, f); \
  111. for (integer _i = 1; _i <= our x.size; _i ++) { \
  112. ItemClass data = our x.at [_i]; \
  113. data -> struct##ItemClass :: v_writeBinary (f); \
  114. }
  115. #define oo_COLLECTION(Class, x, ItemClass, version) \
  116. binputinteger32BE (our x ? our x->size : 0, f); \
  117. if (our x) { \
  118. for (integer _i = 1; _i <= our x->size; _i ++) { \
  119. ItemClass data = our x->at [_i]; \
  120. data -> struct##ItemClass :: v_writeBinary (f); \
  121. } \
  122. }
  123. #define oo_FILE(x)
  124. #define oo_DIR(x)
  125. #define oo_DEFINE_STRUCT(Type) \
  126. void struct##Type :: writeBinary (FILE *f) {
  127. #define oo_END_STRUCT(Type) \
  128. }
  129. #define oo_DEFINE_CLASS(Class, Parent) \
  130. void struct##Class :: v_writeBinary (FILE *f) { \
  131. Class##_Parent :: v_writeBinary (f);
  132. #define oo_END_CLASS(Class) \
  133. }
  134. #define oo_FROM(from)
  135. #define oo_ENDFROM
  136. #define oo_DECLARING 0
  137. #define oo_DESTROYING 0
  138. #define oo_COPYING 0
  139. #define oo_COMPARING 0
  140. #define oo_VALIDATING_ENCODING 0
  141. #define oo_READING 0
  142. #define oo_READING_TEXT 0
  143. #define oo_READING_BINARY 0
  144. #define oo_WRITING 1
  145. #define oo_WRITING_TEXT 0
  146. #define oo_WRITING_BINARY 1
  147. #define oo_DESCRIBING 0
  148. /* End of file oo_WRITE_BINARY.h */