oo_READ_BINARY.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* oo_READ_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. our x = binget##storage (_filePointer_);
  21. #define oo_SET(type, storage, x, setType) \
  22. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  23. our x [_i] = binget##storage (_filePointer_); \
  24. }
  25. #define oo_VECTOR(type, storage, x, min, max) \
  26. { \
  27. integer _min = (min), _max = (max); \
  28. if (_max >= _min) { \
  29. our x = NUMvector_readBinary_##storage (_min, _max, _filePointer_); \
  30. } \
  31. }
  32. #define oo_ANYVEC(type, storage, x, sizeExpression) \
  33. { \
  34. integer _size = (sizeExpression); \
  35. if (_size > 0) { \
  36. our x.at = NUMvector_readBinary_##storage (1, _size, _filePointer_); \
  37. our x.size = _size; \
  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 (_row2 >= _row1 && _col2 >= _col1) { \
  44. our x = NUMmatrix_readBinary_##storage (_row1, _row2, _col1, _col2, _filePointer_); \
  45. } \
  46. }
  47. #define oo_ANYMAT(type, storage, x, nrowExpression, ncolExpression) \
  48. { \
  49. integer _nrow = (nrowExpression), _ncol = (ncolExpression); \
  50. if (_nrow > 0 && _ncol > 0) { \
  51. our x.at = NUMmatrix_readBinary_##storage (1, _nrow, 1, _ncol, _filePointer_); \
  52. our x.nrow = _nrow; \
  53. our x.ncol = _ncol; \
  54. } \
  55. }
  56. #define oo_ENUMx(kType, storage, x) \
  57. our x = (kType) binget##storage (_filePointer_, (int) kType::MIN, (int) kType::MAX, U"" #kType);
  58. //#define oo_ENUMx_SET(kType, storage, x, setType) \
  59. // for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  60. // our x [_i] = (kType) binget##storage (_filePointer_, (int) kType::MIN, (int) kType::MAX, U"" #kType); \
  61. // }
  62. //#define oo_ENUMx_VECTOR(kType, storage, x, min, max) \
  63. // { \
  64. // integer _min = (min), _max = (max); \
  65. // if (_max >= _min) { \
  66. // our x = NUMvector <kType> (_min, _max); \
  67. // for (integer _i = _min; _i <= _max; _i ++) { \
  68. // our x [_i] = (kType) binget##storage (_filePointer_, (int) kType::MIN, (int) kType::MAX, U"" #kType); \
  69. // } \
  70. // }
  71. #define oo_STRINGx(storage, x) \
  72. our x = binget##storage (_filePointer_);
  73. #define oo_STRINGx_SET(storage, x, setType) \
  74. for (int _i = 0; _i <= setType::MAX; _i ++) { \
  75. our x [_i] = binget##storage (_filePointer_); \
  76. }
  77. #define oo_STRINGx_VECTOR(storage, x, n) \
  78. { \
  79. integer _size = (n); \
  80. if (_size >= 1) { \
  81. our x = autostring32vector (_size); \
  82. for (integer _i = 1; _i <= _size; _i ++) { \
  83. our x [_i] = binget##storage (_filePointer_); \
  84. } \
  85. } \
  86. }
  87. #define oo_STRUCT(Type,x) \
  88. our x. readBinary (_filePointer_, _formatVersion_);
  89. #define oo_STRUCT_SET(Type, x, setType) \
  90. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  91. our x [_i]. readBinary (_filePointer_, _formatVersion_); \
  92. }
  93. #define oo_STRUCT_VECTOR_FROM(Type, x, min, max) \
  94. { \
  95. integer _min = (min), _max = (max); \
  96. if (_max >= _min) { \
  97. our x = NUMvector <struct##Type> (_min, _max); \
  98. for (integer _i = _min; _i <= _max; _i ++) { \
  99. our x [_i]. readBinary (_filePointer_, _formatVersion_); \
  100. } \
  101. } \
  102. }
  103. #define oo_STRUCT_MATRIX_FROM(Type, x, row1, row2, col1, col2) \
  104. { \
  105. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  106. if (_row2 >= _row1 && _col2 >= _col1) { \
  107. our x = NUMmatrix <struct##Type> (_row1, _row2, _col1, _col2); \
  108. for (integer _irow = _row1; _irow <= _row2; _irow ++) { \
  109. for (integer _icol = _col1; _icol <= _col2; _icol ++) { \
  110. our x [_irow] [_icol]. readBinary (_filePointer_, _formatVersion_); \
  111. } \
  112. } \
  113. } \
  114. }
  115. #define oo_OBJECT(Class, formatVersion, x) \
  116. { \
  117. int _formatVersion = (formatVersion); \
  118. if (bingetex (_filePointer_)) { \
  119. our x = Thing_new (Class); \
  120. our x -> v_readBinary (_filePointer_, _formatVersion); \
  121. } \
  122. }
  123. #define oo_COLLECTION_OF(Class, x, ItemClass, formatVersion) \
  124. { \
  125. int _formatVersion = (formatVersion); \
  126. integer _n = bingetinteger32BE (_filePointer_); \
  127. for (integer _i = 1; _i <= _n; _i ++) { \
  128. auto##ItemClass _item = Thing_new (ItemClass); \
  129. _item -> v_readBinary (_filePointer_, _formatVersion); \
  130. our x.addItem_move (_item.move()); \
  131. } \
  132. }
  133. #define oo_COLLECTION(Class, x, ItemClass, formatVersion) \
  134. { \
  135. int _formatVersion = (formatVersion); \
  136. integer _n = bingetinteger32BE (_filePointer_); \
  137. our x = Class##_create (); \
  138. for (integer _i = 1; _i <= _n; _i ++) { \
  139. auto##ItemClass _item = Thing_new (ItemClass); \
  140. _item -> v_readBinary (_filePointer_, _formatVersion); \
  141. our x -> addItem_move (_item.move()); \
  142. } \
  143. }
  144. #define oo_FILE(x)
  145. #define oo_DIR(x)
  146. #define oo_DEFINE_STRUCT(Type) \
  147. void struct##Type :: readBinary (FILE *_filePointer_, int _formatVersion_) { \
  148. (void) _formatVersion_;
  149. #define oo_END_STRUCT(Type) \
  150. }
  151. #define oo_DEFINE_CLASS(Class, Parent) \
  152. void struct##Class :: v_readBinary (FILE *_filePointer_, int _formatVersion_) { \
  153. Melder_require (_formatVersion_ <= our classInfo -> version, \
  154. U"The format of this file is too new. Download a newer version of Praat."); \
  155. Class##_Parent :: v_readBinary (_filePointer_, _formatVersion_);
  156. #define oo_END_CLASS(Class) \
  157. }
  158. #define oo_FROM(from) \
  159. { \
  160. int _from = (from); \
  161. if (_formatVersion_ >= _from) {
  162. #define oo_ENDFROM \
  163. } \
  164. }
  165. #define oo_DECLARING 0
  166. #define oo_DESTROYING 0
  167. #define oo_COPYING 0
  168. #define oo_COMPARING 0
  169. #define oo_VALIDATING_ENCODING 0
  170. #define oo_READING 1
  171. #define oo_READING_TEXT 0
  172. #define oo_READING_BINARY 1
  173. #define oo_WRITING 0
  174. #define oo_WRITING_TEXT 0
  175. #define oo_WRITING_BINARY 0
  176. #define oo_DESCRIBING 0
  177. /* End of file oo_READ_BINARY.h */