diff options
author | lloyd <[email protected]> | 2008-03-11 19:10:05 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-03-11 19:10:05 +0000 |
commit | 83de95aacd2b1e82f885b62676622f2723276671 (patch) | |
tree | bb21cd06f9ac458899508f25312a982eb25006bd | |
parent | c2469e38aa1c5bbecc5d1164134267d42c1a0dc9 (diff) |
Add a new constructor for DataSource_Stream taking in a std::istream.
Previously the only method allowed was with a pathname, which is pretty
inflexible since it prevents you from using devices like std::cin, etc
-rw-r--r-- | include/data_src.h | 5 | ||||
-rw-r--r-- | src/data_src.cpp | 28 |
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; } } |