warangpsd/TimeData.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of warangpsd.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2011-06-29
00021 **  Authors:
00022 **    Marc Wathelet (ISTerre, Grenoble, France)
00023 **
00024 ***************************************************************************/
00025 
00026 #ifndef TIMEDATA_H
00027 #define TIMEDATA_H
00028 
00029 #include <sys/time.h>
00030 
00031 #include <GpCoreTools.h>
00032 
00033 class TimeData
00034 {
00035 public:
00036   inline TimeData();
00037   inline TimeData(const TimeData& o);
00038 
00039   inline void littleEndianValues();
00040   inline void bigEndianValues();
00041 
00042   inline void currentTime();
00043 
00044   int seconds() const {return _seconds;}
00045   int microSeconds() const {return _microSeconds;}
00046 private:
00047   int _seconds;
00048   int _microSeconds;
00049 };
00050 
00051 inline TimeData::TimeData()
00052 {
00053   _seconds=0;
00054   _microSeconds=0;
00055 }
00056 
00057 inline TimeData::TimeData(const TimeData& o)
00058 {
00059   _seconds=o._seconds;
00060   _microSeconds=o._microSeconds;
00061 }
00062 
00063 inline void TimeData::littleEndianValues()
00064 {
00065   _seconds=ByteOrder::littleEndianToNative(_seconds);
00066   _microSeconds=ByteOrder::littleEndianToNative(_microSeconds);
00067 }
00068 
00069 inline void TimeData::bigEndianValues()
00070 {
00071   _seconds=ByteOrder::bigEndianToNative(_seconds);
00072   _microSeconds=ByteOrder::bigEndianToNative(_microSeconds);
00073 }
00074 
00075 inline void TimeData::currentTime()
00076 {
00077   timeval sysTime;
00078   gettimeofday(&sysTime, 0);
00079   _seconds=(int)sysTime.tv_sec;
00080   _microSeconds=(int)sysTime.tv_usec;
00081 }
00082 
00083 #endif // TIMEDATA_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines