2009-12-31 14:48:34 +01:00
|
|
|
#ifndef MANGLE_STREAM_FILESERVER_H
|
|
|
|
#define MANGLE_STREAM_FILESERVER_H
|
|
|
|
|
2010-06-03 20:13:27 +02:00
|
|
|
#include "std_stream.hpp"
|
2009-12-31 14:48:34 +01:00
|
|
|
#include <fstream>
|
2010-09-02 22:19:44 +02:00
|
|
|
#include <stdexcept>
|
2009-12-31 14:48:34 +01: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 16:39:11 +01:00
|
|
|
file.open(name.c_str(), std::ios::binary);
|
2010-01-02 13:06:37 +01:00
|
|
|
|
|
|
|
if(file.fail())
|
2010-09-02 22:19:44 +02:00
|
|
|
throw std::runtime_error("FileStream: failed to open file " + name);
|
2009-12-31 14:48:34 +01:00
|
|
|
}
|
|
|
|
~FileStream() { file.close(); }
|
|
|
|
};
|
|
|
|
|
2009-12-31 15:37:01 +01:00
|
|
|
typedef boost::shared_ptr<FileStream> FileStreamPtr;
|
|
|
|
|
2009-12-31 14:48:34 +01:00
|
|
|
}} // namespaces
|
|
|
|
#endif
|