From 7825985f1dc57a013d823af4730161010d30e149 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Thu, 16 Jul 2015 23:34:43 +0300 Subject: [PATCH] Dictionary type changed from std::map to std::multimap. But need to improve this --- CrossBench/CrossBench.project | 2 +- CrossGen.workspace | 6 +++--- src/crossbasetypes.hpp | 4 +++- src/crossgen.cpp | 8 ++++---- wxCrossGen/fmain.cpp | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CrossBench/CrossBench.project b/CrossBench/CrossBench.project index ea8cc9b..70868a4 100644 --- a/CrossBench/CrossBench.project +++ b/CrossBench/CrossBench.project @@ -1,6 +1,7 @@ + - diff --git a/CrossGen.workspace b/CrossGen.workspace index 4b0988b..855376d 100644 --- a/CrossGen.workspace +++ b/CrossGen.workspace @@ -1,7 +1,7 @@ - - + + @@ -12,7 +12,7 @@ - + diff --git a/src/crossbasetypes.hpp b/src/crossbasetypes.hpp index d436486..f44ec8c 100644 --- a/src/crossbasetypes.hpp +++ b/src/crossbasetypes.hpp @@ -6,7 +6,9 @@ #include #include -typedef std::map< wxString, wxString > DictType; +// TODO: Improve worling with multiple definition of words. Move working with it +// to crossgen.cpp from fmain.cpp +typedef std::multimap< wxString, wxString > DictType; typedef std::vector< std::vector< wxChar > > GridType; typedef uint8_t TransedChar; diff --git a/src/crossgen.cpp b/src/crossgen.cpp index c2976fd..8e94325 100644 --- a/src/crossgen.cpp +++ b/src/crossgen.cpp @@ -14,7 +14,7 @@ void readDict(const wxString &path, DictType &dict_out){ int del_ind = str.Index('-'); wxString key = str.Left(del_ind-1); wxString val = str.Right(str.size() - del_ind - 2); - dict_out[key] = val; + dict_out.insert(std::make_pair(key,val)); } f.Close(); }; @@ -304,7 +304,7 @@ bool procCross( t_grid[cur_wi.x][j + cur_wi.y] = cur_word[j]; } - if (procCross(t_used, words, t_grid, winfos, cur_word_ind + 1, out)){ + if ( procCross(t_used, words, t_grid, winfos, cur_word_ind + 1, out) ){ out.push_back(cur_word); return true; } @@ -318,9 +318,9 @@ void generateCross(const GridType &grid, const AllWordsType &words, std::vector winfos; generateWordInfo(grid, winfos); - for (size_t i = 0; i < winfos.size(); ++i) + for (auto el: winfos) wxLogDebug(wxT("Word at (%2d,%2d) with len = %2d and index = %2d and dir = %d"), - winfos.at(i).x,winfos.at(i).y,winfos.at(i).len, winfos.at(i).ind, int(winfos.at(i).direct)); + el.x,el.y,el.len, el.ind, int(el.direct)); WorkGridType grid_work; toWorkGridType(grid, grid_work); diff --git a/wxCrossGen/fmain.cpp b/wxCrossGen/fmain.cpp index 4db9ba9..7fa7ae8 100644 --- a/wxCrossGen/fmain.cpp +++ b/wxCrossGen/fmain.cpp @@ -142,7 +142,7 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) { _ques.clear(); for (size_t i = 0; i < words_out.size(); ++i) - _ques.push_back(_dict[words_out.at(i)]); + _ques.push_back(_dict.find(words_out.at(i))->second); tOutput->Clear();