aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/data_src.h5
-rw-r--r--src/data_src.cpp28
2 files changed, 25 insertions, 8 deletions
diff --git a/include/data_src.h b/include/data_src.h
index b7df4857b..87a7b9128 100644
--- a/include/data_src.h
+++ b/include/data_src.h
@@ -62,10 +62,13 @@ class DataSource_Stream : public DataSource
bool end_of_data() const;
std::string id() const;
+ DataSource_Stream(std::istream&, const std::string& id = "");
DataSource_Stream(const std::string&, bool = false);
~DataSource_Stream();
private:
- const std::string fsname;
+ const std::string identifier;
+ const bool owner;
+
std::istream* source;
u32bit total_read;
};
diff --git a/src/data_src.cpp b/src/data_src.cpp
index 2a83a3860..dd3218151 100644
--- a/src/data_src.cpp
+++ b/src/data_src.cpp
@@ -158,22 +158,35 @@ bool DataSource_Stream::end_of_data() const
*************************************************/
std::string DataSource_Stream::id() const
{
- return fsname;
+ return identifier;
}
/*************************************************
* DataSource_Stream Constructor *
*************************************************/
-DataSource_Stream::DataSource_Stream(const std::string& file,
- bool use_binary) : fsname(file)
+DataSource_Stream::DataSource_Stream(const std::string& path,
+ bool use_binary) :
+ identifier(path), owner(true)
{
if(use_binary)
- source = new std::ifstream(fsname.c_str(), std::ios::binary);
+ source = new std::ifstream(path.c_str(), std::ios::binary);
else
- source = new std::ifstream(fsname.c_str());
+ source = new std::ifstream(path.c_str());
if(!source->good())
- throw Stream_IO_Error("DataSource_Stream: Failure opening " + fsname);
+ throw Stream_IO_Error("DataSource: Failure opening file " + path);
+
+ total_read = 0;
+ }
+
+/*************************************************
+* DataSource_Stream Constructor *
+*************************************************/
+DataSource_Stream::DataSource_Stream(std::istream& in,
+ const std::string& name) :
+ identifier(name), owner(false)
+ {
+ source = ∈
total_read = 0;
}
@@ -182,7 +195,8 @@ DataSource_Stream::DataSource_Stream(const std::string& file,
*************************************************/
DataSource_Stream::~DataSource_Stream()
{
- delete source;
+ if(owner)
+ delete source;
}
}