-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathtest_rapid.cpp
More file actions
48 lines (39 loc) · 1.03 KB
/
test_rapid.cpp
File metadata and controls
48 lines (39 loc) · 1.03 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
#include "rapidjson/document.h"
#include <cstdio>
#include <iostream>
#include <libnotify.hpp>
#include <sstream>
#include <unistd.h>
#include <fstream>
using namespace std;
using namespace rapidjson;
void read_file(const string& filename, stringstream &buffer) {
ifstream f(filename);
if (f.good()) {
buffer << f.rdbuf();
}
}
int main() {
stringstream ss;
read_file("/tmp/1.json", ss);
string text = ss.str();
stringstream ostr;
ostr << "C++ RapidJSON\t" << getpid();
notify(ostr.str());
Document jobj;
jobj.Parse(text.c_str());
const Value &coordinates = jobj["coordinates"];
SizeType len = coordinates.Size();
double x = 0, y = 0, z = 0;
for (SizeType i = 0; i < len; i++) {
const Value &coord = coordinates[i];
x += coord["x"].GetDouble();
y += coord["y"].GetDouble();
z += coord["z"].GetDouble();
}
std::cout << x / len << std::endl;
std::cout << y / len << std::endl;
std::cout << z / len << std::endl;
notify("stop");
return 0;
}