AXCEL C++ Framework
Elegance through abstraction
|
00001 00030 #ifndef AXCEL 00031 #define AXCEL 00032 #include <cstdio> 00033 #include <cstdlib> 00034 #include <cstring> 00035 #include <cstdarg> 00036 #include <cmath> 00037 #include <climits> 00038 #include <cctype> 00039 #include <deque> 00040 00041 #ifdef _WIN32 00042 #define _WIN32_WINNT 0x0600 00043 #define WINVER 0x0600 00044 #define WIN32_LEAN_AND_MEAN 00045 #define popen _popen 00046 #define pclose _pclose 00047 #include <windows.h> 00048 #include <winsock2.h> 00049 #include <ws2tcpip.h> 00050 #include <conio.h> 00051 #include <io.h> 00052 #include <fcntl.h> 00053 #include <tlhelp32.h> 00054 #include <errno.h> 00055 00056 #undef min 00057 #include <time.h> 00058 #else 00059 #include <errno.h> 00060 #include <ctime> 00061 #include <sys/types.h> 00062 #include <sys/stat.h> 00063 #include <sys/wait.h> 00064 #include <fcntl.h> 00065 #include <sys/ioctl.h> 00066 #include <poll.h> 00067 #include <unistd.h> 00068 #include <dirent.h> 00069 #include <sys/socket.h> 00070 #include <netdb.h> 00071 #include <arpa/inet.h> 00072 #include <termios.h> 00073 #include <wordexp.h> 00074 00075 #include <signal.h> 00076 #include <pthread.h> 00077 #include <semaphore.h> 00078 00079 #include <dlfcn.h> 00080 #endif 00081 00082 #define use using namespace 00083 00084 #define unless(x) if (!(x)) 00085 00086 #define until(x) while (!(x)) 00087 00088 #define loop() for (;;) 00089 00090 #define crap(...)\ 00091 if (1) {\ 00092 fprintf(stderr, __VA_ARGS__);\ 00093 return;} 00094 00095 #define craps(x, ...) \ 00096 if (1) {\ 00097 fprintf(stderr, __VA_ARGS__);\ 00098 return x; } 00099 00100 #define warn(...) \ 00101 fprintf(stderr, __VA_ARGS__); 00102 00103 typedef unsigned char uchar; 00104 typedef unsigned short ushort; 00105 typedef unsigned int uint; 00106 typedef unsigned long ulong; 00107 00108 template <typename T> 00109 inline bool gt(T a, T b) { return a > b; } 00110 00111 template <typename T> 00112 inline bool lt(T a, T b) { return a < b; } 00113 00114 template <typename T> 00115 inline bool eq(T a, T b) { return a == b; } 00116 00117 template <typename T> 00118 inline bool gte(T a, T b) { return a >= b; } 00119 00120 template <typename T> 00121 inline bool lte(T a, T b) { return a <= b; } 00122 00123 template <typename T> 00124 inline bool neq(T a, T b) { return a != b; } 00125 00149 char* strcpy2(char* s1, const char* s2); 00150 char* strncpy2(char* s1, const char* s2, size_t n); 00151 00152 const char* strstrs(const char* src, ...); 00153 00154 int strstrc(const char* src, ...); 00155 00157 namespace axcel { 00158 class object; 00159 class data; 00160 class string; 00161 class console; 00162 class exception; 00163 00165 namespace io { 00166 class iob; 00167 class iofmt; 00168 class input; 00169 class output; 00170 class ios; 00171 }; 00172 00174 namespace fs { 00175 class file; 00176 }; 00177 00179 namespace proc { 00181 class thread; 00182 class mutex; 00183 class semaphore; 00185 class pstream; 00187 class library; 00189 class environment; 00190 }; 00191 00193 namespace net { 00195 class ipaddr; 00197 class dgram; 00198 00199 00214 namespace socket { 00216 class tcp; 00218 class udp; 00219 }; 00221 namespace irc { 00223 class msg; 00224 }; 00226 namespace http { 00228 class field; 00230 class request; 00232 class header; 00234 class response; 00236 class query; 00237 }; 00238 }; 00239 00240 00249 class object { 00250 protected: int errnum; 00251 public: 00252 object() { errnum = 0; } 00253 00257 virtual string type() = 0; 00258 00262 virtual operator string () = 0; 00263 00267 string tostr(); 00268 00272 exception error(); 00273 00274 }; 00275 00276 namespace io { 00279 class iofmt : virtual public object { 00280 public: 00281 virtual string type(); 00282 virtual operator string (); 00283 size_t width; 00284 size_t precis; 00285 iofmt(); 00286 bool bin(int i = -1); 00287 bool btoa(int i = -1); 00288 bool base(int i = -1); 00289 bool zpad(int i = -1); 00290 bool sign(int i = -1); 00291 bool deaf(int i = -1); 00292 bool dec(int i = -1); 00293 bool hex(int i = -1); 00294 bool oct(int i = -1); 00295 bool ltrim(int i = -1); 00296 bool endnl(int i = -1); 00297 bool left(int i = -1); 00298 bool right(int i = -1); 00299 bool fix(int i = -1); 00300 bool sci(int i = -1); 00301 private: 00302 bool gsbit(int i, long j); 00303 long lfmt; 00304 }; 00305 00308 class iob : virtual public object { 00309 public: 00310 virtual string type(); 00311 virtual operator string (); 00312 //io::iob* knot; 00313 iob() { /*knot = 0;*/ istat = 0; heal(); } 00314 iofmt fmt; 00315 bool ok(); 00316 bool hurt(); 00317 bool dead(); 00318 bool eof(); 00319 void heal(); 00320 void hit(); 00321 void kill(); 00322 void drain(); 00323 private: 00324 int istat; 00325 }; 00326 00329 class input : virtual public iob { 00330 public: 00331 virtual string type(); 00332 00344 virtual int getc() = 0; 00345 virtual char* gets(char* s, int size = 0); 00346 virtual string gets(int size = 0); 00347 virtual int scanf(const char* format, ...); 00348 virtual size_t read(char* ptr, size_t size, size_t nmemb); 00349 virtual data read(size_t size, size_t nmemb); 00350 virtual data dump(); 00351 virtual string drink(const char* eol = 0); 00352 virtual data suck(const char* eol, size_t len = 0); 00353 input& operator>> (bool& val); 00354 input& operator>> (short& val); 00355 input& operator>> (unsigned short& val); 00356 input& operator>> (int& val); 00357 input& operator>> (unsigned int& val); 00358 input& operator>> (long& val); 00359 input& operator>> (unsigned long& val); 00360 input& operator>> (long long& val); 00361 input& operator>> (unsigned long long& val); 00362 input& operator>> (float& val); 00363 input& operator>> (double& val); 00364 input& operator>> (long double& val); 00365 input& operator>> (void*& val); 00366 input& operator>> (char& c); 00367 input& operator>> (char* s); 00368 input& operator>> (string& s); 00369 private: 00370 char* in_fmt(char* s, char d, char m); 00371 }; 00372 00375 class output : virtual public iob { 00376 public: 00377 virtual string type(); 00378 00389 virtual int putc(int c) = 0; 00390 virtual int puts(const char* s); 00391 virtual int printf(const char* format, ...); 00392 virtual size_t write(const char* ptr, size_t size, size_t nmemb); 00393 virtual size_t write(data d); 00394 output& operator<< (object& o); 00395 output& operator<< (bool val); 00396 output& operator<< (short val); 00397 output& operator<< (unsigned short val); 00398 output& operator<< (int val); 00399 output& operator<< (unsigned int val); 00400 output& operator<< (long val); 00401 output& operator<< (unsigned long val); 00402 output& operator<< (float val); 00403 output& operator<< (double val); 00404 output& operator<< (long double val); 00405 output& operator<< (const void* val); 00406 output& operator<< (char c); 00407 output& operator<< (signed char c); 00408 output& operator<< (unsigned char c); 00409 output& operator<< (const char* s); 00410 output& operator<< (string s); 00411 output& put(object& o); 00412 inline output& put(bool val) { return operator<<(val); } 00413 inline output& put(short val) { return operator<<(val); } 00414 inline output& put(unsigned short val) { return operator<<(val); } 00415 inline output& put(int val) { return operator<<(val); } 00416 inline output& put(long val) { return operator<<(val); } 00417 inline output& put(unsigned long val) { return operator<<(val); } 00418 inline output& put(float val) { return operator<<(val); } 00419 inline output& put(double val) { return operator<<(val); } 00420 inline output& put(long double val) { return operator<<(val); } 00421 inline output& put(const void* val) { return operator<<(val); } 00422 inline output& put(char c) { return operator<<(c); } 00423 inline output& put(signed char c) { return operator<<(c); } 00424 inline output& put(unsigned char c) { return operator<<(c); } 00425 inline output& put(const char* s) { return operator<<(s); } 00426 output& echo(object& o); 00427 inline output& echo() { putc('\n'); return *this; } 00428 inline output& echo(bool val) { operator<<(val); putc('\n'); return *this; } 00429 inline output& echo(short val) { operator<<(val); putc('\n'); return *this; } 00430 inline output& echo(unsigned short val) { operator<<(val); putc('\n'); return *this; } 00431 inline output& echo(int val) { operator<<(val); putc('\n'); return *this; } 00432 inline output& echo(size_t val) { operator<<(val); putc('\n'); return *this; } 00433 inline output& echo(long val) { operator<<(val); putc('\n'); return *this; } 00434 inline output& echo(unsigned long val) { operator<<(val); putc('\n'); return *this; } 00435 inline output& echo(float val) { operator<<(val); putc('\n'); return *this; } 00436 inline output& echo(double val) { operator<<(val); putc('\n'); return *this; } 00437 inline output& echo(long double val) { operator<<(val); putc('\n'); return *this; } 00438 inline output& echo(const void* val) { operator<<(val); putc('\n'); return *this; } 00439 inline output& echo(char c) { operator<<(c); putc('\n'); return *this; } 00440 inline output& echo(signed char c) { operator<<(c); putc('\n'); return *this; } 00441 inline output& echo(unsigned char c) { operator<<(c); putc('\n'); return *this; } 00442 inline output& echo(const char* s) { operator<<(s); putc('\n'); return *this; } 00443 output& put(string s); 00444 output& echo(string s); 00445 00446 private: 00447 char* out_fmt(char* s, char t, const char* m); 00448 }; 00449 00457 class ios : virtual public input, virtual public output { 00458 public: 00459 string type(); 00460 operator string(); 00461 ios& operator<< (object& o); 00462 ios& operator<< (bool val); 00463 ios& operator<< (short val); 00464 ios& operator<< (unsigned short val); 00465 ios& operator<< (int val); 00466 ios& operator<< (unsigned int val); 00467 ios& operator<< (long val); 00468 ios& operator<< (unsigned long val); 00469 ios& operator<< (float val); 00470 ios& operator<< (double val); 00471 ios& operator<< (long double val); 00472 ios& operator<< (const void* val); 00473 ios& operator<< (char c); 00474 ios& operator<< (signed char c); 00475 ios& operator<< (unsigned char c); 00476 ios& operator<< (const char* s); 00477 ios& operator<< (string s); 00478 ios& put(object& o); 00479 ios& put(string s); 00480 ios& echo(object& o); 00481 ios& echo(string s); 00482 ios& put(bool val); 00483 ios& put(short val); 00484 ios& put(unsigned short val); 00485 ios& put(int val); 00486 ios& put(long val); 00487 ios& put(unsigned long val); 00488 ios& put(float val); 00489 ios& put(double val); 00490 ios& put(long double val); 00491 ios& put(const void* val); 00492 ios& put(char c); 00493 ios& put(signed char c); 00494 ios& put(unsigned char c); 00495 ios& put(const char* s); 00496 ios& echo(); 00497 ios& echo(bool val); 00498 ios& echo(short val); 00499 ios& echo(unsigned short val); 00500 ios& echo(int val); 00501 ios& echo(size_t val); 00502 ios& echo(long val); 00503 ios& echo(unsigned long val); 00504 ios& echo(float val); 00505 ios& echo(double val); 00506 ios& echo(long double val); 00507 ios& echo(const void* val); 00508 ios& echo(char c); 00509 ios& echo(signed char c); 00510 ios& echo(unsigned char c); 00511 ios& echo(const char* s); 00512 ios& operator>> (bool& val); 00513 ios& operator>> (short& val); 00514 ios& operator>> (unsigned short& val); 00515 ios& operator>> (int& val); 00516 ios& operator>> (unsigned int& val); 00517 ios& operator>> (long& val); 00518 ios& operator>> (unsigned long& val); 00519 ios& operator>> (long long& val); 00520 ios& operator>> (unsigned long long& val); 00521 ios& operator>> (float& val); 00522 ios& operator>> (double& val); 00523 ios& operator>> (long double& val); 00524 ios& operator>> (void*& val); 00525 ios& operator>> (char& c); 00526 ios& operator>> (char* s); 00527 ios& operator>> (string& s); 00528 }; 00529 00530 } 00531 00536 class data : virtual public io::ios { 00537 protected: 00538 size_t pos, mlen, slen; 00539 public: 00540 char* buf; 00541 00543 virtual string type(); 00544 00550 virtual operator string (); 00551 data(const data& d); 00552 char& operator [](int i); 00553 data& operator= (const char* s); 00554 data& operator= (object& o); 00555 data& operator= (data d); 00556 bool operator== (data d); 00557 bool operator== (const char* s); 00558 bool operator== (object& o); 00559 bool operator!= (data d); 00560 bool operator!= (const char* s); 00561 bool operator!= (object& o); 00562 data(); 00563 ~data(); 00564 virtual int getc(); 00565 virtual int putc(int c); 00566 virtual bool seek(long offset, int whence); 00567 virtual size_t tell(); 00568 virtual void rewind(); 00569 virtual void unwind(); 00570 virtual bool ffwd(size_t offset); 00571 virtual bool prev(size_t offset); 00572 virtual size_t len() const; 00573 virtual void realloc(size_t n); 00574 virtual operator void* () { return (void*)buf; } 00575 virtual operator char* () { return buf; } 00576 }; 00577 00586 class string : virtual public data { 00587 public: 00588 virtual string type(); 00589 virtual operator string (); 00590 string(); 00591 string(const char* s); 00592 string(size_t n); 00593 string(const string& s); 00594 string(const data& s); 00595 ~string(); 00596 int getc(); 00597 int putc(int c); 00598 string& clear(); 00599 bool empty(); 00600 size_t len(); 00601 size_t msize() const; 00602 string cat(const char* s, size_t n = 0); 00603 string cat(int c, size_t n = 1); 00604 string prep(const char* s, size_t n = 0); 00605 string prep(int c, size_t n = 1); 00606 long chr(int c, size_t index = 0); 00607 long rchr(int c); 00608 long str(const char* s, size_t index = 0); 00609 long rstr(const char* s); 00610 bool starts(const char* s); 00611 bool starts(int c); 00612 bool ends(const char* s); 00613 bool ends(int c); 00614 bool is(const char* s); 00615 bool is(int c); 00616 string cpy(const char* src, size_t index = 0, size_t count = 0); 00617 string cpy(int c, size_t index = 0, size_t count = 1); 00618 //string ncpy(const char* src, size_t n = 0, size_t index = 0); 00619 size_t spn(const char* accept, size_t index = 0); 00620 size_t spn(int c, size_t index = 0); 00621 size_t cspn(const char* reject, size_t index = 0); 00622 size_t cspn(int c, size_t index = 0); 00623 string fry(); 00624 long pbrk(const char* accept, size_t index = 0); 00625 long rpbrk(const char* accept, size_t index = 0); 00626 string substr(size_t start, size_t count); 00627 string tok(size_t index, const char* delim = " "); 00628 string tok(size_t index, int delim); 00629 size_t ntok(const char* delim = " "); 00630 size_t ntok(int delim); 00631 long itok(size_t index, const char* delim = " "); 00632 long itok(size_t index, int delim); 00633 std::deque<axcel::string> split(const char* delim = " "); 00634 std::deque<axcel::string> split(int delim); 00635 string wrap(size_t len, const char* eol = "\r\n"); 00636 string left(size_t n); 00637 string right(size_t n); 00638 size_t nchr(int ch); 00639 size_t nstr(const char* str); 00640 string rep(const char* oldstr, const char* newstr); 00641 string rep(int oldc, int newc); 00642 string ins(size_t index, const char* str); 00643 string ins(size_t index, int c); 00644 string rm(size_t index, size_t n); 00645 string rev(size_t start = 0, size_t count = 0); 00646 string dup(int i); 00647 string ror(size_t i = 1, size_t index = 0, size_t count = 0); 00648 string rol(size_t i = 1, size_t index = 0, size_t count = 0); 00649 string shl(size_t n = 1); 00650 string shr(size_t n = 1); 00651 string lc(size_t start = 0, size_t count = 0); 00652 string uc(size_t start = 0, size_t count = 0); 00653 string q(); 00654 string qq(); 00655 string qx(); 00656 char& front(); 00657 char& back(); 00658 string esc(const char* format, int (*charfilter)(int) = NULL); 00659 string esc(const char* format, const char* chrs); 00660 string uesc(const char* format, int (*charfilter)(int) = NULL); 00661 string uesc(const char* format, const char* chrs); 00662 string untag(int opentag = '<', int closetag = '>'); 00663 //string htmlesc(); 00664 //string htmluesc(); 00665 string ltrim(); 00666 string rtrim(); 00667 string strip(); 00668 string chop(); 00669 string chomp(const char* eat = "\r\n"); 00670 string chomp(char eat); 00671 string cut(); 00672 string munch(const char* eat); 00673 string munch(char eat); 00674 string prefix(const char* str); 00675 string suffix(const char* str); 00676 00684 inline string slurp(char c) { return shl(chr(c) + 1); } 00685 00693 inline string rslurp(char c) { return shl(rchr(c) + 1); } 00694 00702 inline string burn(char c) { if (chr(c) > -1) return shr(len() - chr(c)); else return *this; } 00703 00711 inline string rburn(char c) { if (chr(c) > -1) return shr(len() - rchr(c)); else return *this; } 00712 00720 inline string slurp(const char* s) { return shl(str(s) + strlen(s)); } 00721 00729 inline string rslurp(const char* s) { return shl(rstr(s) + strlen(s)); } 00730 00738 inline string burn(const char* s) { if (str(s) > -1) return shr(len() - str(s)); else return *this; } 00739 00747 inline string rburn(const char* s) { if (str(s) > -1) return shr(len() - rstr(s)); else return *this; } 00748 string& swap(string& s); 00749 string center(size_t newlen, const char* left, const char* right); 00750 string center(size_t newlen, int left, int right); 00751 string center(size_t newlen, const char* pad = " "); 00752 string center(size_t newlen, int pad); 00753 string lpad(size_t newlen, const char* pad = " "); 00754 string lpad(size_t newlen, int pad); 00755 string rpad(size_t newlen, const char* pad = " "); 00756 string rpad(size_t newlen, int pad); 00757 string squeeze(const char* chrs = 0); 00758 string squeeze(int chr); 00759 string alnums(); 00760 string alphas(); 00761 string cntrls(); 00762 string digits(); 00763 string graphs(); 00764 string lowers(); 00765 string prints(); 00766 string puncts(); 00767 string spaces(); 00768 string uppers(); 00769 string xdigits(); 00770 string ctypes(int (*cfunc)(int)); 00771 string ctypes(const char* chrs); 00772 bool isalnum(); 00773 bool isalpha(); 00774 bool iscntrl(); 00775 bool isdigit(); 00776 bool isgraph(); 00777 bool islower(); 00778 bool isprint(); 00779 bool ispunct(); 00780 bool isspace(); 00781 bool isupper(); 00782 bool isxdigit(); 00783 bool isctype(int (*cfunc)(int)); 00784 bool isctype(const char* chrs); 00785 string inc(); 00786 string dec(); 00787 string incn(); 00788 string decn(); 00789 string add(int n); 00790 string add(const char* s); 00791 string sub(int n); 00792 string sub(const char* s); 00793 string addn(int n); 00794 string addn(const char* s); 00795 string subn(int n); 00796 string subn(const char* s); 00797 unsigned short cksum(); 00798 int cmpstr(const char* s, ...); 00799 int cmpinstr(const char* s, ...); 00800 int cmpleft(const char* s, ...); 00801 int cmpright(const char* s, ...); 00802 string& operator =(string s); 00803 string& operator =(const char* s); 00804 string& operator =(const data& d); 00805 //string& operator =(char c); 00806 string operator +(const char* str); 00807 string operator +(char c); 00808 string& operator +=(const char* str); 00809 string& operator +=(char c); 00810 string operator -(const char* str); 00811 string operator -(char c); 00812 string& operator -=(const char* str); 00813 string& operator -=(char c); 00814 bool operator ==(const char* s); 00815 bool operator ==(char c); 00816 bool operator !=(const char* s); 00817 bool operator !=(char c); 00818 char& operator [](int i); 00819 string operator *(int i); 00820 string& operator *=(int i); 00821 string operator ()(); 00822 operator const char*() { return buf; } 00823 operator char*() { return buf; } 00824 string& operator ++(); 00825 string operator ++(int foo); 00826 string& operator --(); 00827 string operator --(int foo); 00828 }; 00829 00839 class fs::file : virtual public io::ios { 00840 public: 00841 virtual string type(); 00842 virtual operator string (); 00843 bool operator! (); 00844 FILE* fd; 00845 file() {} 00846 file(const char* name, const char* mode); 00847 file(FILE* f); 00848 file(int fh, const char* mode); 00849 int putc(int c); 00850 int getc(); 00851 //string gets(int size = 0); 00852 FILE* open(const char* fname, const char* mode); 00853 FILE* dopen(int fh, const char* mode); 00854 FILE* reopen(const char* fname, const char* mode); 00855 bool close(); 00856 bool flush(); 00857 bool seek(long offset, int whence); 00858 long tell(); 00859 bool rewind(); 00860 bool unwind(); 00861 bool ffwd(long offset); 00862 bool prev(long offset); 00863 bool nobuf(); 00864 bool lbuf(); 00865 bool fbuf(char* buf, size_t size); 00866 int ungetc(int c); 00867 operator FILE*() { return fd; } 00868 private: 00869 string filename; 00870 }; 00871 00873 class net::ipaddr : virtual public object { 00874 private: 00875 bool cmp(const char* s, struct in_addr * ia4, struct in6_addr * ia6, int op); 00876 #ifdef _WIN32 00877 void initwsa(); 00878 #endif 00879 public: 00880 virtual string type(); 00881 virtual operator string (); 00882 int af; 00883 union { struct in_addr addr4; struct in6_addr addr6; }; 00884 ipaddr(const char* s = "127.0.0.1"); 00885 ipaddr(struct in_addr* s); 00886 ipaddr(struct in6_addr* s); 00887 #ifdef _WIN32 00888 ~ipaddr() { WSACleanup(); } 00889 #endif 00890 net::ipaddr& operator= (const char* s); 00891 net::ipaddr& operator= (struct in_addr* s); 00892 net::ipaddr& operator= (struct in6_addr* s); 00893 bool operator== (const char* s); 00894 bool operator== (struct in_addr* s); 00895 bool operator== (struct in6_addr* s); 00896 bool operator!= (const char* s); 00897 bool operator!= (struct in_addr* s); 00898 bool operator!= (struct in6_addr* s); 00899 bool operator> (const char* s); 00900 bool operator> (struct in_addr* s); 00901 bool operator> (struct in6_addr* s); 00902 bool operator< (const char* s); 00903 bool operator< (struct in_addr* s); 00904 bool operator< (struct in6_addr* s); 00905 bool operator>= (const char* s); 00906 bool operator>= (struct in_addr* s); 00907 bool operator>= (struct in6_addr* s); 00908 bool operator<= (const char* s); 00909 bool operator<= (struct in_addr* s); 00910 bool operator<= (struct in6_addr* s); 00911 net::ipaddr operator+ (int i); 00912 net::ipaddr operator- (int i); 00913 net::ipaddr& operator+= (int i); 00914 net::ipaddr& operator-= (int i); 00915 net::ipaddr& operator++ (); 00916 net::ipaddr operator++ (int foo); 00917 net::ipaddr& operator-- (); 00918 net::ipaddr operator-- (int foo); 00919 00920 }; 00921 00923 class net::socket::tcp : virtual public io::ios { 00924 private: int af; 00925 #ifdef _WIN32 00926 int wsatoerr(int i); 00927 #endif 00928 public: 00929 virtual string type(); 00930 virtual operator string (); 00931 #ifdef _WIN32 00932 SOCKET fd; 00933 ~tcp(); 00934 #else 00935 int fd; 00936 #endif 00937 tcp(); 00938 int putc(int c); 00939 int getc(); 00940 data dump(); 00941 int puts(const char* s); 00942 int send(const char* buf, size_t len); 00943 int recv(char* buf, size_t len); 00944 bool connect(const char* host, const char* port); 00945 bool listen(const char* port, int backlog); 00946 bool accept(tcp& f); 00947 bool blocking(int i = -1); 00948 bool ready(); 00949 bool close(); 00950 bool connected(); 00951 string ip(); 00952 string name(); 00953 #ifdef _WIN32 00954 private: 00955 bool blking; 00956 #endif 00957 }; 00958 00960 class net::socket::udp : virtual public object { 00961 public: 00962 #ifdef _WIN32 00963 SOCKET fd; 00964 #else 00965 int fd; 00966 #endif 00967 udp(); 00968 ~udp(); 00969 virtual string type(); 00970 virtual operator string(); 00971 int post(dgram dg); 00972 net::dgram get(); 00973 bool bind(const char* port); 00974 void unbind(); 00975 int check(); 00976 }; 00977 00979 class net::dgram : virtual public object { 00980 public: 00981 virtual string type(); 00982 virtual operator string (); 00983 net::ipaddr ip; 00984 unsigned short port; 00985 data msg; 00986 }; 00987 00988 #ifdef _WIN32 00989 #define daylight _daylight 00990 struct tm *localtime_r (const time_t *, struct tm * result); 00991 struct tm *gmtime_r (const time_t *, struct tm * result); 00992 #endif 00993 00994 time_t axcel_timegm(struct tm* tm); 00995 00998 class timer : virtual public object { 00999 public: 01000 virtual string type(); 01001 virtual operator string (); 01002 01008 bool UTC; 01009 timer(); 01010 timer(const char* s); 01011 struct tm t; 01012 int sec(); 01013 int min(); 01014 int hour(); 01015 int mday(); 01016 int mon(); 01017 int year(); 01018 int wday(); 01019 string str(); 01020 timer& operator= (const char* s); 01021 timer& operator= (struct tm* tm); 01022 timer& operator= (time_t raw); 01023 bool operator== (const char* s); 01024 bool operator!= (const char* s); 01025 bool operator> (const char* s); 01026 bool operator< (const char* s); 01027 bool operator<= (const char* s); 01028 bool operator>= (const char* s); 01029 timer operator+ (const char* s); 01030 timer operator- (const char* s); 01031 timer& operator+= (const char* s); 01032 timer& operator-= (const char* s); 01033 static string ltime(); 01034 static string utime(); 01035 private: 01036 01037 template <typename T> 01038 bool op(bool (*cmp)(T, T), const char* s) { 01039 int i; 01040 const char* c; 01041 struct tm z; 01042 time_t a = 0, b = 0; 01043 z.tm_sec = -1; 01044 z.tm_min = -1; 01045 z.tm_hour = -1; 01046 z.tm_mday = -1; 01047 z.tm_mon = -1; 01048 z.tm_year = -1; 01049 z.tm_wday = -1; 01050 for (c = strpbrk(s, "0123456789"); c != NULL; c = strpbrk(c, "0123456789")) { 01051 i = atoi(c); 01052 while (isdigit(*c)) c++; 01053 if (*c == ':') { 01054 z.tm_hour = i; 01055 z.tm_min = atoi(++c); 01056 while (isdigit(*c)) c++; 01057 if (*c == ':') z.tm_sec = atoi(++c); 01058 while (isdigit(*c)) c++; 01059 if (isspace(*c)) c++; 01060 if (!strncmp(c, "PM", 2) || !strncmp(c, "pm", 2) || !strncmp(c, "p.m.", 4)) 01061 { if (z.tm_hour != 12) z.tm_hour += 12; } 01062 else if (!strncmp(c, "AM", 2) || !strncmp(c, "am", 2) || !strncmp(c, "a.m.", 4)) 01063 { if (z.tm_hour == 12) z.tm_hour = 0; } 01064 } else { 01065 if (i > 0 && i < 32) z.tm_mday = i; 01066 else z.tm_year = i - 1900; 01067 } 01068 } 01069 if (strstr(s, "Sun")) z.tm_wday = 0; 01070 else if (strstr(s, "Mon")) z.tm_wday = 1; 01071 else if (strstr(s, "Tue")) z.tm_wday = 2; 01072 else if (strstr(s, "Wed")) z.tm_wday = 3; 01073 else if (strstr(s, "Thu")) z.tm_wday = 4; 01074 else if (strstr(s, "Fri")) z.tm_wday = 5; 01075 else if (strstr(s, "Sat")) z.tm_wday = 6; 01076 if (strstr(s, "Jan")) z.tm_mon = 0; 01077 else if (strstr(s, "Feb")) z.tm_mon = 1; 01078 else if (strstr(s, "Mar")) z.tm_mon = 2; 01079 else if (strstr(s, "Apr")) z.tm_mon = 3; 01080 else if (strstr(s, "May")) z.tm_mon = 4; 01081 else if (strstr(s, "Jun")) z.tm_mon = 5; 01082 else if (strstr(s, "Jul")) z.tm_mon = 6; 01083 else if (strstr(s, "Aug")) z.tm_mon = 7; 01084 else if (strstr(s, "Sep")) z.tm_mon = 8; 01085 else if (strstr(s, "Oct")) z.tm_mon = 9; 01086 else if (strstr(s, "Nov")) z.tm_mon = 10; 01087 else if (strstr(s, "Dec")) z.tm_mon = 11; 01088 if (z.tm_sec != -1) { a += z.tm_sec; b += t.tm_sec; } 01089 if (z.tm_min != -1) { a += z.tm_min * 60; b += t.tm_min * 60; } 01090 if (z.tm_hour != -1) { a += z.tm_hour * 60 * 60; b += t.tm_hour * 60 * 60; } 01091 if (z.tm_mday != -1) { a += z.tm_mday * 60 * 60 * 24; b += t.tm_mday * 60 * 60 * 24; } 01092 if (z.tm_mon != -1) { a += z.tm_mon * 60 * 60 * 24 * 30; b += t.tm_mon * 60 * 60 * 24 * 30; } 01093 if (z.tm_year != -1) { a += z.tm_year * 60 * 60 * 24 * 30 * 12; b += t.tm_year * 60 * 60 * 24 * 30 * 12; } 01094 if (z.tm_wday != -1) { a += z.tm_wday * 60 * 60 * 24; b += t.tm_wday * 60 * 60 * 24; } 01095 if (!(cmp(b, a))) return false; 01096 return true; 01097 } 01098 }; 01099 01100 01101 namespace color { 01102 #ifndef _WIN32 01103 enum { 01104 black, red, green, yellow, blue, 01105 purple, aqua, white 01106 }; 01107 #else 01108 enum { 01109 black = 0, 01110 blue = FOREGROUND_BLUE, 01111 green = FOREGROUND_GREEN, 01112 red = FOREGROUND_RED, 01113 aqua = FOREGROUND_BLUE | FOREGROUND_GREEN, 01114 purple = FOREGROUND_BLUE | FOREGROUND_RED, 01115 yellow = FOREGROUND_GREEN | FOREGROUND_RED, 01116 white = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE 01117 }; 01118 #endif 01119 } 01120 01128 class console : virtual public io::ios { 01129 public: 01130 virtual string type(); 01131 virtual operator string (); 01132 FILE* in; 01133 FILE* out; 01134 console() { in = stdin; out = stdout; } 01135 int putc(int c); 01136 int getc(); 01137 int getch(); 01138 int getche(); 01139 bool kbhit(); 01140 data dump(); 01141 console& putcr(); 01142 console& putbs(); 01143 console& cls(); 01144 console& bel(); 01145 console& setxy(int x, int y); 01146 console& setx(int x); 01147 console& sety(int y); 01148 console& up(int n); 01149 console& dn(int n); 01150 console& lt(int n); 01151 console& rt(int n); 01152 console& rmln(); 01153 console& fglite(); 01154 console& fgdark(); 01155 console& fgcol(short color); 01156 console& bgcol(short color); 01157 private: 01158 char s[8]; 01159 #ifdef _WIN32 01160 HANDLE conout; 01161 CONSOLE_SCREEN_BUFFER_INFO bi; 01162 HANDLE coninfo(HANDLE* h, CONSOLE_SCREEN_BUFFER_INFO* bi); 01163 #endif 01164 }; 01165 01166 extern console con; 01167 01180 template <typename type> 01181 type stoi(const char* s, int base = 10) { 01182 bool neg = false; 01183 type ret = 0, num, place = 1; 01184 while (isspace(*s)) s++; 01185 if (*s == '-') { neg = true; s++; } 01186 else if (*s == '+') s++; 01187 if (base == 0) { 01188 if (*s == '0') { 01189 if (tolower(s[1]) == 'x') { base = 16; s += 2; } 01190 else { base = 8; s++; } 01191 } else base = 10; 01192 } else { 01193 if (*s == '0') { 01194 if (tolower(s[1]) == 'x' && base == 16) s += 2; 01195 else if (base == 8) s++; 01196 else return 0; 01197 } 01198 } 01199 const char \ 01200 *set = "0123456789abcdefghijklmnopqrstuvwxyz", 01201 *t = s + strlen(s) - 1, 01202 *tmp; 01203 for (t = s; *t; t++) { 01204 tmp = strchr(set, tolower(*t)); 01205 if (tmp == NULL) break; 01206 if (tmp - set >= base) break; 01207 } 01208 t--; 01209 if (t <= s) { 01210 tmp = strchr(set, tolower(*t)); 01211 if (tmp == NULL) return 0; 01212 if (tmp - set >= base) return 0; 01213 } 01214 for (; t >= s; t--, place *= base) { 01215 if (!place) return 0; 01216 tmp = strchr(set, tolower(*t)); 01217 if (tmp == NULL) return 0; 01218 if (tmp - set >= base) return 0; 01219 num = (tmp - set) * place; 01220 if (neg) { 01221 if ((type)(ret - (num ? num : place) > ret)) 01222 return 0; 01223 ret -= num; 01224 if (ret >= 0 && num != 0) return 0; 01225 } else { 01226 if ((type)(ret + (num ? num : place) < ret)) return 0; 01227 ret += num; 01228 if (ret <= 0 && num != 0) return 0; 01229 } 01230 } 01231 return ret; 01232 } 01233 01242 template <typename type> 01243 type stof(const char* s) { 01244 int i; 01245 type ret = 0, num = 0, place = 1; 01246 bool neg = false; 01247 const char *t; 01248 bool pineapple = false; 01249 while (isspace(*s)) s++; 01250 if (*s == '-') { neg = true; s++; } 01251 else if (*s == '+') s++; 01252 if ((t = strchr(s, '.')) == NULL) 01253 if ((t = strchr(s, 'e')) == NULL) 01254 t = s + strlen(s); 01255 for (t--; t >= s; t--, place *= 10) { 01256 goto stof_smoothie; 01257 stof_forloop_1: ; 01258 } 01259 if ((t = strchr(s, '.')) == NULL) goto stof_blend_ice; 01260 pineapple = true; 01261 for (t++, place = 0.1; 01262 *t != 'e' && *t != 0; 01263 t++, place /= 10) { 01264 goto stof_smoothie; 01265 stof_forloop_2: ; 01266 } 01267 01268 stof_blend_ice: 01269 if ((t = strchr(s, 'e')) == NULL) 01270 return ret; 01271 else { 01272 i = stoi<int>(t + 1, 10); 01273 if (i < 0) { 01274 for (; i < 0; i++) { 01275 num = ret / 10; 01276 if (num >= ret) return 0; 01277 else ret = num; 01278 } 01279 } else { 01280 for (; i > 0; i--) { 01281 num = ret * 10; 01282 if (num <= ret) return 0; 01283 else ret = num; 01284 } 01285 } 01286 } 01287 return ret; 01288 stof_smoothie: 01289 if (!place) 01290 if (neg) return 0; 01291 if (!isdigit(*t)) return 0; 01292 num = (*t - '0') * place; 01293 if (neg) { 01294 if ((type)(ret - (num ? num : place) > ret)) 01295 return 0; 01296 ret -= num; 01297 if (ret >= 0 && num != 0) return 0; 01298 } else { 01299 if ((type)(ret + (num ? num : place) <= ret)) return 0; 01300 ret += num; 01301 if (ret <= 0 && num != 0) return 0; 01302 } 01303 if (pineapple) goto stof_forloop_2; 01304 else goto stof_forloop_1; 01305 } 01306 01318 template <typename type> 01319 string itos(type t, int base = 10, bool showbase = false) { 01320 string s; 01321 if (base == 10) s.fmt.dec(1); 01322 else if (base == 16) s.fmt.hex(1); 01323 else if (base == 8) s.fmt.oct(1); 01324 s.fmt.base(showbase); 01325 s << t; 01326 return s; 01327 } 01328 01336 template <typename type> 01337 string ftos(type t, bool sci = false) { 01338 string s; 01339 s.fmt.sci(sci); 01340 s << t; 01341 return s; 01342 } 01343 01352 void die(const char* format, ...); 01353 01360 inline void print(const char* s, FILE* stream = stdout) { fputs(s, stream); } 01361 01368 inline void print(int ch, FILE* stream = stdout) { fputc(ch, stream); fflush(stream); } 01369 01376 int rand(int min = 0, int max = 0); 01377 01385 int rands(unsigned int seed, int min = 0, int max = 0); 01386 01392 char* memrev(char* s, size_t size, size_t n); 01393 01399 char* memrol(char* s, size_t size, size_t n); 01400 01406 char* memror(char* s, size_t size, size_t n); 01407 01413 char* memshl(char* s, size_t size, size_t n); 01414 01420 char* memshr(char* s, size_t size, size_t n); 01421 01429 string chop(const char* str); 01430 01438 string chomp(const char* str, const char* eat = "\r\n"); 01439 01446 string cut(const char* str); 01447 01455 string munch(const char* str, const char* eat); 01456 01464 string ltrim(const char* str); 01465 01473 string rtrim(const char* str); 01474 01482 string strip(const char* str); 01483 01489 inline long index(const char* str, const char* find) { return strstr(str, find) - str; } 01490 01496 inline long index(const char* str, int find) { return strchr(str, find) - str; } 01497 01502 inline long length(const char* str) { return strlen(str); } 01503 01509 inline bool eq(const char* s1, const char* s2) { return !strcmp(s1, s2); } 01510 01516 inline bool sfront(const char* s1, const char* s2) { return !strncmp(s1, s2, strlen(s2)); } 01517 01523 inline bool sback(const char* s1, const char* s2) { return !strncmp(s1 + strlen(s1) - strlen(s2), s2, strlen(s2)); } 01524 01531 string substr(const char* str, size_t offset, size_t length); 01532 01537 string lc(const char* str); 01538 01543 string lcfirst(const char* str); 01544 01549 string uc(const char* str); 01550 01555 string ucfirst(const char* str); 01556 01561 inline long dec(const char* str) { return stoi<long>(str, 10); } 01562 01567 inline long bin(const char* str) { return stoi<long>(str, 2); } 01568 01573 inline long oct(const char* str) { return stoi<long>(str, 8); } 01574 01579 inline long hex(const char* str) { return stoi<long>(str, 16); } 01580 01586 long rindex(const char* str, const char* find); 01587 01593 long rindex(const char* str, int find); 01594 01599 unsigned short cksum(const char* buf); 01600 01605 string q(const char* str); 01606 01611 string qq(const char* str); 01612 01617 string qx(const char* exec); 01618 01624 string scat(const char* s1, const char* s2); 01625 01631 string sdup(const char* str, int x); 01632 01639 string tok(size_t index, const char* str, const char* delim = " "); 01640 01647 string tok(size_t index, const char* str, int delim); 01648 01654 long ntok(const char* str, const char* delim = " "); 01655 01661 long ntok(const char* str, int delim); 01662 01669 long itok(size_t index, const char* str, const char* delim = " "); 01670 01677 long itok(size_t index, const char* str, int delim); 01678 01684 std::deque<axcel::string> split(const char* str, const char* delim); 01685 01691 std::deque<axcel::string> split(const char* str, int delim); 01692 01698 string join(std::deque<axcel::string> v, const char* delim = " "); 01699 01705 string join(std::deque<axcel::string> v, int delim); 01706 01707 01708 namespace fs { 01709 01710 #ifdef _WIN32 01711 01715 inline bool cd(const char* path) { return SetCurrentDirectoryA(path); } 01716 01721 inline bool rm(const char* fname) { return DeleteFileA(fname); } 01722 01727 inline bool md(const char* path) { return CreateDirectoryA(path, NULL); } 01728 #else 01729 01733 bool cd(const char* path); 01734 01739 bool rm(const char* fname); 01740 01745 bool md(const char* path); 01746 #endif 01747 01751 string gcd(); 01752 01760 string ls(const char* dir = 0); 01761 01766 bool creat(const char* fname); 01767 01768 /*bool mkfifo(const char* fname); 01769 bool mkhlnk(const char* ofname, const char* lfname); 01770 bool mkslnk(const char* ofname, const char* lfname); 01771 string rdlnk(const char* lfname);*/ 01772 01784 bool trunc(const char* fname, unsigned long len); 01785 01795 bool rd(const char* dir, bool rmsub = 1); 01796 01802 bool cp(const char* src, const char* dst); 01803 01809 bool mv(const char* src, const char* dst); 01810 01815 size_t fsize(const char* fname); 01816 01821 bool fexist(const char* fname); 01822 01827 bool fisdir(const char* fname); 01828 01833 bool fisreg(const char* fname); 01834 01840 string fread(const char* fname, size_t len = 0); 01841 01848 size_t fread(const char* fname, char* buf, size_t len = 0); 01849 01852 data fbread(const char* fname, size_t len = 0); 01853 01856 size_t fbwrite(const char* fname, data d, size_t len = 0); 01857 01864 size_t fwrite(const char* fname, const char* buf, size_t len = 0); 01865 01872 size_t fcat(const char* fname, const char* buf, size_t len = 0); 01873 01879 bool fcmp(const char* src, const char* dst); 01880 01885 timer fatime(const char* fname); 01886 01891 timer fmtime(const char* fname); 01892 01896 string tmpnam(); 01897 01898 }; 01899 01900 namespace proc { 01901 01910 class thread : virtual public object { 01911 public: 01912 virtual string type(); 01913 virtual operator string (); 01914 #ifdef _WIN32 01915 DWORD tid; 01916 #else 01917 pthread_t tid; 01918 #endif 01919 size_t stack; 01920 01921 void* (*sub)(void*); 01922 thread(); 01923 ~thread(); 01924 thread(void* (*tfunc)(void*)); 01925 bool start(void* param = 0); 01926 bool stop(); 01927 bool join(void ** ret = 0); 01928 bool tjoin(size_t ms, void ** ret = 0); 01929 bool getret(void ** retval = 0); 01930 proc::thread& operator= (void* (*tfunc)(void*)); 01931 proc::thread& operator= (proc::thread t); 01932 bool operator!= (void* (*tfunc)(void*)); 01933 bool operator!= (proc::thread t); 01934 bool operator== (void* (*tfunc)(void*)); 01935 bool operator== (proc::thread t); 01936 01937 static void exit(void* retval); 01938 static proc::thread self(); 01939 private: 01940 #ifdef _WIN32 01941 HANDLE fd; 01942 #else 01943 pthread_attr_t attr; 01944 #endif 01945 }; 01946 01966 #ifdef _WIN32 01967 inline void delay(size_t ms) { Sleep(ms); } 01968 DWORD run(const char* program, const char* argv = 0, void* envp = 0); 01969 #else 01970 void delay(size_t ms); 01971 pid_t run(const char* program, const char* argv = 0, void* envp = 0); 01972 #endif 01973 01977 string lsproc(); 01978 01983 bool killp(size_t pid); 01984 01989 bool killp(const char* name); 01990 01995 bool freeze(size_t pid); 01996 02001 bool freeze(const char* name); 02002 02007 bool cont(size_t pid); 02008 02013 bool cont(const char* name); 02014 02020 bool envset(const char* name, const char* value); 02021 02026 string envget(const char* name); 02027 02033 class library : virtual public object { 02034 public: 02035 virtual string type(); 02036 virtual operator string (); 02037 #ifdef _WIN32 02038 HMODULE fd; 02039 #else 02040 void* fd; 02041 #endif 02042 library() { fd = 0; } 02043 ~library(); 02044 library& operator =(const char* libname); 02045 library& operator= (library s); 02046 bool operator== (library s); 02047 bool operator!= (library s); 02048 void* operator[] (const char* name); 02049 private: 02050 string libraryname; 02051 }; 02052 02063 class mutex : virtual public object { 02064 public: 02065 virtual string type(); 02066 virtual operator string (); 02067 #ifdef _WIN32 02068 CRITICAL_SECTION id; 02069 #else 02070 pthread_mutex_t id; 02071 #endif 02072 mutex(); 02073 ~mutex(); 02074 void lock(); 02075 bool trylock(); 02076 void unlock(); 02077 }; 02078 02093 class semaphore : virtual public object { 02094 public: 02095 virtual string type(); 02096 virtual operator string (); 02097 #ifdef _WIN32 02098 HANDLE id; 02099 #else 02100 sem_t* id; 02101 #endif 02102 bool named; 02103 semaphore() {} 02104 semaphore(size_t count); 02105 semaphore(const char* name); 02106 ~semaphore(); 02107 bool init(size_t count); 02108 bool die(); 02109 bool open(const char* name); 02110 bool close(); 02111 bool get(size_t ms = 0); 02112 bool tryget(); 02113 bool ret(); 02114 private: 02115 #ifndef _WIN32 02116 char* n; 02117 sem_t s; 02118 #endif 02119 }; 02120 02131 #ifndef _WIN32 02132 sem_t* mksem(const char* name, size_t count); 02133 bool rmsem(const char* name); 02134 #else 02135 HANDLE mksem(const char* name, size_t count); 02136 02137 /* DOES NOTHING! Just for compatability */ 02138 inline bool rmsem(const char* name) { return true; } 02139 #endif 02140 02146 class pstream : virtual public io::ios { 02147 private: 02148 string pname; size_t p; 02149 #ifndef _WIN32 02150 int wpipe[2]; int rpipe[2]; 02151 #else 02152 HANDLE rin, win, rout, wout, rerr, werr, ph; 02153 #endif 02154 public: 02155 02164 bool blocking; 02165 pstream(); 02166 02168 virtual string type(); 02169 02176 virtual operator string (); 02177 02179 string name(); 02180 02181 int getc(); 02182 int putc(int c); 02183 02203 bool open(const char* program, const char* argv = 0, void* envp = 0); 02204 bool open(const char* program, const char* argv, environment envp); 02205 bool open(const char* program, const char* argv, data envp); 02206 02212 void close(); 02213 02217 size_t pid(); 02218 operator size_t () { return pid(); } 02219 }; 02220 02231 class environment : virtual public object { 02232 private: 02233 struct p { string k; string v; }; 02234 std::deque<p> e; 02235 public: 02241 string type(); 02248 operator string (); 02249 02255 string vars(); 02256 02262 string& operator[] (const char* s); 02263 02269 string& at(size_t i); 02270 02275 size_t len(); 02276 02281 environment& clear(); 02282 02287 bool empty(); 02288 02295 data bake(); 02296 }; 02297 02298 } 02299 02301 namespace net { 02302 02304 namespace irc { 02305 02310 class msg : virtual public object { 02311 public: 02313 virtual string type(); 02315 virtual operator string (); 02316 02318 string buf; 02319 msg(const char* line = 0); 02320 msg& operator= (const char* line); 02321 bool operator== (const char* line); 02322 bool operator!= (const char* line); 02323 02325 string server(); 02327 string nick(); 02329 string user(); 02331 string host(); 02333 string cmd(); 02335 string param(int index); 02337 string data(); 02338 }; 02339 /* 02340 class msg : virtual public object { 02341 public: 02342 virtual string type(); 02343 operator string (); 02344 msg(const char* line = 0); 02345 msg& operator= (const char* line); 02346 msg& operator= (const msg& s); 02347 bool operator== (const char* line); 02348 bool operator!= (const char* line); 02349 bool operator== (msg im); 02350 bool operator!= (msg im); 02351 const char* server; 02352 const char* nick; 02353 const char* user; 02354 const char* host; 02355 const char* cmd; 02356 const char* param(int index); 02357 const char* data; 02358 private: 02359 char buf[536]; 02360 };*/ 02361 02362 }; 02363 02365 namespace http { 02366 02367 data download(const char* url, const char* port = "80"); 02368 02370 class query : virtual public axcel::object { 02371 private: 02372 struct svarpair { string n; string v; }; 02373 std::deque<svarpair> svars; 02374 public: 02375 string type(); 02376 operator string(); 02377 string buf; 02378 string vars(); 02379 string& var(const char* v); 02380 query& operator= (const char* s); 02381 string& operator[] (const char* v); 02382 query() {} 02383 query(const char* s); 02384 bool operator== (const char* s); 02385 bool operator== (query q); 02386 bool operator!= (const char* s); 02387 bool operator!= (query q); 02388 }; 02389 02391 class field : virtual public axcel::object { 02392 private: 02393 struct svarpair { string n; string v; }; 02394 std::deque<svarpair> svars; 02395 public: 02396 string type(); 02397 operator string(); 02398 field() {} 02399 field(const char* s); 02400 string name; 02401 string data(); 02402 string vars(); 02403 string& var(const char* v = 0); 02404 field& operator= (const char* s); 02405 string& operator[] (const char* v); 02406 bool operator== (const char* s); 02407 bool operator== (field f); 02408 bool operator!= (const char* s); 02409 bool operator!= (field f); 02410 }; 02411 02413 class request : virtual public axcel::object { 02414 public: 02415 string type(); 02416 operator string (); 02417 request& operator= (const char* s); 02418 request() {} 02419 request(const char* s) { this->operator=(s); } 02420 string file; 02421 string qstr; 02422 string method; 02423 double ver; 02424 bool operator== (const char* s); 02425 bool operator== (request r); 02426 bool operator!= (const char* s); 02427 bool operator!= (request r); 02428 }; 02429 02431 class response : virtual public axcel::object { 02432 public: 02433 string type(); 02434 operator string (); 02435 response& operator= (const char* s); 02436 response() {} 02437 response(const char* s) { this->operator=(s); } 02438 double ver; 02439 int code; 02440 string status; 02441 bool operator== (const char* s); 02442 bool operator== (response r); 02443 bool operator!= (const char* s); 02444 bool operator!= (response r); 02445 }; 02446 02448 class header : virtual public axcel::object { 02449 private: 02450 std::deque<field> f; 02451 public: 02452 string type(); 02453 operator string (); 02454 size_t len(); 02455 string vars(); 02456 field& var(const char* s); 02457 field& operator[] (const char* s); 02458 field& at(size_t i); 02459 header& operator= (const char* s); 02460 header& clear(); 02461 header() {} 02462 header(const char* s); 02463 bool operator== (const char* s); 02464 bool operator== (header h); 02465 bool operator!= (const char* s); 02466 bool operator!= (header h); 02467 }; 02468 02469 }; 02470 02471 02472 }; 02473 02474 struct errno_str { int no; const char* str; }; 02475 extern struct errno_str errno_strs[]; 02476 02482 class exception : virtual public object { 02483 public: 02484 02571 int no; 02572 string desc; 02573 string type(); 02574 operator string(); 02575 //operator int() { return no; } 02576 //operator bool() { return no; } 02577 bool operator !() { return !no; } 02578 exception(); 02579 exception(int number); 02580 exception(const exception& e); 02581 exception(const char* msg); 02582 exception& operator= (int number); 02583 exception& operator= (const exception e); 02584 exception& operator= (const char* msg); 02585 bool operator== (exception e); 02586 bool operator== (const char* s); 02587 bool operator== (int num); 02588 bool operator!= (exception e); 02589 bool operator!= (const char* s); 02590 bool operator!= (int num); 02591 }; 02592 02593 02594 02595 } 02596 02597 using namespace axcel; 02598 02599 #endif