-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileTransformers.h
82 lines (64 loc) · 2.43 KB
/
FileTransformers.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include <string>
// future extension and improvement...
class ITransformMethod
{
public:
virtual ~ITransformMethod() { }
// estimates about the final output file size
virtual size_t ComputeFinalFileSize(size_t inputFileSize) = 0;
// size of the output buffer, it can be the same as inputBufferSize (we process files block by block)
virtual size_t GetDefaultOutbutBufferSize(size_t inputBufferSize) = 0;
// inBuf, outBuf, sizeInBytes: transforms inBuf and writes into outBuf,
// poutSize informs about written bytes into the output buffer (might be less than GetDefaultOutbutBufferSize)
virtual void Process(uint8_t* inBuf, uint8_t* outBuf, size_t inSize, size_t* pOutSize) = 0;
};
// base class for our tests, defines basic interface and common methods
// takes two file names, transforms the first file and writes output to the second file
// transform using external function, operates on blocks of bytes
class IFileTransformer
{
public:
IFileTransformer(std::wstring strFirstFile, std::wstring strSecondFile, size_t blockSizeInBytes, bool useSequential)
: m_strFirstFile(std::move(strFirstFile))
, m_strSecondFile(std::move(strSecondFile))
, m_blockSizeInBytes(blockSizeInBytes)
, m_useSequential(useSequential)
{ }
virtual ~IFileTransformer() { }
using TProcessFunc = void(*) (uint8_t*, uint8_t*, size_t);
virtual bool Process(TProcessFunc func) = 0;
protected:
const std::wstring m_strFirstFile;
const std::wstring m_strSecondFile;
const size_t m_blockSizeInBytes;
const bool m_useSequential;
};
// transformer using STDIO,
class StdioFileTransformer : public IFileTransformer
{
public:
using IFileTransformer::IFileTransformer; // inheriting constructor
virtual bool Process(TProcessFunc func) override;
};
// transformer using STD library from C++, streams,
class IoStreamFileTransformer : public IFileTransformer
{
public:
using IFileTransformer::IFileTransformer; // inheriting constructor
virtual bool Process(TProcessFunc func) override;
};
// transformer using Windows Api, standard
class WinFileTransformer : public IFileTransformer
{
public:
using IFileTransformer::IFileTransformer; // inheriting constructor
virtual bool Process(TProcessFunc func) override;
};
// transformer using Windows Api, memory mapped files
class MappedWinFileTransformer : public IFileTransformer
{
public:
using IFileTransformer::IFileTransformer; // inheriting constructor
virtual bool Process(TProcessFunc func) override;
};