Utils.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2007-2008 Anael Orlinski
00003 *
00004 * This file is part of Panomatic.
00005 *
00006 * Panomatic is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * Panomatic 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
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with Panomatic; if not, write to the Free Software
00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef __utils_h
00022 #define __utils_h
00023 
00024 #ifdef WIN32
00025 #include <vigra/windows.h>
00026 #include <process.h>
00027 #else
00028 //#include <pthread.h>
00029 #include <sys/time.h>
00030 #endif
00031 
00032 #include <zthread/Condition.h>
00033 #include <zthread/FastMutex.h>
00034 #include <zthread/Guard.h>
00035 
00036 
00037 
00038 #define TIMETRACE(TEXT, CODE) { utils::os_TIME t1,t2; utils::os_GetTime(&t1); CODE; \
00039         utils::os_GetTime(&t2); std::cout << TEXT << " took " << utils::os_TimeDiff(&t2,&t1)/1000.0 << " seconds." << std::endl; }
00040 
00041 
00042 namespace utils
00043 {
00044 
00045 //extern "C" {
00046 
00047 #ifdef WIN32
00048 typedef DWORD os_TIME;
00049 #else
00050 typedef struct timeval os_TIME;
00051 #endif
00052 
00053 inline void os_GetTime(os_TIME* time)
00054 {
00055 #ifdef WIN32
00056     *time = GetTickCount();
00057 #else
00058     struct timezone tz;
00059     gettimeofday(time, &tz);
00060 #endif
00061 }
00062 
00063 inline int os_TimeDiff(os_TIME* time1, os_TIME* time2)
00064 {
00065 #ifdef WIN32
00066     return *time1 - *time2;
00067 #else
00068     return (int)((double)time1->tv_sec*1000 + ((double)time1->tv_usec)*1e-3 -
00069                  (double)time2->tv_sec*1000 - ((double)time2->tv_usec)*1e-3);
00070 #endif
00071 }
00072 
00074 unsigned long long getTotalMemory();
00075 
00076 }
00077 
00078 #endif // __utils_h

Generated on Wed Apr 16 01:25:39 2014 for Hugintrunk by  doxygen 1.3.9.1