-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecord.cpp
More file actions
64 lines (52 loc) · 1.33 KB
/
Record.cpp
File metadata and controls
64 lines (52 loc) · 1.33 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
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
/*
* Record.cpp
*
* Created on: 26 Nov 2011
* Author: Max Foster
*/
#include <fstream>
using namespace std;
#include "Record.h"
bool Record::operator ==(const Record &record) const
{
return (id == record.id);
}
bool Record::operator ==(const int recordId) const
{
return (id == recordId);
}
void Record::operator = (const Record &record)
{
id = record.id;
filePosition = record.filePosition;
}
int Record::getId() const
{
return id;
}
bool Record::null() const
{
return (id < 0);
}
bool Record::hasMatchingField(const std::string &fieldName, const int searchTerm) const
{
// If fieldName matches the name of a field, return whether the value of that field matches searchTerm
if (fieldName == "id") return (id == searchTerm);
return false;
}
int Record::size()
{
// Only data member is an integer, so just return the size of an integer
return sizeof(int);
}
Record::Record() : id(-1), filePosition(-1) {}
void Record::writeToFile(fstream &file) const
{
// Convert the ID field into a writable form (i.e. an array of characters) before writing
file.write(reinterpret_cast<const char *>(&id), sizeof(id));
}
void Record::readFromFile(fstream &file)
{
// Convert the array of characters read in into an integer while reading
file.read(reinterpret_cast<char *>(&id), sizeof(id));
}