File: InMemoryFile.h

package info (click to toggle)
cryfs 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,412 kB
  • sloc: cpp: 150,187; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (41 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (4)
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
#pragma once
#ifndef MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
#define MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_

#include <cpp-utils/data/Data.h>
#include <fspp/fs_interface/Types.h>

class InMemoryFile {
public:
  InMemoryFile(cpputils::Data data);
  virtual ~InMemoryFile();

  fspp::num_bytes_t read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const;

  const void *data() const;
  fspp::num_bytes_t size() const;

  bool fileContentEquals(const cpputils::Data &expected, fspp::num_bytes_t offset) const;

protected:
  cpputils::Data _data;
};

class WriteableInMemoryFile: public InMemoryFile {
public:
  WriteableInMemoryFile(cpputils::Data data);

  void write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);

  bool sizeUnchanged() const;
  bool regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const;

private:
  void _extendFileSizeIfNecessary(fspp::num_bytes_t size);
  void _extendFileSize(fspp::num_bytes_t size);

  cpputils::Data _originalData;
};


#endif