Skip to content

Commit 77a3a66

Browse files
committed
settings finished(1st version)
1 parent 213e2d4 commit 77a3a66

20 files changed

+436
-41
lines changed

basic.cpp

+33-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void Basic::transStrToProp(const string& infoStr) {
2020
rp = infoStr.find(".", lp) - 1;
2121
timestamp = str::strToInt(infoStr.substr(lp, rp - lp + 1));
2222
}
23+
2324
lp = infoStr.find("@level@");
2425
if (lp == string::npos) {
2526
level = 0;
@@ -30,23 +31,33 @@ void Basic::transStrToProp(const string& infoStr) {
3031
level = str::strToInt(infoStr.substr(lp, rp - lp + 1));
3132
}
3233

33-
/*
34-
lp = infoStr.find("@strategy@");
34+
lp = infoStr.find("@selectstrategy@");
3535
if (lp == string::npos) {
36-
///////////
36+
sstraNum = -1;
3737
}
3838
else {
39-
lp += 10;
39+
lp += 16;
4040
rp = infoStr.find(".", lp) - 1;
41-
///////////
41+
sstraNum = str::strToInt(infoStr.substr(lp, rp - lp + 1));
4242
}
43-
*/
43+
44+
lp = infoStr.find("@formstrategy@");
45+
if (lp == string::npos) {
46+
sstraNum = 0;
47+
}
48+
else {
49+
lp += 14;
50+
rp = infoStr.find(".", lp) - 1;
51+
fstraNum = str::strToInt(infoStr.substr(lp, rp - lp + 1));
52+
}
53+
4454
}
4555

4656
string Basic::transPropToStr() {
4757
string res = "@timestamp@" + str::intToStr(timestamp) + ".\n";
48-
res += "@level@" + str::intToStr(level) + ".";
49-
////////
58+
res += "@level@" + str::intToStr(level) + ".\n";
59+
res += "@selectstrategy@" + str::intToStr(sstraNum) + ".\n";
60+
res += "@formstrategy@" + str::intToStr(fstraNum) + ".\n";
5061
return res;
5162
}
5263

@@ -59,7 +70,13 @@ int Basic::getLevel() {
5970
return level;
6071
}
6172

62-
////////// getStrategy()
73+
int Basic::getSelectStrategy() {
74+
return sstraNum;
75+
}
76+
77+
int Basic::getFormStrategy() {
78+
return fstraNum;
79+
}
6380

6481
void Basic::setTimestamp(int ts) {
6582
timestamp = ts;
@@ -69,4 +86,10 @@ void Basic::setLevel(int le) {
6986
level = le;
7087
}
7188

72-
////////// setStrategy()
89+
void Basic::setSelectStrategy(int ss) {
90+
sstraNum = ss;
91+
}
92+
93+
void Basic::setFormStrategy(int fs) {
94+
fstraNum = fs;
95+
}

basic.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ class Basic : public ComplexInfo {
1111

1212
int getTimestamp();
1313
int getLevel();
14+
int getSelectStrategy();
15+
int getFormStrategy();
1416
void setTimestamp(int ts);
1517
void setLevel(int le);
18+
void setSelectStrategy(int ss);
19+
void setFormStrategy(int fs);
20+
1621

1722
protected:
1823
void transStrToProp(const string& infoStr);
1924
string transPropToStr();
2025

2126
private:
22-
int timestamp, level;
27+
int timestamp, level, sstraNum, fstraNum;
2328

2429
};
2530

env.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ string Env::getUserName() {
6565
return userName;
6666
}
6767

68+
void Env::setUserName(const string& newUserName) {
69+
userName = newUserName;
70+
}
71+
6872
void Env::pass(const string& word, int diffi, bool ok) {
6973
statList[diffi]->setTotal(statList[diffi]->getTotal() + 1);
7074
Progress prog(fsbProg, word);

env.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Env {
2020

2121
void pass(const string& word, int diffi, bool ok);
2222
string getUserName();
23+
void setUserName(const string& newUserName);
2324

2425
FileStrBridge* fsbDef;
2526
FileStrBridge* fsbSent;

factory.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "factory.h"
2+
3+
Factory::Factory(Env* env) : env(env) {
4+
}
5+
6+
SelectStrategyFactory::SelectStrategyFactory(Env* env) :
7+
Factory(env) {
8+
}
9+
10+
SelectStrategy* SelectStrategyFactory::produce(int diffi) {
11+
if (diffi == -1) {
12+
return new RandomSelection(env);
13+
}
14+
if (diffi == DIFFI_NUM) {
15+
return new SmartSelection(env);
16+
}
17+
if (diffi >= 0 && diffi < DIFFI_NUM) {
18+
return new FixedSelection(env, diffi);
19+
}
20+
return NULL;
21+
}
22+
23+
24+
25+
FormStrategyFactory::FormStrategyFactory(Env* env) : Factory(env) {
26+
}
27+
28+
FormStrategy* FormStrategyFactory::produce(int n) {
29+
switch (n) {
30+
31+
case 0:
32+
return new RemOrNotForm;
33+
default:
34+
return NULL;
35+
36+
}
37+
}

factory.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef FACTORY_H
2+
#define FACTORY_H
3+
4+
#include "env.h"
5+
#include "strategy.h"
6+
7+
class Factory {
8+
9+
public:
10+
Factory(Env* env);
11+
12+
protected:
13+
Env* env;
14+
15+
};
16+
17+
class SelectStrategyFactory : public Factory {
18+
19+
public:
20+
SelectStrategyFactory(Env* env);
21+
SelectStrategy* produce(int diffi);
22+
23+
private:
24+
int diffi;
25+
26+
};
27+
28+
class FormStrategyFactory : public Factory {
29+
30+
public:
31+
FormStrategyFactory(Env* env);
32+
FormStrategy* produce(int n);
33+
34+
};
35+
36+
37+
#endif

file_system.cpp

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//Some file system API adapter
2+
3+
#include "file_system.h"
4+
5+
6+
//============For Windows=============
7+
8+
#ifdef _WIN32
9+
10+
#include <sys/stat.h>
11+
#include <direct.h>
12+
13+
14+
bool dirExists(char* dirName)
15+
{
16+
struct _stat fileStat;
17+
if ((_stat(dirName, &fileStat) == 0) && (fileStat.st_mode & _S_IFDIR))
18+
{
19+
return true;
20+
}
21+
else
22+
{
23+
return false;
24+
}
25+
}
26+
27+
bool makeDir(char* dirName)
28+
{
29+
if (dirExists(dirName))
30+
{
31+
return true;
32+
}
33+
mkdir(dirName);
34+
return dirExists(dirName);
35+
}
36+
37+
#endif
38+
39+
40+
//===============For Linux=================
41+
42+
#ifdef _linux_
43+
44+
#include <sys/stat.h>
45+
#include <sys/types.h>
46+
#include <unistd.h>
47+
48+
49+
bool dirExists(char* dirName)
50+
{
51+
struct stat fileStat;
52+
if ((stat(dirName, &fileStat) == 0) && S_ISDIR(fileStat.st_mode))
53+
{
54+
return true;
55+
}
56+
else
57+
{
58+
return false;
59+
}
60+
}
61+
62+
bool makeDir(char* dirName)
63+
{
64+
if (dirExists(dirName))
65+
{
66+
return true;
67+
}
68+
mkdir(dirName, S_IRWXG);
69+
return dirExists(dirName);
70+
}
71+
72+
73+
#endif
74+
75+
76+
//=================For Mac OS===================
77+
78+
#ifdef _APPLE_
79+
80+
bool dirExists(char* dirName)
81+
{
82+
83+
}
84+
85+
bool makeDir(char* dirName)
86+
{
87+
88+
}
89+
90+
#endif
91+
92+
93+
//===============General===================
94+
95+
bool dirExists(std::string dirName)
96+
{
97+
char *dir = (char*)dirName.data();
98+
return dirExists(dir);
99+
}
100+
101+
bool makeDir(std::string dirName)
102+
{
103+
char *dir = (char*)dirName.data();
104+
return makeDir(dir);
105+
}
106+
107+
bool smartMakeDir(char* dirName)
108+
{
109+
char *tag;
110+
for(tag = dirName; *tag; tag++)
111+
{
112+
if (*tag == '\\')
113+
{
114+
char buf[1000], path[1000];
115+
strcpy(buf, dirName);
116+
buf[strlen(dirName) - strlen(tag) + 1] = NULL;
117+
strcpy(path, buf);
118+
if (! dirExists(path))
119+
{
120+
makeDir(path);
121+
}
122+
}
123+
}
124+
return dirExists(dirName);
125+
}
126+
127+
bool smartMakeDir(std::string dirName)
128+
{
129+
char *dir = (char*)dirName.data();
130+
return smartMakeDir(dir);
131+
}

file_system.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//Some file system API adapter
2+
3+
#ifndef FILE_SYSTEM_H
4+
#define FILE_SYSTEM_H
5+
6+
#include <string>
7+
#include <cstring>
8+
9+
//If a folder exists
10+
bool dirExists(char* dirName);
11+
bool dirExists(std::string dirName);
12+
//Create a new folder
13+
bool makeDir(char* dirName);
14+
bool makeDir(std::string dirName);
15+
16+
//Create multilayer folder
17+
bool smartMakeDir(char* dirName);
18+
bool smartMakeDir(std::string dirName);
19+
20+
#endif

interaction.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ string LearnOneWord::getWord() {
7474

7575
void LearnOneWord::ask() {
7676
word = sstra->next(diffi);
77-
cout << " @@@@diffi: " << diffi << endl;
77+
//cout << " @@@@diffi: " << diffi << endl;
7878
fstra->setWord(word);
7979
cout << fstra->display();
8080
}
@@ -252,12 +252,3 @@ void Count::work() {
252252
cout << " " << cnt << endl << endl;
253253
}
254254

255-
256-
// -----------------
257-
258-
259-
Settings::Settings(Env* env) : Interaction(env) {
260-
}
261-
262-
void Settings::work() {
263-
}

interaction.h

-8
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,5 @@ class Count : public Interaction {
109109

110110
};
111111

112-
class Settings : public Interaction {
113-
114-
public:
115-
Settings(Env* env);
116-
void work();
117-
118-
};
119-
120112

121113
#endif

main_interface.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "interaction.h"
55
#include "test.h"
6+
#include "settings.h"
67

78

89
class MainInterface : public Interaction {

0 commit comments

Comments
 (0)