xoreos  0.0.5
writefile.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_WRITEFILE_H
26 #define COMMON_WRITEFILE_H
27 
28 #include <cstdio>
29 
30 #include <boost/noncopyable.hpp>
31 
32 #include "src/common/types.h"
33 #include "src/common/writestream.h"
34 
35 namespace Common {
36 
37 class UString;
38 
40 class WriteFile : boost::noncopyable, public SeekableWriteStream {
41 public:
42  WriteFile();
43  WriteFile(const UString &fileName);
44  ~WriteFile();
45 
51  bool open(const UString &fileName);
52 
54  void close();
55 
60  bool isOpen() const;
61 
62  void flush();
63 
64  size_t write(const void *dataPtr, size_t dataSize);
65 
67  size_t size() const;
68 
70  size_t pos() const;
71 
73  size_t seek(ptrdiff_t offset, Origin whence = SeekableWriteStream::kOriginBegin);
74 
75 protected:
76  std::FILE *_handle;
77 
78  size_t _size;
79 };
80 
81 } // End of namespace Common
82 
83 #endif // COMMON_WRITEFILE_H
size_t write(const void *dataPtr, size_t dataSize)
Write data into the stream.
Definition: writefile.cpp:91
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
std::FILE * _handle
The actual file handle.
Definition: writefile.h:76
bool open(const UString &fileName)
Try to open the file with the given fileName.
Definition: writefile.cpp:50
bool isOpen() const
Checks if the object opened a file successfully.
Definition: writefile.cpp:79
Basic writing stream interfaces.
Low-level type definitions to handle fixed width types portably.
size_t seek(ptrdiff_t offset, Origin whence=SeekableWriteStream::kOriginBegin)
Seek to the speciied offset from the specified origin.
Definition: writefile.cpp:112
void flush()
Commit any buffered data to the underlying channel or storage medium; unbuffered streams can use the ...
Definition: writefile.cpp:83
void close()
Close the file, if open.
Definition: writefile.cpp:69
Origin
The position a seeking offset takes as a base.
Definition: writestream.h:218
A simple streaming file writing class.
Definition: writefile.h:40
size_t size() const
Return the number of bytes written to the current file in total.
Definition: writefile.cpp:104
Seek from the begin of the stream.
Definition: writestream.h:219
size_t pos() const
Return the current position ot the stream in the file.
Definition: writefile.cpp:108