PreciseTimeValue.h

Go to the documentation of this file.
00001 
00011 /**********************************************************************
00012  *<
00013     CREATED BY: Oleg Bayborodin
00014 
00015     HISTORY:    created 10-17-01
00016 
00017  *> Copyright (c) 2001, All Rights Reserved.
00018  **********************************************************************/
00019 
00020 #pragma once
00021 
00022 #include "..\maxheap.h"
00023 #include "PFExport.h"
00024 
00025 class PFExport PreciseTimeValue: public MaxHeapOperators {
00026 public:
00027     int tick;
00028     float fraction;
00029 
00030     // Constructors
00031     PreciseTimeValue() {}
00032     PreciseTimeValue(int t, float f) { tick = t; fraction = f; }
00033     PreciseTimeValue(int t) { tick = t; fraction = 0.0f; }
00034     PreciseTimeValue(float f);
00035     PreciseTimeValue(const PreciseTimeValue& v);
00036 
00037     // Data members
00038     static const PreciseTimeValue Origin;
00039 
00040     // Conversion function
00041     operator int() { return tick; }
00042     operator float() { return tick+fraction; }
00043 
00044     // Unary operators
00045     PreciseTimeValue operator-() const;
00046     PreciseTimeValue operator+() const { return *this; }
00047 
00048     // Property functions
00049     int TimeValue() const { return tick; }
00050     float PreciseTime() const { return tick+fraction; }
00051 
00052     // Assignment operators
00053     PreciseTimeValue& operator-=(const PreciseTimeValue&);
00054     PreciseTimeValue& operator-=(const int v) { tick -= v; return *this; }
00055     PreciseTimeValue& operator-=(const float);
00056     PreciseTimeValue& operator+=(const PreciseTimeValue&);
00057     PreciseTimeValue& operator+=(const int v) { tick += v; return *this; }
00058     PreciseTimeValue& operator+=(const float);
00059     PreciseTimeValue& operator*=(const int);
00060     PreciseTimeValue& operator*=(const float);
00061     PreciseTimeValue& operator/=(const float);
00062 
00063     PreciseTimeValue& Set(int t, float f) { tick=t; fraction=f; return *this; }
00064 
00065     // Test for equality
00066     int operator==(const PreciseTimeValue& v) const
00067             { return ((v.tick==tick)&&(v.fraction==fraction)); }
00068     int operator!=(const PreciseTimeValue& v) const
00069             { return ((v.tick!=tick)||(v.fraction!=fraction)); }
00070     int Equals(const PreciseTimeValue& v, float epsilon = 1E-6f) const;
00071     int Equals(int t, float epsilon = 1E-6f) const;
00072     int Equals(float t, float epsilon = 1E-6f) const;
00073     int operator>(const PreciseTimeValue& v) const;
00074     int operator<(const PreciseTimeValue& v) const;
00075     int operator>=(const PreciseTimeValue& v) const;
00076     int operator<=(const PreciseTimeValue& v) const;
00077 
00078     // Binary operators
00079     PreciseTimeValue operator-(const PreciseTimeValue&) const;
00080     PreciseTimeValue operator-(const int) const;
00081     PreciseTimeValue operator-(const float) const;
00082     PreciseTimeValue operator+(const PreciseTimeValue&) const;
00083     PreciseTimeValue operator+(const int) const;
00084     PreciseTimeValue operator+(const float) const;
00085     PreciseTimeValue operator*(const int) const;
00086     PreciseTimeValue operator*(const float) const;
00087     PreciseTimeValue operator/(const float) const;
00088 
00089     // internal use
00090     void AdjustFraction();
00091 };
00092 
00093