-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataKeeper.h
90 lines (67 loc) · 2.84 KB
/
dataKeeper.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
/* Copyright: 2021 Donat Zenichev development <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
On Debian systems, the complete text of the GNU General
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". */
#include <fstream>
#include <cstring>
#include <chrono>
#include <thread>
#include "SDL2/SDL.h"
#include <vector>
#include <iterator>
#include <map>
#include <random>
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define ALLOWED_AMOUNT_LINES 50 // alowed amount of processable text lines
#define NEXT_TIME_MIN 5 // min amount of seconds before next appear
#define NEXT_TIME_MAX 10 // max amount of seconds before next appear
#define DELIMITER ":" // delimiter used to divide word and translation
#define RESULTS_FILE_NAME "last_run.deck" // file with results of previous run
/* the class which is dedicated to work with the data */
class dataKeeper {
private:
std::map<std::string,std::string> myWords;
std::vector<std::string> myLearnedWords;
std::vector<std::string> myForgottenWords;
int wordsLearned;
int wordsForgotten;
int slotsIDs;
int nextTime;
bool inArray(const std::vector<std::string> & array, const std::string & value) {
return std::find(array.begin(), array.end(), value) != array.end() ? true : false;
}
bool inIDsArray(const std::vector<int> & array, const int & value) {
return std::find(array.begin(), array.end(), value) != array.end() ? true : false;
}
public:
int wordsAmount;
const int & showStopperA = wordsLearned; /* word learned */
const int & showStopperB = wordsForgotten; /* words forgotten */
public:
dataKeeper();
~dataKeeper() {}
void appendToWords(std::string & newWord);
void setWordStatus(bool status, std::string & word);
void showTranslation();
std::pair<std::string, std::string> randomlyGiveWords();
int getNextTime();
template<typename Iter, typename RandomGenerator>
Iter select_randomly(Iter start, Iter end, RandomGenerator& g);
template<typename Iter>
Iter select_randomly(Iter start, Iter end);
void giveResults(std::string & givenResults);
int saveCurrentResults(std::string & givenResults, const char * dir);
};