Athena IO Library
FileWriter.hpp
1 #ifndef FILEWRITER_HPP
2 #define FILEWRITER_HPP
3 
4 #include "athena/IStreamWriter.hpp"
5 #include <stdio.h>
6 
7 namespace athena
8 {
9 namespace io
10 {
11 class FileWriter : public IStreamWriter
12 {
13 public:
14  FileWriter(const std::string& filename, bool overwrite = true, bool globalErr=true);
15  FileWriter(const std::wstring& filename, bool overwrite = true, bool globalErr=true);
16  virtual ~FileWriter();
17 
18  inline std::string filename() const
19  {
20 #if _WIN32
21  return utility::wideToUtf8(m_filename);
22 #else
23  return m_filename;
24 #endif
25  }
26  inline std::wstring wfilename() const
27  {
28 #if _WIN32
29  return m_filename;
30 #else
31  return utility::utf8ToWide(m_filename);
32 #endif
33  }
34 
35  void open(bool overwrite = true);
36  void close();
37  inline bool isOpen() const
38  {return m_fileHandle != NULL;}
39  void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
40  atUint64 position() const;
41  atUint64 length() const;
42  void writeUBytes(const atUint8* data, atUint64 len);
43 
44  FILE* _fileHandle() {return m_fileHandle;}
45 private:
46 #if _WIN32
47  std::wstring m_filename;
48 #else
49  std::string m_filename;
50 #endif
51  FILE* m_fileHandle;
52  atUint8 m_currentByte;
53  atUint64 m_bytePosition;
54  bool m_globalErr;
55 };
56 }
57 } // Athena
58 
59 #ifndef FILEWRITER_BASE
60 #define FILEWRITER_BASE() \
61 private: \
62  typedef athena::io::FileWriter base;
63 
64 #endif // FILEWRITER_BASE
65 #endif // FILEWRITER_HPP
void seek(atInt64 pos, SeekOrigin origin=SeekOrigin::Current)
Sets the buffers position relative to the specified position. It seeks relative to the current posit...
atUint64 position() const
Returns the current position in the stream.
void writeUBytes(const atUint8 *data, atUint64 len)
Writes the given buffer with the specified length, buffers can be bigger than the length however it&#39;s...
atUint64 length() const
Returns whether or not the stream is at the end.