Move DataTypes.h to include/llvm/System, update all users. This breaks the last
[oota-llvm.git] / include / llvm / System / TimeValue.h
index 6e5e271c98e46e269f2157e1e7f3079e9974001e..168e2a7dcb66dc5bf202fd9abc302934911864ae 100644 (file)
@@ -1,17 +1,17 @@
 //===-- TimeValue.h - Declare OS TimeValue Concept --------------*- C++ -*-===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Reid Spencer and is distributed under the 
-// University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
 //===----------------------------------------------------------------------===//
 //
 //  This header file declares the operating system TimeValue concept.
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 #ifndef LLVM_SYSTEM_TIMEVALUE_H
 
 namespace llvm {
 namespace sys {
-  /// 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 
+  /// 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
   /// timeout, etc.
   /// @since 1.4
   /// @brief Provides an abstraction for a fixed point in time.
@@ -75,16 +75,16 @@ namespace sys {
       NANOSECONDS_PER_MICROSECOND = 1000,   ///< One Thousand
       NANOSECONDS_PER_MILLISECOND = 1000000,///< One Million
       NANOSECONDS_PER_POSIX_TICK = 100,     ///< Posix tick is 100 Hz (10ms)
-      NANOSECONDS_PER_WIN32_TICK = 100,     ///< Win32 tick is 100 Hz (10ms)
+      NANOSECONDS_PER_WIN32_TICK = 100      ///< Win32 tick is 100 Hz (10ms)
     };
 
   /// @}
   /// @name Constructors
   /// @{
   public:
-    /// Caller provides the exact value in seconds and nanoseconds. The 
+    /// Caller provides the exact value in seconds and nanoseconds. The
     /// \p nanos argument defaults to zero for convenience.
-    /// @brief Explicit constructor 
+    /// @brief Explicit constructor
     explicit TimeValue (SecondsType seconds, NanoSecondsType nanos = 0)
       : seconds_( seconds ), nanos_( nanos ) { this->normalize(); }
 
@@ -92,10 +92,10 @@ namespace sys {
     /// fractional part representing nanoseconds.
     /// @brief Double Constructor.
     explicit TimeValue( double new_time )
-      : seconds_( 0 ) , nanos_ ( 0 ) { 
+      : seconds_( 0 ) , nanos_ ( 0 ) {
       SecondsType integer_part = static_cast<SecondsType>( new_time );
       seconds_ = integer_part;
-      nanos_ = static_cast<NanoSecondsType>( (new_time - 
+      nanos_ = static_cast<NanoSecondsType>( (new_time -
                static_cast<double>(integer_part)) * NANOSECONDS_PER_SECOND );
       this->normalize();
     }
@@ -167,7 +167,7 @@ namespace sys {
     /// @brief True iff *this == that.
     /// @brief True if this == that.
     int operator == (const TimeValue &that) const {
-      return (this->seconds_ == that.seconds_) && 
+      return (this->seconds_ == that.seconds_) &&
              (this->nanos_ == that.nanos_);
     }
 
@@ -195,24 +195,24 @@ namespace sys {
     /// Returns only the seconds component of the TimeValue. The nanoseconds
     /// portion is ignored. No rounding is performed.
     /// @brief Retrieve the seconds component
-    SecondsType seconds( void ) const { return seconds_; }
+    SecondsType seconds() const { return seconds_; }
 
     /// Returns only the nanoseconds component of the TimeValue. The seconds
-    /// portion is ignored. 
+    /// portion is ignored.
     /// @brief Retrieve the nanoseconds component.
-    NanoSecondsType nanoseconds( void ) const { return nanos_; }
+    NanoSecondsType nanoseconds() const { return nanos_; }
 
     /// 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;
-    uint32_t microseconds( void ) const { 
+    uint32_t microseconds() const {
       return nanos_ / NANOSECONDS_PER_MICROSECOND;
     }
 
     /// Returns only the fractional portion of the TimeValue rounded down to the
     /// nearest millisecond (divide by one million).
     /// @brief Retrieve the fractional part as milliseconds;
-    uint32_t milliseconds( void ) const {
+    uint32_t milliseconds() const {
       return nanos_ / NANOSECONDS_PER_MILLISECOND;
     }
 
@@ -221,40 +221,40 @@ namespace sys {
     /// 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)
-    uint64_t usec( void ) const {
-      return seconds_ * MICROSECONDS_PER_SECOND + 
+    uint64_t usec() const {
+      return seconds_ * MICROSECONDS_PER_SECOND +
              ( nanos_ / NANOSECONDS_PER_MICROSECOND );
     }
 
     /// Returns the TimeValue as a number of milliseconds. Note that the value
-    /// returned can overflow because the range of a uint64_t is smaller than 
+    /// 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 milliseconds (can overflow)
-    uint64_t msec( void ) const {
-      return seconds_ * MILLISECONDS_PER_SECOND + 
+    uint64_t msec() const {
+      return seconds_ * MILLISECONDS_PER_SECOND +
              ( nanos_ / NANOSECONDS_PER_MILLISECOND );
     }
 
     /// 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)
-    uint64_t toPosixTime( void ) const {
+    uint64_t toPosixTime() const {
       uint64_t result = seconds_ - PosixZeroTime.seconds_;
       result += nanos_ / NANOSECONDS_PER_POSIX_TICK;
       return result;
     }
 
-    /// Converts the TimeValue into the corresponding number of seconds 
-    /// since the epoch (00:00:00 Jan 1,1970). 
-    uint64_t toEpochTime(void) const {
+    /// Converts the TimeValue into the corresponding number of seconds
+    /// since the epoch (00:00:00 Jan 1,1970).
+    uint64_t toEpochTime() const {
       return seconds_ - PosixZeroTime.seconds_;
     }
 
-    /// Converts the TiemValue into the correspodning number of "ticks" for
+    /// Converts the TimeValue into the corresponding number of "ticks" for
     /// Win32 platforms, correcting for the difference in Win32 zero time.
     /// @brief Convert to windows time (seconds since 12:00:00a Jan 1, 1601)
-    uint64_t toWin32Time( void ) const {
+    uint64_t toWin32Time() const {
       uint64_t result = seconds_ - Win32ZeroTime.seconds_;
       result += nanos_ / NANOSECONDS_PER_WIN32_TICK;
       return result;
@@ -271,7 +271,7 @@ namespace sys {
     /// Provides conversion of the TimeValue into a readable time & date.
     /// @returns std::string containing the readable time value
     /// @brief Convert time to a string.
-    std::string toString();
+    std::string str() const;
 
   /// @}
   /// @name Mutators
@@ -302,19 +302,19 @@ namespace sys {
     void microseconds ( int32_t micros ) {
       this->nanos_ = micros * NANOSECONDS_PER_MICROSECOND;
       this->normalize();
-    };
+    }
 
     /// 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();
-    };
+    }
 
     /// @brief Converts from microsecond format to TimeValue format
     void usec( int64_t microseconds ) {
       this->seconds_ = microseconds / MICROSECONDS_PER_SECOND;
-      this->nanos_ = (microseconds % MICROSECONDS_PER_SECOND) * 
+      this->nanos_ = NanoSecondsType(microseconds % MICROSECONDS_PER_SECOND) *
         NANOSECONDS_PER_MICROSECOND;
       this->normalize();
     }
@@ -322,7 +322,7 @@ namespace sys {
     /// @brief Converts from millisecond format to TimeValue format
     void msec( int64_t milliseconds ) {
       this->seconds_ = milliseconds / MILLISECONDS_PER_SECOND;
-      this->nanos_ = (milliseconds % MILLISECONDS_PER_SECOND) * 
+      this->nanos_ = NanoSecondsType(milliseconds % MILLISECONDS_PER_SECOND) *
         NANOSECONDS_PER_MILLISECOND;
       this->normalize();
     }
@@ -336,6 +336,14 @@ namespace sys {
       this->normalize();
     }
 
+    /// 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;
+    }
+
   /// @}
   /// @name Implementation
   /// @{
@@ -343,16 +351,15 @@ namespace sys {
     /// This causes the values to be represented so that the fractional
     /// part is minimized, possibly incrementing the seconds part.
     /// @brief Normalize to canonical form.
-    void normalize (void);
+    void normalize();
 
-/// @}
+  /// @}
   /// @name Data
   /// @{
   private:
-      /// Store the values as a <timeval>.
-      SecondsType      seconds_;///< Stores the seconds part of the TimeVal
-      NanoSecondsType  nanos_;  ///< Stores the nanoseconds part of the TimeVal
-
+    /// Store the values as a <timeval>.
+    SecondsType      seconds_;///< Stores the seconds part of the TimeVal
+    NanoSecondsType  nanos_;  ///< Stores the nanoseconds part of the TimeVal
   /// @}
 
   };
@@ -372,5 +379,4 @@ inline TimeValue operator - (const TimeValue &tv1, const TimeValue &tv2) {
 }
 }
 
-// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
 #endif