| 1 | #ifndef _FileInMemory_h_ |
| 2 | #define _FileInMemory_h_ |
| 3 | /* FileInMemory.h |
| 4 | * |
| 5 | * Copyright (C) 2011-2020 David Weenink, 2015,2018,2024,2025 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 3 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. See the GNU |
| 15 | * 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 | #include "Collection.h" |
| 22 | #include "Strings_.h" |
| 23 | |
| 24 | #include "FileInMemory_def.h" |
| 25 | |
| 26 | Collection_define (FileInMemorySet, SortedSetOfStringOf, FileInMemory) { |
| 27 | void v1_info () |
| 28 | override; |
| 29 | }; |
| 30 | |
| 31 | autoFileInMemory FileInMemory_create (MelderFile file); |
| 32 | |
| 33 | /* |
| 34 | If the FileInMemory is created from static data we do not need to copy the data into the object but only |
| 35 | create a link to the data. This implies that the data cannot be deleted if the FileInMemory object gets |
| 36 | destroyed. However, if the FileInMemory object is copied, for example, then we also have to copy the data, |
| 37 | and the copied object has to become owner of these copied data. This is automatically guaranteed by our |
| 38 | implementation, because _dontOwnData is default-initialised as false. |
| 39 | Only if we create a FileInMemory object from data do we have to be explicit about ownership. |
| 40 | */ |
| 41 | autoFileInMemory FileInMemory_createWithData (integer numberOfBytes, uint8 *data, bool isStaticData, conststring32 path); |
| 42 | |
| 43 | void FileInMemory_showAsCode (FileInMemory me, conststring32 name, integer numberOfBytesPerLine); |
| 44 | |
| 45 | /* |
| 46 | File open and read emulations. |
| 47 | */ |
| 48 | |
| 49 | FileInMemory FileInMemory_fopen (FileInMemory me, const char *mode); |
| 50 | |
| 51 | FileInMemory FileInMemorySet_fopen (FileInMemorySet me, const char *fileName, const char *mode); |
| 52 | |
| 53 | void FileInMemory_rewind (FileInMemory stream); |
| 54 | |
| 55 | int FileInMemory_fclose (FileInMemory stream); |
| 56 | |
| 57 | int FileInMemory_feof (FileInMemory stream); |
| 58 | |
| 59 | int FileInMemory_ferror (FileInMemory stream); |
| 60 | |
| 61 | integer FileInMemory_ftell (FileInMemory stream); |
| 62 | |
| 63 | int FileInMemory_fseek (FileInMemory stream, integer offset, int origin); |
| 64 | |
| 65 | char *FileInMemory_fgets (char *str, int num, FileInMemory stream); |
| 66 | |
| 67 | size_t FileInMemory_fread (void *ptr, size_t size, size_t count, FileInMemory stream); |
| 68 | |
| 69 | int FileInMemory_fgetc (FileInMemory stream); |
| 70 | |
| 71 | int FileInMemory_ungetc (int character, FileInMemory stream); |
| 72 | |
| 73 | int FileInMemorySet_stat (FileInMemorySet me, const char *path, struct stat *buf); |
| 74 | |
| 75 | /* |
| 76 | FileInMemorySet bookkeeping. |
| 77 | */ |
| 78 | |
| 79 | autoFileInMemorySet FileInMemorySet_createFromDirectoryContents (conststring32 dirpath, conststring32 file); |
| 80 | |
| 81 | autoFileInMemorySet FilesInMemory_to_FileInMemorySet (OrderedOf<structFileInMemory>& list); |
| 82 | |
| 83 | autoFileInMemorySet FileInMemorySet_extractFiles (FileInMemorySet me, kMelder_string which, conststring32 criterion); |
| 84 | autoFileInMemorySet FileInMemorySet_removeFiles (FileInMemorySet me, kMelder_string which, conststring32 criterion); |
| 85 | |
| 86 | /* Only creates references to files in memory. Once me is deleted, the references are not valid any more!! */ |
| 87 | autoFileInMemorySet FileInMemorySet_listFiles (FileInMemorySet me, kMelder_string which, conststring32 criterion); |
| 88 | |
| 89 | integer FileInMemorySet_getTotalNumberOfBytes (FileInMemorySet me); |
| 90 | |
| 91 | autoFileInMemorySet FileInMemorySets_merge (OrderedOf<structFileInMemorySet>& list); |
| 92 | |
| 93 | void FileInMemorySet_showAsCode (FileInMemorySet me, conststring32 name, integer numberOfBytesPerLine); |
| 94 | |
| 95 | void FileInMemorySet_showOneFileAsCode (FileInMemorySet me, integer index, conststring32 name, integer numberOfBytesPerLine); |
| 96 | |
| 97 | integer FileInMemorySet_findNumberOfMatches_path (FileInMemorySet me, kMelder_string which, conststring32 criterion); |
| 98 | |
| 99 | bool FileInMemorySet_hasDirectory (FileInMemorySet me, conststring32 name); |
| 100 | |
| 101 | autoStrings FileInMemorySet_to_Strings_path (FileInMemorySet me); |
| 102 | |
| 103 | /* |
| 104 | Testing. |
| 105 | */ |
| 106 | void test_FileInMemory_io (); |
| 107 | |
| 108 | |
| 109 | /* End of file FileInMemory.h */ |
| 110 | #endif |