SBtrdTimeOfDay.cpp
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. /* SBtrdTimeOfDay, utility class for handling a time of day */
  2. /****************License************************************************
  3.  * Vocalocity OpenVXI
  4.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License
  7.  * as published by the Free Software Foundation; either version 2
  8.  * of the License, or (at your option) any later version.
  9.  *  
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  19.  * registered trademarks of Vocalocity, Inc. 
  20.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  21.  * by Vocalocity.
  22.  ***********************************************************************/
  23. // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
  24. #define SBTRDUTIL_EXPORTS
  25. #include "SBtrdTimeOfDay.hpp"           // For this class
  26. #ifdef WIN32
  27. #define WIN32_LEAN_AND_MEAN
  28. #include <windows.h>
  29. #endif
  30. #include <sys/types.h>
  31. #include <sys/timeb.h>                 // for ftime( )/_ftime( )
  32. #ifdef WIN32
  33. #define SBtrdFtime(x) _ftime(x)
  34. #define SBtrdTimeb struct _timeb
  35. #else
  36. #define SBtrdFtime(x) ftime(x)
  37. #define SBtrdTimeb struct timeb
  38. #endif
  39. // -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8
  40. // Constructor
  41. SBTRDUTIL_API_CLASS SBtrdTimeOfDay::SBtrdTimeOfDay( ) :
  42.   _time(0), _millitm(0)
  43. {
  44. }
  45. // Destructor
  46. SBTRDUTIL_API_CLASS SBtrdTimeOfDay::~SBtrdTimeOfDay( )
  47. {
  48. }
  49. // Set the time to the current time of day
  50. SBTRDUTIL_API_CLASS bool SBtrdTimeOfDay::SetCurrentTime( )
  51. {
  52.   SBtrdTimeb tbuf;
  53.   SBtrdFtime(&tbuf);
  54.   _time = tbuf.time;
  55.   _millitm = tbuf.millitm;
  56.   return true;
  57. }
  58. // Clear the time
  59. SBTRDUTIL_API_CLASS void SBtrdTimeOfDay::Clear( ) 
  60. {
  61.   _time = 0;
  62.   _millitm = 0;
  63. }
  64. // Offset the time of day
  65. SBTRDUTIL_API_CLASS void SBtrdTimeOfDay::operator+=(VXIint32 offsetMs)
  66. {
  67.   _time += static_cast<time_t>(offsetMs / 1000);
  68.   _millitm += static_cast<unsigned short>(offsetMs % 1000);
  69.   if ( _millitm > 1000 ) {
  70.     _time++;
  71.     _millitm -= 1000;
  72.   }
  73. }
  74. // Determine if the time is set
  75. SBTRDUTIL_API_CLASS bool SBtrdTimeOfDay::IsSet( ) const 
  76. {
  77.   return ((_time) || (_millitm) ? true : false);
  78. }
  79. // Get the milliseconds offset from the current time value
  80. SBTRDUTIL_API_CLASS VXIlong SBtrdTimeOfDay::GetMsecBeforeTime( ) const
  81. {
  82.   SBtrdTimeOfDay current;
  83.   current.SetCurrentTime( );
  84.   return (_time - current._time) * 1000 + (_millitm - current._millitm);
  85. }
  86. // Get the milliseconds offset from the current time value
  87. SBTRDUTIL_API_CLASS VXIlong SBtrdTimeOfDay::GetMsecAfterTime( ) const 
  88. {
  89.   return -GetMsecBeforeTime( );
  90. }
  91. // Get the milliseconds offset from another time value
  92. SBTRDUTIL_API_CLASS VXIlong 
  93. SBtrdTimeOfDay::GetMsecBeforeTime (const SBtrdTimeOfDay &tod) const
  94. {
  95.   return (_time - tod._time) * 1000 + (_millitm - tod._millitm);
  96. }
  97. // Get the milliseconds offset from another time value
  98. SBTRDUTIL_API_CLASS VXIlong 
  99. SBtrdTimeOfDay::GetMsecAfterTime (const SBtrdTimeOfDay &tod) const 
  100. {
  101.   return -GetMsecBeforeTime (tod); 
  102. }
  103. // Comparison operator
  104. SBTRDUTIL_API_CLASS bool 
  105. SBtrdTimeOfDay::operator< (const SBtrdTimeOfDay &tod) const 
  106. {
  107.   return ((_time < tod._time) || 
  108.           ((_time == tod._time) && (_millitm < tod._millitm)));
  109. }
  110. // Comparison operator
  111. SBTRDUTIL_API_CLASS bool 
  112. SBtrdTimeOfDay::operator> (const SBtrdTimeOfDay &tod) const 
  113. {
  114.   return ((_time > tod._time) || 
  115.           ((_time == tod._time) && (_millitm > tod._millitm)));
  116. }
  117. // Comparison operator
  118. SBTRDUTIL_API_CLASS bool 
  119. SBtrdTimeOfDay::operator== (const SBtrdTimeOfDay &tod) const 
  120. {
  121.   return ((_time != tod._time) || (_millitm != tod._millitm));
  122. }