2004-10-12 21:48:02 +00:00
|
|
|
//===-- TimeValue.h - Declare OS TimeValue Concept --------------*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-09-24 23:25:19 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-09-24 23:25:19 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header file declares the operating system TimeValue concept.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-26 01:35:46 +00:00
|
|
|
#include "llvm/System/DataTypes.h"
|
2004-11-14 21:53:55 +00:00
|
|
|
#include <string>
|
2004-09-24 23:25:19 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_SYSTEM_TIMEVALUE_H
|
|
|
|
#define LLVM_SYSTEM_TIMEVALUE_H
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
2005-04-21 20:48:15 +00:00
|
|
|
/// This class is used where a precise fixed point in time is required. The
|
|
|
|
/// range of TimeValue spans many hundreds of billions of years both past and
|
|
|
|
/// present. The precision of TimeValue is to the nanosecond. However, the
|
|
|
|
/// actual precision of its values will be determined by the resolution of
|
|
|
|
/// the system clock. The TimeValue class is used in conjunction with several
|
|
|
|
/// other lib/System interfaces to specify the time at which a call should
|
2004-09-25 08:29:54 +00:00
|
|
|
/// timeout, etc.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @since 1.4
|
|
|
|
/// @brief Provides an abstraction for a fixed point in time.
|
|
|
|
class TimeValue {
|
2004-09-25 08:29:54 +00:00
|
|
|
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @name Constants
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// A constant TimeValue representing the smallest time
|
2004-09-25 08:29:54 +00:00
|
|
|
/// value permissable by the class. MinTime is some point
|
|
|
|
/// in the distant past, about 300 billion years BCE.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief The smallest possible time value.
|
|
|
|
static const TimeValue MinTime;
|
|
|
|
|
|
|
|
/// A constant TimeValue representing the largest time
|
2004-09-25 08:29:54 +00:00
|
|
|
/// value permissable by the class. MaxTime is some point
|
2004-09-24 23:25:19 +00:00
|
|
|
/// in the distant future, about 300 billion years AD.
|
|
|
|
/// @brief The largest possible time value.
|
|
|
|
static const TimeValue MaxTime;
|
|
|
|
|
|
|
|
/// A constant TimeValue representing the base time,
|
|
|
|
/// or zero time of 00:00:00 (midnight) January 1st, 2000.
|
|
|
|
/// @brief 00:00:00 Jan 1, 2000 UTC.
|
|
|
|
static const TimeValue ZeroTime;
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// A constant TimeValue for the Posix base time which is
|
2004-09-24 23:25:19 +00:00
|
|
|
/// 00:00:00 (midnight) January 1st, 1970.
|
|
|
|
/// @brief 00:00:00 Jan 1, 1970 UTC.
|
|
|
|
static const TimeValue PosixZeroTime;
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// A constant TimeValue for the Win32 base time which is
|
2004-09-24 23:25:19 +00:00
|
|
|
/// 00:00:00 (midnight) January 1st, 1601.
|
|
|
|
/// @brief 00:00:00 Jan 1, 1601 UTC.
|
|
|
|
static const TimeValue Win32ZeroTime;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Types
|
|
|
|
/// @{
|
|
|
|
public:
|
2009-11-07 06:33:01 +00:00
|
|
|
typedef int64_t SecondsType; ///< Type used for representing seconds.
|
|
|
|
typedef int32_t NanoSecondsType;///< Type used for representing nanoseconds.
|
2004-09-24 23:25:19 +00:00
|
|
|
|
|
|
|
enum TimeConversions {
|
2004-09-25 08:29:54 +00:00
|
|
|
NANOSECONDS_PER_SECOND = 1000000000, ///< One Billion
|
|
|
|
MICROSECONDS_PER_SECOND = 1000000, ///< One Million
|
|
|
|
MILLISECONDS_PER_SECOND = 1000, ///< One Thousand
|
|
|
|
NANOSECONDS_PER_MICROSECOND = 1000, ///< One Thousand
|
|
|
|
NANOSECONDS_PER_MILLISECOND = 1000000,///< One Million
|
|
|
|
NANOSECONDS_PER_POSIX_TICK = 100, ///< Posix tick is 100 Hz (10ms)
|
2006-02-22 16:23:43 +00:00
|
|
|
NANOSECONDS_PER_WIN32_TICK = 100 ///< Win32 tick is 100 Hz (10ms)
|
2004-09-24 23:25:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
|
|
|
public:
|
2005-04-21 20:48:15 +00:00
|
|
|
/// Caller provides the exact value in seconds and nanoseconds. The
|
2004-09-25 08:29:54 +00:00
|
|
|
/// \p nanos argument defaults to zero for convenience.
|
2005-04-21 20:48:15 +00:00
|
|
|
/// @brief Explicit constructor
|
2004-09-25 08:29:54 +00:00
|
|
|
explicit TimeValue (SecondsType seconds, NanoSecondsType nanos = 0)
|
2004-10-19 00:29:16 +00:00
|
|
|
: seconds_( seconds ), nanos_( nanos ) { this->normalize(); }
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Caller provides the exact value as a double in seconds with the
|
|
|
|
/// fractional part representing nanoseconds.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief Double Constructor.
|
2004-09-25 08:29:54 +00:00
|
|
|
explicit TimeValue( double new_time )
|
2005-04-21 20:48:15 +00:00
|
|
|
: seconds_( 0 ) , nanos_ ( 0 ) {
|
2004-09-25 08:29:54 +00:00
|
|
|
SecondsType integer_part = static_cast<SecondsType>( new_time );
|
|
|
|
seconds_ = integer_part;
|
2005-04-21 20:48:15 +00:00
|
|
|
nanos_ = static_cast<NanoSecondsType>( (new_time -
|
2004-09-25 08:29:54 +00:00
|
|
|
static_cast<double>(integer_part)) * NANOSECONDS_PER_SECOND );
|
|
|
|
this->normalize();
|
2004-09-24 23:25:19 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// This is a static constructor that returns a TimeValue that represents
|
|
|
|
/// the current time.
|
|
|
|
/// @brief Creates a TimeValue with the current time (UTC).
|
|
|
|
static TimeValue now();
|
2004-09-24 23:25:19 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Operators
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// Add \p that to \p this.
|
|
|
|
/// @returns this
|
|
|
|
/// @brief Incrementing assignment operator.
|
|
|
|
TimeValue& operator += (const TimeValue& that ) {
|
|
|
|
this->seconds_ += that.seconds_ ;
|
|
|
|
this->nanos_ += that.nanos_ ;
|
|
|
|
this->normalize();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Subtract \p that from \p this.
|
|
|
|
/// @returns this
|
|
|
|
/// @brief Decrementing assignment operator.
|
|
|
|
TimeValue& operator -= (const TimeValue &that ) {
|
|
|
|
this->seconds_ -= that.seconds_ ;
|
|
|
|
this->nanos_ -= that.nanos_ ;
|
|
|
|
this->normalize();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Determine if \p this is less than \p that.
|
|
|
|
/// @returns True iff *this < that.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief True if this < that.
|
|
|
|
int operator < (const TimeValue &that) const { return that > *this; }
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Determine if \p this is greather than \p that.
|
|
|
|
/// @returns True iff *this > that.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief True if this > that.
|
|
|
|
int operator > (const TimeValue &that) const {
|
2004-09-25 08:29:54 +00:00
|
|
|
if ( this->seconds_ > that.seconds_ ) {
|
2004-09-24 23:25:19 +00:00
|
|
|
return 1;
|
2004-09-25 08:29:54 +00:00
|
|
|
} else if ( this->seconds_ == that.seconds_ ) {
|
2004-09-24 23:25:19 +00:00
|
|
|
if ( this->nanos_ > that.nanos_ ) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Determine if \p this is less than or equal to \p that.
|
|
|
|
/// @returns True iff *this <= that.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief True if this <= that.
|
|
|
|
int operator <= (const TimeValue &that) const { return that >= *this; }
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Determine if \p this is greater than or equal to \p that.
|
|
|
|
/// @returns True iff *this >= that.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief True if this >= that.
|
|
|
|
int operator >= (const TimeValue &that) const {
|
2004-09-25 08:29:54 +00:00
|
|
|
if ( this->seconds_ > that.seconds_ ) {
|
2004-09-24 23:25:19 +00:00
|
|
|
return 1;
|
2004-09-25 08:29:54 +00:00
|
|
|
} else if ( this->seconds_ == that.seconds_ ) {
|
2004-09-24 23:25:19 +00:00
|
|
|
if ( this->nanos_ >= that.nanos_ ) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Determines if two TimeValue objects represent the same moment in time.
|
|
|
|
/// @brief True iff *this == that.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief True if this == that.
|
|
|
|
int operator == (const TimeValue &that) const {
|
2005-04-21 20:48:15 +00:00
|
|
|
return (this->seconds_ == that.seconds_) &&
|
2004-09-24 23:25:19 +00:00
|
|
|
(this->nanos_ == that.nanos_);
|
|
|
|
}
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Determines if two TimeValue objects represent times that are not the
|
|
|
|
/// same.
|
|
|
|
/// @return True iff *this != that.
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @brief True if this != that.
|
|
|
|
int operator != (const TimeValue &that) const { return !(*this == that); }
|
|
|
|
|
|
|
|
/// Adds two TimeValue objects together.
|
|
|
|
/// @returns The sum of the two operands as a new TimeValue
|
|
|
|
/// @brief Addition operator.
|
|
|
|
friend TimeValue operator + (const TimeValue &tv1, const TimeValue &tv2);
|
|
|
|
|
|
|
|
/// Subtracts two TimeValue objects.
|
|
|
|
/// @returns The difference of the two operands as a new TimeValue
|
|
|
|
/// @brief Subtraction operator.
|
|
|
|
friend TimeValue operator - (const TimeValue &tv1, const TimeValue &tv2);
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Accessors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Returns only the seconds component of the TimeValue. The nanoseconds
|
|
|
|
/// portion is ignored. No rounding is performed.
|
|
|
|
/// @brief Retrieve the seconds component
|
2004-11-16 06:22:17 +00:00
|
|
|
SecondsType seconds() const { return seconds_; }
|
2004-09-25 08:29:54 +00:00
|
|
|
|
|
|
|
/// Returns only the nanoseconds component of the TimeValue. The seconds
|
2005-04-21 20:48:15 +00:00
|
|
|
/// portion is ignored.
|
2004-09-25 08:29:54 +00:00
|
|
|
/// @brief Retrieve the nanoseconds component.
|
2004-11-16 06:22:17 +00:00
|
|
|
NanoSecondsType nanoseconds() const { return nanos_; }
|
2004-09-25 08:29:54 +00:00
|
|
|
|
|
|
|
/// Returns only the fractional portion of the TimeValue rounded down to the
|
|
|
|
/// nearest microsecond (divide by one thousand).
|
|
|
|
/// @brief Retrieve the fractional part as microseconds;
|
2005-04-21 20:48:15 +00:00
|
|
|
uint32_t microseconds() const {
|
2004-09-25 08:29:54 +00:00
|
|
|
return nanos_ / NANOSECONDS_PER_MICROSECOND;
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-10-19 00:29:16 +00:00
|
|
|
/// Returns only the fractional portion of the TimeValue rounded down to the
|
2004-09-25 08:29:54 +00:00
|
|
|
/// nearest millisecond (divide by one million).
|
|
|
|
/// @brief Retrieve the fractional part as milliseconds;
|
2004-11-16 06:22:17 +00:00
|
|
|
uint32_t milliseconds() const {
|
2004-09-25 08:29:54 +00:00
|
|
|
return nanos_ / NANOSECONDS_PER_MILLISECOND;
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Returns the TimeValue as a number of microseconds. Note that the value
|
|
|
|
/// returned can overflow because the range of a uint64_t is smaller than
|
|
|
|
/// the range of a TimeValue. Nevertheless, this is useful on some operating
|
|
|
|
/// systems and is therefore provided.
|
|
|
|
/// @brief Convert to a number of microseconds (can overflow)
|
2004-11-16 06:22:17 +00:00
|
|
|
uint64_t usec() const {
|
2005-04-21 20:48:15 +00:00
|
|
|
return seconds_ * MICROSECONDS_PER_SECOND +
|
2004-09-25 08:29:54 +00:00
|
|
|
( nanos_ / NANOSECONDS_PER_MICROSECOND );
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Returns the TimeValue as a number of milliseconds. Note that the value
|
2005-04-21 20:48:15 +00:00
|
|
|
/// returned can overflow because the range of a uint64_t is smaller than
|
2004-09-25 08:29:54 +00:00
|
|
|
/// the range of a TimeValue. Nevertheless, this is useful on some operating
|
|
|
|
/// systems and is therefore provided.
|
|
|
|
/// @brief Convert to a number of milliseconds (can overflow)
|
2004-11-16 06:22:17 +00:00
|
|
|
uint64_t msec() const {
|
2005-04-21 20:48:15 +00:00
|
|
|
return seconds_ * MILLISECONDS_PER_SECOND +
|
2004-09-25 08:29:54 +00:00
|
|
|
( nanos_ / NANOSECONDS_PER_MILLISECOND );
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Converts the TimeValue into the corresponding number of "ticks" for
|
|
|
|
/// Posix, correcting for the difference in Posix zero time.
|
|
|
|
/// @brief Convert to unix time (100 nanoseconds since 12:00:00a Jan 1,1970)
|
2004-11-16 06:22:17 +00:00
|
|
|
uint64_t toPosixTime() const {
|
2004-09-25 08:29:54 +00:00
|
|
|
uint64_t result = seconds_ - PosixZeroTime.seconds_;
|
|
|
|
result += nanos_ / NANOSECONDS_PER_POSIX_TICK;
|
|
|
|
return result;
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
/// Converts the TimeValue into the corresponding number of seconds
|
|
|
|
/// since the epoch (00:00:00 Jan 1,1970).
|
2004-11-16 06:22:17 +00:00
|
|
|
uint64_t toEpochTime() const {
|
2004-11-14 21:53:55 +00:00
|
|
|
return seconds_ - PosixZeroTime.seconds_;
|
|
|
|
}
|
|
|
|
|
2009-10-11 18:53:09 +00:00
|
|
|
/// Converts the TimeValue into the corresponding number of "ticks" for
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Win32 platforms, correcting for the difference in Win32 zero time.
|
|
|
|
/// @brief Convert to windows time (seconds since 12:00:00a Jan 1, 1601)
|
2004-11-16 06:22:17 +00:00
|
|
|
uint64_t toWin32Time() const {
|
2004-09-25 08:29:54 +00:00
|
|
|
uint64_t result = seconds_ - Win32ZeroTime.seconds_;
|
|
|
|
result += nanos_ / NANOSECONDS_PER_WIN32_TICK;
|
|
|
|
return result;
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// Provides the seconds and nanoseconds as results in its arguments after
|
|
|
|
/// correction for the Posix zero time.
|
|
|
|
/// @brief Convert to timespec time (ala POSIX.1b)
|
2004-11-14 21:53:55 +00:00
|
|
|
void getTimespecTime( uint64_t& seconds, uint32_t& nanos ) const {
|
2004-09-25 08:29:54 +00:00
|
|
|
seconds = seconds_ - PosixZeroTime.seconds_;
|
|
|
|
nanos = nanos_;
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-11-14 21:53:55 +00:00
|
|
|
/// Provides conversion of the TimeValue into a readable time & date.
|
|
|
|
/// @returns std::string containing the readable time value
|
|
|
|
/// @brief Convert time to a string.
|
2009-08-23 22:45:37 +00:00
|
|
|
std::string str() const;
|
2004-11-14 21:53:55 +00:00
|
|
|
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
2004-09-25 08:29:54 +00:00
|
|
|
public:
|
|
|
|
/// The seconds component of the TimeValue is set to \p sec without
|
2004-10-26 18:00:03 +00:00
|
|
|
/// modifying the nanoseconds part. This is useful for whole second
|
|
|
|
/// arithmetic.
|
2004-09-25 08:29:54 +00:00
|
|
|
/// @brief Set the seconds component.
|
|
|
|
void seconds (SecondsType sec ) {
|
|
|
|
this->seconds_ = sec;
|
|
|
|
this->normalize();
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// The nanoseconds component of the TimeValue is set to \p nanos without
|
|
|
|
/// modifying the seconds part. This is useful for basic computations
|
|
|
|
/// involving just the nanoseconds portion. Note that the TimeValue will be
|
|
|
|
/// normalized after this call so that the fractional (nanoseconds) portion
|
|
|
|
/// will have the smallest equivalent value.
|
|
|
|
/// @brief Set the nanoseconds component using a number of nanoseconds.
|
|
|
|
void nanoseconds ( NanoSecondsType nanos ) {
|
|
|
|
this->nanos_ = nanos;
|
|
|
|
this->normalize();
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// The seconds component remains unchanged.
|
|
|
|
/// @brief Set the nanoseconds component using a number of microseconds.
|
|
|
|
void microseconds ( int32_t micros ) {
|
|
|
|
this->nanos_ = micros * NANOSECONDS_PER_MICROSECOND;
|
|
|
|
this->normalize();
|
2007-05-03 18:13:15 +00:00
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// The seconds component remains unchanged.
|
|
|
|
/// @brief Set the nanoseconds component using a number of milliseconds.
|
|
|
|
void milliseconds ( int32_t millis ) {
|
|
|
|
this->nanos_ = millis * NANOSECONDS_PER_MILLISECOND;
|
|
|
|
this->normalize();
|
2007-05-03 18:13:15 +00:00
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// @brief Converts from microsecond format to TimeValue format
|
|
|
|
void usec( int64_t microseconds ) {
|
|
|
|
this->seconds_ = microseconds / MICROSECONDS_PER_SECOND;
|
2005-04-21 20:48:15 +00:00
|
|
|
this->nanos_ = NanoSecondsType(microseconds % MICROSECONDS_PER_SECOND) *
|
2004-09-25 08:29:54 +00:00
|
|
|
NANOSECONDS_PER_MICROSECOND;
|
|
|
|
this->normalize();
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-09-25 08:29:54 +00:00
|
|
|
/// @brief Converts from millisecond format to TimeValue format
|
|
|
|
void msec( int64_t milliseconds ) {
|
|
|
|
this->seconds_ = milliseconds / MILLISECONDS_PER_SECOND;
|
2005-04-21 20:48:15 +00:00
|
|
|
this->nanos_ = NanoSecondsType(milliseconds % MILLISECONDS_PER_SECOND) *
|
2004-09-25 08:29:54 +00:00
|
|
|
NANOSECONDS_PER_MILLISECOND;
|
2004-11-09 20:29:10 +00:00
|
|
|
this->normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Converts the \p seconds argument from PosixTime to the corresponding
|
|
|
|
/// TimeValue and assigns that value to \p this.
|
|
|
|
/// @brief Convert seconds form PosixTime to TimeValue
|
2004-11-14 21:53:55 +00:00
|
|
|
void fromEpochTime( SecondsType seconds ) {
|
2004-11-09 20:29:10 +00:00
|
|
|
seconds_ = seconds + PosixZeroTime.seconds_;
|
|
|
|
nanos_ = 0;
|
2004-09-25 08:29:54 +00:00
|
|
|
this->normalize();
|
|
|
|
}
|
2004-09-24 23:25:19 +00:00
|
|
|
|
2004-12-14 05:26:43 +00:00
|
|
|
/// Converts the \p win32Time argument from Windows FILETIME to the
|
|
|
|
/// corresponding TimeValue and assigns that value to \p this.
|
|
|
|
/// @brief Convert seconds form Windows FILETIME to TimeValue
|
|
|
|
void fromWin32Time( uint64_t win32Time ) {
|
|
|
|
this->seconds_ = win32Time / 10000000 + Win32ZeroTime.seconds_;
|
|
|
|
this->nanos_ = NanoSecondsType(win32Time % 10000000) * 100;
|
|
|
|
}
|
|
|
|
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @}
|
2004-09-25 08:29:54 +00:00
|
|
|
/// @name Implementation
|
|
|
|
/// @{
|
|
|
|
private:
|
|
|
|
/// This causes the values to be represented so that the fractional
|
|
|
|
/// part is minimized, possibly incrementing the seconds part.
|
|
|
|
/// @brief Normalize to canonical form.
|
2004-11-16 06:22:17 +00:00
|
|
|
void normalize();
|
2004-09-25 08:29:54 +00:00
|
|
|
|
2006-08-22 17:38:05 +00:00
|
|
|
/// @}
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @name Data
|
|
|
|
/// @{
|
|
|
|
private:
|
2006-08-22 17:38:05 +00:00
|
|
|
/// Store the values as a <timeval>.
|
|
|
|
SecondsType seconds_;///< Stores the seconds part of the TimeVal
|
|
|
|
NanoSecondsType nanos_; ///< Stores the nanoseconds part of the TimeVal
|
2004-09-24 23:25:19 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline TimeValue operator + (const TimeValue &tv1, const TimeValue &tv2) {
|
|
|
|
TimeValue sum (tv1.seconds_ + tv2.seconds_, tv1.nanos_ + tv2.nanos_);
|
|
|
|
sum.normalize ();
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TimeValue operator - (const TimeValue &tv1, const TimeValue &tv2) {
|
|
|
|
TimeValue difference (tv1.seconds_ - tv2.seconds_, tv1.nanos_ - tv2.nanos_ );
|
|
|
|
difference.normalize ();
|
|
|
|
return difference;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|