diff options
author | vng <viktor.govako@gmail.com> | 2011-07-02 19:36:01 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:20:18 +0300 |
commit | 5ebfd29c0dc9b0374c9aae684db8e057a5862caa (patch) | |
tree | 5a21676e164ddca0807fb9bebb8ef845f65c554f | |
parent | dd8c96cfb3a6c97eb959f2df76b3deabb1a432f1 (diff) |
- Take care about Reader exceptions;
- Avoid code duplicating in framework.cpp;
-rw-r--r-- | coding/internal/file_data.cpp | 7 | ||||
-rw-r--r-- | indexer/index_builder.cpp | 9 | ||||
-rw-r--r-- | map/feature_vec_model.cpp | 12 | ||||
-rw-r--r-- | map/framework.cpp | 155 |
4 files changed, 97 insertions, 86 deletions
diff --git a/coding/internal/file_data.cpp b/coding/internal/file_data.cpp index 6e1fb725a1..a59d065521 100644 --- a/coding/internal/file_data.cpp +++ b/coding/internal/file_data.cpp @@ -162,12 +162,9 @@ bool GetFileSize(string const & fName, uint64_t & sz) sz = f.Size(); return true; } - catch (Writer::SeekException const &) - { - return false; - } - catch (Reader::OpenException const &) + catch (RootException const &) { + // supress all exceptions here return false; } } diff --git a/indexer/index_builder.cpp b/indexer/index_builder.cpp index a73439aac7..84aa27bb03 100644 --- a/indexer/index_builder.cpp +++ b/indexer/index_builder.cpp @@ -27,19 +27,14 @@ namespace indexer writeCont.Finish(); } - catch (Reader::OpenException const & e) - { - LOG(LERROR, (e.what(), " file is not found")); - return false; - } catch (Reader::Exception const & e) { - LOG(LERROR, ("Unknown error while reading file ", e.what())); + LOG(LERROR, ("Error while reading file: ", e.what())); return false; } catch (Writer::Exception const & e) { - LOG(LERROR, ("Error writing index file", e.what())); + LOG(LERROR, ("Error writing index file: ", e.what())); } #ifdef DEBUG diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp index 616ce07958..fa275398e9 100644 --- a/map/feature_vec_model.cpp +++ b/map/feature_vec_model.cpp @@ -29,7 +29,11 @@ void FeaturesFetcher::InitClassificator() } catch (FileAbsentException const & e) { - LOG(LERROR, ("Classificator not found ", e.what())); + LOG(LERROR, ("Classificator not found: ", e.what())); + } + catch (Reader::Exception const & e) + { + LOG(LERROR, ("Classificator read error: ", e.what())); } } @@ -39,13 +43,9 @@ void FeaturesFetcher::AddMap(ReaderT const & file) { m_multiIndex.Add(file); } - catch (Reader::OpenException const & e) - { - LOG(LERROR, ("Data file not found: ", e.what())); - } catch (Reader::Exception const & e) { - LOG(LCRITICAL, ("Unknown error while reading file: ", e.what())); + LOG(LERROR, ("Data file adding error: ", e.what())); } } diff --git a/map/framework.cpp b/map/framework.cpp index 680e27a664..a4c54672ed 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -392,7 +392,6 @@ void FrameWork<TModel>::AddRedrawCommandSure() // set language priorities languages::CodesT langCodes; languages::GetCurrentSettings(langCodes); - languages::SaveSettings(langCodes); } template <typename TModel> @@ -498,14 +497,15 @@ void FrameWork<TModel>::AddRedrawCommandSure() class ReadersAdder { + protected: typedef vector<ModelReaderPtr> maps_list_t; + private: Platform & m_pl; maps_list_t & m_lst; public: ReadersAdder(Platform & pl, maps_list_t & lst) : m_pl(pl), m_lst(lst) {} - void operator() (string const & f) { m_lst.push_back(m_pl.GetReader(f)); @@ -538,113 +538,131 @@ void FrameWork<TModel>::AddRedrawCommandSure() ++it; } - filesList.clear(); - for_each(resFiles.begin(), resFiles.end(), ReadersAdder(pl, filesList)); - for_each(dataFiles.begin(), dataFiles.end(), ReadersAdder(pl, filesList)); + try + { + filesList.clear(); + for_each(resFiles.begin(), resFiles.end(), ReadersAdder(pl, filesList)); + for_each(dataFiles.begin(), dataFiles.end(), ReadersAdder(pl, filesList)); + } + catch (RootException const & e) + { + LOG(LERROR, ("Can't add map: ", e.what())); + } } - template <typename TModel> - void FrameWork<TModel>::EnumBenchmarkMaps(maps_list_t & filesList) + template <class ToDo> + void ForEachBenchmarkRecord(ToDo & toDo) { Platform & pl = GetPlatform(); - set<string> files; - ifstream fin(pl.WritablePathForFile("benchmarks/config.info").c_str()); + string buffer; + try + { + ReaderPtr<Reader>(pl.GetReader("benchmarks/config.info")).ReadAsString(buffer); + } + catch (RootException const & e) + { + LOG(LERROR, ("Error reading benchmarks: ", e.what())); + return; + } - filesList.clear(); - char buf[256]; + istringstream stream(buffer); - while (true) + string line; + while (stream.good()) { - fin.getline(buf, 256); - - if (!fin) - break; + getline(stream, line); vector<string> parts; - string s(buf); - strings::SimpleTokenizer it(s, " "); + strings::SimpleTokenizer it(line, " "); while (it) { parts.push_back(*it); ++it; } - filesList.push_back(pl.GetReader(parts[0])); + if (!parts.empty()) + toDo(parts); } } - template <typename TModel> - void FrameWork<TModel>::InitBenchmark() + class FirstReaderAdder : public ReadersAdder { - //m2::RectD wr(MercatorBounds::minX, MercatorBounds::minY, MercatorBounds::maxX, MercatorBounds::maxY); - //m2::RectD r(wr.Center().x, wr.Center().y + wr.SizeY() / 8, wr.Center().x + wr.SizeX() / 8, wr.Center().y + wr.SizeY() / 4); - - set<string> files; - ifstream fin(GetPlatform().WritablePathForFile("benchmarks/config.info").c_str()); - while (true) + typedef ReadersAdder base_type; + public: + FirstReaderAdder(maps_list_t & lst) : base_type(GetPlatform(), lst) {} + void operator() (vector<string> const & v) { - string name; - m2::RectD r; - - char buf[256]; + base_type::operator() (v[0]); + } + }; - fin.getline(buf, 256); + template <typename TModel> + void FrameWork<TModel>::EnumBenchmarkMaps(maps_list_t & filesList) + { + FirstReaderAdder adder(filesList); + ForEachBenchmarkRecord(adder); + } - if (!fin) - break; + template <class T> class DoGetBenchmarks + { + set<string> m_processed; + vector<T> & m_benchmarks; + Platform & m_pl; - vector<string> parts; - string s(buf); - strings::SimpleTokenizer it(s, " "); - while (it) - { - parts.push_back(*it); - ++it; - } + public: + DoGetBenchmarks(vector<T> & benchmarks) + : m_benchmarks(benchmarks), m_pl(GetPlatform()) + { + } - Benchmark b; - b.m_name = parts[1]; + void operator() (vector<string> const & v) + { + T b; + b.m_name = v[1]; - if (files.find(parts[0]) == files.end()) + m2::RectD r; + if (m_processed.insert(v[0]).second) { - files.insert(parts[0]); - if (GetPlatform().IsFileExists(GetPlatform().WritablePathForFile(parts[0]))) + try { - try - { - feature::DataHeader header; - header.Load(FilesContainerR(GetPlatform().WritablePathForFile(parts[0])).GetReader(HEADER_FILE_TAG)); - - r = header.GetBounds(); - } - catch (std::exception const &) - { - LOG(LINFO, ("cannot add ", parts[0], " file to benchmark")); - } + feature::DataHeader header; + header.Load(FilesContainerR(m_pl.GetReader(v[0])).GetReader(HEADER_FILE_TAG)); + r = header.GetBounds(); + } + catch (RootException const & e) + { + LOG(LINFO, ("Cannot add ", v[0], " file to benchmark: ", e.what())); + return; } } int lastScale; - - LOG(LINFO, (parts)); - if (parts.size() > 3) + if (v.size() > 3) { double x0, y0, x1, y1; - strings::to_double(parts[2], x0); - strings::to_double(parts[3], y0); - strings::to_double(parts[4], x1); - strings::to_double(parts[5], y1); + strings::to_double(v[2], x0); + strings::to_double(v[3], y0); + strings::to_double(v[4], x1); + strings::to_double(v[5], y1); r = m2::RectD(x0, y0, x1, y1); - strings::to_int(parts[6], lastScale); + strings::to_int(v[6], lastScale); } else - strings::to_int(parts[2], lastScale); + strings::to_int(v[2], lastScale); + ASSERT ( r != m2::RectD::GetEmptyRect(), (r) ); b.m_provider.reset(new BenchmarkRectProvider(scales::GetScaleLevel(r), r, lastScale)); m_benchmarks.push_back(b); } + }; + + template <typename TModel> + void FrameWork<TModel>::InitBenchmark() + { + DoGetBenchmarks<Benchmark> doGet(m_benchmarks); + ForEachBenchmarkRecord(doGet); m_curBenchmark = 0; @@ -658,7 +676,8 @@ void FrameWork<TModel>::AddRedrawCommandSure() } template <typename TModel> - void FrameWork<TModel>::initializeGL(shared_ptr<yg::gl::RenderContext> const & primaryContext, + void FrameWork<TModel>::initializeGL( + shared_ptr<yg::gl::RenderContext> const & primaryContext, shared_ptr<yg::ResourceManager> const & resourceManager) { m_resourceManager = resourceManager; |