| 1 | /* oo_READ_TEXT.h |
| 2 | * |
| 3 | * Copyright (C) 1994-2009,2011-2020,2022,2024,2026 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 3 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 | |
| 19 | #include "oo_undef.h" |
| 20 | |
| 21 | #define oo_SIMPLE(type, storage, x) \ |
| 22 | try { \ |
| 23 | our x = texget##storage (_textSource_); \ |
| 24 | } catch (MelderError) { \ |
| 25 | Melder_throw (U"\"" #x U"\" not read."); \ |
| 26 | } |
| 27 | |
| 28 | #define oo_SET(type, storage, x, setType) \ |
| 29 | for (integer _i = 0; _i <= (int) setType::MAX; _i ++) { \ |
| 30 | try { \ |
| 31 | our x [_i] = texget##storage (_textSource_); \ |
| 32 | } catch (MelderError) { \ |
| 33 | Melder_throw (U"Element ", _i+1, U" of \"" #x, U"\" not read."); \ |
| 34 | } \ |
| 35 | } |
| 36 | |
| 37 | #define oo_ANYVEC(type, storage, x, sizeExpression) \ |
| 38 | { \ |
| 39 | const integer _size = (sizeExpression); \ |
| 40 | our x = vector_readText_##storage (_size, _textSource_, #x); \ |
| 41 | } |
| 42 | |
| 43 | #define oo_ANYMAT(type, storage, x, nrowExpression, ncolExpression) \ |
| 44 | { \ |
| 45 | const integer _nrow = (nrowExpression), _ncol = (ncolExpression); \ |
| 46 | our x = matrix_readText_##storage (_nrow, _ncol, _textSource_, #x); \ |
| 47 | } |
| 48 | |
| 49 | #define oo_ANYTEN3(type, storage, x, ndim1Expression, ndim2Expression, ndim3Expression) \ |
| 50 | { \ |
| 51 | const integer _ndim1 = (ndim1Expression), _ndim2 = (ndim2Expression), _ndim3 = (ndim3Expression); \ |
| 52 | our x = tensor3_readText_##storage (_ndim1, _ndim2, _ndim3, _textSource_, #x); \ |
| 53 | } |
| 54 | |
| 55 | #define oo_ENUMx(kType, storage, x) \ |
| 56 | our x = (kType) texget##storage (_textSource_, (enum_generic_getValue) kType##_getValue); |
| 57 | |
| 58 | #define oo_STRINGx(storage, x) \ |
| 59 | try { \ |
| 60 | our x = texget##storage (_textSource_); \ |
| 61 | } catch (MelderError) { \ |
| 62 | Melder_throw (U"String \"" #x U"\" not read."); \ |
| 63 | } |
| 64 | |
| 65 | #define oo_STRINGx_SET(storage, x, setType) \ |
| 66 | for (integer _i = 0; _i <= setType::MAX; _i ++) { \ |
| 67 | our x [_i] = texget##storage (_textSource_); \ |
| 68 | } |
| 69 | |
| 70 | #define oo_STRINGx_VECTOR(storage, x, sizeExpression) \ |
| 71 | { \ |
| 72 | const integer _size = (sizeExpression); \ |
| 73 | if (_size > 0) { \ |
| 74 | our x = autoSTRVEC (_size); \ |
| 75 | for (integer _i = 1; _i <= _size; _i ++) { \ |
| 76 | try { \ |
| 77 | our x [_i] = texget##storage (_textSource_); \ |
| 78 | } catch (MelderError) { \ |
| 79 | Melder_throw (U"Element ", _i, U" of \"" #x U"\" not read."); \ |
| 80 | } \ |
| 81 | } \ |
| 82 | } \ |
| 83 | } |
| 84 | |
| 85 | #define oo_STRUCT(Type, x) \ |
| 86 | our x. readText (_textSource_, _formatVersion_); |
| 87 | |
| 88 | #define oo_STRUCT_SET(Type, x, setType) \ |
| 89 | for (integer _i = 0; _i <= (int) setType::MAX; _i ++) { \ |
| 90 | our x [_i]. readText (_textSource_, _formatVersion_); \ |
| 91 | } |
| 92 | |
| 93 | #define oo_STRUCTVEC(Type, x, sizeExpression) \ |
| 94 | { \ |
| 95 | const integer _size = (sizeExpression); \ |
| 96 | if (_size > 0) { \ |
| 97 | our x = newvectorzero <struct##Type> (_size); \ |
| 98 | for (integer _i = 1; _i <= _size; _i ++) { \ |
| 99 | our x [_i]. readText (_textSource_, _formatVersion_); \ |
| 100 | } \ |
| 101 | } \ |
| 102 | } |
| 103 | |
| 104 | #define oo_STRUCTMAT(Type, x, nrowExpression, ncolExpression) \ |
| 105 | { \ |
| 106 | const integer _nrow = (nrowExpression), _ncol = (ncolExpression); \ |
| 107 | if (_nrow > 0 && _ncol > 0) { \ |
| 108 | our x = newmatrixzero <struct##Type> (_nrow, _ncol); \ |
| 109 | for (integer _irow = 1; _irow <= _nrow; _irow ++) { \ |
| 110 | for (integer _icol = 1; _icol <= _ncol; _icol ++) { \ |
| 111 | our x [_irow] [_icol]. readText (_filePointer_, _formatVersion_); \ |
| 112 | } \ |
| 113 | } \ |
| 114 | } \ |
| 115 | } |
| 116 | |
| 117 | #define oo_OBJECT(Class, formatVersion, x) \ |
| 118 | { \ |
| 119 | const int _formatVersion = (formatVersion); \ |
| 120 | if (texgetex (_textSource_) == 1) { \ |
| 121 | our x = Thing_new (Class); \ |
| 122 | our x -> v1_readText (_textSource_, _formatVersion); \ |
| 123 | } \ |
| 124 | } |
| 125 | |
| 126 | #define oo_COLLECTION_OF(Class, x, ItemClass, formatVersion) \ |
| 127 | { \ |
| 128 | const int _formatVersion = (formatVersion); \ |
| 129 | const integer _n = texgetinteger (_textSource_); \ |
| 130 | for (integer _i = 1; _i <= _n; _i ++) { \ |
| 131 | auto##ItemClass _item = Thing_new (ItemClass); \ |
| 132 | _item -> v1_readText (_textSource_, _formatVersion); \ |
| 133 | our x. addItem_move (_item.move()); \ |
| 134 | } \ |
| 135 | } |
| 136 | |
| 137 | #define oo_COLLECTION(Class, x, ItemClass, formatVersion) \ |
| 138 | { \ |
| 139 | const int _formatVersion = (formatVersion); \ |
| 140 | const integer _n = texgetinteger (_textSource_); \ |
| 141 | our x = Class##_create (); \ |
| 142 | for (integer _i = 1; _i <= _n; _i ++) { \ |
| 143 | auto##ItemClass _item = Thing_new (ItemClass); \ |
| 144 | _item -> v1_readText (_textSource_, _formatVersion); \ |
| 145 | our x -> addItem_move (_item.move()); \ |
| 146 | } \ |
| 147 | } |
| 148 | |
| 149 | #define oo_TRANSIENT_FILE(x) |
| 150 | |
| 151 | #define oo_TRANSIENT_FOLDER(x) |
| 152 | |
| 153 | #define oo_UNSAFE_BORROWED_TRANSIENT_CONST_OBJECT_REFERENCE(Class, x) |
| 154 | |
| 155 | #define oo_UNSAFE_BORROWED_TRANSIENT_MUTABLE_OBJECT_REFERENCE(Class, x) |
| 156 | |
| 157 | #define oo_DEFINE_STRUCT(Type) \ |
| 158 | void struct##Type :: readText (MelderReadText _textSource_, int _formatVersion_) { \ |
| 159 | (void) _formatVersion_; |
| 160 | |
| 161 | #define oo_END_STRUCT(Type) \ |
| 162 | } |
| 163 | |
| 164 | #define oo_DEFINE_CLASS(Class, Parent) \ |
| 165 | void struct##Class :: v1_readText (MelderReadText _textSource_, int _formatVersion_) { \ |
| 166 | Melder_require (_formatVersion_ <= our classInfo -> version, \ |
| 167 | U"The format of this file is too new. Download a newer version of Praat."); \ |
| 168 | Class##_Parent :: v1_readText (_textSource_, _formatVersion_); |
| 169 | |
| 170 | #define oo_END_CLASS(Class) \ |
| 171 | } |
| 172 | |
| 173 | #define oo_FROM(from) \ |
| 174 | { \ |
| 175 | const int _from = (from); \ |
| 176 | if (_formatVersion_ >= _from) { |
| 177 | |
| 178 | #define oo_ENDFROM \ |
| 179 | } \ |
| 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 | |
| 195 | /* End of file oo_READ_TEXT.h */ |