29.07.2011 - fundamental new

This commit is contained in:
peri4
2011-07-29 08:17:24 +04:00
parent b21a0496cd
commit 29190ea465
49 changed files with 4704 additions and 1052 deletions

View File

@@ -7,33 +7,48 @@
#if __QNX__
# define QNX
#endif
#ifndef WINDOWS
# ifndef QNX
# define LINUX
# endif
#endif
#include <iostream>
#include <unistd.h>
#include <stdarg.h>
#include <stddef.h>
#ifndef QNX
# include <cstdio>
# include <cstdlib>
# include <cstdio>
# include <cstdlib>
# include <clocale>
#else
# include <stdio.h>
# include <stdlib.h>
# include <stdio.h>
# include <locale.h>
#endif
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <cctype>
#include <typeinfo>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <list>
#include <queue>
#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 (;;)
#define FOREVER_WAIT FOREVER msleep(10);
#define FOREVER_WAIT FOREVER msleep(1);
typedef long long llong;
typedef unsigned char uchar;
@@ -49,60 +64,46 @@ using std::endl;
using std::flush;
using std::vector;
using std::list;
using std::queue;
using std::deque;
using std::stack;
using std::set;
using std::string;
#ifndef QNX
using std::wstring;
# ifndef WINDOWS
static locale_t currentLocale_t = 0;
# endif
#else
typedef std::basic_string<wchar_t> wstring;
#endif
template<typename Type, typename Allocator = std::allocator<Type> >
class PIVector: public vector<Type, Allocator> {
static bool isPIInit = false;
class piInit {
public:
inline const Type & at(uint index) const {return (*this)[index];}
inline Type & at(uint index) {return (*this)[index];}
inline const Type * data(uint index = 0) const {return &(*this)[index];}
inline Type * data(uint index = 0) {return &(*this)[index];}
inline void fill(const Type & t) {vector<Type, Allocator>::assign(vector<Type, Allocator>::size(), t);}
inline void pop_front() {vector<Type, Allocator>::erase(vector<Type, Allocator>::begin());}
inline void push_front(const Type & t) {vector<Type, Allocator>::insert(vector<Type, Allocator>::begin(), t);}
inline void remove(uint num) {vector<Type, Allocator>::erase(vector<Type, Allocator>::begin() + num);}
inline void remove(uint num, uint count) {vector<Type, Allocator>::erase(vector<Type, Allocator>::begin() + num, vector<Type, Allocator>::begin() + num + count);}
inline void insert(uint pos, const Type & t) {vector<Type, Allocator>::insert(vector<Type, Allocator>::begin() + pos, t);}
piInit() {
if (isPIInit) return;
isPIInit = true;
#ifdef LINUX
if (currentLocale_t != 0) {
freelocale(currentLocale_t);
currentLocale_t = 0;
}
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0);
#else
setlocale(LC_ALL, "");
#endif
}
~piInit() {
//if (currentLocale_t != 0) freelocale(currentLocale_t);
}
};
template<typename Type, typename Allocator = std::allocator<Type> >
class PIList: public list<Type, Allocator> {
public:
inline const Type * data(uint index = 0) const {return &(*this)[index];}
inline Type * data(uint index = 0) {return &(*this)[index];}
inline void fill(const Type & t) {list<Type, Allocator>::assign(list<Type, Allocator>::size(), t);}
inline void remove(uint num) {list<Type, Allocator>::erase(list<Type, Allocator>::begin() + num);}
inline void remove(uint num, uint count) {list<Type, Allocator>::erase(list<Type, Allocator>::begin() + num, list<Type, Allocator>::begin() + num + count);}
inline void insert(uint pos, const Type & t) {list<Type, Allocator>::insert(list<Type, Allocator>::begin() + pos, t);}
};
static piInit __pi_init;
static lconv * currentLocale = std::localeconv();
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 const char * errorString() {return strerror(errno);}
#ifdef WINDOWS
inline int random() {return rand();}
@@ -113,6 +114,7 @@ template<typename Type> inline Type piMin(const Type & f, const Type & s) {retur
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, const Type & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);}
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) {