Split and Rtimes
[FreeRecite.git] / src / core / Manager.h
blob3c60f49d3e0c5f23cbddbe21bb6d66ef7bbb7cc3
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 (中文名:梅延涛).
6 * All Rights Reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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 //If the loadfile can not be read, it returns false.
57 bool load();
59 //Save the information to freeRecite.mgr file.
60 bool save();
62 //Refresh the Manager information.
63 bool refresh();
65 //Test whether this task ID is available.
66 bool hasTask(time_t taskID);
68 //Get the task's name.
69 const std::string &getTaskName(time_t taskID)const;
71 //Get the next reviewing time which is nearest.
72 time_t getNextTime() const;
74 //Get the conrespond task's next reviewing time.
75 time_t getNextTime(time_t taskID) const;
77 //Get the step of the task.
78 int getTaskStep(time_t taskID) const;
80 //Create a new task with the words set.
81 bool createTask(const std::set<std::string> &words,
82 const char *taskName = 0,
83 unsigned maxLimit = 100000);
85 //Get the number of the tasks that should be reviewed.
86 int getActiveTaskNum() const;
88 /**
89 * Get a point to the Task which is active.
90 **/
91 const std::vector<time_t> &getActiveTasks() const;
93 // Call this method will add one to the task's words amount.
94 void addWord(time_t taskID);
96 // Call this method will subtract one from task's words amount.
97 void removeWord(time_t taskID);
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 * true: If you can pass it.
106 * false: If you can't pass it.
108 * After calling this method, itr will point to the tested Task
109 * object, see Task::test() for more information.
111 bool test(time_t taskID,int mark);
112 private:
114 * mgrDir is the directory where default freeRecite.mgr
115 * file is saved. This file name is set by default, and
116 * anyone can NOT modify it at Run-time,including that
117 * they can't creat a file with this name under the same
118 * directory.
120 time_t firstReviewTime;
121 std::map<time_t,Task> allTasks;
122 std::vector<time_t> activeID;
123 time_t maxTaskID;
126 inline
127 time_t Manager::getNextTime() const {
128 return firstReviewTime;
131 } //namaspace freeRecite end
133 #endif