-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileHandler.h
72 lines (57 loc) · 1.5 KB
/
FileHandler.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
//
// Created by hmaurya on 20/02/20.
//
#ifndef AUDIO_FILEHANDLER_H
#define AUDIO_FILEHANDLER_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
class FileHandler {
private:
string filename;
ofstream fileOutStream;
public:
FileHandler() = default;
explicit FileHandler(string filename) {
this->filename = std::move(filename);
this->fileOutStream.open(this->filename, ios_base::binary);
}
/**
* Initialize file if not initialized with constructor
* @param newFilename
*/
void initializeFile(string newFilename);
/**
* Appends a single byte at the end of file
* @param toWrite
*/
void writeByte(char toWrite);
/**
* Write bytes from given data in little-endian format
* @tparam T
* @param data
*/
template <typename T>
void writeBytes(T data, size_t numberOfBytes);
template <typename T>
void modifyBytes(T data, unsigned int bytePosition, size_t numberOfBytes);
/**
* Writes string in big-endian format
* @param toWrite
*/
void writeString(const string& toWrite);
/**
* Get number of bytes that have been written via object of this class.
* @return Number of bytes written
*/
int currentSize();
/**
* Get current write pointer (byte number) associated with the file
* @return
*/
unsigned int currentWriteHeadPosition();
void close();
};
#include "FileHandler.tpp"
#endif //AUDIO_FILEHANDLER_H