9.10.2011 - stable backup commit
This commit is contained in:
83
piincludes.h
83
piincludes.h
@@ -1,29 +1,44 @@
|
||||
#ifndef PIINCLUDES_H
|
||||
#define PIINCLUDES_H
|
||||
|
||||
#if __WIN32__ || __WIN64__
|
||||
#if __WIN32__ || __WIN64__ || WIN32 || WIN64
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if __QNX__
|
||||
#if __QNX__ || __QNXNTO__
|
||||
# define QNX
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
# ifndef QNX
|
||||
# define LINUX
|
||||
# endif
|
||||
# ifndef QNX
|
||||
# define LINUX
|
||||
# endif
|
||||
#endif
|
||||
#if __GNUC__
|
||||
# define CC_GCC
|
||||
#elif _MSC_VER
|
||||
# define CC_VC
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
# ifdef CC_GCC
|
||||
# define typeof __typeof
|
||||
# endif
|
||||
#else
|
||||
# define typeof __typeof__
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#ifdef CC_GCC
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#ifndef QNX
|
||||
# include <cstdio>
|
||||
# include <cstdlib>
|
||||
# include <clocale>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <clocale>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -40,11 +55,10 @@
|
||||
#include <deque>
|
||||
#include <stack>
|
||||
#include <set>
|
||||
|
||||
#ifdef WINDOWS
|
||||
# include <conio.h>
|
||||
# include <windows.h>
|
||||
# include <wincon.h>
|
||||
#include <conio.h>
|
||||
#include <windows.h>
|
||||
#include <wincon.h>
|
||||
#endif
|
||||
|
||||
#define FOREVER for (;;)
|
||||
@@ -71,9 +85,9 @@ using std::set;
|
||||
using std::string;
|
||||
#ifndef QNX
|
||||
using std::wstring;
|
||||
# ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
static locale_t currentLocale_t = 0;
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
typedef std::basic_string<wchar_t> wstring;
|
||||
#endif
|
||||
@@ -103,43 +117,76 @@ public:
|
||||
static piInit __pi_init;
|
||||
static lconv * currentLocale = std::localeconv();
|
||||
|
||||
inline const char * errorString() {return strerror(errno);}
|
||||
|
||||
#ifdef CC_VC
|
||||
inline string errorString() {char buff[1024]; strerror_s(buff, 1024, GetLastError()); return string(buff);}
|
||||
#else
|
||||
inline string errorString() {return string(strerror(errno));}
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
inline int random() {return rand();}
|
||||
# ifdef CC_VC
|
||||
inline double round(const double & v) {return floor(v + 0.5);}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
template<typename Type> inline void piSwap(Type & f, Type & s) {Type t = f; f = s; s = t;}
|
||||
template<typename Type> inline Type piMin(const Type & f, const Type & s) {return (f > s) ? s : f;}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s) {return (f < s) ? s : f;}
|
||||
template<typename Type> inline Type piMin(const Type & f, const Type & s, const Type & t) {return (f < s && f < t) ? f : ((s < t) ? s : t);}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s) {return (f < s) ? s : f;}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s, const Type & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);}
|
||||
template<typename Type> inline Type piClamp(const Type & v, const Type & min, const Type & max) {return (v > max ? max : (v < min ? min : v));}
|
||||
inline ushort letobe_s(ushort v) {return v = (v << 8) | (v >> 8);}
|
||||
inline bool atob(const string & str) { return str == "1" ? true : false;};
|
||||
inline string btos(const bool num) { return num ? "0" : "1";};
|
||||
inline string itos(const int num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%d", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%d", num);
|
||||
#endif
|
||||
return string(ch); };
|
||||
inline string ltos(const long num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%ld", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%ld", num);
|
||||
#endif
|
||||
return string(ch); };
|
||||
inline string uitos(const uint num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%ud", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%ud", num);
|
||||
#endif
|
||||
return string(ch); };
|
||||
inline string ultos(const ulong num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%lud", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%lud", num);
|
||||
#endif
|
||||
return string(ch); };
|
||||
inline string ftos(const float num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%g", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%g", num);
|
||||
#endif
|
||||
return string(ch); };
|
||||
inline string dtos(const double num) {
|
||||
char ch[256];
|
||||
#ifndef CC_VC
|
||||
sprintf(ch, "%g", num);
|
||||
#else
|
||||
sprintf_s(ch, 256, "%g", num);
|
||||
#endif
|
||||
return string(ch); };
|
||||
|
||||
#endif // PIINCLUDES_H
|
||||
|
||||
Reference in New Issue
Block a user