7 #include "ForgetCurve.h"
10 namespace freeRecite
{
12 static const std::string managerFile
= "freeRecite.mgr";
14 bool Manager::load(const std::string
&dir
) {
15 std::string mgrFile
= dir
+freeRecite::managerFile
;
16 std::ifstream
ifs(mgrFile
.c_str());
23 while(amount
> 0 && ifs
.good()) {
25 allTasks
[tmpTask
.getID()] = tmpTask
;
26 if(tmpTask
.shouldReview())
27 activeID
.push_back(tmpTask
.getID());
34 bool Manager::save() {
35 std::string mgrFile
= mgrDir
+ freeRecite::managerFile
;
36 std::ofstream
ofs(mgrFile
.c_str());
39 ofs
<< static_cast<unsigned>(allTasks
.size()) << '\n';
40 std::map
<time_t,Task
>::const_iterator itr
= allTasks
.begin();
41 while(itr
!= allTasks
.end()){
45 if((itr
->second
).isAvailable())
53 bool Manager::refresh() {
62 bool Manager::hasTask(time_t taskID
) {
63 if(allTasks
.find(taskID
) == allTasks
.end())
69 bool Manager::creatTask(const std::set
<std::string
> &words
,
70 const char *taskName
) {
76 timeinfo
= localtime(&curTime
);
77 strftime(buffer
,20,"%Y%m%d%H%M%S.tkwd",timeinfo
);
79 std::string desFileName
= mgrDir
+ "tasks/" + buffer
;
85 * If there're some new words, then load them to this
86 * soft ware's standard file. By the way, the desFile
87 * coincide with the task's ID.
89 std::ofstream
desFile(desFileName
.c_str());
90 if(!desFile
.is_open())
93 std::set
<std::string
>::const_iterator itr_words
= words
.begin();
94 while(itr_words
!= words
.end()) {
97 if(!itr_words
->empty())
98 desFile
<< *itr_words
<< std::endl
;
103 //Choose the task's name.
105 newTask
= new Task(curTime
,buffer
);
107 newTask
= new Task(curTime
,taskName
);
109 allTasks
[newTask
->getID()] = *newTask
;
110 activeID
.push_back(newTask
->getID());
115 const std::vector
<time_t> &Manager::getActiveTasks() const{
119 int Manager::getActiveTaskNum() const {
120 return activeID
.size();
123 //Get the task's name.
124 const std::string
&Manager::getTaskName(time_t taskID
)const {
125 return (allTasks
.find(taskID
)->second
).getName();
128 //Get the step of the task.
129 int Manager::getTaskStep(time_t taskID
)const {
130 return (allTasks
.find(taskID
)->second
).getStep();
133 bool Manager::test(time_t taskID
,int mark
) {
134 bool result
= (allTasks
[taskID
]).test(mark
);
135 return (refresh() && result
);
138 } //namespace freeRecite end