diff --git a/base/base.pro b/base/base.pro index 27aa74814f..4ebc56f18a 100644 --- a/base/base.pro +++ b/base/base.pro @@ -24,6 +24,8 @@ SOURCES += \ normalize_unicode.cpp \ runner.cpp \ timer.cpp \ + internal/message.cpp \ + exception.cpp HEADERS += \ SRC_FIRST.hpp \ diff --git a/base/base_tests/assert_test.cpp b/base/base_tests/assert_test.cpp index 62d650942b..399489c855 100644 --- a/base/base_tests/assert_test.cpp +++ b/base/base_tests/assert_test.cpp @@ -2,6 +2,9 @@ #include "../../testing/testing.hpp" #include "../../base/base.hpp" +#include "../../base/exception.hpp" +#include "../../base/logging.hpp" + UNIT_TEST(Assert_Smoke) { @@ -18,3 +21,15 @@ UNIT_TEST(Check_Smoke) CHECK_NOT_EQUAL ( x, 6, () ); //CHECK_EQUAL ( x, 666, ("Skip this to continue test") ); } + +UNIT_TEST(Exception_Formatting) +{ + try + { + MYTHROW(RootException, ("String1", "String2", "String3")); + } + catch (RootException const & e) + { + LOG(LINFO, ("Exception string: ", e.what())); + } +} diff --git a/base/exception.cpp b/base/exception.cpp new file mode 100644 index 0000000000..389cb86af0 --- /dev/null +++ b/base/exception.cpp @@ -0,0 +1,21 @@ +#include "exception.hpp" + +char const * RootException::what() const throw() +{ + size_t const count = m_Msg.size(); + + string asciiMsg; + asciiMsg.resize(count); + + for (size_t i = 0; i < count; ++i) + { + if (static_cast(m_Msg[i]) < 128) + asciiMsg[i] = char(m_Msg[i]); + else + asciiMsg[i] = '?'; + } + + static string msg; + msg = string(m_What) + ", \"" + asciiMsg + "\""; + return msg.c_str(); +} diff --git a/base/exception.hpp b/base/exception.hpp index 09d8703097..14756e926a 100644 --- a/base/exception.hpp +++ b/base/exception.hpp @@ -16,25 +16,7 @@ public: { } - virtual char const * what() const throw() - { - size_t const count = m_Msg.size(); - - string asciiMsg; - asciiMsg.resize(count); - - for (size_t i = 0; i < count; ++i) - { - if (static_cast(m_Msg[i]) < 128) - asciiMsg[i] = char(m_Msg[i]); - else - asciiMsg[i] = '?'; - } - - static string msg; - msg = string(m_What) + ", \"" + asciiMsg + "\""; - return msg.c_str(); - } + virtual char const * what() const throw(); string const & Msg() const throw() { diff --git a/base/internal/message.cpp b/base/internal/message.cpp new file mode 100644 index 0000000000..07c63a5dd7 --- /dev/null +++ b/base/internal/message.cpp @@ -0,0 +1,27 @@ +#include "message.hpp" + +string debug_print(string const & t) +{ + string res; + res.push_back('\"'); + for (string::const_iterator it = t.begin(); it != t.end(); ++it) + { + static char const toHex[] = "0123456789abcdef"; + unsigned char const c = static_cast(*it); + if (c >= ' ' && c <= '~' && c != '\\' && c != '"') + res.push_back(*it); + else + { + res.push_back('\\'); + if (c == '\\' || c == '"') + res.push_back(c); + else + { + res.push_back(toHex[c >> 4]); + res.push_back(toHex[c & 0xf]); + } + } + } + res.push_back('\"'); + return res; +} diff --git a/base/internal/message.hpp b/base/internal/message.hpp index fa88b6eeec..e602f8d373 100644 --- a/base/internal/message.hpp +++ b/base/internal/message.hpp @@ -10,41 +10,21 @@ #include "../../std/vector.hpp" +/// @name Declarations. +//@{ template inline string debug_print(T const & t); -inline string debug_print(string const & t); + +string debug_print(string const & t); inline string debug_print(char const * t); inline string debug_print(char t); + template inline string debug_print(pair const & p); template inline string debug_print(list const & v); template inline string debug_print(vector const & v); template inline string debug_print(set const & v); template inline string debug_print(map const & v); +//@} -inline string debug_print(string const & t) -{ - string res; - res.push_back('\"'); - for (string::const_iterator it = t.begin(); it != t.end(); ++it) - { - static char const toHex[] = "0123456789abcdef"; - unsigned char const c = static_cast(*it); - if (c >= ' ' && c <= '~' && c != '\\' && c != '"') - res.push_back(*it); - else - { - res.push_back('\\'); - if (c == '\\' || c == '"') - res.push_back(c); - else - { - res.push_back(toHex[c >> 4]); - res.push_back(toHex[c & 0xf]); - } - } - } - res.push_back('\"'); - return res; -} inline string debug_print(char const * t) { diff --git a/map/framework.cpp b/map/framework.cpp index 1fd61effb1..cbd92f7a20 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -451,11 +451,10 @@ void FrameWork::AddRedrawCommandSure() template void FrameWork::SendBenchmarkResults() { -// ofstream fout(GetPlatform().WritablePathForFile("benchmarks/results.txt").c_str(), ios::app); -// fout << "[COMPLETED]"; -// fout.close(); - /// send to server for adding to statistics graphics - /// and delete results file + //ofstream fout(GetPlatform().WritablePathForFile("benchmarks/results.txt").c_str(), ios::app); + //fout << "[COMPLETED]"; + //fout.close(); + /// @todo send to server for adding to statistics graphics and delete results file } template @@ -690,7 +689,8 @@ void FrameWork::AddRedrawCommandSure() } template - void FrameWork::initializeGL(shared_ptr const & primaryContext, + void FrameWork::initializeGL( + shared_ptr const & primaryContext, shared_ptr const & resourceManager) { m_resourceManager = resourceManager; @@ -844,8 +844,7 @@ void FrameWork::AddRedrawCommandSure() void FrameWork::PaintImpl(shared_ptr e, ScreenBase const & screen, m2::RectD const & selectRect, - int scaleLevel - ) + int scaleLevel) { fwork::DrawProcessor doDraw(selectRect, screen, e, scaleLevel, m_renderQueue.renderStatePtr(), e->drawer()->screen()->glyphCache()); m_renderQueue.renderStatePtr()->m_isEmptyModelCurrent = true; @@ -1149,7 +1148,7 @@ void FrameWork::AddRedrawCommandSure() void FrameWork::Move(double azDir, double factor) { m_navigator.Move(azDir, factor); -// m_tiler.seed(m_navigator.Screen(), m_tileSize); + //m_tiler.seed(m_navigator.Screen(), m_tileSize); UpdateNow(); } //@} @@ -1178,7 +1177,7 @@ void FrameWork::AddRedrawCommandSure() void FrameWork::Scale(double scale) { m_navigator.Scale(scale); -// m_tiler.seed(m_navigator.Screen(), m_tileSize); + //m_tiler.seed(m_navigator.Screen(), m_tileSize); UpdateNow(); }