src: refactoring TimePoint
* removed typedef utility::TimePoint and replaced all its usages by using the class TimePoint instead.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "data/Storage.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
TaskCleanStorage::TaskCleanStorage(Storage* storage, const std::vector<FilePath>& filePaths)
|
||||
: m_storage(storage)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
class Storage;
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
std::vector<FilePath> m_filePaths;
|
||||
const size_t m_fileCount;
|
||||
|
||||
utility::TimePoint m_start;
|
||||
TimePoint m_start;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_CXX_H
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
TaskParseCxx::TaskParseCxx(
|
||||
ParserClient* client,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <queue>
|
||||
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
|
||||
@@ -34,7 +34,7 @@ private:
|
||||
|
||||
std::queue<FilePath> m_sourcePaths;
|
||||
|
||||
utility::TimePoint m_start;
|
||||
TimePoint m_start;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_CXX_H
|
||||
|
||||
@@ -19,3 +19,13 @@ TimePoint::TimePoint(std::string s)
|
||||
{
|
||||
m_time = boost::posix_time::time_from_string(s);
|
||||
}
|
||||
|
||||
std::string TimePoint::toString() const
|
||||
{
|
||||
std::stringstream stream;
|
||||
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
|
||||
facet->format("%Y-%m-%d %H:%M:%S");
|
||||
stream.imbue(std::locale(std::locale::classic(), facet));
|
||||
stream << m_time;
|
||||
return stream.str();
|
||||
}
|
||||
@@ -11,6 +11,8 @@ public:
|
||||
//TimePoint(time_t t);
|
||||
TimePoint(std::string s);
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
|
||||
inline bool operator!=(const TimePoint& rhs){ return m_time != rhs.m_time; }
|
||||
inline bool operator<(const TimePoint& rhs){ return m_time < rhs.m_time; }
|
||||
@@ -18,6 +20,8 @@ public:
|
||||
inline bool operator<=(const TimePoint& rhs){ return m_time <= rhs.m_time; }
|
||||
inline bool operator>=(const TimePoint& rhs){ return m_time >= rhs.m_time; }
|
||||
|
||||
inline float operator-(const TimePoint& rhs){ return (m_time - rhs.m_time).total_milliseconds() / 1000.0f; }
|
||||
|
||||
private:
|
||||
boost::posix_time::ptime m_time;
|
||||
};
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "utility/utility.h"
|
||||
#include "boost/date_time/time_clock.hpp"
|
||||
|
||||
utility::TimePoint utility::durationStart()
|
||||
TimePoint utility::durationStart()
|
||||
{
|
||||
return std::chrono::system_clock::now();
|
||||
return TimePoint(boost::posix_time::microsec_clock::local_time());
|
||||
}
|
||||
|
||||
float utility::duration(const TimePoint& start)
|
||||
{
|
||||
std::chrono::duration<float> duration =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start);
|
||||
return duration.count();
|
||||
TimePoint now = durationStart();
|
||||
return now - start;
|
||||
}
|
||||
|
||||
float utility::duration(std::function<void()> func)
|
||||
@@ -30,12 +30,7 @@ std::string utility::timeToString(const time_t time)
|
||||
|
||||
std::string utility::timeToString(const boost::posix_time::ptime time)
|
||||
{
|
||||
std::stringstream stream;
|
||||
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
|
||||
facet->format("%Y-%m-%d %H:%M:%S");
|
||||
stream.imbue(std::locale(std::locale::classic(), facet));
|
||||
stream << time;
|
||||
return stream.str();
|
||||
return TimePoint(time).toString();
|
||||
}
|
||||
|
||||
bool utility::intersectionPoint(Vec2f a1, Vec2f b1, Vec2f a2, Vec2f b2, Vec2f* i)
|
||||
|
||||
@@ -2,18 +2,16 @@
|
||||
#define UTILITY_H
|
||||
|
||||
#include <deque>
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
#include <time.h>
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
#include "utility/math/Vector2.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
namespace utility
|
||||
{
|
||||
typedef std::chrono::time_point<std::chrono::system_clock> TimePoint;
|
||||
|
||||
TimePoint durationStart();
|
||||
float duration(const TimePoint& start);
|
||||
float duration(std::function<void()> func);
|
||||
|
||||
Reference in New Issue
Block a user