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