Skip to content
Snippets Groups Projects
Commit 4281114a authored by Benedikt Hegner's avatar Benedikt Hegner
Browse files

Merge branch 'allow_adl_in_time' into 'master'

enable ADL lookup for binary Time,Time and TimeSpan,TimeSpan operators

See merge request !290
parents 8b38c49d 2dc4fde7
No related branches found
No related tags found
1 merge request!290enable ADL lookup for binary Time,Time and TimeSpan,TimeSpan operators
Pipeline #
......@@ -17,15 +17,12 @@
* @author Marco Clemencic
* @date 2005-12-14
*/
class GAUDI_API TimeException: public GaudiException {
public:
struct GAUDI_API TimeException: GaudiException {
// Standard constructor
TimeException( std::string Message = "unspecified exception",
std::string Tag = "*Gaudi::Time*",
StatusCode Code = StatusCode::FAILURE ):
GaudiException(std::move(Message),std::move(Tag),std::move(Code)) {}
/// Destructor needed to match the signature of GaudiException::~GaudiException().
virtual ~TimeException() throw() {}
};
struct tm;
......@@ -58,21 +55,23 @@ namespace Gaudi {
public:
typedef longlong ValueType;
TimeSpan (void);
TimeSpan (Time t);
TimeSpan (ValueType nsecs);
TimeSpan (ValueType secs, int nsecs);
TimeSpan (int days, int hours, int mins, int secs, int nsecs);
/** Initialize an empty (zero) time difference. */
TimeSpan() = default;
int days (void) const;
int hours (void) const;
int minutes (void) const;
ValueType seconds (void) const;
TimeSpan(Time t);
TimeSpan(ValueType nsecs);
TimeSpan(ValueType secs, int nsecs);
TimeSpan(int days, int hours, int mins, int secs, int nsecs);
int lastHours (void) const;
int lastMinutes (void) const;
int lastSeconds (void) const;
int lastNSeconds (void) const;
int days() const;
int hours() const;
int minutes() const;
ValueType seconds() const;
int lastHours() const;
int lastMinutes() const;
int lastSeconds() const;
int lastNSeconds() const;
TimeSpan & operator+= (const TimeSpan &x);
TimeSpan & operator-= (const TimeSpan &x);
......@@ -80,10 +79,34 @@ namespace Gaudi {
TimeSpan & operator/= (const TimeSpan &n);
TimeSpan & operator%= (const TimeSpan &n);
ValueType ns (void) const;
ValueType ns() const;
friend bool operator== (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
{ return t1.ns() == t2.ns(); }
friend bool operator!= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
{ return t1.ns() != t2.ns(); }
friend bool operator< (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
{ return t1.ns() < t2.ns(); }
friend bool operator<= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
{ return t1.ns() <= t2.ns(); }
friend bool operator> (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
{ return t1.ns() > t2.ns(); }
friend bool operator>= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
{ return t1.ns() >= t2.ns(); }
friend Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
{ return Gaudi::TimeSpan (ts1.ns() + ts2.ns()); }
friend Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
{ return Gaudi::TimeSpan (ts1.ns() - ts2.ns()); }
private:
ValueType m_nsecs; //< The span length.
ValueType m_nsecs = 0; //< The span length.
};
......@@ -240,22 +263,24 @@ namespace Gaudi {
/** Nanoseconds in one second. */
static const ValueType SEC_NSECS = 1000000000;
Time (void);
Time (TimeSpan ts);
Time (ValueType nsecs);
Time (ValueType secs, int nsecs);
Time (int year, int month, int day, int hour, int min, int sec,
ValueType nsecs, bool local = true);
/** Initialize an empty (zero) time value. */
Time() = default;
Time(TimeSpan ts);
Time(ValueType nsecs);
Time(ValueType secs, int nsecs);
Time(int year, int month, int day, int hour, int min, int sec,
ValueType nsecs, bool local = true);
// implicit copy constructor
// implicit assignment operator
// implicit destructor
/// Returns the minimum time.
static Time epoch (void);
static Time epoch();
/// Returns the maximum time.
static Time max (void);
static Time max();
/// Returns the current time.
static Time current (void);
static Time current();
# ifdef WIN32
static Time from (const FILETIME *systime);
# endif
......@@ -271,7 +296,7 @@ namespace Gaudi {
int hour (bool local) const;
int minute (bool local) const;
int second (bool local) const;
int nsecond (void) const;
int nsecond () const;
int weekday (bool local) const;
bool isdst (bool local) const;
......@@ -281,7 +306,7 @@ namespace Gaudi {
Time & operator+= (const TimeSpan &x);
Time & operator-= (const TimeSpan &x);
ValueType ns (void) const;
ValueType ns() const;
std::string format (bool local, std::string spec = "%c") const;
std::string nanoformat (size_t minwidth = 1, size_t maxwidth = 9) const;
......@@ -292,8 +317,26 @@ namespace Gaudi {
static unsigned toDosDate (Time time);
static Time fromDosDate (unsigned dosDate);
friend bool operator== (const Gaudi::Time &t1, const Gaudi::Time &t2)
{ return t1.ns() == t2.ns(); }
friend bool operator!= (const Gaudi::Time &t1, const Gaudi::Time &t2)
{ return t1.ns() != t2.ns(); }
friend bool operator< (const Gaudi::Time &t1, const Gaudi::Time &t2)
{ return t1.ns() < t2.ns(); }
friend bool operator<= (const Gaudi::Time &t1, const Gaudi::Time &t2)
{ return t1.ns() <= t2.ns(); }
friend bool operator> (const Gaudi::Time &t1, const Gaudi::Time &t2)
{ return t1.ns() > t2.ns(); }
friend bool operator>= (const Gaudi::Time &t1, const Gaudi::Time &t2)
{ return t1.ns() >= t2.ns(); }
private:
ValueType m_nsecs; //< Time value as nsecs from #epoch().
ValueType m_nsecs = 0; //< Time value as nsecs from #epoch().
inline void TimeAssert(bool cond, const std::string &msg = "time assertion failed") const {
if (!cond) throw TimeException(msg);
......
......@@ -5,9 +5,6 @@
namespace Gaudi {
/** Initialize an empty (zero) time value. */
inline Time::Time (void): m_nsecs(0) {}
/** Initialize time to @a nsecs nanoseconds since 00:00:00 on January
1, 1970 in UTC. */
inline Time::Time (ValueType nsecs): m_nsecs(nsecs) {
......@@ -29,7 +26,7 @@ namespace Gaudi {
/** Return the time as nanoseconds since 00:00:00 on January 1, 1970
in UTC. */
inline Time::ValueType Time::ns (void) const {
inline Time::ValueType Time::ns() const {
return m_nsecs;
}
......@@ -50,12 +47,12 @@ namespace Gaudi {
}
/** Return the time for the epoch (= zero time). */
inline Time Time::epoch (void) {
inline Time Time::epoch() {
return 0LL;
}
/** Return the maximum time. */
inline Time Time::max (void) {
inline Time Time::max() {
return 0x7fffffffffffffffLL;
}
......@@ -69,8 +66,6 @@ namespace Gaudi {
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/** Initialize an empty (zero) time difference. */
inline TimeSpan::TimeSpan (void): m_nsecs(0) {}
/** Initialize a time span from #Time @a t. */
inline TimeSpan::TimeSpan (Time t): m_nsecs (t.m_nsecs) {}
......@@ -105,51 +100,51 @@ namespace Gaudi {
}
/** Get the number of complete days in the span. */
inline int TimeSpan::days (void) const {
inline int TimeSpan::days() const {
return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_DAY);
}
/** Get the number of complete hours in the span. */
inline int TimeSpan::hours (void) const {
inline int TimeSpan::hours() const {
return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_HOUR);
}
/** Get the number of complete minutes in the span. */
inline int TimeSpan::minutes (void) const {
inline int TimeSpan::minutes() const {
return int(m_nsecs / Time::SEC_NSECS / 60);
}
/** Get the number of complete seconds in the span. */
inline TimeSpan::ValueType TimeSpan::seconds (void) const {
inline TimeSpan::ValueType TimeSpan::seconds() const {
return m_nsecs / Time::SEC_NSECS;
}
/** Return the time span as nanoseconds. */
inline TimeSpan::ValueType TimeSpan::ns (void) const {
inline TimeSpan::ValueType TimeSpan::ns() const {
return m_nsecs;
}
/** Get the number of complete hours in the last incomplete day of the
span. */
inline int TimeSpan::lastHours (void) const {
inline int TimeSpan::lastHours() const {
return hours () - days () * 24;
}
/** Get the number of complete minutes in the last incomplete hour of
the span. */
inline int TimeSpan::lastMinutes (void) const {
inline int TimeSpan::lastMinutes() const {
return minutes () - hours () * 60;
}
/** Get the number of complete seconds in the last incomplete minute
of the span. */
inline int TimeSpan::lastSeconds (void) const {
inline int TimeSpan::lastSeconds() const {
return int(seconds() - ( (ValueType)minutes() * (ValueType)60 ));
}
/** Get the number of nanoseconds in the last incomplete second
of the span. */
inline int TimeSpan::lastNSeconds (void) const {
inline int TimeSpan::lastNSeconds() const {
return int(m_nsecs % Time::SEC_NSECS);
}
......@@ -209,41 +204,6 @@ inline Gaudi::Time operator- (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
return Gaudi::Time (t.ns() - ts.ns());
}
//inline Gaudi::TimeSpan operator* (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
// return Gaudi::TimeSpan (t.ns() * ts.ns());
//}
//inline Gaudi::TimeSpan operator/ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
// return Gaudi::TimeSpan (t.ns() / ts.ns());
//}
//inline Gaudi::TimeSpan operator% (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
// return Gaudi::TimeSpan (t.ns() % ts.ns());
//}
inline bool operator== (const Gaudi::Time &t1, const Gaudi::Time &t2) {
return t1.ns() == t2.ns();
}
inline bool operator!= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
return t1.ns() != t2.ns();
}
inline bool operator< (const Gaudi::Time &t1, const Gaudi::Time &t2) {
return t1.ns() < t2.ns();
}
inline bool operator<= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
return t1.ns() <= t2.ns();
}
inline bool operator> (const Gaudi::Time &t1, const Gaudi::Time &t2) {
return t1.ns() > t2.ns();
}
inline bool operator>= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
return t1.ns() >= t2.ns();
}
inline bool operator! (const Gaudi::Time &t) {
return ! t.ns();
......@@ -261,50 +221,6 @@ inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts) {
return Gaudi::TimeSpan (-ts.ns());
}
inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
return Gaudi::TimeSpan (ts1.ns() + ts2.ns());
}
inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
return Gaudi::TimeSpan (ts1.ns() - ts2.ns());
}
//inline Gaudi::TimeSpan operator* (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
// return Gaudi::TimeSpan (ts1.ns() * ts2.ns());
//}
//inline Gaudi::TimeSpan operator/ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
// return Gaudi::TimeSpan (ts1.ns() / ts2.ns());
//}
//inline Gaudi::TimeSpan operator% (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
// return Gaudi::TimeSpan (ts1.ns() % ts2.ns());
//}
inline bool operator== (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
return t1.ns() == t2.ns();
}
inline bool operator!= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
return t1.ns() != t2.ns();
}
inline bool operator< (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
return t1.ns() < t2.ns();
}
inline bool operator<= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
return t1.ns() <= t2.ns();
}
inline bool operator> (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
return t1.ns() > t2.ns();
}
inline bool operator>= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
return t1.ns() >= t2.ns();
}
inline bool operator! (const Gaudi::TimeSpan &ts) {
return ! ts.ns();
}
......@@ -323,4 +239,11 @@ inline StreamBuffer& operator>>(StreamBuffer &s, Gaudi::Time &t) {
return s;
}
// make sure that "namespace Gaudi { using ::operator<; }" continues to compile...
// to be removed once all instances of the above have been removed from user code...
class backwards_compatibility_hack_time_timespan {backwards_compatibility_hack_time_timespan()=delete; };
inline bool operator<(backwards_compatibility_hack_time_timespan,backwards_compatibility_hack_time_timespan) {
return false;
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment