WSL/SLF GitLab Repository

Commit 6a7fd7fc authored by Mathias Bavay's avatar Mathias Bavay
Browse files

All the "#ifdef(_WIN)" have been replaced by "#ifdef(WIN)" for consistency....

All the "#ifdef(_WIN)" have been replaced by "#ifdef(WIN)" for consistency. The message box code for Windows and osX has been reorganized, the console messages are now better colorized and the backtrace comes before the error message itself.
parent cc8fb417
......@@ -84,7 +84,7 @@ IF(UNIX)
ENDIF(APPLE)
ELSE(UNIX)
IF(WIN32)
SET(PLATFORM "-D_WIN32")
SET(PLATFORM "-DWIN32")
SET(DLL_EXT "dll")
SET(STAT_EXT "a")
ENDIF(WIN32)
......
......@@ -38,7 +38,6 @@ IF(POPC)
SET(POPC_EXT "popc")
ENDIF(POPC)
# FilterAlgorithms.cc obsoleted
SET(meteoio_sources
IOManager.cc
libsmet.cc
......
......@@ -25,8 +25,10 @@
#include <cxxabi.h>
#endif
#endif
#if defined(_WIN32)
#include <windows.h>
#if defined(WIN32)
#include <windows.h>
#undef max
#undef min
#endif
#if defined(APPLE)
#include <CoreFoundation/CoreFoundation.h>
......@@ -36,23 +38,45 @@ using namespace std;
namespace mio {
#if defined(LINUX) && !defined(ANDROID) && !defined(CYGWIN)
void messageBox(const std::string& /*msg*/) {
//const string box_msg = msg + "\n\nPlease check the terminal for more information!";
//MessageBoxX11("Oops, something went wrong!", box_msg.c_str());
#else
void messageBox(const std::string& msg) {
#if defined(WIN32)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
MessageBox( NULL, box_msg.c_str(), TEXT("Oops, something went wrong!"), MB_OK | MB_ICONERROR );
#endif
#if defined(APPLE)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
const void* keys[] = { kCFUserNotificationAlertHeaderKey,
kCFUserNotificationAlertMessageKey };
const void* values[] = { CFSTR("Oops, something went wrong!"),
CFStringCreateWithCString(NULL, box_msg.c_str(), kCFStringEncodingMacRoman) };
CFDictionaryRef dict = CFDictionaryCreate(0, keys, values,
sizeof(keys)/sizeof(*keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
SInt32 error = 0;
CFUserNotificationCreate(NULL, 0, kCFUserNotificationStopAlertLevel, &error, dict);
#endif
#endif
}
#ifdef _POPC_
IOException::IOException(const std::string& message, const std::string& position) : POPException(STD_EXCEPTION)
#else
IOException::IOException(const std::string& message, const std::string& position) : msg()
IOException::IOException(const std::string& message, const std::string& position) : msg(), full_output()
#endif
{
if (position=="") {
msg = "At unknown position: " + message;
} else {
msg = "[" + (strrchr(position.c_str(), '/') ? strrchr(position.c_str(), '/') + 1 : position) + "] " + message;
//msg = position + ": " + message;
}
const std::string where = (position.size()>0)? (strrchr(position.c_str(), '/') ? strrchr(position.c_str(), '/') + 1 : position) : "unknown position";
msg = "[" + where + "] " + message;
#if defined(LINUX) && !defined(ANDROID) && !defined(CYGWIN)
void* tracearray[25]; //maximal size for backtrace: 25 pointers
size_t tracesize = backtrace(tracearray, 25); //obtains backtrace for current thread
char** symbols = backtrace_symbols(tracearray, tracesize); //translate pointers to strings
msg += "\n\n\033[01;30m**** backtrace ****\n"; //we use ASCII color codes to make the backtrace less visible/aggressive
std::string backtrace_info = "\n\033[01;30m**** backtrace ****\n"; //we use ASCII color codes to make the backtrace less visible/aggressive
for (unsigned int ii=1; ii<tracesize; ii++) {
#ifdef __GNUC__
std::stringstream ss;
......@@ -78,17 +102,20 @@ IOException::IOException(const std::string& message, const std::string& position
} else { // otherwise, print the whole line
ss << "\t(" << ii << ") at " << symbols[ii];
}
msg += ss.str()+"\n";
backtrace_info += ss.str()+"\n";
#else
msg += "\tat " + string(symbols[ii]) + "\n";
backtrace_info += "\tat " + string(symbols[ii]) + "\n";
#endif
}
msg += "\033[0m"; //back to normal color
backtrace_info += "\033[0m"; //back to normal color
free(symbols);
full_output = backtrace_info + "[" + where + "] \033[31;1m" + message + "\033[0m";
#else
full_output = msg;
#endif
#ifdef _POPC_
//printf("IOException(%d): %s\n",Code(),msg.c_str());
SetExtra(msg.c_str());
const string tmp = backtrace_info + "\n\n" + msg;
SetExtra(tmp.c_str());
#endif
}
......@@ -97,25 +124,8 @@ IOException::~IOException() throw(){
const char* IOException::what() const throw()
{
#if defined(_WIN32)
const string tmp = msg + "\n\nPlease check the terminal for more information!";
MessageBox ( NULL, tmp.c_str(), TEXT("Oops, something went wrong!"), MB_OK | MB_ICONERROR );
#endif
#if defined(APPLE)
const string tmp = msg + "\n\nPlease check the terminal for more information!";
const void* keys[] = { kCFUserNotificationAlertHeaderKey,
kCFUserNotificationAlertMessageKey };
const void* values[] = { CFSTR("Oops, something went wrong!"),
CFStringCreateWithCString(NULL, tmp.c_str(), kCFStringEncodingMacRoman) };
CFDictionaryRef dict = CFDictionaryCreate(0, keys, values,
sizeof(keys)/sizeof(*keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
SInt32 error = 0;
CFUserNotificationCreate(NULL, 0, kCFUserNotificationStopAlertLevel, &error, dict);
#endif
return msg.c_str();
messageBox(msg);
return full_output.c_str();
}
} //namespace
......@@ -49,7 +49,7 @@ class MIO_API IOException : public POPException {
virtual const char* what() const throw();
protected:
std::string msg;
std::string msg, full_output;
};
/**
......
......@@ -24,7 +24,7 @@
#include <meteoio/Config.h> // to avoid forward declaration hell
#include <meteoio/MeteoData.h> // to avoid forward declaration hell
#ifdef _WIN32
#ifdef WIN32
#include <windows.h>
//removing two macros defined in windows.h
#undef max
......@@ -256,7 +256,7 @@ bool validFileName(const std::string& filename)
return true;
}
#ifdef _WIN32
#ifdef WIN32
bool fileExists(const std::string& filename)
{
return ( GetFileAttributes( filename.c_str() ) != INVALID_FILE_ATTRIBUTES );
......
......@@ -20,7 +20,7 @@
// Mathias Bavay (port and rewrite for Alpine3D, then MeteoIO)
#include <stdio.h>
#ifdef _WIN32
#ifdef WIN32
#include <windows.h>
#undef max
#undef min
......@@ -89,7 +89,7 @@ double Timer::getElapsed() const {
return elapsed;
}
#ifdef _WIN32
#ifdef WIN32
double Timer::getCurrentTime() const {
SYSTEMTIME systemTime;
GetSystemTime( &systemTime );
......
......@@ -20,7 +20,7 @@
#define __EXPORTS_H__
// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
#if defined WIN32 || defined __CYGWIN__
#define MIO_HELPER_DLL_IMPORT __declspec(dllimport)
#define MIO_HELPER_DLL_EXPORT __declspec(dllexport)
#define MIO_HELPER_DLL_LOCAL
......
......@@ -8,7 +8,7 @@
#ifndef _Included_SYNCHRONIZED_H_
#define _Included_SYNCHRONIZED_H_
#ifdef _WIN32
#ifdef WIN32
/* link to kernel32.dll */
#include <windows.h>
#undef max
......@@ -58,7 +58,7 @@ public:
Mutex()
{
#ifdef _WIN32
#ifdef WIN32
InitializeCriticalSection(&m_criticalSection);
#else
pthread_mutex_init(&m_criticalSection, NULL);
......@@ -69,7 +69,7 @@ public:
~Mutex()
{
#ifdef _WIN32
#ifdef WIN32
DeleteCriticalSection(&m_criticalSection);
#else
pthread_mutex_destroy( &m_criticalSection );
......@@ -80,7 +80,7 @@ public:
void lock()
{
#ifdef _WIN32
#ifdef WIN32
EnterCriticalSection(&m_criticalSection);
#else
pthread_mutex_lock( &m_criticalSection );
......@@ -91,7 +91,7 @@ public:
void unlock()
{
#ifdef _WIN32
#ifdef WIN32
LeaveCriticalSection(&m_criticalSection);
#else
pthread_mutex_unlock( &m_criticalSection );
......@@ -103,7 +103,7 @@ private:
* Critical section Object.
* Initialized at runtime, when Mutex instance is created
*/
#ifdef _WIN32
#ifdef WIN32
CRITICAL_SECTION m_criticalSection;
#else //assumes it's a Unix/Linux system
pthread_mutex_t m_criticalSection;
......
......@@ -41,7 +41,7 @@
//#include "gsn/GSNWebServiceSoap12Binding.nsmap"
#endif
#ifdef _WIN32 //because we collected c**p from windows.h
#ifdef WIN32 //because we collected c**p from windows.h that was included by gsoap
#undef max
#undef min
#endif
......
......@@ -335,7 +335,7 @@ void PNGIO::setFile(const std::string& filename, png_structp& png_ptr, png_infop
}
// Setup Exception handling
#ifdef _WIN32
#ifdef WIN32
#pragma warning(disable:4611) //the setjmp of libpng has been set up so that it can safely be called from c++
#endif
if (setjmp(png_jmpbuf(png_ptr))) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment