2009-12-31 13:48:34 +00:00
|
|
|
#ifndef MANGLE_STREAM_FILESERVER_H
|
|
|
|
#define MANGLE_STREAM_FILESERVER_H
|
|
|
|
|
2010-06-03 18:13:27 +00:00
|
|
|
#include "std_stream.hpp"
|
2009-12-31 13:48:34 +00:00
|
|
|
#include <fstream>
|
2010-09-02 20:19:44 +00:00
|
|
|
#include <stdexcept>
|
2009-12-31 13:48:34 +00:00
|
|
|
|
|
|
|
namespace Mangle {
|
|
|
|
namespace Stream {
|
|
|
|
|
|
|
|
/** Very simple file input stream, based on std::ifstream
|
|
|
|
*/
|
|
|
|
class FileStream : public StdStream
|
|
|
|
{
|
|
|
|
std::ifstream file;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileStream(const std::string &name)
|
|
|
|
: StdStream(&file)
|
|
|
|
{
|
2010-01-01 15:39:11 +00:00
|
|
|
file.open(name.c_str(), std::ios::binary);
|
2010-01-02 12:06:37 +00:00
|
|
|
|
|
|
|
if(file.fail())
|
2010-09-02 20:19:44 +00:00
|
|
|
throw std::runtime_error("FileStream: failed to open file " + name);
|
2009-12-31 13:48:34 +00:00
|
|
|
}
|
|
|
|
~FileStream() { file.close(); }
|
|
|
|
};
|
|
|
|
|
2009-12-31 14:37:01 +00:00
|
|
|
typedef boost::shared_ptr<FileStream> FileStreamPtr;
|
|
|
|
|
2009-12-31 13:48:34 +00:00
|
|
|
}} // namespaces
|
|
|
|
#endif
|