00001
00002
00003 #ifndef __H_STANDARD_H_
00004 #define __H_STANDARD_H_
00005
00006 #include <sstream>
00007
00008 #include <string>
00009 #include <iostream>
00010 #include <fstream>
00011
00012 #include <vector>
00013 #include <list>
00014 #include <map>
00015
00016 using namespace std;
00017
00018 #define H_DUMP(filename,text) {ofstream out_err(filename,ios::out); out_err<<text; out_err.close();}
00019 extern ofstream log_file;
00020
00021
00022 #ifndef PI
00023 #define PI 3.14159265358979323846f
00024 #endif
00025
00026 typedef float REAL;
00027 #define H_EPSILON 0.000001f
00028
00029
00030 #define LIMIT(a,b,c) (((a)>(b)) ? (a) : (((b)>(c)) ? (c) : (b)))
00031 #define ABS(x) (((x)>=0) ? (x) : -(x))
00032 #define H_MIN(a,b) (((a)>(b)) ? (b) : (a))
00033 #define H_MAX(a,b) (((a)>(b)) ? (a) : (b))
00034
00035 #define ARRAY_SIZE(T) (sizeof(T)/sizeof(T[0]))
00036
00037 using namespace std;
00038
00039 class HException : public exception
00040 {
00041 public:
00042 HException(const string &s) throw();
00043 virtual ~HException() throw();
00044 virtual const char *what() const throw();
00045 private:
00046 string s;
00047 };
00048
00049 string PathOf(const string &AString);
00050 string TitleOf(const string &AString);
00051 void OpenDataFile(ifstream &infile, const char *FileName);
00052 istream &EatWhite(istream &in);
00053
00054 template <class T> string to_string(T x)
00055 {
00056 stringstream tmp;
00057 tmp << x;
00058 return tmp.str();
00059 }
00060
00061 template <class T> class HPointer
00062 {
00063 private:
00064 class Ref
00065 {
00066 public:
00067 Ref() : ptr(NULL) {}
00068 void reset(T* Aptr) {ptr=Aptr;count=1;}
00069 ~Ref() {delete ptr;}
00070 public:
00071 T* ptr;
00072 unsigned int count;
00073 };
00074 static list<Ref> RefList;
00075 typename list<Ref>::iterator pos;
00076 public:
00077 HPointer() {AddRef(NULL);}
00078 HPointer(T *ptr) {AddRef(ptr);}
00079 HPointer(const HPointer &Hptr) {pos=Hptr.pos; (*pos).count++;}
00080 T* c_ptr() const {return (*pos).ptr;}
00081 operator T *() const {return c_ptr();}
00082 T *operator = (T *ptr) {UnRef(); AddRef(ptr); return c_ptr();}
00083 HPointer &operator = (const HPointer &Hptr)
00084 {UnRef(); pos=Hptr.pos; (*pos).count++; return *this;}
00085 ~HPointer() {UnRef();}
00086
00087 private:
00088 void AddRef(T* ptr)
00089 {RefList.push_front(Ref()); pos = RefList.begin(); (*pos).reset(ptr);}
00090 void UnRef() {if ((--(*pos).count)==0) RefList.erase(pos);}
00091 };
00092
00093 class Command
00094 {
00095 public:
00096 Command();
00097 Command(const string &AString);
00098 bool IsIn(const char *AArgument) const;
00099 int FindArg(const char *AArgument) const;
00100 const string &operator[] (unsigned int i) const;
00101 unsigned int size() const;
00102
00103 friend istream &operator>> (istream &in, Command &A);
00104 private:
00105 vector<string> data;
00106 };
00107
00108 #endif //__H_STANDARD_H_