a couple more writable-vfs migrations

This commit is contained in:
David Rose 2011-09-17 00:40:29 +00:00
parent 191ce517da
commit 278bc55d62
6 changed files with 22 additions and 40 deletions

View File

@ -3779,21 +3779,18 @@ do_store_one(PNMImage &pnmimage, int z, int n) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Texture:: bool Texture::
do_write_txo_file(const Filename &fullpath) const { do_write_txo_file(const Filename &fullpath) const {
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
Filename filename = Filename::binary_filename(fullpath); Filename filename = Filename::binary_filename(fullpath);
pofstream out; ostream *out = vfs->open_write_file(filename, true, true);
if (!filename.open_write(out)) { if (out == NULL) {
gobj_cat.error() gobj_cat.error()
<< "Unable to open " << filename << "\n"; << "Unable to open " << filename << "\n";
return false; return false;
} }
#ifdef HAVE_ZLIB bool success = do_write_txo(*out, fullpath);
if (fullpath.get_extension() == "pz") { vfs->close_write_file(out);
OCompressStream compressor(&out, false); return success;
return do_write_txo(compressor, "stream");
}
#endif // HAVE_ZLIB
return do_write_txo(out, fullpath);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -285,22 +285,11 @@ make_writer(const Filename &filename, PNMFileType *type) const {
} }
} else { } else {
pofstream *new_ostream = new pofstream; VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
Filename actual_name = Filename::binary_filename(filename); Filename actual_name = Filename::binary_filename(filename);
if (!actual_name.open_write(*new_ostream)) { file = vfs->open_write_file(actual_name, true, true);
delete new_ostream; if (file != NULL) {
} else {
owns_file = true; owns_file = true;
file = new_ostream;
#ifdef HAVE_ZLIB
if (filename.get_extension() == "pz") {
// The filename ends in .pz, which means to automatically
// compress the image file that we write.
file = new OCompressStream(file, true);
}
#endif // HAVE_ZLIB
} }
} }

View File

@ -83,7 +83,6 @@ open(istream &in, const Filename &filename) {
void DatagramInputFile:: void DatagramInputFile::
close() { close() {
_vfile.clear(); _vfile.clear();
_in_file.close();
if (_owns_in) { if (_owns_in) {
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->close_read_file(_in); vfs->close_read_file(_in);

View File

@ -56,7 +56,6 @@ private:
bool _error; bool _error;
CPT(FileReference) _file; CPT(FileReference) _file;
PT(VirtualFile) _vfile; PT(VirtualFile) _vfile;
pifstream _in_file;
istream *_in; istream *_in;
bool _owns_in; bool _owns_in;
Filename _filename; Filename _filename;

View File

@ -32,19 +32,15 @@ open(const FileReference *file) {
// DatagramOutputFiles are always binary. // DatagramOutputFiles are always binary.
_filename.set_binary(); _filename.set_binary();
_out = &_out_file; VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
_owns_out = false; _vfile = vfs->create_file(_filename);
if (_vfile == (VirtualFile *)NULL) {
#ifdef HAVE_ZLIB // No such file.
if (_filename.get_extension() == "pz") { return false;
// The filename ends in .pz, which means to automatically
// compress the bam file that we write.
_out = new OCompressStream(_out, _owns_out);
_owns_out = true;
} }
#endif // HAVE_ZLIB _out = _vfile->open_write_file(true, true);
_owns_out = (_out != (ostream *)NULL);
return _filename.open_write(_out_file); return _owns_out && !_out->fail();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -79,10 +75,11 @@ open(ostream &out, const Filename &filename) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DatagramOutputFile:: void DatagramOutputFile::
close() { close() {
_vfile.clear();
if (_owns_out) { if (_owns_out) {
delete _out; VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->close_write_file(_out);
} }
_out_file.close();
_out = (ostream *)NULL; _out = (ostream *)NULL;
_owns_out = false; _owns_out = false;

View File

@ -20,6 +20,7 @@
#include "datagramSink.h" #include "datagramSink.h"
#include "filename.h" #include "filename.h"
#include "fileReference.h" #include "fileReference.h"
#include "virtualFile.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : DatagramOutputFile // Class : DatagramOutputFile
@ -54,7 +55,7 @@ private:
bool _wrote_first_datagram; bool _wrote_first_datagram;
bool _error; bool _error;
CPT(FileReference) _file; CPT(FileReference) _file;
pofstream _out_file; PT(VirtualFile) _vfile;
ostream *_out; ostream *_out;
bool _owns_out; bool _owns_out;
Filename _filename; Filename _filename;