oo_WRITE_TEXT.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* oo_WRITE_TEXT.h
  2. *
  3. * Copyright (C) 1994-2005,2007-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. texput##storage (file, our x, U"" #x);
  21. #define oo_SET(type, storage, x, setType) \
  22. texputintro (file, U"" #x U" []:"); \
  23. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  24. texput##storage (file, our x [_i], U"" #x U" [", setType##_getText ((setType) _i), U"]"); \
  25. } \
  26. texexdent (file);
  27. #define oo_VECTOR(type, storage, x, min, max) \
  28. { \
  29. integer _min = (min), _max = (max); \
  30. if (our x) { \
  31. NUMvector_writeText_##storage (our x, _min, _max, file, U"" #x); \
  32. } \
  33. }
  34. #define oo_ANYVEC(type, storage, x, sizeExpression) \
  35. { \
  36. integer _size = (sizeExpression); \
  37. Melder_assert (our x.size == _size); \
  38. if (our x.at) { \
  39. NUMvector_writeText_##storage (our x.at, 1, _size, file, U"" #x); \
  40. } \
  41. }
  42. #define oo_MATRIX(type, storage, x, row1, row2, col1, col2) \
  43. { \
  44. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  45. if (our x) { \
  46. NUMmatrix_writeText_##storage (our x, _row1, _row2, _col1, _col2, file, U"" #x); \
  47. } \
  48. }
  49. #define oo_ANYMAT(type, storage, x, nrowExpression, ncolExpression) \
  50. { \
  51. integer _nrow = (nrowExpression), _ncol = (ncolExpression); \
  52. Melder_assert (our x.nrow == _nrow && our x.ncol == _ncol); \
  53. if (our x.at) { \
  54. NUMmatrix_writeText_##storage (our x.at, 1, _nrow, 1, _ncol, file, U"" #x); \
  55. } \
  56. }
  57. #define oo_ENUMx(kType, storage, x) \
  58. texput##storage (file, (int) our x, (const char32* (*) (int)) kType##_getText, U"" #x);
  59. //#define oo_ENUMx_SET(kType, storage, x, setType) \
  60. // texputintro (file, U"" #x U" []: ", n ? nullptr : U"(empty)"); \
  61. // for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  62. // texput##storage (file, (int) our x [_i], (const char32* (*) (int)) kType##_getText, U"" #x U" [", setType##_getText ((setType) _i), U"]"); \
  63. // } \
  64. // texexdent (file);
  65. //#define oo_ENUMx_VECTOR(kType, storage, x, min, max) \
  66. // { \
  67. // integer _min = (min), _max = (max); \
  68. // texputintro (file, U"" #x U" []: ", _max >= _min ? nullptr : U"(empty)"); \
  69. // for (integer _i = _min; _i <= _max; _i ++) { \
  70. // texput##storage (file, (int) our x [_i], (const char32* (*) (int)) kType##_getText, U"" #x U" [", Melder_integer (_i), U"]"); \
  71. // } \
  72. // texexdent (file); \
  73. // }
  74. #define oo_STRINGx(storage, x) \
  75. texput##storage (file, our x.get(), U""#x);
  76. #define oo_STRINGx_SET(storage, x, setType) \
  77. texputintro (file, U"" #x U" []:"); \
  78. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  79. texput##storage (file, our x [_i].get(), U"" #x U" [", setType##_getText ((setType) _i), U"]"); \
  80. } \
  81. texexdent (file);
  82. #define oo_STRINGx_VECTOR(storage, x, n) \
  83. { \
  84. integer _size = (n); \
  85. Melder_assert (_size == our x.size); \
  86. texputintro (file, U"" #x U" []: ", _size >= 1 ? nullptr : U"(empty)"); \
  87. for (integer _i = 1; _i <= _size; _i ++) { \
  88. texput##storage (file, our x [_i].get(), U"" #x U" [", Melder_integer (_i), U"]"); \
  89. } \
  90. texexdent (file); \
  91. }
  92. #define oo_STRUCT(Type, x) \
  93. texputintro (file, U"" #x U":"); \
  94. our x. writeText (file); \
  95. texexdent (file);
  96. #define oo_STRUCT_SET(Type, x, setType) \
  97. texputintro (file, U"" #x U" []:"); \
  98. for (int _i = 0; _i <= (int) setType::MAX; _i ++) { \
  99. texputintro (file, U"" #x U" [", setType##_getText ((setType) _i), U"]:"); \
  100. our x [_i]. writeText (file); \
  101. texexdent (file); \
  102. } \
  103. texexdent (file);
  104. #define oo_STRUCT_VECTOR_FROM(Type, x, min, max) \
  105. { \
  106. integer _min = (min), _max = (max); \
  107. texputintro (file, U"" #x U" []: ", _max >= _min ? nullptr : U"(empty)"); \
  108. for (integer _i = _min; _i <= _max; _i ++) { \
  109. texputintro (file, U"" #x U" [", Melder_integer (_i), U"]:"); \
  110. our x [_i]. writeText (file); \
  111. texexdent (file); \
  112. } \
  113. texexdent (file); \
  114. }
  115. #define oo_STRUCT_MATRIX_FROM(Type, x, row1, row2, col1, col2) \
  116. { \
  117. integer _row1 = (row1), _row2 = (row2), _col1 = (col1), _col2 = (col2); \
  118. texputintro (file, U"" #x U" [] []: ", _row2 >= _row1 ? nullptr : U"(empty)"); \
  119. for (integer _irow = _row1; _irow <= _row2; _irow ++) { \
  120. texputintro (file, U"" #x U" [", Melder_integer (_irow), U"]:"); \
  121. for (integer _icol = _col1; _icol <= _col2; _icol ++) { \
  122. texputintro (file, U"" #x U" [", Melder_integer (_irow), U"] [", Melder_integer (_icol), U"]:"); \
  123. our x [_irow] [_icol]. writeText (file); \
  124. texexdent (file); \
  125. } \
  126. texexdent (file); \
  127. } \
  128. texexdent (file); \
  129. }
  130. #define oo_OBJECT(Class, version, x) \
  131. texputex (file, !! our x, U"" #x); \
  132. if (our x) { \
  133. Data_writeText (our x.get(), file); \
  134. }
  135. #define oo_COLLECTION_OF(Class, x, ItemClass, version) \
  136. texputinteger (file, our x.size, U"" #x U": size"); \
  137. for (integer _i = 1; _i <= our x.size; _i ++) { \
  138. ItemClass data = our x.at [_i]; \
  139. texputintro (file, U"" #x U" [", Melder_integer (_i), U"]:"); \
  140. data -> struct##ItemClass :: v_writeText (file); \
  141. texexdent (file); \
  142. }
  143. #define oo_COLLECTION(Class, x, ItemClass, version) \
  144. texputinteger (file, our x ? our x->size : 0, U"" #x U": size"); \
  145. if (our x) { \
  146. for (integer _i = 1; _i <= our x->size; _i ++) { \
  147. ItemClass data = our x->at [_i]; \
  148. texputintro (file, U"" #x U" [", Melder_integer (_i), U"]:"); \
  149. data -> struct##ItemClass :: v_writeText (file); \
  150. texexdent (file); \
  151. } \
  152. }
  153. #define oo_FILE(x)
  154. #define oo_DIR(x)
  155. #define oo_DEFINE_STRUCT(Type) \
  156. void struct##Type :: writeText (MelderFile file) {
  157. #define oo_END_STRUCT(Type) \
  158. }
  159. #define oo_DEFINE_CLASS(Class, Parent) \
  160. void struct##Class :: v_writeText (MelderFile file) { \
  161. Class##_Parent :: v_writeText (file);
  162. #define oo_END_CLASS(Class) \
  163. }
  164. #define oo_FROM(from)
  165. #define oo_ENDFROM
  166. #define oo_DECLARING 0
  167. #define oo_DESTROYING 0
  168. #define oo_COPYING 0
  169. #define oo_COMPARING 0
  170. #define oo_VALIDATING_ENCODING 0
  171. #define oo_READING 0
  172. #define oo_READING_TEXT 0
  173. #define oo_READING_BINARY 0
  174. #define oo_WRITING 1
  175. #define oo_WRITING_TEXT 1
  176. #define oo_WRITING_BINARY 0
  177. #define oo_DESCRIBING 0
  178. /* End of file oo_WRITE_TEXT.h */