QxOrm  1.4.9
C++ Object Relational Mapping library
pctimer.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 // vim:tabstop=4:shiftwidth=4:expandtab:
00003 
00004 /*
00005  * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net>
00006  *
00007  * This software is provided 'as-is', without any express or implied
00008  * warranty.  In no event will the authors be held liable for any
00009  * damages arising from the use of this software.
00010  *
00011  * Permission is granted to anyone to use this software for any purpose,
00012  * including commercial applications, and to alter it and redistribute
00013  * it freely, subject to the following restrictions:
00014  *
00015  * 1. The origin of this software must not be misrepresented; you must
00016  *    not claim that you wrote the original software.  If you use this
00017  *    software in a product, an acknowledgement in the product
00018  *    documentation would be appreciated but is not required.
00019  * 2. Altered source versions must be plainly marked as such, and must
00020  *    not be misrepresented as being the original software.
00021  * 3. This notice may not be removed or altered from any source
00022  *    distribution.
00023  *
00024  * This file is part of Stones of Nvwa:
00025  *      http://sourceforge.net/projects/nvwa
00026  *
00027  */
00028 
00040 #ifndef QT_NO_DEBUG
00041 #ifndef _QX_MODE_RELEASE
00042 #if _QX_USE_MEM_LEAK_DETECTION
00043 #ifndef _PCTIMER_H
00044 
00045 namespace qx {
00046 namespace memory {
00047 
00048 typedef double pctimer_t;
00049 
00050 } // namespace memory
00051 } // namespace qx
00052 
00053 #if defined(_WIN32) || defined(__CYGWIN__)
00054 
00055 #ifndef _WIN32
00056 #define _PCTIMER_NO_WIN32
00057 #endif /* _WIN32 */
00058 
00059 #ifndef WIN32_LEAN_AND_MEAN
00060 #define WIN32_LEAN_AND_MEAN
00061 #endif /* WIN32_LEAN_AND_MEAN */
00062 #include <windows.h>
00063 
00064 #ifdef _PCTIMER_NO_WIN32
00065 #undef _PCTIMER_NO_WIN32
00066 #undef _WIN32
00067 #endif /* _PCTIMER_NO_WIN32 */
00068 
00069 namespace qx {
00070 namespace memory {
00071 
00072 __inline pctimer_t pctimer(void)
00073 {
00074     static LARGE_INTEGER __pcount, __pcfreq;
00075     static int __initflag;
00076 
00077     if (!__initflag)
00078     {
00079         QueryPerformanceFrequency(&__pcfreq);
00080         __initflag++;
00081     }
00082 
00083     QueryPerformanceCounter(&__pcount);
00084     return (double)__pcount.QuadPart / (double)__pcfreq.QuadPart;
00085 }
00086 
00087 } // namespace memory
00088 } // namespace qx
00089 
00090 #else /* Not Win32/Cygwin */
00091 
00092 #include <sys/time.h>
00093 
00094 namespace qx {
00095 namespace memory {
00096 
00097 __inline pctimer_t pctimer(void)
00098 {
00099     struct timeval __tv;
00100     gettimeofday(&__tv, NULL);
00101     return (double)__tv.tv_sec + (double)__tv.tv_usec / 1000000;
00102 }
00103 
00104 } // namespace memory
00105 } // namespace qx
00106 
00107 #endif /* Win32/Cygwin */
00108 
00109 #endif /* _PCTIMER_H */
00110 #endif // _QX_USE_MEM_LEAK_DETECTION
00111 #endif // _QX_MODE_RELEASE
00112 #endif // QT_NO_DEBUG