?? ptypes.h
字號:
/* * * C++ Portable Types Library (PTypes) * Version 1.7.5 Released 9-Mar-2003 * * Copyright (c) 2001, 2002, 2003 Hovik Melikyan * * http://www.melikyan.com/ptypes/ * http://ptypes.sourceforge.net/ * */#ifndef __PTYPES_H__#define __PTYPES_H__#ifndef _INC_STRING#include <string.h>#endif#ifndef __PPORT_H__#include "pport.h"#endifPTYPES_BEGIN#ifdef _MSC_VER#pragma pack(push, 4)#endif// -------------------------------------------------------------------- //// --- string class -------------------------------------------------- //// -------------------------------------------------------------------- //struct _strrec { int refcount; int length;};typedef _strrec* _pstrrec;#define STR_BASE(x) (_pstrrec(x)-1)#define STR_REFCOUNT(x) (STR_BASE(x)->refcount)#define STR_LENGTH(x) (STR_BASE(x)->length)#define PTR_TO_PSTRING(p) (pstring(&(p)))#define PTR_TO_STRING(p) (*PTR_TO_PSTRING(p))const int strrecsize = sizeof(_strrec);ptpublic extern char* emptystr;ptpublic extern int stralloc;class ptpublic string {protected: char* data; void _alloc(int); void _realloc(int); void _free(); void initialize() { data = emptystr; } void initialize(const char*, int); void initialize(const char*); void initialize(char); void initialize(const string& s); void initialize(const char*, int, const char*, int); void finalize(); void assign(const char*, int); void assign(const char*); void assign(const string&); void assign(char); string(const char* s1, int len1, const char* s2, int len2) { initialize(s1, len1, s2, len2); } public: friend inline int length(const string& s) { return STR_LENGTH(s.data); } friend inline int refcount(const string& s) { return STR_REFCOUNT(s.data); } friend inline void assign(string& s, const char* buf, int len) { s.assign(buf, len); } friend inline void clear(string& s) { s.finalize(); } friend inline bool isempty(const string& s) { return length(s) == 0; } ptpublic friend void setlength(string&, int); ptpublic friend char* unique(string&); ptpublic friend void concat(string& s, const char* sc, int catlen); ptpublic friend void concat(string& s, const char* s1); ptpublic friend void concat(string& s, char s1); ptpublic friend void concat(string& s, const string& s1); ptpublic friend string copy(const string& s, int from, int cnt); ptpublic friend void ins(const char* s1, int s1len, string& s, int at); ptpublic friend void ins(const char* s1, string& s, int at); ptpublic friend void ins(char s1, string& s, int at); ptpublic friend void ins(const string& s1, string& s, int at); ptpublic friend void del(string& s, int at, int cnt); ptpublic friend int pos(const char* s1, const string& s); ptpublic friend int pos(char s1, const string& s); ptpublic friend int rpos(char s1, const string& s); ptpublic friend bool contains(const char* s1, int len, const string& s, int at); ptpublic friend bool contains(const char* s1, const string& s, int at); ptpublic friend bool contains(char s1, const string& s, int at); ptpublic friend bool contains(const string& s1, const string& s, int at); friend inline int pos(const string& s1, const string& s) { return pos(s1.data, s); } ptpublic friend string dup(const string& s); string() { initialize(); } string(const char* sc, int initlen) { initialize(sc, initlen); } string(const char* sc) { initialize(sc); } string(char c) { initialize(c); } string(const string& s) { initialize(s); } ~string() { finalize(); } string& operator= (const char* sc) { assign(sc); return *this; } string& operator= (char c) { assign(c); return *this; } string& operator= (const string& s) { assign(s); return *this; } string& operator+= (const char* sc) { concat(*this, sc); return *this; } string& operator+= (char c) { concat(*this, c); return *this; } string& operator+= (const string& s) { concat(*this, s); return *this; } string operator+ (const char* sc) const; string operator+ (char c) const; string operator+ (const string& s) const; ptpublic friend string operator+ (const char* sc, const string& s); ptpublic friend string operator+ (char c, const string& s); bool operator== (const char* sc) const { return strcmp(data, sc) == 0; } bool operator== (char) const; bool operator== (const string&) const; bool operator!= (const char* sc) const { return !(*this == sc); } bool operator!= (char c) const { return !(*this == c); } bool operator!= (const string& s) const { return !(*this == s); } operator const char*() const { return data; } operator const uchar*() const { return (uchar*)data; } #ifdef CHECK_BOUNDS char& operator[] (int i);#else char& operator[] (int i) { return unique(*this)[i]; }#endif friend inline void initialize(string& s) { s.initialize(); } friend inline void initialize(string& s, const string& s1) { s.initialize(s1); } friend inline void initialize(string& s, const char* s1) { s.initialize(s1); } friend inline void finalize(string& s) { s.finalize(); }};typedef string* pstring;ptpublic extern string nullstring;// -------------------------------------------------------------------- //// --- string utilities ---------------------------------------------- //// -------------------------------------------------------------------- //ptpublic string fill(int width, char pad);ptpublic string pad(const string& s, int width, char c, bool left = true);ptpublic string itobase(large value, int base, int width = 0, char pad = 0);ptpublic string itostring(int v);ptpublic string itostring(large v);ptpublic large stringtoi(const char*);ptpublic string lowercase(const char* s);ptpublic string lowercase(const string& s);char hex4(char c);inline char locase(char c) { if (c >= 'A' && c <= 'Z') return char(c + 32); return c; }inline char upcase(char c) { if (c >= 'a' && c <= 'z') return char(c - 32); return c; }inline int hstrlen(const char* p) // some Unix systems do not accept NULL { return p == nil ? 0 : strlen(p); }// -------------------------------------------------------------------- //// --- character set class ------------------------------------------- //// -------------------------------------------------------------------- //const int _csetbits = 256;const int _csetbytes = _csetbits / 8;const int _csetwords = _csetbytes / sizeof(int);const char _csetesc = '~';class ptpublic cset {protected: char data[_csetbytes]; void assign(const cset& s) { memcpy(data, s.data, _csetbytes); } void assign(const char* setinit); void clear() { memset(data, 0, _csetbytes); } void fill() { memset(data, -1, _csetbytes); } void include(char b) { data[uchar(b) / 8] |= uchar(1 << (uchar(b) % 8)); } void include(char min, char max); void exclude(char b) { data[uchar(b) / 8] &= uchar(~(1 << (uchar(b) % 8))); } void unite(const cset& s); void subtract(const cset& s); void intersect(const cset& s); void invert(); bool contains(char b) const { return (data[uchar(b) / 8] & (1 << (uchar(b) % 8))) != 0; } bool eq(const cset& s) const { return memcmp(data, s.data, _csetbytes) == 0; } bool le(const cset& s) const;public: cset() { clear(); } cset(const cset& s) { assign(s); } cset(const char* setinit) { assign(setinit); } cset& operator= (const cset& s) { assign(s); return *this; } cset& operator+= (const cset& s) { unite(s); return *this; } cset& operator+= (char b) { include(b); return *this; } cset operator+ (const cset& s) const { cset t = *this; return t += s; } cset operator+ (char b) const { cset t = *this; return t += b; } cset& operator-= (const cset& s) { subtract(s); return *this; } cset& operator-= (char b) { exclude(b); return *this; } cset operator- (const cset& s) const { cset t = *this; return t -= s; } cset operator- (char b) const { cset t = *this; return t -= b; } cset& operator*= (const cset& s) { intersect(s); return *this; } cset operator* (const cset& s) const { cset t = *this; return t *= s; } cset operator! () const { cset t = *this; t.invert(); return t; } bool operator== (const cset& s) const { return eq(s); } bool operator!= (const cset& s) const { return !eq(s); } bool operator<= (const cset& s) const { return le(s); } bool operator>= (const cset& s) const { return s.le(*this); } friend inline cset operator+ (char b, const cset& s) { return s + b; } friend inline bool operator& (char b, const cset& s) { return s.contains(b); } friend inline void assign(cset& s, const char* setinit) { s.assign(setinit); } friend inline void clear(cset& s) { s.clear(); } friend inline void fill(cset& s) { s.fill(); } friend inline void include(cset& s, char b) { s.include(b); } friend inline void exclude(cset& s, char b) { s.exclude(b); } friend inline void include(cset& s, char min, char max) { s.include(min, max); } ptpublic friend string asstring(const cset& s);};// -------------------------------------------------------------------- //// --- basic abstract class ------------------------------------------ //// -------------------------------------------------------------------- //class ptpublic unknown {public: unknown(); virtual ~unknown();};typedef unknown* punknown;ptpublic extern int objalloc;// -------------------------------------------------------------------- //// --- component ----------------------------------------------------- //// -------------------------------------------------------------------- //PTYPES_ENDnamespace ox // our friends in the Objection framework{ class ox_class; class ox_machine;}PTYPES_BEGINclass objlist;//// class ID's for all basic types: the first byte (least significant)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -