Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

# SbTime.h

    00001 #ifndef COIN_SBTIME_H
    00002 #define COIN_SBTIME_H
    00003
    00004 /**************************************************************************\
    00005  *
    00006  *  This file is part of the Coin 3D visualization library.
    00007  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
    00008  *
    00009  *  This library is free software; you can redistribute it and/or
    00010  *  modify it under the terms of the GNU General Public License
    00011  *  ("GPL") version 2 as published by the Free Software Foundation.
    00012  *  See the file LICENSE.GPL at the root directory of this source
    00013  *  distribution for additional information about the GNU GPL.
    00014  *
    00015  *  For using Coin with software that can not be combined with the GNU
    00016  *  GPL, and for taking advantage of the additional benefits of our
    00017  *  support services, please contact Systems in Motion about acquiring
    00018  *  a Coin Professional Edition License.
    00019  *
    00020  *  See <URL:http://www.coin3d.org> for  more information.
    00021  *
    00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00023  *  <URL:http://www.sim.no>.
    00024  *
    00025 \**************************************************************************/
    00026
    00027 #include <stdio.h>
    00028
    00029 #include <Inventor/system/inttypes.h>
    00030 #include <Inventor/SbBasic.h>
    00031 #include <Inventor/SbString.h>
    00032
    00033 // Avoid problem with Microsoft Visual C++ Win32 API headers (they
    00034 // #define "max" (in 3 different header files, no less)).
    00035 #ifdef max
    00036 #define SBTIME_UNDEF_MAX
    00037 #undef max
    00038 #endif // max
    00039
    00040
    00041 class COIN_DLL_API SbTime {
    00042 public:
    00043   SbTime(void);
    00044   SbTime(const double sec);
    00045   SbTime(const int32_t sec, const long usec);
    00046   SbTime(const struct timeval * const tv);
    00047   static SbTime getTimeOfDay(void);
    00048   void setToTimeOfDay(void);
    00049   static SbTime zero(void);
    00050
    00051   static SbTime max(void);
    00052   static SbTime maxTime(void);
    00053   void setValue(const double sec);
    00054   void setValue(const int32_t sec, const long usec);
    00055   void setValue(const struct timeval * const tv);
    00056   void setMsecValue(const unsigned long msec);
    00057   double getValue(void) const;
    00058   void getValue(time_t & sec, long & usec) const;
    00059   void getValue(struct timeval * tv) const;
    00060   unsigned long getMsecValue(void) const;
    00061   SbString format(const char * const fmt = "%S.%i") const;
    00062   SbString formatDate(const char * const fmt = NULL) const;
    00063   SbBool parsedate(const char * const date);
    00064   friend COIN_DLL_API SbTime operator +(const SbTime & t0, const SbTime & t1);
    00065   friend COIN_DLL_API SbTime operator -(const SbTime & t0, const SbTime & t1);
    00066   SbTime & operator +=(const SbTime & tm);
    00067   SbTime & operator -=(const SbTime & tm);
    00068   SbTime operator-(void) const;
    00069   friend COIN_DLL_API SbTime operator *(const double s, const SbTime & tm);
    00070   friend COIN_DLL_API SbTime operator *(const SbTime & tm, const double s);
    00071   friend COIN_DLL_API SbTime operator /(const SbTime & tm, const double s);
    00072   SbTime & operator *=(const double s);
    00073   SbTime & operator /=(const double s);
    00074   double operator /(const SbTime & tm) const;
    00075   SbTime operator %(const SbTime & tm) const;
    00076   int operator ==(const SbTime & tm) const;
    00077   int operator !=(const SbTime & tm) const;
    00078   SbBool operator <(const SbTime & tm) const;
    00079   SbBool operator >(const SbTime & tm) const;
    00080   SbBool operator <=(const SbTime & tm) const;
    00081   SbBool operator >=(const SbTime & tm) const;
    00082
    00083   void print(FILE * fp) const;
    00084
    00085 private:
    00086   double dtime;
    00087   void addToString(SbString & str, const double val) const;
    00088 };
    00089
    00090 COIN_DLL_API SbTime operator +(const SbTime & t0, const SbTime & t1);
    00091 COIN_DLL_API SbTime operator -(const SbTime & t0, const SbTime & t1);
    00092 COIN_DLL_API SbTime operator *(const double s, const SbTime & tm);
    00093 COIN_DLL_API SbTime operator *(const SbTime & tm, const double s);
    00094 COIN_DLL_API SbTime operator /(const SbTime & tm, const double s);
    00095
    00096 // Avoid problem with Microsoft Win32 API headers (see above).
    00097 // Redefine macro max() back to a definition compatible with what it
    00098 // is in the MSVC header files.
    00099 #ifdef SBTIME_UNDEF_MAX
    00100 #define max(a,b) (((a) > (b)) ? (a) : (b))
    00101 #undef SBTIME_UNDEF_MAX
    00102 #endif // SBTIME_UNDEF_MAX
    00103
    00104 #endif // !COIN_SBTIME_H