- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPersistentObjectUtility.cpp
More file actions
Latest commit
32 lines (31 loc) · 1.17 KB
/
Copy pathPersistentObjectUtility.cpp
File metadata and controls
32 lines (31 loc) · 1.17 KB
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
#include"PersistentObjectUtility.h"
#include"UserDatabase.h"
#include<typeinfo>
#include<cstring>
#include<fstream>
template <classDataType> PersistentObjectUtility<DataType>::PersistentObjectUtility(DataType &obj):
filename(std::strcat((std::strcpy((newchar[strlen(typeid(obj).name())+strlen(FileNameSuffix)+1]), typeid(obj).name())), FileNameSuffix)) {
database_object = &obj;
}
template <classDataType> PersistentObjectUtility<DataType>::~PersistentObjectUtility() {
delete[] filename;
}
template <classDataType> void PersistentObjectUtility<DataType>::ReadFromFile(std::vector<char> &file_array) {
std::ifstream persistent_file;
persistent_file.open(filename);
if (persistent_file.is_open()) {
char c;
while (persistent_file.get(c)) {
file_array.push_back(c);
}
}
persistent_file.close();
}
template <classDataType> void PersistentObjectUtility<DataType>::WriteToFile() {
std::ofstream persistent_file;
persistent_file.open(filename);
persistent_file<<*database_object;
persistent_file.close();
}
//Template types to be used in this project
template classPersistentObjectUtility<UserDatabase>;