FreeRecite Version 2.0
[FreeRecite.git] / src / core / Manager.h
blobca867cceb2cee86b3d7255e883b9c8198ff26ce0
1 /**
2 * FileName: Manager.h.
3 * Used to define the class Manager which is used to handle the tasks.
5 * Copyright (C) 2008 Kermit Mei <kermit.mei@gmail.com>
6 * All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation.
22 * Written by Kermit Mei <kermit.mei@gmail.com>
24 * Many of the ideas implemented here are from the author's experiment.
25 * But the dictionary's format coincide with the other word recite software
26 * to help the users get more available data. And the review times designed
27 * by means of the theory named Forgetting Curve which dicoveried by the
28 * German psychologist named Hermann Ebbinghaus(1850–1909).
30 **/
33 #ifndef MANAGER_H
34 #define MANAGER_H
36 #include <list>
37 #include <map>
38 #include <vector>
39 #include "ConfigHolder.h"
40 #include "Task.h"
42 namespace freeRecite {
44 class Manager;
45 extern Manager manager;
47 class Manager
49 public:
51 Manager()
52 :firstReviewTime(0)
53 { /* Do Nothing Here! */ }
55 //Read the information from freeRecite.mgr file.
56 bool load();
58 //Save the information to freeRecite.mgr file.
59 bool save();
61 //Refresh the Manager information.
62 bool refresh();
64 //Test whether this task ID is available.
65 bool hasTask(time_t taskID);
67 //Get the task's name.
68 const std::string &getTaskName(time_t taskID)const;
70 //Get the next reviewing time which is nearest.
71 time_t getNextTime() const;
73 //Get the conrespond task's next reviewing time.
74 time_t getNextTime(time_t taskID) const;
76 //Get the step of the task.
77 int getTaskStep(time_t taskID) const;
79 //Create a new task with the words set.
80 bool createTask(const std::set<std::string> &words,
81 const char *taskName = 0,
82 unsigned maxLimit = 100000);
84 //Remove a task which had been created.
85 void removeTask(time_t taskID);
87 //Get the number of the current reciting words.
88 int currNumWords();
90 //Get the number of the tasks that should be reviewed.
91 int getActiveTaskNum() const;
93 //Get the active tasks' ID.
94 const std::vector<time_t> &getActiveTasks() const;
96 //Get all of the tasks.
97 const std::map<time_t,Task> &getAllTasks() const;
99 /**
100 * This method is used to test whether the mark you got can pass
101 * this test. If you pass it, the task will come to the next step,
102 * else it won't.
104 * Return Value:
105 * -1: If you can't pass it.
106 * 0: If you pass this setp.
107 * 1: If you complish this task.
109 * After calling this method, itr will point to the tested Task
110 * object, see Task::test() for more information.
112 int test(const time_t &taskID, const int &mark);
113 private:
115 * mgrDir is the directory where default freeRecite.mgr
116 * file is saved. This file name is set by default, and
117 * anyone can NOT modify it at Run-time,including that
118 * they can't creat a file with this name under the same
119 * directory.
121 time_t firstReviewTime;
122 std::map<time_t,Task> allTasks;
123 std::vector<time_t> activeID;
124 time_t maxTaskID;
127 inline
128 time_t Manager::getNextTime() const {
129 return firstReviewTime;
132 } //namaspace freeRecite end
134 #endif