diff options
author | lloyd <[email protected]> | 2008-03-11 19:08:54 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-03-11 19:08:54 +0000 |
commit | c2469e38aa1c5bbecc5d1164134267d42c1a0dc9 (patch) | |
tree | 4ddca0842f896cd983f649218ae0b35d29d382b1 /src/data_snk.cpp | |
parent | 58f9a9c32dae6c359451d682f6120fb170a7dd3f (diff) |
In DataSink_Stream, allow explicitly setting a pathname (for
identification purposes) when passing in a std::ostream, since there
is no portable way to go from a std::ostream to the file or other device
that it names
Diffstat (limited to 'src/data_snk.cpp')
-rw-r--r-- | src/data_snk.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/data_snk.cpp b/src/data_snk.cpp index a76fbfa09..729816520 100644 --- a/src/data_snk.cpp +++ b/src/data_snk.cpp @@ -15,32 +15,34 @@ void DataSink_Stream::write(const byte out[], u32bit length) { sink->write(reinterpret_cast<const char*>(out), length); if(!sink->good()) - throw Stream_IO_Error("DataSink_Stream: Failure writing to " + fsname); + throw Stream_IO_Error("DataSink_Stream: Failure writing to " + + identifier); } /************************************************* * DataSink_Stream Constructor * *************************************************/ -DataSink_Stream::DataSink_Stream(std::ostream& stream) : fsname("std::ostream") +DataSink_Stream::DataSink_Stream(std::ostream& out, + const std::string& name) : + identifier(name != "" ? name : "<std::ostream>"), owner(false) { - sink = &stream; - owns = false; + sink = &out; } /************************************************* * DataSink_Stream Constructor * *************************************************/ -DataSink_Stream::DataSink_Stream(const std::string& file, - bool use_binary) : fsname(file) +DataSink_Stream::DataSink_Stream(const std::string& path, + bool use_binary) : + identifier(path), owner(true) { if(use_binary) - sink = new std::ofstream(fsname.c_str(), std::ios::binary); + sink = new std::ofstream(path.c_str(), std::ios::binary); else - sink = new std::ofstream(fsname.c_str()); + sink = new std::ofstream(path.c_str()); if(!sink->good()) - throw Stream_IO_Error("DataSink_Stream: Failure opening " + fsname); - owns = true; + throw Stream_IO_Error("DataSink_Stream: Failure opening " + path); } /************************************************* @@ -48,7 +50,7 @@ DataSink_Stream::DataSink_Stream(const std::string& file, *************************************************/ DataSink_Stream::~DataSink_Stream() { - if(owns) + if(owner) delete sink; sink = 0; } |