update dict
[QFreeRecite.git] / src / core / Task.cpp
blob34a3296e0f1034c278c5d602888587aba43a20ae
1 #include "Task.h"
2 #include "ForgetCurve.h"
3 #include "ConfigHolder.h"
5 namespace freeRecite {
7 Task::~Task() {
8 /*
9 if(curve != 0)
10 delete curve;
14 std::istream&
15 operator>>(std::istream &istrm, Task &tsk) {
17 istrm >> tsk.id;
18 istrm.ignore(1,',');
20 istrm >> tsk.reviewTime;
21 istrm.ignore(1,',');
23 istrm >> tsk.step;
24 istrm.ignore(1,',');
26 istrm >> tsk.name;
27 istrm.ignore(1,'\n');
28 return istrm;
31 std::ostream&
32 operator<<(std::ostream &ostrm, const Task &tsk) {
33 ostrm << tsk.id << ','
34 << tsk.reviewTime << ','
35 << tsk.step << ','
36 << tsk.name << '\n';
37 return ostrm;
40 bool operator>(const Task &src, const Task &tar) {
41 return src.reviewTime > tar.reviewTime;
44 bool operator<(const Task &src, const Task &tar) {
45 return src.reviewTime < tar.reviewTime;
48 bool operator==(const Task &src, const Task &tar) {
49 return src.id == tar.id;
52 bool Task::shouldReview() const {
53 std::time_t current;
54 std::time(&current);
55 return reviewTime <= current;
58 int Task::test(int mark) {
59 if(!shouldReview())
60 return -1;
61 if( forgetCurve.pass(step,mark) ) { //If have passed
62 ++step;
63 if(step == 8) {//This task has finished
64 reviewTime = 0;
65 return 1;
66 }else
67 reviewTime = forgetCurve.getReviewTime(step);
68 return 0;
69 }else { //If haven't passed
70 reviewTime = forgetCurve.getReviewTime(step);
71 return -1;
75 }//namespace freeRecite end