xoreos  0.0.5
readfile.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_READFILE_H
26 #define COMMON_READFILE_H
27 
28 #include <cstdio>
29 
30 #include <boost/noncopyable.hpp>
31 
32 #include "src/common/types.h"
33 #include "src/common/readstream.h"
34 
35 namespace Common {
36 
37 class UString;
38 
40 class ReadFile : boost::noncopyable, public SeekableReadStream {
41 public:
42  ReadFile();
43  ReadFile(const UString &fileName);
44  ~ReadFile();
45 
51  bool open(const UString &fileName);
52 
54  void close();
55 
60  bool isOpen() const;
61 
62  bool eos() const;
63 
64  size_t pos() const;
65  size_t size() const;
66 
67  size_t seek(ptrdiff_t offset, Origin whence = kOriginBegin);
68  size_t read(void *dataPtr, size_t dataSize);
69 
70 protected:
71  std::FILE *_handle;
72  size_t _size;
73 };
74 
75 } // End of namespace Common
76 
77 #endif // COMMON_READFILE_H
size_t pos() const
Obtains the current value of the stream position indicator of the stream.
Definition: readfile.cpp:103
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
A simple streaming file reading class.
Definition: readfile.h:40
size_t _size
The file&#39;s size.
Definition: readfile.h:72
bool eos() const
Returns true if a read failed because the stream has been reached.
Definition: readfile.cpp:96
size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)
Sets the stream position indicator for the stream.
Definition: readfile.cpp:114
Origin
The position a seeking offset takes as a base.
Definition: readstream.h:268
bool open(const UString &fileName)
Try to open the file with the given fileName.
Definition: readfile.cpp:61
size_t read(void *dataPtr, size_t dataSize)
Read data from the stream.
Definition: readfile.cpp:134
Low-level type definitions to handle fixed width types portably.
Basic reading stream interfaces.
std::FILE * _handle
The actual file handle.
Definition: readfile.h:71
size_t size() const
Obtains the total size of the stream, measured in bytes.
Definition: readfile.cpp:110
bool isOpen() const
Checks if the object opened a file successfully.
Definition: readfile.cpp:92
Seek from the begin of the stream.
Definition: readstream.h:269
void close()
Close the file, if open.
Definition: readfile.cpp:84
Interface for a seekable & readable data stream.
Definition: readstream.h:265