oo_READ_TEXT.h 6.5 KB

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