📄 object.h
字号:
if (Class::_storeVBase((void*)this)) classname::storer(strm); \
} \
#define _DEFINE_CASTDOWN(classname) \
void* classname::_castdown(const Class& target) const \
{ \
if (&target == desc()) return (void*)this; \
return BASE::_castdown(target); \
} \
#define DEFINE_CLASS(classname,version,identification,initor1,initor2) \
_DEFINE_CLASS(classname) \
_DEFINE_CLASS_ALWAYS(classname,version,identification,initor1,initor2) \
_DEFINE_CASTDOWN(classname) \
#define DEFINE_ABSTRACT_CLASS(classname,version,identification,initor1,initor2) \
_DEFINE_ABSTRACT_CLASS(classname) \
_DEFINE_CLASS_ALWAYS(classname,version,identification,initor1,initor2) \
_DEFINE_CASTDOWN(classname) \
#define DEFINE_CLASS_MI(classname,version,identification,initor1,initor2) \
_DEFINE_CLASS(classname) \
_DEFINE_CLASS_ALWAYS(classname,version,identification,initor1,initor2) \
#define DEFINE_ABSTRACT_CLASS_MI(classname,version,identification,initor1,initor2) \
_DEFINE_ABSTRACT_CLASS(classname) \
_DEFINE_CLASS_ALWAYS(classname,version,identification,initor1,initor2) \
class Object : public NIHCL { // abstract class
public:
static Object& castdown(Object& p) { return p; }
static const Object& castdown(const Object& p) { return p; }
static Object* castdown(Object* p) { return p; }
static const Object* castdown(const Object* p) { return p; }
static const Class* desc();
virtual const Class* isA() const = 0;
virtual Object* shallowCopy() const = 0;
/* WATCOM private: */ public:
static Object* reader(OIOin& strm);
static Object* reader(OIOifd& fd);
public: // static member variables
static Object* const nil; // pointer to sole instance of nil object
public: // static member functions
static Object* readFrom(OIOifd& fd);
static Object* readFrom(OIOin& strm);
protected: // constructors for object I/O
Object(OIOifd&);
Object(OIOin&);
protected: // storer() functions for object I/O
virtual void storer(OIOofd&) const;
virtual void storer(OIOout&) const;
friend class OIOout;
friend class OIOofd;
protected:
Object() {}
void ambigCheck(void*&, void*&, const Class&) const; // check for ambiguous castdown()
public:
void assertArgClass(const Class& expect, const char* fname) const; // validate non-member function argument class
void assertArgClass(const Object& ob, const Class& expect, const char* fname) const; // validate member function argument class
void assertArgSpecies(const Class& expect, const char* fname) const; // validate non-member function argument species
void assertArgSpecies(const Object& ob, const Class& expect, const char* fname) const; // validate member function argument species
void assertClass(const Class& expect) const; // validate object class
void assertSpecies(const Class& expect) const; // validate object species
const char* className() const; // return class name
Object* deepCopy() const; // copy with distinct instance variables
void derivedClassResponsibility(const char*) const; // unimplemented virtual function
void invalidArgClass(const Class& expect, const char* fname) const; // invalid non-member function argument class
void invalidArgClass(const Object& ob, const Class& expect, const char* fname) const; // invalid member function argument class
void invalidArgSpecies(const Class& expect, const char* fname) const; // invalid non-member function argument species error
void invalidArgSpecies(const Object& ob, const Class& expect, const char* fname) const; // invalid member function argument species error
void invalidClass(const Class& expect) const; // invalid object class error
void invalidSpecies(const Class& expect) const; // invalid object species error
bool isKindOf(const Class&) const; // YES if MemberOf class or a superclass
bool isMemberOf(const Class& clid) const { return isA()==&clid; }
bool isSame(const Object& ob) const { return this==&ob; }
bool isSpecies(const Class& clid) const { return species()==&clid; }
void shouldNotImplement(const char*) const; /* class cannot implement this function */
void storeMemberOn(OIOofd&) const; // store object member in binary on file
void storeMemberOn(OIOout&) const; // store object member on stream
void storeOn(OIOofd&) const; // store object in binary on file
void storeOn(OIOout&) const; // store object on stream
void* _safe_castdown(const Class&) const; // checked call to _castdown()
virtual Object* addDependent(Object&); // add dependent object
virtual unsigned capacity() const; // subclass capacity
virtual void changed(); // notify dependents of change
virtual void changed(const Object&); // notify dependents of change
virtual int compare(const Object&) const = 0; // compare objects
virtual Object* copy() const; // copy defaulted as shallowCopy
virtual void deepenShallowCopy() = 0; // convert shallow copy to deep copy
virtual OrderedCltn& dependents() const; // return list of dependent objects
virtual void destroyer(); // destroy object
virtual void dumpOn(ostream& strm =cerr) const; // printOn() with class name
virtual unsigned hash() const = 0; // calculate object hash
virtual bool isEqual(const Object&) const = 0; // equality test
virtual void scanFrom(istream& strm); // parse object from stream
virtual void printOn(ostream& strm =cout) const = 0; // print object on stream
virtual void release(); // remove all dependent objects
virtual Object* removeDependent(const Object&); // remove dependent object
virtual unsigned size() const; // # of objects in array/container subclass
virtual const Class* species() const; // return species class descriptor address
virtual void update(const Object&, const Object&); // object change notification
virtual void* _castdown(const Class&) const; // cast this to derived class
};
#ifndef NESTED_TYPES
typedef void (*initorTy)(const Class&);
#endif
class StoreOnTblMgr;
class ReadFromTblMgr;
class Class : public VIRTUAL Object { // class descriptor object
private: // static member variables
static unsigned long readFrom_level; // reset readFromTbl when 0
static unsigned long storeOn_level; // reset storeOnTbl when 0
static unsigned long addObjectFlag; // add object to readFromTbl when 0
friend Object::Object(OIOin&);
friend Object::Object(OIOifd&);
static IdentSet* storeVBaseTbl; // table used by storeOn()
friend class StoreOnTblMgr;
friend class ReadFromTblMgr;
public: // static member variables
static Dictionary& dictionary; // class descriptor dictionary
static ReadFromTbl* readFromTbl; // tables used by readFrom()
static StoreOnTbl* storeOnTbl; // tables used by storeOn()
public:
#ifdef NESTED_TYPES
typedef void (*initorTy)(const Class&);
#endif
static const Class* desc();
virtual const Class* isA() const;
virtual Object* shallowCopy() const;
/* WATCOM private: */ public: // static member functions
static Object* reader(OIOin& strm);
static Object* reader(OIOifd& fd);
public: // static member functions
DECLARE_CASTDOWN(Class)
static void initialize(); // class initialization
static const Class* lookup(const char* name);
static unsigned long readFromLevel() { return readFrom_level; }
static unsigned long storeOnLevel() { return storeOn_level; }
static bool _deepenVBase(void*);
static bool _storeVBase(void*);
private: // member variables
const char* class_name; // class name
const char* class_ident; // class RCS identification header
/* WATCOM const */ Class* */* WATCOM const*/ class_bases; // pointer to base class list
/* WATCOM const */ Class* */* WATCOM const*/ class_members; // pointer to member class list
/* WATCOM const */ Class* */* WATCOM const*/ class_vbases; // pointer to virtual base class list
/* WATCOM const */ unsigned class_version; // class version number
/* WATCOM const */ unsigned inst_size; // sizeof instance variables
Object* (*/* WATCOM const*/ inst_reader)(OIOin&); // object reader function
Object* (*/* WATCOM const*/ inst_binreader)(OIOifd&); // binary reader function
/* WATCOM const */ initorTy class_initor2; // phase 2 class initor
Class* nextClass; // link for list of all Class objects
unsigned long class_signature; // class signature
unsigned class_number; // class number, used by storeOn()
private: // private member functions
unsigned number(unsigned n) { return class_number = n; }
friend class StoreOnTbl;
Object* readObject(OIOin&) const;
friend class OIOin;
Object* readObject(OIOifd&) const;
friend class OIOifd;
void addSignature(unsigned long);
void computeSignature();
public:
Class(const char* name,
const ClassList& bases, const ClassList& members, const ClassList& vbases,
unsigned version, const char* ident, unsigned size,
Object* (*reader)(OIOin&),
Object* (*binreader)(OIOifd&),
initorTy initor1 =0, initorTy initor2 =0);
Class(const Class&);
Class(OIOifd&);
Class(OIOin&);
const char* name() const { return class_name; }
/* WATCOM const */ Class** baseClasses() const { return class_bases; }
/* WATCOM const */ Class** memberClasses() const { return class_members; }
/* WATCOM const */ Class** virtualBaseClasses() const { return class_vbases; }
const char* ident() const { return class_ident; }
unsigned number() const { return class_number; }
unsigned long signature() const {
if (class_signature == 0) ((Class*)this)->computeSignature();
return class_signature;
}
unsigned version() const { return class_version; }
Object* readFrom(OIOifd& fd) const; // read binary object from file
Object* readFrom(OIOin&) const; // read object from stream
bool _isKindOf(const Class&) const;
virtual int compare(const Object&) const; // compare class names
virtual void dumpOn(ostream& strm =cerr) const;
virtual unsigned hash() const;
virtual bool isEqual(const Object& ob) const;
virtual void printOn(ostream& strm =cout) const;
virtual unsigned size() const;
virtual void* _castdown(const Class&) const;
private: // shouldNotImplement
virtual void deepenShallowCopy();
virtual void storer(OIOout&) const;
virtual void storer(OIOofd&) const;
};
inline const char* Object::className() const { return isA()->name(); }
inline Object* Object::readFrom(OIOifd& fd) { return desc()->readFrom(fd); }
inline Object* Object::readFrom(OIOin& strm) { return desc()->readFrom(strm); }
inline void Object::assertArgClass(const Class& expect, const char* fname) const
{
if (!isKindOf(expect)) invalidArgClass(expect,fname);
}
inline void Object::assertArgClass(const Object& ob, const Class& expect, const char* fname) const
{
if (!(ob.isKindOf(expect))) invalidArgClass(ob,expect,fname);
}
inline void Object::assertArgSpecies(const Class& expect, const char* fname) const
{
if (!isSpecies(expect)) invalidArgSpecies(expect,fname);
}
inline void Object::assertArgSpecies(const Object& ob, const Class& expect, const char* fname) const
{
if (!(ob.isSpecies(expect))) this->invalidArgSpecies(ob,expect,fname);
}
inline void Object::assertClass(const Class& expect) const
{
if (!isKindOf(expect)) invalidClass(expect);
}
inline void Object::assertSpecies(const Class& expect) const
{
if (!isSpecies(expect)) invalidSpecies(expect);
}
inline istream& operator>>(istream& strm, Object& ob)
{
ob.scanFrom(strm);
return strm;
}
inline ostream& operator<<(ostream& strm, const Object& ob)
{
ob.printOn(strm);
return strm;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -