Welcome to mirror list, hosted at ThFree Co, Russian Federation.

file_writer.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad2f2afc1e40c842de249c347c6f0a1e490a50db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "writer.hpp"
#include "../base/base.hpp"
#include "../std/scoped_ptr.hpp"

namespace my { class FileData; }

// FileWriter, not thread safe.
class FileWriter : public Writer
{
public:
  // Values actually match internal FileData::Op enum.
  enum Op
  {
    // Create an empty file for writing. If a file with the same name already exists
    // its content is erased and the file is treated as a new empty file.
    OP_WRITE_TRUNCATE = 1,
    // Open a file for update. The file is created if it does not exist.
    OP_WRITE_EXISTING = 2,
    // Append to a file. Writing operations append data at the end of the file.
    // The file is created if it does not exist.
    // Seek should not be called, if file is opened for append.
    OP_APPEND = 3
  };

  /// Works like "move semantics".
  /// Added for use in FilesContainerW interface.
  FileWriter(FileWriter const & rhs);

  explicit FileWriter(string const & fileName,
                      Op operation = OP_WRITE_TRUNCATE, bool bTruncOnClose = false);
  ~FileWriter();

  void Seek(int64_t pos);
  int64_t Pos() const;
  void Write(void const * p, size_t size);

  uint64_t Size() const;
  void Flush();

  void Reserve(uint64_t size);

  static void DeleteFileX(string const & fName);

  string GetName() const;

private:
  typedef my::FileData fdata_t;
  scoped_ptr<fdata_t> m_pFileData;
  bool m_bTruncOnClose;
};