diff --git a/src/Base/TimeInfo.cpp b/src/Base/TimeInfo.cpp index 104404a7e..2e2470148 100644 --- a/src/Base/TimeInfo.cpp +++ b/src/Base/TimeInfo.cpp @@ -1,109 +1,109 @@ -/*************************************************************************** - * Copyright (c) Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -#endif - -#include "TimeInfo.h" - - -using namespace Base; - - -/** - * A constructor. - * A more elaborate description of the constructor. - */ -TimeInfo::TimeInfo() -{ - setCurrent(); -} - -/** - * A destructor. - * A more elaborate description of the destructor. - */ -TimeInfo::~TimeInfo() -{ -} - - -//************************************************************************** -// separator for other implemetation aspects - -void TimeInfo::setCurrent(void) -{ -#if defined (_MSC_VER) - _ftime( &timebuffer ); -#elif defined(__GNUC__) - ftime( &timebuffer ); -#endif -} - -void TimeInfo::setTime_t (uint64_t seconds) -{ - timebuffer.time = seconds; -} - -const char* TimeInfo::currentDateTimeString() -{ - struct tm* systime; - time_t sec; - - time(&sec); - systime = localtime(&sec); - - const char* dt = asctime(systime); - return dt; -} - -std::string TimeInfo::diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd ) -{ - std::stringstream str; - str << diffTimeF(timeStart,timeEnd); - return str.str(); -} - -float TimeInfo::diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd ) -{ - if(timeStart.getSeconds()==timeEnd.getSeconds()) - return float(timeEnd.getMiliseconds())/1000.0 - float(timeStart.getMiliseconds())/1000.0; - else - return float(timeEnd.getSeconds()-timeStart.getSeconds()-1)+float((1000-timeStart.getMiliseconds())/1000.0)+float(timeEnd.getMiliseconds())/1000.0; -} - -TimeInfo TimeInfo::null() -{ - TimeInfo ti; - ti.timebuffer.time = 0; - ti.timebuffer.millitm = 0; - return ti; -} - -bool TimeInfo::isNull() const -{ - return (*this) == TimeInfo::null(); -} +/*************************************************************************** + * Copyright (c) Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include "TimeInfo.h" + + +using namespace Base; + + +/** + * A constructor. + * A more elaborate description of the constructor. + */ +TimeInfo::TimeInfo() +{ + setCurrent(); +} + +/** + * A destructor. + * A more elaborate description of the destructor. + */ +TimeInfo::~TimeInfo() +{ +} + + +//************************************************************************** +// separator for other implemetation aspects + +void TimeInfo::setCurrent(void) +{ +#if defined (_MSC_VER) + _ftime( &timebuffer ); +#elif defined(__GNUC__) + ftime( &timebuffer ); +#endif +} + +void TimeInfo::setTime_t (uint64_t seconds) +{ + timebuffer.time = seconds; +} + +const char* TimeInfo::currentDateTimeString() +{ + struct tm* systime; + time_t sec; + + time(&sec); + systime = localtime(&sec); + + const char* dt = asctime(systime); + return dt; +} + +std::string TimeInfo::diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd ) +{ + std::stringstream str; + str << diffTimeF(timeStart,timeEnd); + return str.str(); +} + +float TimeInfo::diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd ) +{ + int64_t ds = int64_t(timeEnd.getSeconds() - timeStart.getSeconds()); + int dms = int(timeEnd.getMiliseconds()) - int(timeStart.getMiliseconds()); + + return float(ds) + float(dms) * 0.001; +} + +TimeInfo TimeInfo::null() +{ + TimeInfo ti; + ti.timebuffer.time = 0; + ti.timebuffer.millitm = 0; + return ti; +} + +bool TimeInfo::isNull() const +{ + return (*this) == TimeInfo::null(); +} diff --git a/src/Base/TimeInfo.h b/src/Base/TimeInfo.h index b59900b89..d2ad6c202 100644 --- a/src/Base/TimeInfo.h +++ b/src/Base/TimeInfo.h @@ -1,149 +1,149 @@ -/*************************************************************************** - * Copyright (c) Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef BASE_TIMEINFO_H -#define BASE_TIMEINFO_H - -// Std. configurations - - -#include -#include -#include - -#ifdef __GNUC__ -# include -#endif - -namespace Base -{ -/// BaseClass class and root of the type system -class BaseExport TimeInfo -{ - -public: - /// Construction - TimeInfo(); - /// Destruction - virtual ~TimeInfo(); - - /// sets the object to the actual system time - void setCurrent(void); - void setTime_t (uint64_t seconds); - - uint64_t getSeconds(void) const; - unsigned short getMiliseconds(void) const; - - void operator = (const TimeInfo &time); - bool operator == (const TimeInfo &time) const; - bool operator != (const TimeInfo &time) const; - - bool operator < (const TimeInfo &time) const; - bool operator <= (const TimeInfo &time) const; - bool operator >= (const TimeInfo &time) const; - bool operator > (const TimeInfo &time) const; - - static const char* currentDateTimeString(); - static std::string diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd = TimeInfo()); - static float diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd ); - bool isNull() const; - static TimeInfo null(); - -protected: -#if defined (_MSC_VER) - struct _timeb timebuffer; -#elif defined(__GNUC__) - struct timeb timebuffer; -#endif -}; - - - inline uint64_t TimeInfo::getSeconds(void) const - { - return timebuffer.time; - } - - inline unsigned short TimeInfo::getMiliseconds(void) const - { - return timebuffer.millitm; - } - -inline bool -TimeInfo::operator != (const TimeInfo &time) const -{ - return (timebuffer.time != time.timebuffer.time || timebuffer.millitm != time.timebuffer.millitm); -} - -inline void -TimeInfo::operator = (const TimeInfo &time) -{ - timebuffer = time.timebuffer; -} - -inline bool -TimeInfo::operator == (const TimeInfo &time) const -{ - return (timebuffer.time == time.timebuffer.time && timebuffer.millitm == time.timebuffer.millitm); -} - -inline bool -TimeInfo::operator < (const TimeInfo &time) const -{ - if (timebuffer.time == time.timebuffer.time) - return timebuffer.millitm < time.timebuffer.millitm; - else - return timebuffer.time < time.timebuffer.time; -} - -inline bool -TimeInfo::operator <= (const TimeInfo &time) const -{ - if (timebuffer.time == time.timebuffer.time) - return timebuffer.millitm <= time.timebuffer.millitm; - else - return timebuffer.time <= time.timebuffer.time; -} - -inline bool -TimeInfo::operator >= (const TimeInfo &time) const -{ - if (timebuffer.time == time.timebuffer.time) - return timebuffer.millitm >= time.timebuffer.millitm; - else - return timebuffer.time >= time.timebuffer.time; -} - -inline bool -TimeInfo::operator > (const TimeInfo &time) const -{ - if (timebuffer.time == time.timebuffer.time) - return timebuffer.millitm > time.timebuffer.millitm; - else - return timebuffer.time > time.timebuffer.time; -} - -} //namespace Base - - -#endif // BASE_TIMEINFO_H - +/*************************************************************************** + * Copyright (c) Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef BASE_TIMEINFO_H +#define BASE_TIMEINFO_H + +// Std. configurations + + +#include +#include +#include + +#ifdef __GNUC__ +# include +#endif + +namespace Base +{ +/// BaseClass class and root of the type system +class BaseExport TimeInfo +{ + +public: + /// Construction + TimeInfo(); + /// Destruction + virtual ~TimeInfo(); + + /// sets the object to the actual system time + void setCurrent(void); + void setTime_t (uint64_t seconds); + + uint64_t getSeconds(void) const; + unsigned short getMiliseconds(void) const; + + void operator = (const TimeInfo &time); + bool operator == (const TimeInfo &time) const; + bool operator != (const TimeInfo &time) const; + + bool operator < (const TimeInfo &time) const; + bool operator <= (const TimeInfo &time) const; + bool operator >= (const TimeInfo &time) const; + bool operator > (const TimeInfo &time) const; + + static const char* currentDateTimeString(); + static std::string diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd = TimeInfo()); + static float diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd = TimeInfo()); + bool isNull() const; + static TimeInfo null(); + +protected: +#if defined (_MSC_VER) + struct _timeb timebuffer; +#elif defined(__GNUC__) + struct timeb timebuffer; +#endif +}; + + + inline uint64_t TimeInfo::getSeconds(void) const + { + return timebuffer.time; + } + + inline unsigned short TimeInfo::getMiliseconds(void) const + { + return timebuffer.millitm; + } + +inline bool +TimeInfo::operator != (const TimeInfo &time) const +{ + return (timebuffer.time != time.timebuffer.time || timebuffer.millitm != time.timebuffer.millitm); +} + +inline void +TimeInfo::operator = (const TimeInfo &time) +{ + timebuffer = time.timebuffer; +} + +inline bool +TimeInfo::operator == (const TimeInfo &time) const +{ + return (timebuffer.time == time.timebuffer.time && timebuffer.millitm == time.timebuffer.millitm); +} + +inline bool +TimeInfo::operator < (const TimeInfo &time) const +{ + if (timebuffer.time == time.timebuffer.time) + return timebuffer.millitm < time.timebuffer.millitm; + else + return timebuffer.time < time.timebuffer.time; +} + +inline bool +TimeInfo::operator <= (const TimeInfo &time) const +{ + if (timebuffer.time == time.timebuffer.time) + return timebuffer.millitm <= time.timebuffer.millitm; + else + return timebuffer.time <= time.timebuffer.time; +} + +inline bool +TimeInfo::operator >= (const TimeInfo &time) const +{ + if (timebuffer.time == time.timebuffer.time) + return timebuffer.millitm >= time.timebuffer.millitm; + else + return timebuffer.time >= time.timebuffer.time; +} + +inline bool +TimeInfo::operator > (const TimeInfo &time) const +{ + if (timebuffer.time == time.timebuffer.time) + return timebuffer.millitm > time.timebuffer.millitm; + else + return timebuffer.time > time.timebuffer.time; +} + +} //namespace Base + + +#endif // BASE_TIMEINFO_H +