#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: "<<Debug::demangle(typeid(e).name())<<'\n';
buf<<w<<": ";
#ifdef WIN32
char msg[1024];
- if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, e, 0, msg, sizeof(msg), 0))
+ if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, e, 0, msg, sizeof(msg), 0))
buf<<msg;
else
buf<<e;
Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
+#ifndef WIN32
#include <sys/time.h>
+#endif
#include <errno.h>
#include "semaphore.h"
#include "../time/timestamp.h"
*/
#include <cstdlib>
+#ifdef __GNUC__
#include <cxxabi.h>
+#endif
#include "demangle.h"
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)
{
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),
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),
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),
validate();
}
-void DateTime::add_days(int32_t days)
+void DateTime::add_days(int days)
{
unsigned new_year=year;
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<month; ++i)
return ss.str();
}
-void DateTime::add_raw(int64_t raw)
+void DateTime::add_raw(RawTime raw)
{
- int32_t days=raw/86400000000LL;
+ int days=static_cast<int>(raw/86400000000LL);
raw%=86400000000LL;
if(raw<0)
{
#ifndef MSP_TIME_DATETIME_H_
#define MSP_TIME_DATETIME_H_
-#include <stdint.h>
#include <string>
+#include "types.h"
namespace Msp {
namespace Time {
{
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 &);
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;
};
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<unit && first)
return;
ostringstream ss;
ss.fill('0');
- int64_t value=td.raw();
+ RawTime value=td.raw();
if(value<0)
{
#ifndef MSP_TIME_TIMEDELTA_H_
#define MSP_TIME_TIMEDELTA_H_
-#include <stdint.h>
#include <time.h>
#include <ostream>
#include "types.h"
TimeDelta &operator-=(const TimeDelta &t) { usec-=t.usec; return *this; }
template<typename T>
- TimeDelta operator*(T a) const { return TimeDelta(int64_t(usec*a)); }
+ TimeDelta operator*(T a) const { return TimeDelta(RawTime(usec*a)); }
template<typename T>
- TimeDelta &operator*=(T a) { usec=int64_t(usec*a); return *this; }
+ TimeDelta &operator*=(T a) { usec=RawTime(usec*a); return *this; }
template<typename T>
- TimeDelta operator/(T a) const { return TimeDelta(int64_t(usec/a)); }
+ TimeDelta operator/(T a) const { return TimeDelta(RawTime(usec/a)); }
template<typename T>
- 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; }
#ifndef MSP_TIME_TIMESTAMP_H_
#define MSP_TIME_TIMESTAMP_H_
-#include <stdint.h>
#include "timedelta.h"
#include "types.h"
#ifndef MSP_TIME_TYPES_H_
#define MSP_TIME_TYPES_H_
+#ifndef WIN32
#include <stdint.h>
+#endif
namespace Msp {
namespace Time {
+#ifdef WIN32
+typedef __int64 RawTime;
+#else
typedef int64_t RawTime;
+#endif
} // namespace Time
} // namespace Msp
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;
FILETIME ft;
SystemTimeToFileTime(&st, &ft);
- epoch=(ft.dwLowDateTime+((int64_t)ft.dwHighDateTime<<32))/10;
+ epoch=(ft.dwLowDateTime+(static_cast<RawTime>(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<RawTime>(ft.dwHighDateTime)<<32))/10-epoch);
#endif
}