?? ptypes.h
字號(hào):
// contains the base ID, the next is for the second level of inheritance,// etc. total of 4 levels allowed for basic types. call classid() for an// object, mask out first N bytes of interest and compare with a CLASS_XXX// value. f.ex. to determine whether an object is of type infile or any// derivative: (o->classid() & 0xffff) == CLASS_INFILE. this scheme is for// internal use by PTypes and Objection; partly replaces the costly C++ RTTI// system.//// first level of inheritanceconst int CLASS_UNDEFINED = 0x00000000;const int CLASS_INSTM = 0x00000001;const int CLASS_OUTSTM = 0x00000002;const int CLASS_UNIT = 0x00000003;// second level of inheritanceconst int CLASS_INFILE = 0x00000100 | CLASS_INSTM;const int CLASS_OUTFILE = 0x00000100 | CLASS_OUTSTM;const int CLASS_INMEMORY = 0x00000200 | CLASS_INSTM;const int CLASS_OUTMEMORY = 0x00000200 | CLASS_OUTSTM;class ptpublic component: public unknown {protected: friend class ox::ox_class; // our friends in the Objection! system friend class ox::ox_machine; int refcount; // reference counting, used by addref() and release() objlist* freelist; // list of components to notify about destruction, safer alternative to ref-counting ox::ox_class* typeinfo; // assigned by the Objection virtual machine if created using clone() virtual void freenotify(component* sender);public: component(); virtual ~component(); void addnotification(component* obj); void delnotification(component* obj); ptpublic friend component* addref(component*); ptpublic friend bool release(component*); inline ptpublic friend int refcount(component* c) { return c->refcount; } virtual int classid(); ox::ox_class* get_typeinfo() { return typeinfo; }};typedef component* pcomponent;template <class T> inline T* taddref(T* c) // MSVC can't handle this template correctly if we name { return (T*)addref((component*)c); } // it as addref(). (gcc is fine though)template <class T> class compref{protected: T* ref;public: compref() { ref = 0; } compref(const compref& r) { ref = taddref<T>(r.ref); } compref(T* u) { ref = taddref<T>(u); } ~compref() { release(ref); } void operator= (const compref& r) { release(ref); ref = taddref<T>(r.ref); } void operator= (T* u) { release(ref); ref = taddref<T>(u); } T& operator* () { return *ref; } T* operator-> () { return ref; } bool operator== (const compref& r) const { return ref == r.ref; } bool operator== (const T* u) const { return ref == u; } bool operator!= (const compref& r) const { return ref != r.ref; } bool operator!= (const T* u) const { return ref != u; } operator T* () { return ref; }};// -------------------------------------------------------------------- //// --- exception class ----------------------------------------------- //// -------------------------------------------------------------------- //class ptpublic exceptobj: public unknown {protected: string message;public: exceptobj(const char* imsg); exceptobj(const string& imsg); virtual ~exceptobj(); virtual string get_message() { return message; }};// -------------------------------------------------------------------- //// --- object list --------------------------------------------------- //// -------------------------------------------------------------------- //class ptpublic objlist: public unknown {protected: unknown** list; int count; int capacity; bool ownobjects; void idxerror() const; void setcapacity(int newcap); int getcount() const { return count; } void setcount(int newcount); void grow(); void clear(); void insitem(int i, unknown* iobj); void putitem(int i, unknown* iobj); void delitem(int i); unknown* getitem(int i) const { return list[i]; }public: objlist(); objlist(bool iownobjects); virtual ~objlist(); void checkidx(int i) const { if (i < 0 || i >= count) idxerror(); } friend inline int length(const objlist& s) { return s.getcount(); } friend inline void setlength(objlist& s, int newcount) { s.setcount(newcount); } friend inline void pack(objlist& s) { s.setcapacity(s.count); } friend inline void clear(objlist& s) { s.clear(); } ptpublic friend void ins(objlist& s, int i, unknown* iobj); ptpublic friend int add(objlist& s, unknown* iobj); ptpublic friend void put(objlist& s, int i, unknown* iobj); ptpublic friend void del(objlist& s, int i); ptpublic friend int indexof(const objlist& s, unknown* iobj); ptpublic friend unknown* pop(objlist& s); friend inline unknown* top(const objlist& s) { return get(s, length(s) - 1); } friend inline int push(objlist& s, unknown* obj) { return add(s, obj); }#ifdef CHECK_BOUNDS ptpublic friend unknown* get(const objlist& s, int i);#else friend inline unknown* get(const objlist& s, int i) { return s.getitem(i); }#endif unknown* operator[] (int i) const { return PTYPES_NAMESPACE::get(*this, i); }};// a fully inlined objlist template for use with any class// derived from unknown. provided to get rid of typecasts.template <class T> class tobjlist: public objlist{public: tobjlist(): objlist() {} tobjlist(bool iownobjects): objlist(iownobjects) {} friend inline void ins(tobjlist& s, int i, T* obj) { PTYPES_NAMESPACE::ins(s, i, (unknown*)obj); } friend inline int add(tobjlist& s, T* obj) { return PTYPES_NAMESPACE::add(s, (unknown*)obj); } friend inline void put(tobjlist& s, int i, T* obj) { PTYPES_NAMESPACE::put(s, i, (unknown*)obj); } friend inline int indexof(const tobjlist& s, T* obj) { return PTYPES_NAMESPACE::indexof(s, (unknown*)obj); } friend inline int push(tobjlist& s, T* obj) { return PTYPES_NAMESPACE::push(s, (unknown*)obj); } friend inline T* pop(tobjlist& s) { return (T*)PTYPES_NAMESPACE::pop((objlist&)s); } friend inline T* top(const tobjlist& s) { return (T*)PTYPES_NAMESPACE::get(s, length(s) - 1); } friend inline T* get(const tobjlist& s, int i) { return (T*)PTYPES_NAMESPACE::get((const objlist&)s, i); } T* operator[] (int i) const { return (T*)PTYPES_NAMESPACE::get(*this, i); }};// -------------------------------------------------------------------- //// --- string list --------------------------------------------------- //// -------------------------------------------------------------------- //struct _stritem { string str; unknown* obj;};typedef _stritem* pstritem;const int _stritemsize = sizeof(_stritem);enum slflags { SL_SORTED = 0x0001, SL_DUPLICATES = 0x0002, SL_CASESENS = 0x0004, SL_OWNOBJECTS = 0x0008};class ptpublic strlist: public unknown {protected: _stritem* list; int count; int capacity; slflags flags; void idxerror() const; void sortederror() const; void notsortederror() const; void duperror() const; void setcapacity(int newcap); int getcount() const { return count; } void grow(); void clear(); virtual int compare(const string& s1, const string& s2) const; bool search(const string& s, int& index) const; void insitem(int i, const string& istr, unknown* iobj); void putstr(int i, const string& istr); void putobj(int i, unknown* iobj); void delitem(int i); const string& getstr(int i) const { return list[i].str; } unknown* getobj(int i) const { return list[i].obj; }public: strlist(); strlist(slflags iflags); virtual ~strlist(); void checkidx(int i) const { if (i < 0 || i >= count) idxerror(); } bool get_sorted() const { return (SL_SORTED & flags) != 0; } bool get_duplicates() const { return (SL_DUPLICATES & flags) != 0; } bool get_casesens() const { return (SL_CASESENS & flags) != 0; } bool get_ownobjects() const { return (SL_OWNOBJECTS & flags) != 0; } int get_capacity() const { return capacity; } friend inline int length(const strlist& s) { return s.getcount(); } friend inline void clear(strlist& s) { s.clear(); } friend inline void pack(strlist& s) { s.setcapacity(s.count); } ptpublic friend bool search(const strlist& s, const string& key, int& index); ptpublic friend void ins(strlist& s, int i, const string& istr, unknown* iobj); ptpublic friend int add(strlist& s, const string& istr, unknown* iobj); ptpublic friend void put(strlist& s, int i, const string& istr, unknown* iobj); ptpublic friend void put(strlist& s, int i, unknown* iobj); ptpublic friend void del(strlist& s, int i); ptpublic friend int find(const strlist& s, const string& key); ptpublic friend int indexof(const strlist& s, unknown* iobj); ptpublic friend string valueof(const strlist& s, const char* key);#ifdef CHECK_BOUNDS ptpublic friend const string& getstr(const strlist& s, int i); ptpublic friend unknown* get(const strlist& s, int i);#else friend const string& getstr(const strlist& s, int i) { return s.getstr(i); } friend inline unknown* get(const strlist& s, int i) { return s.getobj(i); }#endif unknown* operator[] (int i) const { return PTYPES_NAMESPACE::get(*this, i); }};template <class T> class tstrlist: public strlist{public: tstrlist(): strlist() {} tstrlist(slflags iflags): strlist(iflags) {} friend inline void ins(tstrlist& s, int i, const string& str, T* obj) { PTYPES_NAMESPACE::ins(s, i, str, (unknown*)obj); } friend inline int add(tstrlist& s, const string& str, T* obj) { return PTYPES_NAMESPACE::add(s, str, (unknown*)obj); } friend inline void put(tstrlist& s, int i, const string& str, T* obj) { PTYPES_NAMESPACE::put(s, i, str, (unknown*)obj); } friend inline void put(tstrlist& s, int i, T* obj) { PTYPES_NAMESPACE::put(s, i, (unknown*)obj); } friend inline int indexof(const tstrlist& s, T* obj) { return PTYPES_NAMESPACE::indexof(s, (unknown*)obj); } friend inline T* get(const tstrlist& s, int i) { return (T*)PTYPES_NAMESPACE::get((const strlist&)s, i); } T* operator[] (int i) const { return (T*)PTYPES_NAMESPACE::get(*this, i); }};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -