3 * Used to define the class Reciter which is used to test or recite the words.
5 * Copyright (C) 2008 Kermit Mei (中文名:梅延涛).
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
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).
40 namespace freeRecite
{
46 :score(0),isRedo(false),wordList(0)
47 { /* Do Nothing Here! */ }
49 { /* Do Nothing Here! */ }
52 * Load the words from the file, success return true.
53 * Whenever you want to use this class, you must call it first.
55 bool loadWords(time_t taskID
,const char *configDir
);
57 //The amount of the words in this task.
58 unsigned capability() const;
60 //The number of the unremembered (or untested) words.
61 unsigned size() const;
64 * Get the next word you should recite.
65 * Before you get it, you must test whether it is valid.
67 const std::string
&getWord() const;
69 //If return true, then the object is valid.
72 //Do this test again with an random order.
75 //Add a word to the current task.
76 bool addWord(const std::string
&word
);
78 //Remove a word from the current task.
79 bool removeWord(const std::string
&word
);
81 //Get the number of the words which you answered right.
82 unsigned getScore() const;
85 * Test with the result. The argument 'result' is true when the word
86 * which the user input is correct.
88 void test(bool result
);
91 //Reload the words from the file.
94 //Make words be random.
100 std::vector
<std::string
> words
;
101 std::string taskFileName
;
106 ptrdiff_t operator() (ptrdiff_t max
) {
107 double tmp
= static_cast<double>(rand()) / static_cast<double>(RAND_MAX
);
108 return static_cast<ptrdiff_t>(tmp
* max
);
113 const std::string
&Reciter::getWord() const {
114 return words
[wordList
->getNext()];
119 unsigned Reciter::capability() const {
124 unsigned Reciter::size() const{
127 if(wordList
->isValid())
128 return wordList
->size();
134 bool Reciter::isValid() const {
138 return wordList
->isValid();
142 unsigned Reciter::getScore() const {
143 return score
*100/words
.size();
146 } //namespace freeRecite end