-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (49 loc) · 1.39 KB
/
main.cpp
File metadata and controls
54 lines (49 loc) · 1.39 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
#include <iostream>
#include <sample.hpp>
#include <filewriter.hpp>
#include <random>
#include <chrono>
#include <ctime>
#include <getopt.h>
#include <thread>
void printUsage()
{
std::cout << "Usage ./main [OPTIONS]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -h Print usage" << std::endl;
std::cout << " -d <path> path to serialized file" << std::endl;
std::cout << " -s serialized random data" << std::endl;
}
int main(int argc, char **argv)
{
std::string fileName;
std::random_device rd;
std::default_random_engine generator(rd());
std::uniform_int_distribution<int32_t> rng(-1000, 1000);
auto start = std::chrono::system_clock::now();
FileWriter writer;
switch (getopt(argc, argv, "sd:h"))
{
case 's':
while (true)
{
float elapsed_seconds = std::chrono::duration<float>(std::chrono::system_clock::now() - start).count();
float value = rng(generator) * 0.5;
SamplePtr s(new Sample(5, value, elapsed_seconds));
writer.process(std::move(s));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
break;
case 'd':
fileName = optarg;
writer.deserialize(fileName);
break;
case 'h':
printUsage();
break;
default:
printUsage();
return EXIT_FAILURE;
}
return 0;
}