| 1 | #cxx . . $ `<file>/sys/Data.h`/ifndef _Data_h_ |
| 2 | #define _Data_h_cxx . . $ `sys/Data.h:2:9`! |
| 3 | /* Data.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2009,2011,2012,2014-2019,2021-2024 Paul Boersma |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | * See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* Data inherits from Thing. */ |
| 22 | /* It adds the functionality of reproduction, comparison, reading, and writing. */ |
| 23 | #include "Thing.h"cxx . . $ `<file>/sys/Thing.h`/ |
| 24 | |
| 25 | typedef struct structData_Descriptioncxx . . $ structData_Description# { |
| 26 | conststring32cxx . . $ conststring32# namecxx . . $ structData_Description#name.; // the name of this field |
| 27 | int typecxx . . $ structData_Description#type.; // bytewa..inheritwa, see below |
| 28 | int offsetcxx . . $ structData_Description#offset.; // the offset of this field in the enveloping struct |
| 29 | int sizecxx . . $ structData_Description#size.; // the size of this field if it is in an array |
| 30 | conststring32cxx . . $ conststring32# tagNamecxx . . $ structData_Description#tagName.; // for structs: tag; for classes: class name; for enums: type name |
| 31 | void *tagTypecxx . . $ structData_Description#tagType.; // for structs: offset table; for classes: class pointer; for enums: enum pointer |
| 32 | int rankcxx . . $ structData_Description#rank.; // 0 = single, 1 = vector, 2 = matrix, 3 = set, -1 = array |
| 33 | conststring32cxx . . $ conststring32# min1cxx . . $ structData_Description#min1., max1cxx . . $ structData_Description#max1.; // for vectors and matrices |
| 34 | conststring32cxx . . $ conststring32# min2cxx . . $ structData_Description#min2., max2cxx . . $ structData_Description#max2.; // for matrices |
| 35 | } *Data_Descriptioncxx . . $ Data_Description#; |
| 36 | |
| 37 | /* |
| 38 | * We call the class Daata instead of Data, |
| 39 | * because of a conflict with the use of "Data" in assembler strings in intrin-impl.h on Windows. |
| 40 | */ |
| 41 | |
| 42 | Thing_definecxx . . $ ClassInfo# (Daata, Thing) { |
| 43 | virtual void v1_copycxx . . $ structDaata#v1_copy(42659c2335f2eda7). (Daatacxx . . $ Daata# /* data_to */) const { } |
| 44 | virtual bool v1_equalcxx . . $ structDaata#v1_equal(de90b88e0a4bb7f7). (Daatacxx . . $ Daata# /* otherData */) { |
| 45 | return true; // names of "identical" objects are allowed to be different |
| 46 | } |
| 47 | virtual Data_Descriptioncxx . . $ Data_Description# v_descriptioncxx . . $ structDaata#v_description(669317afad7f96e1). () { return nullptr; } |
| 48 | virtual bool v_writablecxx . . $ structDaata#v_writable(c9857a73d68e59ba). () { return true; } |
| 49 | virtual bool v1_canWriteAsEncodingcxx . . $ structDaata#v1_canWriteAsEncoding(83c267b20bac841a). (int /* outputEncoding */) { return true; } |
| 50 | virtual void v1_writeTextcxx . . $ structDaata#v1_writeText(1145552d769d7b5d). (MelderFilecxx . . $ MelderFile# /* openFile */) { } |
| 51 | virtual void v1_readTextcxx . . $ structDaata#v1_readText(97c85d3b778168ad). (MelderReadTextcxx . . $ MelderReadText# /* text */, int /* formatVersion */) { } |
| 52 | virtual void v1_writeBinarycxx . . $ structDaata#v1_writeBinary(8d4262d45fc644ab). (FILEcxx . . $ FILE# * /* f */) { } |
| 53 | virtual void v1_readBinarycxx . . $ structDaata#v1_readBinary(e780f64711fb334f). (FILEcxx . . $ FILE# * /* f */, int /* formatVersion */) { } |
| 54 | virtual void v_repaircxx . . $ structDaata#v_repair(49f6e7a06ebc5aa8). () { } // after reading Praat data files created by others |
| 55 | // methods for scripting: |
| 56 | virtual bool v_hasGetNrowcxx . . $ structDaata#v_hasGetNrow(50ce9a9e25b4a850). () const { return false; } virtual double v_getNrowcxx . . $ structDaata#v_getNrow(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 57 | virtual bool v_hasGetNcolcxx . . $ structDaata#v_hasGetNcol(50ce9a9e25b4a850). () const { return false; } virtual double v_getNcolcxx . . $ structDaata#v_getNcol(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 58 | virtual bool v_hasGetXmincxx . . $ structDaata#v_hasGetXmin(50ce9a9e25b4a850). () const { return false; } virtual double v_getXmincxx . . $ structDaata#v_getXmin(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 59 | virtual bool v_hasGetXmaxcxx . . $ structDaata#v_hasGetXmax(50ce9a9e25b4a850). () const { return false; } virtual double v_getXmaxcxx . . $ structDaata#v_getXmax(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 60 | virtual bool v_hasGetYmincxx . . $ structDaata#v_hasGetYmin(50ce9a9e25b4a850). () const { return false; } virtual double v_getYmincxx . . $ structDaata#v_getYmin(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 61 | virtual bool v_hasGetYmaxcxx . . $ structDaata#v_hasGetYmax(50ce9a9e25b4a850). () const { return false; } virtual double v_getYmaxcxx . . $ structDaata#v_getYmax(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 62 | virtual bool v_hasGetNxcxx . . $ structDaata#v_hasGetNx(50ce9a9e25b4a850). () const { return false; } virtual double v_getNxcxx . . $ structDaata#v_getNx(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 63 | virtual bool v_hasGetNycxx . . $ structDaata#v_hasGetNy(50ce9a9e25b4a850). () const { return false; } virtual double v_getNycxx . . $ structDaata#v_getNy(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 64 | virtual bool v_hasGetDxcxx . . $ structDaata#v_hasGetDx(50ce9a9e25b4a850). () const { return false; } virtual double v_getDxcxx . . $ structDaata#v_getDx(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 65 | virtual bool v_hasGetDycxx . . $ structDaata#v_hasGetDy(50ce9a9e25b4a850). () const { return false; } virtual double v_getDycxx . . $ structDaata#v_getDy(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 66 | virtual bool v_hasGetXcxx . . $ structDaata#v_hasGetX(50ce9a9e25b4a850). () const { return false; } virtual double v_getXcxx . . $ structDaata#v_getX(9db9ea2d2e621dac). (integercxx . . $ integer# /* ix */) const { return undefinedcxx . . $ undefined.; } |
| 67 | virtual bool v_hasGetYcxx . . $ structDaata#v_hasGetY(50ce9a9e25b4a850). () const { return false; } virtual double v_getYcxx . . $ structDaata#v_getY(9db9ea2d2e621dac). (integercxx . . $ integer# /* iy */) const { return undefinedcxx . . $ undefined.; } |
| 68 | virtual bool v_hasGetRowStrcxx . . $ structDaata#v_hasGetRowStr(50ce9a9e25b4a850). () const { return false; } virtual conststring32cxx . . $ conststring32# v_getRowStrcxx . . $ structDaata#v_getRowStr(ddccc6a34553c711). (integercxx . . $ integer# /* irow */) const { return nullptr; } |
| 69 | virtual bool v_hasGetColStrcxx . . $ structDaata#v_hasGetColStr(50ce9a9e25b4a850). () const { return false; } virtual conststring32cxx . . $ conststring32# v_getColStrcxx . . $ structDaata#v_getColStr(ddccc6a34553c711). (integercxx . . $ integer# /* icol */) const { return nullptr; } |
| 70 | virtual bool v_hasGetCellcxx . . $ structDaata#v_hasGetCell(50ce9a9e25b4a850). () const { return false; } virtual double v_getCellcxx . . $ structDaata#v_getCell(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 71 | virtual bool v_hasGetCellStrcxx . . $ structDaata#v_hasGetCellStr(50ce9a9e25b4a850). () const { return false; } virtual conststring32cxx . . $ conststring32# v_getCellStrcxx . . $ structDaata#v_getCellStr(d608cbfe2b610d03). () const { return nullptr; } |
| 72 | virtual bool v_hasGetVectorcxx . . $ structDaata#v_hasGetVector(50ce9a9e25b4a850). () const { return false; } virtual double v_getVectorcxx . . $ structDaata#v_getVector(f7a1f362ba849873). (integercxx . . $ integer# /* irow */, integercxx . . $ integer# /* icol */) const { return undefinedcxx . . $ undefined.; } |
| 73 | virtual bool v_hasGetVectorStrcxx . . $ structDaata#v_hasGetVectorStr(50ce9a9e25b4a850). () const { return false; } virtual conststring32cxx . . $ conststring32# v_getVectorStrcxx . . $ structDaata#v_getVectorStr(ddccc6a34553c711). (integercxx . . $ integer# /* icol */) const { return nullptr; } |
| 74 | virtual bool v_hasGetMatrixcxx . . $ structDaata#v_hasGetMatrix(50ce9a9e25b4a850). () const { return false; } virtual double v_getMatrixcxx . . $ structDaata#v_getMatrix(f7a1f362ba849873). (integercxx . . $ integer# /* irow */, integercxx . . $ integer# /* icol */) const { return undefinedcxx . . $ undefined.; } |
| 75 | virtual bool v_hasGetMatrixStrcxx . . $ structDaata#v_hasGetMatrixStr(50ce9a9e25b4a850). () const { return false; } virtual conststring32cxx . . $ conststring32# v_getMatrixStrcxx . . $ structDaata#v_getMatrixStr(c8b99bd074b1acbd). (integercxx . . $ integer# /* irow */, integercxx . . $ integer# /* icol */) const { return nullptr; } |
| 76 | virtual bool v_hasGetFunction0cxx . . $ structDaata#v_hasGetFunction0(50ce9a9e25b4a850). () const { return false; } virtual double v_getFunction0cxx . . $ structDaata#v_getFunction0(21b6c25e127938e2). () const { return undefinedcxx . . $ undefined.; } |
| 77 | virtual bool v_hasGetFunction1cxx . . $ structDaata#v_hasGetFunction1(50ce9a9e25b4a850). () const { return false; } virtual double v_getFunction1cxx . . $ structDaata#v_getFunction1(6525b878db7c2448). (integercxx . . $ integer# /* irow */, double /* x */) const { return undefinedcxx . . $ undefined.; } |
| 78 | virtual bool v_hasGetFunction2cxx . . $ structDaata#v_hasGetFunction2(50ce9a9e25b4a850). () const { return false; } virtual double v_getFunction2cxx . . $ structDaata#v_getFunction2(726307d3d9a4aee5). (double /* x */, double /* y */) const { return undefinedcxx . . $ undefined.; } |
| 79 | virtual bool v_hasGetRowIndexcxx . . $ structDaata#v_hasGetRowIndex(50ce9a9e25b4a850). () const { return false; } virtual double v_getRowIndexcxx . . $ structDaata#v_getRowIndex(7ac99ac30f1b1e93). (conststring32cxx . . $ conststring32# /* rowLabel */) const { return undefinedcxx . . $ undefined.; } |
| 80 | virtual bool v_hasGetColIndexcxx . . $ structDaata#v_hasGetColIndex(50ce9a9e25b4a850). () const { return false; } virtual double v_getColIndexcxx . . $ structDaata#v_getColIndex(7ac99ac30f1b1e93). (conststring32cxx . . $ conststring32# /* colLabel */) const { return undefinedcxx . . $ undefined.; } |
| 81 | }; |
| 82 | |
| 83 | template <class T> autoSomeThingcxx . . $ autoSomeThing#<T> Data_copycxx . . $ Data_copy(97a542a26794c80e). (const T* data) { |
| 84 | return _Data_copy (data).template static_cast_move <T>(); |
| 85 | } |
| 86 | autoDaatacxx . . $ autoDaata# _Data_copycxx . . $ _Data_copy(a046ccb3339e7e89). (constDaatacxx . . $ constDaata# me); |
| 87 | /* |
| 88 | Message: |
| 89 | "return a deep copy of yourself." |
| 90 | Postconditions: |
| 91 | result -> name == nullptr; // the only attribute NOT copied |
| 92 | */ |
| 93 | |
| 94 | bool Data_equalcxx . . $ Data_equal(6df46d860ee4054f). (Daatacxx . . $ Daata# data1, Daatacxx . . $ Daata# data2); |
| 95 | /* |
| 96 | Message: |
| 97 | "return true if the shallow or deep attributes of 'data1' and 'data2' are equal; |
| 98 | otherwise, return false." |
| 99 | Comment: |
| 100 | Data_equal (data, Data_copy (data)) should always return 1; the names are not compared. |
| 101 | */ |
| 102 | |
| 103 | typedef MelderCompareHookcxx . . $ MelderCompareHook#<structDaatacxx . . $ structDaata#> Data_CompareHookcxx . . $ Data_CompareHook#; |
| 104 | |
| 105 | bool Data_canWriteAsEncodingcxx . . $ Data_canWriteAsEncoding(c7ae84fff4422498). (Daatacxx . . $ Daata# me, int outputEncoding); |
| 106 | /* |
| 107 | Message: |
| 108 | "Can you write yourself in that encoding?" |
| 109 | The answer depends on whether all members can be written in that encoding. |
| 110 | */ |
| 111 | |
| 112 | bool Data_canWriteTextcxx . . $ Data_canWriteText(de90b88e0a4bb7f7). (Daatacxx . . $ Daata# me); |
| 113 | /* |
| 114 | Message: |
| 115 | "Can you write yourself as text?" |
| 116 | The answer depends on whether the subclass defines the 'writeText' method. |
| 117 | */ |
| 118 | |
| 119 | MelderFilecxx . . $ MelderFile# Data_createTextFilecxx . . $ Data_createTextFile(e035bb54dc67a3c9). ( |
| 120 | Daatacxx . . $ Daata# me, |
| 121 | MelderFilecxx . . $ MelderFile# file, |
| 122 | bool verbose |
| 123 | ); // returns the input MelderFile in order to be caught by an autoMelderFile |
| 124 | |
| 125 | void Data_writeTextcxx . . $ Data_writeText(c3dcdea1be00195). (Daatacxx . . $ Daata# me, MelderFilecxx . . $ MelderFile# openFile); |
| 126 | /* |
| 127 | Message: |
| 128 | "try to write yourself as text to an open file." |
| 129 | Return value: |
| 130 | 1 if OK, 0 in case of failure. |
| 131 | Failures: |
| 132 | I/O error. |
| 133 | Disk full. |
| 134 | Description: |
| 135 | The format depends on the 'writeText' method defined by the subclass. |
| 136 | */ |
| 137 | |
| 138 | void Data_writeToTextFilecxx . . $ Data_writeToTextFile(c3dcdea1be00195). (Daatacxx . . $ Daata# me, MelderFilecxx . . $ MelderFile# file); |
| 139 | /* |
| 140 | Message: |
| 141 | "try to write yourself as text to a file". |
| 142 | Description: |
| 143 | The first line is 'File type = "ooTextFile"'. |
| 144 | Your class name is written in the second line, |
| 145 | e.g., if you are a Person, the second line will be 'Object class = "Person"'. |
| 146 | The format of the lines after the second line is the same as in Data_writeText. |
| 147 | */ |
| 148 | |
| 149 | void Data_writeToShortTextFilecxx . . $ Data_writeToShortTextFile(c3dcdea1be00195). (Daatacxx . . $ Daata# me, MelderFilecxx . . $ MelderFile# file); |
| 150 | /* |
| 151 | Message: |
| 152 | "try to write yourself as text to a file". |
| 153 | Description: |
| 154 | The first line is 'File type = "ooTextFile short"'. |
| 155 | Your class name is written in the second line, |
| 156 | e.g., if you are a Person, the second line will be '"Person"'. |
| 157 | The format of the lines after the second line is the same as in Data_writeText. |
| 158 | */ |
| 159 | |
| 160 | bool Data_canWriteBinarycxx . . $ Data_canWriteBinary(de90b88e0a4bb7f7). (Daatacxx . . $ Daata# me); |
| 161 | /* |
| 162 | Message: |
| 163 | "Can you write yourself as binary data?" |
| 164 | The answer depends on whether the subclass defines the 'writeBinary' method. |
| 165 | */ |
| 166 | |
| 167 | void Data_writeBinarycxx . . $ Data_writeBinary(68e9d566a624648b). (Daatacxx . . $ Daata# me, FILEcxx . . $ FILE# *f); |
| 168 | /* |
| 169 | Message: |
| 170 | "try to write yourself as binary data to an open file." |
| 171 | Failures: |
| 172 | I/O error. |
| 173 | Disk full. |
| 174 | Description: |
| 175 | The format depends on the 'writeBinary' method defined by the subclass, |
| 176 | but is machine independent because it always uses 'most significant byte first' |
| 177 | and IEEE floating-point format. |
| 178 | */ |
| 179 | |
| 180 | void Data_writeToBinaryFilecxx . . $ Data_writeToBinaryFile(c3dcdea1be00195). (Daatacxx . . $ Daata# me, MelderFilecxx . . $ MelderFile# file); |
| 181 | /* |
| 182 | Message: |
| 183 | "try to write yourself as binary data to a file". |
| 184 | Description: |
| 185 | First, your class name is written in the file, |
| 186 | e.g., if you are a Person, the file will start with "PersonBinaryFile". |
| 187 | The format of the file after this is the same as in Data_writeBinary. |
| 188 | */ |
| 189 | |
| 190 | bool Data_canReadTextcxx . . $ Data_canReadText(de90b88e0a4bb7f7). (Daatacxx . . $ Daata# me); |
| 191 | /* |
| 192 | Message: |
| 193 | "Can you read yourself as text?" |
| 194 | The answer depends on whether the subclass defines a 'readText' method, |
| 195 | but is preferably the same as the answer from Data_canWriteText. |
| 196 | */ |
| 197 | |
| 198 | void Data_readTextcxx . . $ Data_readText(e29ade1c14d5e948). (Daatacxx . . $ Daata# me, MelderReadTextcxx . . $ MelderReadText# text, int formatVersion); |
| 199 | /* |
| 200 | Message: |
| 201 | "try to read yourself as text from a string." |
| 202 | Failures: |
| 203 | The 'readText' method of the subclass failed. |
| 204 | I/O error. |
| 205 | Early end of file detected. |
| 206 | Description: |
| 207 | The format depends on the 'readText' method defined by the subclass, |
| 208 | but is preferably the same as the format produced by the 'writeText' method. |
| 209 | */ |
| 210 | |
| 211 | autoDaatacxx . . $ autoDaata# Data_readFromTextFilecxx . . $ Data_readFromTextFile(da9ba57d6e09e2a7). (MelderFilecxx . . $ MelderFile# file); |
| 212 | /* |
| 213 | Message: |
| 214 | "try to read a Data as text from a file". |
| 215 | Description: |
| 216 | The Data's class name is read from the first line, |
| 217 | e.g., if the first line is "PersonTextFile", the Data will be a Person. |
| 218 | The format of the lines after the first line is the same as in Data_readText. |
| 219 | Return value: |
| 220 | the new object. |
| 221 | Failures: |
| 222 | Error opening file <fileName>. |
| 223 | The file <fileName> does not contain an object. |
| 224 | (plus those from Data_readText) |
| 225 | */ |
| 226 | |
| 227 | bool Data_canReadBinarycxx . . $ Data_canReadBinary(de90b88e0a4bb7f7). (Daatacxx . . $ Daata# me); |
| 228 | /* |
| 229 | Message: |
| 230 | "Can you read yourself as binary data?" |
| 231 | The answer depends on whether the subclass defines a 'readBinary' method, |
| 232 | but is preferably the same as the answer from Data_canWriteBinary. |
| 233 | */ |
| 234 | |
| 235 | void Data_readBinarycxx . . $ Data_readBinary(dfb403fb68f74b69). (Daatacxx . . $ Daata# me, FILEcxx . . $ FILE# *f, int formatVersion); |
| 236 | /* |
| 237 | Message: |
| 238 | "try to read yourself as binary data from the stream <f>." |
| 239 | Failures: |
| 240 | The 'readBinary' method of the subclass throws an error. |
| 241 | I/O error. |
| 242 | Early end of file detected. |
| 243 | Description: |
| 244 | The format depends on the 'readBinary' method defined by the subclass, |
| 245 | but is preferably the same as the format produced by the 'writeBinary' method. |
| 246 | */ |
| 247 | |
| 248 | autoDaatacxx . . $ autoDaata# Data_readFromBinaryFilecxx . . $ Data_readFromBinaryFile(da9ba57d6e09e2a7). (MelderFilecxx . . $ MelderFile# file); |
| 249 | /* |
| 250 | Message: |
| 251 | "try to read a Data as binary data from a file". |
| 252 | Description: |
| 253 | The Data's class name is read from the start of the file, |
| 254 | e.g., if the file starts with is "PersonBinaryFile", the Data will be a Person. |
| 255 | The format of the file after this is the same as in Data_readBinary. |
| 256 | Return value: |
| 257 | the new object. |
| 258 | Failures: |
| 259 | Error opening file <fileName>. |
| 260 | The file <fileName> does not contain an object. |
| 261 | (plus those from Data_readBinary) |
| 262 | */ |
| 263 | |
| 264 | using Data_FileTypeRecognizercxx . . $ Data_FileTypeRecognizer# = autoDaatacxx . . $ autoDaata# (*) (integercxx . . $ integer# numberOfBytesRead, const char *header, MelderFilecxx . . $ MelderFile# file); |
| 265 | |
| 266 | void Data_recognizeFileTypecxx . . $ Data_recognizeFileType(7ed4186908013b3d). (Data_FileTypeRecognizercxx . . $ Data_FileTypeRecognizer# recognizer); |
| 267 | /* |
| 268 | Purpose: |
| 269 | to make sure that a file can be read by Data_readFromFile. |
| 270 | Arguments: |
| 271 | recognizer |
| 272 | a routine that tries to identify a file as being of a certain type, |
| 273 | from the information in the header of the file and/or from the file name. |
| 274 | If the identification succeeds, the recognizer routine should call the routine |
| 275 | that actually reads the file. |
| 276 | nread |
| 277 | the length of the header of the file. The maximum value of nread is 512, |
| 278 | but it is smaller if the file is shorter than 512 bytes. |
| 279 | header |
| 280 | a buffer that contains the first nread bytes of the file; |
| 281 | the data were put there by Data_readFromFile before calling the recognizers. |
| 282 | The first byte is in header [0]. |
| 283 | fileName |
| 284 | the name of the file that is to be recognized. The recognizer routine uses this name |
| 285 | to actually read the file if it positively identifies the file. The recognizer routine |
| 286 | may also use %fileName in the recognition process; e.g. some files with raw sound data |
| 287 | have names that make them recognizable as files with raw sound data. |
| 288 | Defining a file-type recognizer: |
| 289 | You define a file-type recognizer as in the following example, |
| 290 | which tries to identify and read a Sun audio file. |
| 291 | A Sun audio file should contain at least 24 bytes and start with the string ".snd": |
| 292 | autoDaata Sound_sunAudioFileRecognizer (int nread, const char *header, MelderFile file) { |
| 293 | if (nread >= 24 && strnequ (& header [0], ".snd", 4)) |
| 294 | return Sound_readFromSunAudioFile (file); |
| 295 | else |
| 296 | return autoDaata (); |
| 297 | } |
| 298 | From this example, we see that if the file is recognized, it should be read immediately, |
| 299 | and the resulting object (always a descendant of class Data) should be returned. |
| 300 | We also see that the return value nullptr is used for notifying Data_readFromFile |
| 301 | of the fact that the file is not a Sun audio file. |
| 302 | Registering a file-type recognizer: |
| 303 | You would put a statement like the following in the initialization section of your program: |
| 304 | Data_recognizeFileType (Sound_sunAudioFileRecognizer); |
| 305 | After this, Data_readFromFile is able to read Sun audio files. |
| 306 | */ |
| 307 | |
| 308 | autoDaatacxx . . $ autoDaata# Data_readFromFilecxx . . $ Data_readFromFile(da9ba57d6e09e2a7). (MelderFilecxx . . $ MelderFile# file); |
| 309 | /* |
| 310 | Purpose: |
| 311 | to read a file with data of any kind. |
| 312 | Return value: |
| 313 | the object read from `file`, or null if there was no object (as with Picture_readFromPraatPictureFile). |
| 314 | Failure: |
| 315 | the file was not recognized. |
| 316 | Behaviour: |
| 317 | Data_readFromFile first checks whether the file is a text file |
| 318 | that is readable by Data_readFromTextFile, or a binary file |
| 319 | written by Data_writeToBinaryFile, or a file as written by Data_writeToLispFile. |
| 320 | If one of these succeeds, the file is read and the resulting object is returned. |
| 321 | If not, the recognizers installed with Data_recognizeFileType are tried. |
| 322 | */ |
| 323 | |
| 324 | inline structMelderFoldercxx . . $ structMelderFolder# Data_directoryBeingReadcxx . . $ Data_directoryBeingRead. { }; |
| 325 | |
| 326 | int Data_publishcxx . . $ Data_publish(795020d01765d2fa). (autoDaatacxx . . $ autoDaata# me); |
| 327 | |
| 328 | void Data_setPublishProccxx . . $ Data_setPublishProc(222770ccd595104f). (int (*publish) (autoDaatacxx . . $ autoDaata#)); |
| 329 | |
| 330 | /* The values of 'type' in struct descriptions. */ |
| 331 | |
| 332 | #define bytewacxx . . $ `sys/Data.h:332:9`! 1 |
| 333 | #define int16wacxx . . $ `sys/Data.h:333:9`! 2 |
| 334 | #define intwacxx . . $ `sys/Data.h:334:9`! 3 |
| 335 | #define integerwacxx . . $ `sys/Data.h:335:9`! 4 |
| 336 | #define ubytewacxx . . $ `sys/Data.h:336:9`! 5 |
| 337 | #define uintwacxx . . $ `sys/Data.h:337:9`! 6 |
| 338 | #define uintegerwacxx . . $ `sys/Data.h:338:9`! 7 |
| 339 | #define floatwacxx . . $ `sys/Data.h:339:9`! 8 |
| 340 | #define doublewacxx . . $ `sys/Data.h:340:9`! 9 |
| 341 | #define complexwacxx . . $ `sys/Data.h:341:9`! 10 |
| 342 | #define enumwacxx . . $ `sys/Data.h:342:9`! 11 |
| 343 | #define lenumwacxx . . $ `sys/Data.h:343:9`! 12 |
| 344 | #define booleanwacxx . . $ `sys/Data.h:344:9`! 13 |
| 345 | #define questionwacxx . . $ `sys/Data.h:345:9`! 14 |
| 346 | #define stringwacxx . . $ `sys/Data.h:346:9`! 15 |
| 347 | #define lstringwacxx . . $ `sys/Data.h:347:9`! 16 |
| 348 | #define maxsingletypewacxx . . $ `sys/Data.h:348:9`! lstringwa |
| 349 | #define structwacxx . . $ `sys/Data.h:349:9`! 17 |
| 350 | #define widgetwacxx . . $ `sys/Data.h:350:9`! 18 |
| 351 | #define objectwacxx . . $ `sys/Data.h:351:9`! 19 |
| 352 | #define collectionofwacxx . . $ `sys/Data.h:352:9`! 20 |
| 353 | #define collectionwacxx . . $ `sys/Data.h:353:9`! 21 |
| 354 | #define inheritwacxx . . $ `sys/Data.h:354:9`! 22 |
| 355 | |
| 356 | /* Recursive routines for working with struct members. */ |
| 357 | |
| 358 | int Data_Description_countMemberscxx . . $ Data_Description_countMembers(e486611939ed5677). (Data_Descriptioncxx . . $ Data_Description# structDescription); |
| 359 | /* Including inherited members. */ |
| 360 | |
| 361 | Data_Descriptioncxx . . $ Data_Description# Data_Description_findMatchcxx . . $ Data_Description_findMatch(4e4ed69fbd16d6e0). (Data_Descriptioncxx . . $ Data_Description# structDescription, conststring32cxx . . $ conststring32# member); |
| 362 | /* Find the location of member 'member' in a struct. */ |
| 363 | /* If 'structDescription' describes a class, the ancestor classes are also searched. */ |
| 364 | |
| 365 | Data_Descriptioncxx . . $ Data_Description# Data_Description_findNumberUsecxx . . $ Data_Description_findNumberUse(4e4ed69fbd16d6e0). (Data_Descriptioncxx . . $ Data_Description# structDescription, conststring32cxx . . $ conststring32# string); |
| 366 | /* Find the first member that uses member 'string' in its size description (max1 or max2 fields). */ |
| 367 | |
| 368 | /* Retrieving data from object + description. */ |
| 369 | |
| 370 | int64cxx . . $ int64# Data_Description_integercxx . . $ Data_Description_integer(e5a3eeb60b524453). (void *structAddress, Data_Descriptioncxx . . $ Data_Description# description); |
| 371 | /* Convert data found at a certain offset from 'address' to an integer, according to the given 'description'. */ |
| 372 | |
| 373 | int Data_Description_evaluateIntegercxx . . $ Data_Description_evaluateInteger(9a36bcb04ff11e98). (void *structAddress, Data_Descriptioncxx . . $ Data_Description# structDescription, |
| 374 | conststring32cxx . . $ conststring32# formula, integercxx . . $ integer# *result); |
| 375 | /* |
| 376 | * Translates a string like '100' or 'numberOfHorses' or 'numberOfCows - 1' to an integer. |
| 377 | * The 'algorithm' does some wild guesses as to the meanings of the 'min1' and 'max1' strings. |
| 378 | * A full-fledged interpretation is preferable... |
| 379 | * Returns 0 if 'formula' cannot be parsed to a number. |
| 380 | */ |
| 381 | |
| 382 | /* End of file Data.h */ |
| 383 | #endif |