Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/file/stdfile.h
2 views
1
/***************************************************************************
2
Copyright (C) 2007 by Nach
3
http://nsrt.edgeemu.com
4
5
Copyright (C) 2007-2011 by Sindre Aamås
6
[email protected]
7
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License version 2 as
10
published by the Free Software Foundation.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License version 2 for more details.
16
17
You should have received a copy of the GNU General Public License
18
version 2 along with this program; if not, write to the
19
Free Software Foundation, Inc.,
20
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
***************************************************************************/
22
#ifndef GAMBATTE_STD_FILE_H
23
#define GAMBATTE_STD_FILE_H
24
25
#include "file.h"
26
#include <fstream>
27
28
namespace gambatte {
29
30
class StdFile : public File {
31
std::ifstream stream;
32
std::size_t fsize;
33
34
public:
35
explicit StdFile(const char *filename)
36
: stream(filename, std::ios::in | std::ios::binary), fsize(0)
37
{
38
if (stream) {
39
stream.seekg(0, std::ios::end);
40
fsize = stream.tellg();
41
stream.seekg(0, std::ios::beg);
42
}
43
}
44
45
virtual void rewind() { stream.seekg(0, std::ios::beg); }
46
virtual std::size_t size() const { return fsize; };
47
virtual void read(char *buffer, std::size_t amount) { stream.read(buffer, amount); }
48
virtual bool fail() const { return stream.fail(); }
49
};
50
51
}
52
53
#endif
54
55