From: Mikko Rasa Date: Thu, 13 Nov 2008 10:40:34 +0000 (+0000) Subject: MSVC compatibility fixes X-Git-Tag: 1.1~9 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cd89068b8ebafdc0f888c1aa21498bb93b55d814;p=libs%2Fcore.git MSVC compatibility fixes --- diff --git a/source/core/application.cpp b/source/core/application.cpp index 82134df..daeb130 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -66,7 +66,7 @@ int Application::run(int argc, char **argv, void *data) #ifdef WIN32 string msg=Debug::demangle(typeid(e).name())+":\n"+e.what(); - MessageBox(0, msg.c_str(), "Uncaught exception", MB_OK|MB_ICONERROR); + MessageBoxA(0, msg.c_str(), "Uncaught exception", MB_OK|MB_ICONERROR); #else cerr<<"An uncaught exception occurred.\n"; cerr<<" type: "< +#endif #include #include "semaphore.h" #include "../time/timestamp.h" diff --git a/source/debug/demangle.cpp b/source/debug/demangle.cpp index 5c34851..fc6ca78 100644 --- a/source/debug/demangle.cpp +++ b/source/debug/demangle.cpp @@ -6,7 +6,9 @@ Distributed under the LGPL */ #include +#ifdef __GNUC__ #include +#endif #include "demangle.h" using namespace std; diff --git a/source/time/datetime.cpp b/source/time/datetime.cpp index 4c10975..2d7c195 100644 --- a/source/time/datetime.cpp +++ b/source/time/datetime.cpp @@ -9,10 +9,10 @@ using namespace std; namespace { -inline bool is_leap_year(int32_t y) +inline bool is_leap_year(int y) { return y%4==0 && (y%100 || y%400==0); } -inline uint8_t month_days(int32_t y, uint8_t m) +inline unsigned char month_days(int y, unsigned char m) { switch(m) { @@ -55,7 +55,7 @@ DateTime::DateTime(const TimeStamp &ts): add_raw(ts.raw()); } -DateTime::DateTime(int32_t y, uint8_t m, uint8_t d): +DateTime::DateTime(int y, unsigned char m, unsigned char d): year(y), month(m), mday(d), @@ -67,7 +67,7 @@ DateTime::DateTime(int32_t y, uint8_t m, uint8_t d): validate(); } -DateTime::DateTime(int32_t y, uint8_t m, uint8_t d, uint8_t h, uint8_t n, uint8_t s): +DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s): year(y), month(m), mday(d), @@ -79,7 +79,7 @@ DateTime::DateTime(int32_t y, uint8_t m, uint8_t d, uint8_t h, uint8_t n, uint8_ validate(); } -DateTime::DateTime(int32_t y, uint8_t m, uint8_t d, uint8_t h, uint8_t n, uint8_t s, uint32_t u): +DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u): year(y), month(m), mday(d), @@ -91,7 +91,7 @@ DateTime::DateTime(int32_t y, uint8_t m, uint8_t d, uint8_t h, uint8_t n, uint8_ validate(); } -void DateTime::add_days(int32_t days) +void DateTime::add_days(int days) { unsigned new_year=year; @@ -194,7 +194,7 @@ TimeStamp DateTime::get_timestamp() const if(year<-289701 || year>293641) throw Exception("DateTime is not representable as a TimeStamp"); - int64_t raw=(((hour*60LL)+minute)*60+second)*1000000+usec; + RawTime raw=(((hour*60LL)+minute)*60+second)*1000000+usec; int days=(year-1970)*365; days+=(year-1)/4-(year-1)/100+(year-1)/400-477; for(unsigned i=1; i(raw/86400000000LL); raw%=86400000000LL; if(raw<0) { diff --git a/source/time/datetime.h b/source/time/datetime.h index 807b16c..57ca89d 100644 --- a/source/time/datetime.h +++ b/source/time/datetime.h @@ -2,8 +2,8 @@ #ifndef MSP_TIME_DATETIME_H_ #define MSP_TIME_DATETIME_H_ -#include #include +#include "types.h" namespace Msp { namespace Time { @@ -24,19 +24,19 @@ class DateTime { public: DateTime(const TimeStamp &); - DateTime(int32_t, uint8_t, uint8_t); - DateTime(int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t); - DateTime(int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint32_t); + DateTime(int, unsigned char, unsigned char); + DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char); + DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned); - int32_t get_year() const { return year; } - uint8_t get_month() const { return month; } - uint8_t get_mday() const { return mday; } - uint8_t get_hour() const { return hour; } - uint8_t get_minute() const { return minute; } - uint8_t get_second() const { return second; } - uint32_t get_usec() const { return usec; } + int get_year() const { return year; } + unsigned char get_month() const { return month; } + unsigned char get_mday() const { return mday; } + unsigned char get_hour() const { return hour; } + unsigned char get_minute() const { return minute; } + unsigned char get_second() const { return second; } + unsigned get_usec() const { return usec; } - void add_days(int32_t); + void add_days(int); DateTime operator+(const TimeDelta &) const; DateTime &operator+=(const TimeDelta &); @@ -52,15 +52,15 @@ public: TimeStamp get_timestamp() const; std::string format(const std::string &) const; private: - int32_t year; - uint8_t month; - uint8_t mday; - uint8_t hour; - uint8_t minute; - uint8_t second; - uint32_t usec; + int year; + unsigned char month; + unsigned char mday; + unsigned char hour; + unsigned char minute; + unsigned char second; + unsigned usec; - void add_raw(int64_t); + void add_raw(RawTime); void normalize(); void validate() const; }; diff --git a/source/time/timedelta.cpp b/source/time/timedelta.cpp index 7d3d4bb..81d3389 100644 --- a/source/time/timedelta.cpp +++ b/source/time/timedelta.cpp @@ -12,7 +12,9 @@ using namespace std; namespace { -void print_part(ostream &out, int64_t &value, int64_t unit, char sep, bool &first) +using Msp::Time::RawTime; + +void print_part(ostream &out, RawTime &value, RawTime unit, char sep, bool &first) { if(value #include #include #include "types.h" @@ -52,14 +51,14 @@ public: TimeDelta &operator-=(const TimeDelta &t) { usec-=t.usec; return *this; } template - TimeDelta operator*(T a) const { return TimeDelta(int64_t(usec*a)); } + TimeDelta operator*(T a) const { return TimeDelta(RawTime(usec*a)); } template - TimeDelta &operator*=(T a) { usec=int64_t(usec*a); return *this; } + TimeDelta &operator*=(T a) { usec=RawTime(usec*a); return *this; } template - TimeDelta operator/(T a) const { return TimeDelta(int64_t(usec/a)); } + TimeDelta operator/(T a) const { return TimeDelta(RawTime(usec/a)); } template - TimeDelta &operator/=(T a) { usec=int64_t(usec/a); return *this; } + TimeDelta &operator/=(T a) { usec=RawTime(usec/a); return *this; } double operator/(const TimeDelta &t) const { return double(usec)/t.usec; } diff --git a/source/time/timestamp.h b/source/time/timestamp.h index 6b264af..2905c6e 100644 --- a/source/time/timestamp.h +++ b/source/time/timestamp.h @@ -6,7 +6,6 @@ Distributed under the LGPL #ifndef MSP_TIME_TIMESTAMP_H_ #define MSP_TIME_TIMESTAMP_H_ -#include #include "timedelta.h" #include "types.h" diff --git a/source/time/types.h b/source/time/types.h index 0d09ac8..1befb9b 100644 --- a/source/time/types.h +++ b/source/time/types.h @@ -1,12 +1,18 @@ #ifndef MSP_TIME_TYPES_H_ #define MSP_TIME_TYPES_H_ +#ifndef WIN32 #include +#endif namespace Msp { namespace Time { +#ifdef WIN32 +typedef __int64 RawTime; +#else typedef int64_t RawTime; +#endif } // namespace Time } // namespace Msp diff --git a/source/time/utils.cpp b/source/time/utils.cpp index f4a5379..c9cc94d 100644 --- a/source/time/utils.cpp +++ b/source/time/utils.cpp @@ -30,7 +30,7 @@ TimeStamp now() gettimeofday(&tv, 0); return TimeStamp(tv.tv_sec*1000000LL+tv.tv_usec); #else - static int64_t epoch=0; + static RawTime epoch=0; if(!epoch) { SYSTEMTIME st; @@ -44,12 +44,12 @@ TimeStamp now() FILETIME ft; SystemTimeToFileTime(&st, &ft); - epoch=(ft.dwLowDateTime+((int64_t)ft.dwHighDateTime<<32))/10; + epoch=(ft.dwLowDateTime+(static_cast(ft.dwHighDateTime)<<32))/10; } FILETIME ft; GetSystemTimeAsFileTime(&ft); - return TimeStamp((ft.dwLowDateTime+((int64_t)ft.dwHighDateTime<<32))/10-epoch); + return TimeStamp((ft.dwLowDateTime+(static_cast(ft.dwHighDateTime)<<32))/10-epoch); #endif }