VTime.hxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:5k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. #ifndef VTIME_H_
  2. #define VTIME_H_
  3. /* ====================================================================
  4.  * The Vovida Software License, Version 1.0 
  5.  * 
  6.  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
  7.  * 
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in
  17.  *    the documentation and/or other materials provided with the
  18.  *    distribution.
  19.  * 
  20.  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
  21.  *    and "Vovida Open Communication Application Library (VOCAL)" must
  22.  *    not be used to endorse or promote products derived from this
  23.  *    software without prior written permission. For written
  24.  *    permission, please contact vocal@vovida.org.
  25.  *
  26.  * 4. Products derived from this software may not be called "VOCAL", nor
  27.  *    may "VOCAL" appear in their name, without prior written
  28.  *    permission of Vovida Networks, Inc.
  29.  * 
  30.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
  31.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  33.  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
  34.  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
  35.  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
  36.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  37.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  41.  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  42.  * DAMAGE.
  43.  * 
  44.  * ====================================================================
  45.  * 
  46.  * This software consists of voluntary contributions made by Vovida
  47.  * Networks, Inc. and many individuals on behalf of Vovida Networks,
  48.  * Inc.  For more information on Vovida Networks, Inc., please see
  49.  * <http://www.vovida.org/>.
  50.  *
  51.  */
  52. static const char* const VTimeHeaderVersion =
  53.     "$Id: VTime.hxx,v 1.15 2001/06/27 22:56:20 bko Exp $";
  54. #ifdef __vxworks
  55. #include <time.h>
  56. #include <sys/times.h>
  57. /**
  58.  ** Operates the same as linux gettimeofday() except the
  59.  ** usec field of struct timeval is rounded to nearest msec
  60.  ** (eg. usec = msec*1000)
  61.  */
  62. int
  63. gettimeofday (struct timeval *tv, struct timezone *tz);
  64. #else
  65. #include "global.h"
  66. #if !defined(WIN32)
  67. #include <sys/time.h>
  68. #endif
  69. #endif
  70. // __vxworks
  71. #ifdef WIN32
  72. #ifndef VOCAL_TOOLCHAIN_MSGNU
  73. #include "StdAfx.h"
  74. #endif
  75. int
  76. gettimeofday (struct timeval *tv, struct timezone *tz);
  77. using namespace std;
  78. #endif // WIN32
  79. #include <sys/types.h>
  80. #include "vtypes.h"
  81. // stuff here
  82. #include <string>
  83. /** Class VThread
  84.  ** Defines a time class which provides means of
  85.  ** creating, adding, subtracting, and comparing times. 
  86.  ** VTime objects contain a second component and a fraction of second
  87.  ** component. Both may be specified and accessed by the user.
  88.  ** Routines to add and subtract times in terms of milliseconds are
  89.  ** also provided.
  90.  **/
  91. class VTime
  92. {
  93.     public:
  94.         /// Create VTime object with specified seconds and fraction of a second.
  95.         VTime( u_int32_t sec, u_int32_t frac ): seconds(sec), fractional(frac)
  96.         {}
  97.         ;
  98.         /// Create a new VTime object with the current system time.
  99.         VTime()
  100.         {
  101.             *this = getVTime();
  102.         };
  103.         /// Access functions
  104.         u_int32_t getSeconds()
  105.         {
  106.             return seconds;
  107.         };
  108.         u_int32_t getFractional()
  109.         {
  110.             return fractional;
  111.         };
  112.         /// Display time stored in VTime in decimal notation
  113.         void print();
  114.         static string strftime(const string & format);
  115.     private:
  116.         // this is the numbers of seconds
  117.         u_int32_t seconds;
  118.         /** this is the fraction of the second.  1 second == 2^32 fractional .
  119.          */
  120.         u_int32_t fractional;
  121.         /// add specified number of milliseconds to VTime
  122.         friend VTime operator+( const VTime& lhs , const unsigned int msec );
  123.         /// subtract specified number of milliseconds from VTime
  124.         friend VTime operator-( const VTime& lhs , const unsigned int msec );
  125.         /// returns difference in terms of milliseconds, or 0 if rhs > lhs
  126.         friend int operator-( const VTime& lhs , const VTime& rhs );
  127.         friend bool operator==( const VTime& lhs , const VTime& rhs );
  128.         friend bool operator<( const VTime& lhs , const VTime& rhs );
  129.         friend bool operator>( const VTime& lhs , const VTime& rhs );
  130.         /// returns a VTime object based on the current system time
  131.         friend VTime getVTime();
  132. };
  133. // V_TIME_H_
  134. #endif