Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglTimespec.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglTimespec.hpp
00021  *  Created: 1 June 2001
00022  *  Summary: Cross platform timing
00023  *****************************************************************************/
00024 
00025 #ifndef __SGL_TIMESPEC_HPP
00026 #define __SGL_TIMESPEC_HPP
00027 
00028 #include <sgl.h>
00029 #include <time.h>
00030 
00031 //----------------------------------------------------------------------------
00032 
00033 class SGL_DLL_API sglTimespec
00034 {
00035 public:
00036    sglTimespec() : m_sec(0), m_nsec(0) {}
00037    sglTimespec(time_t sec, long nsec) : m_sec(sec), m_nsec(nsec) {}
00038    sglTimespec(const sglTimespec &rhs) : m_sec(rhs.m_sec), m_nsec(rhs.m_nsec){}
00039    sglTimespec(double sec) : m_sec((time_t)sec), m_nsec(0)
00040       {
00041          m_nsec = (long)(fabs(sec - m_sec)*1000000000);
00042       }
00043    ~sglTimespec() {}
00044 
00045    sglTimespec &operator=(const sglTimespec &rhs)
00046       {
00047          m_sec = rhs.m_sec; m_nsec = rhs.m_nsec; return *this;
00048       }
00049 
00050    sglTimespec& operator+=(const sglTimespec& rhs);
00051    sglTimespec& operator-=(const sglTimespec& rhs);
00052 
00053    bool operator<(const sglTimespec& rhs)
00054       {
00055          if (m_sec < rhs.m_sec)
00056             return true;
00057          else if (m_sec > rhs.m_sec)
00058             return false;
00059          else if (m_nsec < rhs.m_nsec) // m_sec == rhs.m_sec in this case
00060             return true;
00061 
00062          return false;
00063       }
00064 
00065    const sglTimespec operator+(const sglTimespec& rhs) const;
00066    const sglTimespec operator-(const sglTimespec& rhs) const;
00067 
00068    static double convertToDouble(const sglTimespec &ts)
00069       { return ((double)ts.m_sec) + (1.0e-9*((double)ts.m_nsec)); }
00070 
00071    static void getSysTime(sglTimespec &ts);
00072 
00073 public:
00074    long m_sec;
00075    long m_nsec;
00076 };
00077 
00078 // *************************************************************************
00079 SGL_DLL_API
00080 ostream& operator<<(ostream& strm, const sglTimespec& rhs);
00081 
00082 #endif

Generated at Mon Jul 1 18:00:06 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001