-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic-example.cpp
More file actions
64 lines (47 loc) · 1.26 KB
/
basic-example.cpp
File metadata and controls
64 lines (47 loc) · 1.26 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
#include "../src/CppVec.h"
#include <iostream>
#define MAXBUFLEN 100
using namespace std;
/*
Compile using:
g++ -W -Wall -Werror -std=c++11 basic-example.cpp ../src/CppVec.cpp ../src/VClock/VClock.cpp
*/
int main() {
cout << "Hello CppVector!" << endl;
// Testing of the VClock
VClock clock1 = VClock();
clock1.set("a", 1);
clock1.set("b", 1);
clock1.set("c", 1);
clock1.set("d", 18);
clock1.set("e", 12);
clock1.tick("d");
VClock clock2 = VClock();
clock2.set("a", 3);
clock2.set("b", 5);
clock2.set("c", 1);
clock2.set("d", 15);
clock2.set("e", 11);
cout << "clock1" << endl;
clock1.printVCString();
cout << "clock2" << endl;
clock2.printVCString();
clock1.merge(clock2);
cout << "merged clock" << endl;
clock1.printVCString();
// Testing of the pack and unpack
CppVec cv;
cv.initCppVector("myPID", "logFile");
// Create the buffer
char* buffer;
string s = "placeholder";
buffer = cv.prepareSend("PrepareSend message", "myPayload");
cv.unpackReceive("UnpackReceive message", buffer, &s, MAXBUFLEN);
cout << "Unpacked: " << s << endl;
// Send an int
int x = 100;
buffer = cv.prepareSend("PrepareSend message", 123);
cv.unpackReceive("UnpackReceive message", buffer, &x, MAXBUFLEN);
cout << "Unpacked: " << x << endl;
return 0;
}