Files
pip/piincludes.h
2010-11-30 08:11:27 +03:00

113 lines
3.3 KiB
C++

#ifndef PIINCLUDES_H
#define PIINCLUDES_H
#if __WIN32__ || __WIN64__
# define WINDOWS
#endif
#if __QNX__
# define QNX
#endif
#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <string>
#include <vector>
#include <list>
#include <deque>
#ifdef WINDOWS
#include <conio.h>
#include <windows.h>
#include <wincon.h>
#endif
#define FOREVER for (;;)
#define FOREVER_WAIT FOREVER msleep(10);
typedef long long llong;
typedef unsigned char uchar;
typedef unsigned short int ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ullong;
using std::cout;
using std::cin;
using std::endl;
using std::flush;
using std::vector;
using std::list;
using std::deque;
using std::string;
template<typename Enum>
class Flags {
private:
int flags;
public:
inline Flags(): flags(0) {;}
inline Flags(Enum e): flags(e) {;}
inline Flags(const Flags & f): flags(f.flags) {;}
inline Flags(const int i): flags(i) {;}
inline void operator =(const Flags & f) {flags = f.flags;}
inline void operator |=(const Flags & f) {flags = flags | f.flags;}
inline void operator |=(const Enum & e) {flags = flags | e;}
inline void operator |=(const int i) {flags = flags | i;}
inline void operator &=(const Flags & f) {flags = flags & f.flags;}
inline void operator &=(const Enum & e) {flags = flags & e;}
inline void operator &=(const int i) {flags = flags & i;}
inline Flags & operator |(Flags f) const {Flags tf(flags | f.flags); return tf;}
inline Flags & operator |(Enum e) const {Flags tf(flags | e); return tf;}
inline Flags & operator |(int i) const {Flags tf(flags | i); return tf;}
inline Flags & operator &(Flags f) const {Flags tf(flags & f.flags); return tf;}
inline Flags & operator &(Enum e) const {Flags tf(flags & e); return tf;}
inline Flags & operator &(int i) const {Flags tf(flags & i); return tf;}
inline bool operator [](Enum e) {return (flags & e) == e;}
inline operator int() const {return flags;}
};
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];
sprintf(ch, "%d", num);
return string(ch); };
inline string ltos(const long num) {
char ch[256];
sprintf(ch, "%ld", num);
return string(ch); };
inline string uitos(const uint num) {
char ch[256];
sprintf(ch, "%ud", num);
return string(ch); };
inline string ultos(const ulong num) {
char ch[256];
sprintf(ch, "%lud", num);
return string(ch); };
inline string ftos(const float num) {
char ch[256];
sprintf(ch, "%g", num);
return string(ch); };
inline string dtos(const double num) {
char ch[256];
sprintf(ch, "%g", num);
return string(ch); };
inline string s_left(const string & str, int len) {return str.substr(0, len);};
inline string s_right(const string & str, int len) {return str.size() < len ? str : str.substr(str.size() - len, len);};
inline string s_trimmed(const string & str) {
int st = 0, fn = 0;
for (int i = 0; i < str.size(); ++i)
if (str[i] != ' ' && str[i] != '\t')
{st = i; break;}
for (int i = str.size() - 1; i >= 0; --i)
if (str[i] != ' ' && str[i] != '\t')
{fn = i; break;}
return str.substr(st, fn - st + 1);
};
#endif // PIINCLUDES_H