-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entry.cpp
48 lines (44 loc) · 1.09 KB
/
Entry.cpp
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
/**********************************
* FILE NAME: Application.h
*
* DESCRIPTION: Entry class definition
**********************************/
#include "Entry.h"
/**
* constructor
*/
Entry::Entry(string _value, int _timestamp, ReplicaType _replica){
this->delimiter = ":";
value = _value;
timestamp = _timestamp;
replica = _replica;
}
/**
* constructor
*
* DESCRIPTION: Convert string to get an Entry object
*/
Entry::Entry(string entry){
vector<string> tuple;
this->delimiter = ":";
size_t pos = entry.find(delimiter);
size_t start = 0;
while (pos != string::npos) {
string field = entry.substr(start, pos-start);
tuple.push_back(field);
start = pos + delimiter.size();
pos = entry.find(delimiter, start);
}
tuple.push_back(entry.substr(start));
value = tuple.at(0);
timestamp = stoi(tuple.at(1));
replica = static_cast<ReplicaType>(stoi(tuple.at(2)));
}
/**
* FUNCTION NAME: converToString
*
* DESCRIPTION: Convert the object to a string representation
*/
string Entry::convertToString() {
return value + delimiter + to_string(timestamp) + delimiter + to_string(replica);
}