Added dictionary caching

This commit is contained in:
2015-06-06 13:24:37 +03:00
parent befbe90a88
commit 184d931e6e
3 changed files with 17 additions and 9 deletions

View File

@@ -2,10 +2,10 @@
<CodeLite_Workspace Name="CrossGen" Database=""> <CodeLite_Workspace Name="CrossGen" Database="">
<Project Name="wxCrossGen" Path="wxCrossGen/wxCrossGen.project" Active="Yes"/> <Project Name="wxCrossGen" Path="wxCrossGen/wxCrossGen.project" Active="Yes"/>
<BuildMatrix> <BuildMatrix>
<WorkspaceConfiguration Name="Debug" Selected="yes"> <WorkspaceConfiguration Name="Debug" Selected="no">
<Project Name="wxCrossGen" ConfigName="Debug"/> <Project Name="wxCrossGen" ConfigName="Debug"/>
</WorkspaceConfiguration> </WorkspaceConfiguration>
<WorkspaceConfiguration Name="Release" Selected="no"> <WorkspaceConfiguration Name="Release" Selected="yes">
<Project Name="wxCrossGen" ConfigName="Release"/> <Project Name="wxCrossGen" ConfigName="Release"/>
</WorkspaceConfiguration> </WorkspaceConfiguration>
</BuildMatrix> </BuildMatrix>

View File

@@ -26,6 +26,8 @@ MainFrame::MainFrame(wxWindow* parent, int id, const wxString& title, const wxPo
set_properties(); set_properties();
do_layout(); do_layout();
_isDictLoaded = false;
} }
@@ -162,9 +164,13 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) {
void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) { void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
event.Skip(); event.Skip();
DictType dict;
if ( !_isDictLoaded ) {
readDict(wxT("big_cross_ru.txt"), _dict);
_isDictLoaded = true;
}
std::vector<wxString> words_out; std::vector<wxString> words_out;
readDict(wxT("big_cross_ru.txt"), dict);
GridType grid; GridType grid;
if (tPath->GetValue() == wxEmptyString){ if (tPath->GetValue() == wxEmptyString){
wxMessageBox( wxT("Не указана путь к сетке"), wxT("Инфо"), wxICON_INFORMATION); wxMessageBox( wxT("Не указана путь к сетке"), wxT("Инфо"), wxICON_INFORMATION);
@@ -172,7 +178,7 @@ void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
} }
readGrid(tPath->GetValue(), grid); readGrid(tPath->GetValue(), grid);
try{ try{
generateCross(grid,dict,words_out); generateCross(grid,_dict,words_out);
_words.clear(); _words.clear();
_words = words_out; _words = words_out;
@@ -187,7 +193,7 @@ void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
for (size_t i = 0; i < words_out.size(); ++i){ for (size_t i = 0; i < words_out.size(); ++i){
if (winfos.at(i).direct == false) if (winfos.at(i).direct == false)
tOutput->AppendText(wxString::Format(wxT("%d. "), winfos.at(i).ind) tOutput->AppendText(wxString::Format(wxT("%d. "), winfos.at(i).ind)
+ dict[words_out.at(i)] +wxT("\n")); + _dict[words_out.at(i)] +wxT("\n"));
} }
tOutput->AppendText(wxT("По горизонтали:\n")); tOutput->AppendText(wxT("По горизонтали:\n"));
@@ -195,7 +201,7 @@ void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
for (size_t i = 0; i < words_out.size(); ++i){ for (size_t i = 0; i < words_out.size(); ++i){
if (winfos.at(i).direct == true) if (winfos.at(i).direct == true)
tOutput->AppendText(wxString::Format(wxT("%d. "), winfos.at(i).ind) tOutput->AppendText(wxString::Format(wxT("%d. "), winfos.at(i).ind)
+ dict[words_out.at(i)]+wxT("\n")); + _dict[words_out.at(i)]+wxT("\n"));
} }
if (winfos.size() == 0) if (winfos.size() == 0)
throw 42; throw 42;
@@ -205,7 +211,7 @@ void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) {
catch (...){ catch (...){
tOutput->Clear(); tOutput->Clear();
this->Refresh(); this->Refresh();
wxMessageBox( wxT("Не могу создать кроссворд"), wxT("Ошибка"), wxICON_ERROR); wxMessageBox( wxT("Не могу создать кроссворд"), wxT("Ошибка"), wxICON_ERROR );
} }
} }

View File

@@ -45,6 +45,9 @@ private:
// end wxGlade // end wxGlade
protected: protected:
std::vector<wxString> _words;
DictType _dict;
bool _isDictLoaded;
// begin wxGlade: MainFrame::attributes // begin wxGlade: MainFrame::attributes
wxStaticText* label_1; wxStaticText* label_1;
wxTextCtrl* tPath; wxTextCtrl* tPath;
@@ -52,7 +55,6 @@ protected:
wxTextCtrl* tOutput; wxTextCtrl* tOutput;
wxButton* btnGenerate; wxButton* btnGenerate;
wxStaticBitmap* bPreview; wxStaticBitmap* bPreview;
std::vector<wxString> _words;
// end wxGlade // end wxGlade
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();