aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-03-11 19:08:54 +0000
committerlloyd <[email protected]>2008-03-11 19:08:54 +0000
commitc2469e38aa1c5bbecc5d1164134267d42c1a0dc9 (patch)
tree4ddca0842f896cd983f649218ae0b35d29d382b1
parent58f9a9c32dae6c359451d682f6120fb170a7dd3f (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
-rw-r--r--include/data_snk.h8
-rw-r--r--src/data_snk.cpp24
2 files changed, 18 insertions, 14 deletions
diff --git a/include/data_snk.h b/include/data_snk.h
index 9cdf603ab..34bdaa35e 100644
--- a/include/data_snk.h
+++ b/include/data_snk.h
@@ -32,13 +32,15 @@ class DataSink_Stream : public DataSink
{
public:
void write(const byte[], u32bit);
- DataSink_Stream(std::ostream&);
+
+ DataSink_Stream(std::ostream&, const std::string& = "");
DataSink_Stream(const std::string&, bool = false);
~DataSink_Stream();
private:
- const std::string fsname;
+ const std::string identifier;
+ const bool owner;
+
std::ostream* sink;
- bool owns;
};
}
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;
}