rewrite and reoganize tools functions

* create stdext namespace which contains additional C++ algorithms
* organize stdext in string, math, cast and exception utilities
This commit is contained in:
Eduardo Bart
2012-05-28 10:06:26 -03:00
parent 2676eb4da3
commit 4c80d783d6
75 changed files with 856 additions and 652 deletions

View File

@@ -85,7 +85,7 @@ public:
bool isFullscreen() { return m_fullscreen; }
bool hasFocus() { return m_focused; }
void setOnClose(const SimpleCallback& onClose) { m_onClose = onClose; }
void setOnClose(const std::function<void()>& onClose) { m_onClose = onClose; }
void setOnResize(const OnResizeCallback& onResize) { m_onResize = onResize; }
void setOnInputEvent(const OnInputEventCallback& onInputEvent) { m_onInputEvent = onInputEvent; }
@@ -116,7 +116,7 @@ protected:
Boolean<false> m_fullscreen;
Boolean<false> m_maximized;
SimpleCallback m_onClose;
std::function<void()> m_onClose;
OnResizeCallback m_onResize;
OnInputEventCallback m_onInputEvent;
};

View File

@@ -39,13 +39,13 @@ void crashHandler(int signum, siginfo_t* info, void* secret)
logError("Application crashed");
std::stringstream ss;
ss << Fw::formatString("app name: %s\n", g_app->getName().c_str());
ss << Fw::formatString("app version: %s\n", g_app->getVersion().c_str());
ss << Fw::formatString("build compiler: %s\n", BUILD_COMPILER);
ss << Fw::formatString("build date: %s\n", BUILD_DATE);
ss << Fw::formatString("build type: %s\n", BUILD_TYPE);
ss << Fw::formatString("build revision: %s\n", BUILD_REVISION);
ss << Fw::formatString("crash date: %s\n", Fw::dateTimeString().c_str());
ss << stdext::format("app name: %s\n", g_app->getName());
ss << stdext::format("app version: %s\n", g_app->getVersion());
ss << stdext::format("build compiler: %s\n", BUILD_COMPILER);
ss << stdext::format("build date: %s\n", BUILD_DATE);
ss << stdext::format("build type: %s\n", BUILD_TYPE);
ss << stdext::format("build revision: %s\n", BUILD_REVISION);
ss << stdext::format("crash date: %s\n", stdext::date_time_string());
ss.flags(std::ios::hex | std::ios::showbase);
ucontext_t context = *(ucontext_t*)secret;
@@ -92,7 +92,7 @@ void crashHandler(int signum, siginfo_t* info, void* secret)
demanglePos++;
int len = std::min(line.find_first_of("+", demanglePos), line.find_first_of(")", demanglePos)) - demanglePos;
std::string funcName = line.substr(demanglePos, len);
line.replace(demanglePos, len, Fw::demangleName(funcName.c_str()));
line.replace(demanglePos, len, stdext::demangle_name(funcName.c_str()));
}
#endif
ss << " " << i-1 << ": " << line << std::endl;

View File

@@ -95,9 +95,9 @@ void Stacktrace(LPEXCEPTION_POINTERS e, std::stringstream& ss)
pSym->MaxNameLength = MAX_PATH;
if(SymGetSymFromAddr(process, sf.AddrPC.Offset, &Disp, pSym))
ss << Fw::formatString(" %d: %s(%s+%#0lx) [0x%08lX]\n", count, modname, pSym->Name, Disp, sf.AddrPC.Offset);
ss << stdext::format(" %d: %s(%s+%#0lx) [0x%08lX]\n", count, modname, pSym->Name, Disp, sf.AddrPC.Offset);
else
ss << Fw::formatString(" %d: %s [0x%08lX]\n", count, modname, sf.AddrPC.Offset);
ss << stdext::format(" %d: %s [0x%08lX]\n", count, modname, sf.AddrPC.Offset);
++count;
}
GlobalFree(pSym);
@@ -109,16 +109,16 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e)
SymInitialize(GetCurrentProcess(), 0, TRUE);
std::stringstream ss;
ss << "== application crashed\n";
ss << Fw::formatString("app name: %s\n", g_app->getName().c_str());
ss << Fw::formatString("app version: %s\n", g_app->getVersion().c_str());
ss << Fw::formatString("build compiler: %s\n", BUILD_COMPILER);
ss << Fw::formatString("build date: %s\n", BUILD_DATE);
ss << Fw::formatString("build type: %s\n", BUILD_TYPE);
ss << Fw::formatString("build revision: %s\n", BUILD_REVISION);
ss << Fw::formatString("crash date: %s\n", Fw::dateTimeString().c_str());
ss << Fw::formatString("exception: %s (0x%08lx)\n", getExceptionName(e->ExceptionRecord->ExceptionCode), e->ExceptionRecord->ExceptionCode);
ss << Fw::formatString("exception address: 0x%08lx\n", (long unsigned int)e->ExceptionRecord->ExceptionAddress);
ss << Fw::formatString(" backtrace:\n");
ss << stdext::format("app name: %s\n", g_app->getName().c_str());
ss << stdext::format("app version: %s\n", g_app->getVersion().c_str());
ss << stdext::format("build compiler: %s\n", BUILD_COMPILER);
ss << stdext::format("build date: %s\n", BUILD_DATE);
ss << stdext::format("build type: %s\n", BUILD_TYPE);
ss << stdext::format("build revision: %s\n", BUILD_REVISION);
ss << stdext::format("crash date: %s\n", stdext::date_time_string().c_str());
ss << stdext::format("exception: %s (0x%08lx)\n", getExceptionName(e->ExceptionRecord->ExceptionCode), e->ExceptionRecord->ExceptionCode);
ss << stdext::format("exception address: 0x%08lx\n", (long unsigned int)e->ExceptionRecord->ExceptionAddress);
ss << stdext::format(" backtrace:\n");
Stacktrace(e, ss);
ss << "\n";
SymCleanup(GetCurrentProcess());
@@ -129,7 +129,7 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e)
// write stacktrace to crash_report.txt
char dir[MAX_PATH];
GetCurrentDirectory(sizeof(dir) - 1, dir);
std::string fileName = Fw::formatString("%s\\crash_report.txt", dir);
std::string fileName = stdext::format("%s\\crash_report.txt", dir);
std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::app);
if(fout.is_open() && fout.good()) {
fout << ss.str();
@@ -139,7 +139,7 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e)
logError("Failed to save crash report!");
// inform the user
std::string msg = Fw::formatString("The application has crashed.\n\n"
std::string msg = stdext::format("The application has crashed.\n\n"
"A crash report has been written to:\n"
"%s", fileName.c_str());
MessageBox(NULL, msg.c_str(), "Application crashed", 0);

View File

@@ -708,7 +708,7 @@ void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot)
std::vector<uchar> xorMask(numbytes, 0);
for(int i=0;i<numbits;++i) {
uint32 rgba = Fw::readLE32(apng.pdata + i*4);
uint32 rgba = stdext::readLE32(apng.pdata + i*4);
if(rgba == 0xffffffff) { //white
HSB_BIT_SET(xorMask, i);
} else if(rgba == 0x00000000) { //alpha
@@ -846,7 +846,7 @@ std::string WIN32Window::getClipboardText()
if(hglb) {
LPTSTR lptstr = (LPTSTR)GlobalLock(hglb);
if(lptstr) {
text = Fw::utf8StringToLatin1((uchar*)lptstr);
text = stdext::utf8StringToLatin1((uchar*)lptstr);
GlobalUnlock(hglb);
}
}

View File

@@ -23,7 +23,6 @@
#include "x11window.h"
#include <framework/core/resourcemanager.h>
#include <framework/thirdparty/apngloader.h>
#include <framework/util/utf8.h>
#define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8)))
@@ -878,7 +877,7 @@ void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot)
std::vector<uchar> maskBits(numbytes, 0);
for(int i=0;i<numbits;++i) {
uint32 rgba = Fw::readLE32(apng.pdata + i*4);
uint32 rgba = stdext::readLE32(apng.pdata + i*4);
if(rgba == 0xffffffff) { //white, background
LSB_BIT_SET(maskBits, i);
} else if(rgba == 0xff000000) { //black, foreground
@@ -1031,7 +1030,7 @@ std::string X11Window::getClipboardText()
&bytesLeft,
&data);
if(len > 0) {
clipboardText = Fw::utf8StringToLatin1(data);
clipboardText = stdext::utf8StringToLatin1(data);
}
}