www.pudn.com > MPEG2systemsrc.rar > TimeStamp.C
/* Copyright (C) 1995, Tektronix Inc. All Rights Reserved.
*
* Usage Restrictions
*
* License is granted to copy, to use, and to make and to use derivative
* works for research and evaluation purposes only.
*
* Disclaimer of Warranty
*
* These software programs are available to the user without any license
* fee or royalty on an "as is" basis. Tektronix Inc. disclaims any and
* all warranties, whether express, implied, or statuary, including any
* implied warranties or merchantability or of fitness for a particular
* purpose. In no event shall the copyright-holder be liable for any
* incidental, punitive, or consequential damages of any kind whatsoever
* arising from the use of these programs.
*
* This disclaimer of warranty extends to the user of these programs and
* user's customers, employees, agents, transferees, successors, and
* assigns.
*
* The Tektronix Inc. does not represent or warrant that the programs
* furnished hereunder are free of infringement of any third-party
* patents.
*/
/* TimeStamp implementation */
#include "TimeStamp.H"
#include "Utilities.H"
extern "C"
{
#include
}
TimeStamp90::TimeStamp90 (long b)
{
bit32 = 0;
bits0_31 = b;
}
TimeStamp90::TimeStamp90 (long b, int b32)
{
bit32 = b32;
bits0_31 = b;
}
TimeStamp90::TimeStamp90 (const TimeStamp27& a)
{
bit32 = a.bit32;
bits0_31 = a.bits0_31;
}
void TimeStamp90::print ()
{
// FIX -- the following is a cheap hack
if (bit32) printf("2*");
printf("%d", bits0_31);
}
TimeStamp27::TimeStamp27 () : TimeStamp90 (0)
{
ext = 0;
}
TimeStamp27::TimeStamp27 (long b) : TimeStamp90(b / 300)
{
ext = b % 300;
}
TimeStamp27::TimeStamp27 (long b, short e) : TimeStamp90(b)
{
ext = e;
}
TimeStamp27::TimeStamp27 (long b, int b32, short e) : TimeStamp90(b, b32)
{
ext = e;
}
TimeStamp27& TimeStamp27::operator = (const TimeStamp27& a)
{
bit32 = a.bit32;
bits0_31 = a.bits0_31;
ext = a.ext;
return *this;
}
TimeStamp27& TimeStamp27::operator = (long a)
{
bit32 = 0;
bits0_31 = a / 300;
ext = a % 300;
return *this;
}
TimeStamp27 operator + (TimeStamp27& a, TimeStamp27& b)
{
TimeStamp27 r;
int extsum = a.ext + b.ext;
r.bits0_31 = a.bits0_31 + b.bits0_31;
r.bits0_31 += (extsum > 299) ? 1 : 0;
r.ext = extsum % 300;
return r;
}
TimeStamp27 operator - (TimeStamp27& a, TimeStamp27& b)
{
TimeStamp27 r;
if (b > a)
{
sys_message("can't return negative difference in TimeStamp27 operator-");
return r;
}
if (a.ext < b.ext)
{ // borrow case
r.ext = a.ext + 300 - b.ext;
r.bits0_31 = a.bits0_31 - b.bits0_31 - 1;
}
else
{
r.ext = a.ext - b.ext;
r.bits0_31 = a.bits0_31 - b.bits0_31;
}
return r;
}
int operator > (TimeStamp27& a, TimeStamp27& b)
{
if (a.bits0_31 > b.bits0_31) return 1;
if (a.bits0_31 < b.bits0_31) return 0;
if (a.ext > b.ext) return 1;
if (a.ext < b.ext) return 0;
return 0;
}
long TimeStamp27::useconds ()
{
unsigned long t = bits0_31 * 300 + ext;
return t / 27;
}
void TimeStamp27::print ()
{
printf("(");
if (bit32) printf("2*");
printf("%d", bits0_31);
printf(",%d)", ext);
}