static void _Data_writeToTextFile (Daata me, MelderFile file, bool verbose) { try { if (! Data_canWriteText (me)) Melder_throw (U"Objects of class ", my classInfo -> className, U" cannot be written to a text file."); autoMelderFile mfile = Data_createTextFile (me, file, verbose); #ifndef _WIN32 flockfile (file -> filePointer); // BUG #endif MelderFile_write (file, U"File type = \"ooTextFile\"\nObject class = \"", my classInfo -> className); if (my classInfo -> version > 0) MelderFile_write (file, U" ", my classInfo -> version); MelderFile_write (file, U"\"\n"); Data_writeText (me, file); MelderFile_writeCharacter (file, U'\n'); #ifndef _WIN32 if (file -> filePointer) funlockfile (file -> filePointer); #endif mfile.close (); } catch (MelderError) { #ifndef _WIN32 if (file -> filePointer) funlockfile (file -> filePointer); // the file pointer is null before Data_createTextFile() and after mfile.close() #endif throw; } }
void _CollectionOfDaata_v_writeText (_CollectionOfDaata* me, MelderFile file) { texputi4 (file, my size, U"size", 0,0,0,0,0); texputintro (file, U"item []: ", my size ? nullptr : U"(empty)", 0,0,0,0); for (long i = 1; i <= my size; i ++) { Daata thing = my at [i]; ClassInfo classInfo = thing -> classInfo; texputintro (file, U"item [", Melder_integer (i), U"]:", 0,0,0); if (! Thing_isa (thing, classDaata) || ! Data_canWriteText (thing)) Melder_throw (U"Objects of class ", classInfo -> className, U" cannot be written."); texputw2 (file, classInfo -> version > 0 ? Melder_cat (classInfo -> className, U" ", classInfo -> version) : classInfo -> className, U"class", 0,0,0,0,0); texputw2 (file, thing -> name, U"name", 0,0,0,0,0); Data_writeText (thing, file); texexdent (file); } texexdent (file); }