-
Notifications
You must be signed in to change notification settings - Fork 6
/
forms.h
103 lines (80 loc) · 1.9 KB
/
forms.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Data structures for forms
*/
#ifndef H_FORMS
#define H_FORMS
#include <list>
#include <mutex>
#include <atomic>
#include <string>
#include <vector>
#include "log.h"
#include "data.h"
#include "pixels.h"
struct Form;
class Processor;
// For each image in each PDF
struct FormImage
{
// Image to process
Pixels image;
// Reference to parent, used to log messages
Form& form;
// Processed data
long long id;
long long thread_id;
std::vector<Answer> answers;
FormImage(Form& form, Pixels&& image)
: image(image), form(form), id(-1), thread_id(-1)
{ }
};
// Created for each new PDF to process
struct Form
{
long long id;
long long key;
long long pages;
std::string filename;
// Forms processed
long long done;
std::mutex done_mutex;
// For thread-safe log messages
std::string output;
std::mutex output_mutex;
// The images in the form
std::list<FormImage> formImages;
std::mutex images_mutex;
// Reference to parent
Processor& processor;
Form(Processor& processor)
: id(-1), key(0), pages(-1), done(0), processor(processor)
{ }
Form(Form&&);
Form(long long id, long long key, const std::string& filename,
Processor& processor)
: id(id), key(key), pages(-1), filename(filename), done(0), processor(processor)
{
}
// Increment or get how many forms we've done
void incDone();
long long getDone();
void log(const std::string& msg, const LogType& t = LogType::Error);
};
// Used for searching for the form with a certain ID
class FormPredicate
{
long long id;
public:
FormPredicate(long long id)
: id(id)
{
}
bool operator()(const Form& f)
{
return f.id == id;
}
};
// Equality based on if IDs are equal
bool operator==(const Form& a, const Form& b);
bool operator!=(const Form& a, const Form& b);
#endif