-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample for c++ agent,cpp
56 lines (46 loc) · 1.13 KB
/
sample for c++ agent,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
49
50
51
52
53
54
55
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <agents.h>
#include <string>
#include <iostream>
#include <algorithm>
#include "file_reader.h"
#include <json/json.h>
using namespace concurrency;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
event e;
// The components of the Adler-32 sum.
unsigned int a = 1;
unsigned int b = 0;
// A call object that updates the checksum when it receives data.
call<string> calculate_checksum([&](string s) {
// If the input string is empty, set the event to signal
// the end of processing.
if (s.size() == 0)
e.set();
// Perform the Adler-32 checksum algorithm.
for_each(begin(s), end(s), [&](char c) {
a = (a + c) % 65521;
b = (b + a) % 65521;
});
});
file_reader reader("D:\\test.txt", calculate_checksum);
reader.start();
agent::wait(&reader);
e.wait();
std::exception error;
if (reader.get_error(error))
{
wcout << error.what() << endl;
}
else
{
unsigned int adler32_sum = (b << 16) | a;
wcout << L"Adler-32 sum is " << hex << adler32_sum << endl;
}
getchar();
return 0;
}