20.10.2013 - Modified PIObject - virtual debugName() for macro piCoutObj, improved timer measurements and timers on Windows
This commit is contained in:
81
piincludes.h
81
piincludes.h
@@ -39,7 +39,7 @@
|
||||
#define PIP_VERSION_REVISION PIP_VERSION & 0xFF
|
||||
|
||||
//! Suffix of PIP version
|
||||
#define PIP_VERSION_SUFFIX "_r1"
|
||||
#define PIP_VERSION_SUFFIX "_r3"
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
@@ -185,7 +185,6 @@
|
||||
#include <set>
|
||||
#include <map>
|
||||
#ifdef WINDOWS
|
||||
typedef int socklen_t;
|
||||
# include <conio.h>
|
||||
# include <io.h>
|
||||
# include <winsock2.h>
|
||||
@@ -199,6 +198,13 @@
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
# include <iphlpapi.h>
|
||||
typedef int socklen_t;
|
||||
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
extern long long __pi_perf_freq;
|
||||
extern PINtSetTimerResolution setTimerResolutionAddr;
|
||||
inline long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
|
||||
inline void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
|
||||
#else
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
@@ -276,9 +282,6 @@ using std::wstring;
|
||||
#else
|
||||
typedef std::basic_string<wchar_t> wstring;
|
||||
#endif
|
||||
#ifdef HAS_LOCALE
|
||||
static locale_t currentLocale_t = 0;
|
||||
#endif
|
||||
|
||||
/*! \brief Templated function for swap two values
|
||||
* \details Example:\n \snippet piincludes.cpp swap */
|
||||
@@ -339,7 +342,7 @@ template<typename T> inline T piAbs(const T & v) {return (v >= T(0) ? v : -v);}
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp min2 */
|
||||
template<typename T> inline T piMin(const T & f, const T & s) {return (f > s) ? s : f;}
|
||||
template<typename T> inline T piMin(const T & f, const T & s) {return ((f > s) ? s : f);}
|
||||
|
||||
/*! \brief Templated function return minimum of tree values
|
||||
* \details There is some macros:
|
||||
@@ -352,7 +355,7 @@ template<typename T> inline T piMin(const T & f, const T & s) {return (f > s) ?
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp min3 */
|
||||
template<typename T> inline T piMin(const T & f, const T & s, const T & t) {return (f < s && f < t) ? f : ((s < t) ? s : t);}
|
||||
template<typename T> inline T piMin(const T & f, const T & s, const T & t) {return ((f < s && f < t) ? f : ((s < t) ? s : t));}
|
||||
|
||||
/*! \brief Templated function return maximum of two values
|
||||
* \details There is some macros:
|
||||
@@ -365,7 +368,7 @@ template<typename T> inline T piMin(const T & f, const T & s, const T & t) {retu
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp max2 */
|
||||
template<typename T> inline T piMax(const T & f, const T & s) {return (f < s) ? s : f;}
|
||||
template<typename T> inline T piMax(const T & f, const T & s) {return ((f < s) ? s : f);}
|
||||
|
||||
/*! \brief Templated function return maximum of tree values
|
||||
* \details There is some macros:
|
||||
@@ -378,7 +381,7 @@ template<typename T> inline T piMax(const T & f, const T & s) {return (f < s) ?
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp max3 */
|
||||
template<typename T> inline T piMax(const T & f, const T & s, const T & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);}
|
||||
template<typename T> inline T piMax(const T & f, const T & s, const T & t) {return ((f > s && f > t) ? f : ((s > t) ? s : t));}
|
||||
|
||||
/*! \brief Templated function return clamped value
|
||||
* \details Clamped is the not greater than "max" and not lesser than "min" value \n
|
||||
@@ -434,58 +437,14 @@ extern string ifconfigPath;
|
||||
|
||||
class PIInit {
|
||||
public:
|
||||
PIInit() {
|
||||
if (isPIInit) return;
|
||||
isPIInit = true;
|
||||
#ifndef WINDOWS
|
||||
sigset_t ss;
|
||||
sigemptyset(&ss);
|
||||
sigaddset(&ss, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &ss, 0);
|
||||
pthread_sigmask(SIG_BLOCK, &ss, 0);
|
||||
ifconfigPath = "/bin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "/sbin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "/usr/bin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "/usr/sbin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
#endif
|
||||
//piDebug = true;
|
||||
#ifdef HAS_LOCALE
|
||||
//cout << "has locale" << endl;
|
||||
if (currentLocale_t != 0) {
|
||||
freelocale(currentLocale_t);
|
||||
currentLocale_t = 0;
|
||||
}
|
||||
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0);
|
||||
#else
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
|
||||
#endif
|
||||
}
|
||||
~PIInit() {
|
||||
#ifdef WINDOWS
|
||||
WSACleanup();
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
mach_port_deallocate(mach_task_self(), __pi_mac_clock);
|
||||
#endif
|
||||
//if (currentLocale_t != 0) freelocale(currentLocale_t);
|
||||
}
|
||||
PIInit();
|
||||
~PIInit();
|
||||
private:
|
||||
bool fileExists(const string & p) {FILE * f = fopen(p.c_str(), "r"); if (f == 0) return false; fclose(f); return true;}
|
||||
#ifdef WINDOWS
|
||||
HMODULE ntlib;
|
||||
ULONG prev_res;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern PIInit piInit;
|
||||
@@ -680,7 +639,7 @@ private:
|
||||
#define piCout if (piDebug) PICout()
|
||||
|
||||
//! Macro used for conditional (piDebug and PIObject::debug()) output to PICout for subclasses of PIObject
|
||||
#define piCoutObj if (piDebug && debug_) PICout()
|
||||
#define piCoutObj if (piDebug && debug_) PICout() << (PIString("[") + debugName() + " \"" + name() + "\"]")
|
||||
|
||||
class PIMutex;
|
||||
extern PIMutex __PICout_mutex__;
|
||||
@@ -800,6 +759,8 @@ public:
|
||||
PICout operator <<(const float v);
|
||||
|
||||
//! Output operator for <tt>"double"</tt> values
|
||||
|
||||
//! Output operator for pointers
|
||||
PICout operator <<(const double v);
|
||||
|
||||
//! Output operator for \a PICoutSpecialChar values
|
||||
|
||||
Reference in New Issue
Block a user