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