⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.h

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef OBJECT_H
#define OBJECT_H


/* Object.h -- declarations for class Object and class Class

        THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
        "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
        AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
        CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
        PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
        RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.

Author:
        K. E. Gorlen
        Bg. 12A, Rm. 2033
        Computer Systems Laboratory
        Division of Computer Research and Technology
        National Institutes of Health
        Bethesda, Maryland 20892
        Phone: (301) 496-1111
        uucp: uunet!nih-csl!kgorlen
        Internet: kgorlen@alw.nih.gov
        September, 1985

Function:
        
Define class Object, the root of the class tree, and class Class, the
class that describes class objects.

log:    OBJECT.H $
Revision 1.2  95/01/29  13:27:26  NT_Test_Machine
*** empty log message ***

Revision 1.1  94/09/14  14:28:58  Anthony_Scian
.

 * Revision 3.0  90/05/22  10:42:35  kgorlen
 * Release for 1st edition.
 * 
*/

// c_plusplus   defined by AT&T C++ Translator R2.0 and earlier
// __cplusplus  defined by AT&T C++ Translator R2.0 and later
// __GNUG__     defined by GNU C++
// _CPLUSPLUS_  defined by Oregon C++

// define if typedefs within a class have class scope
//#define NESTED_TYPES

#ifdef __GNUG__
// GNU C++ doesn't have endl
#define endl '\n';
#endif

#define bool int
#include <stddef.h>
#include <stdio.h>
#include <iostream.h>
#include "errors.h"
#undef bool

#ifdef MI
#define VIRTUAL virtual
#else
#define VIRTUAL
#endif

class Class;
class Dictionary;
class OIOifd;
class OIOofd;
class OIOin;
class OIOout;
class Object;
class OrderedCltn;
class ReadFromTbl;
class StoreOnTbl;
class IdentSet;

#define bool BOOL

typedef int bool;
const int YES = 1;
const int NO = 0;

inline char     ABS(char x)     { return x >= 0 ? x : -x; }
inline short    ABS(short x)    { return x >= 0 ? x : -x; }
inline int      ABS(int x)      { return x >= 0 ? x : -x; }
inline long     ABS(long x)     { return x >= 0 ? x : -x; }
inline float    ABS(float x)    { return x >= 0 ? x : -x; }
inline double   ABS(double x)   { return x >= 0 ? x : -x; }

inline char     MAX(char a,char b)      { return a >= b ? a : b; }
inline short    MAX(short a,short b)    { return a >= b ? a : b; }
inline int      MAX(int a,int b)        { return a >= b ? a : b; }
inline long     MAX(long a,long b)      { return a >= b ? a : b; }
inline float    MAX(float a,float b)    { return a >= b ? a : b; }
inline double   MAX(double a,double b)  { return a >= b ? a : b; }
inline void*    MAX(void* a,void* b)    { return a >= b ? a : b; }
inline unsigned char    MAX(unsigned char a, unsigned char b)   { return a >= b ? a : b; }
inline unsigned short   MAX(unsigned short a, unsigned short b) { return a >= b ? a : b; }
inline unsigned int     MAX(unsigned int a, unsigned int b)     { return a >= b ? a : b; }
inline unsigned long    MAX(unsigned long a, unsigned long b)   { return a >= b ? a : b; }

inline char     MIN(char a,char b)      { return a <= b ? a : b; }
inline short    MIN(short a,short b)    { return a <= b ? a : b; }
inline int      MIN(int a,int b)        { return a <= b ? a : b; }
inline long     MIN(long a,long b)      { return a <= b ? a : b; }
inline float    MIN(float a,float b)    { return a <= b ? a : b; }
inline double   MIN(double a,double b)  { return a <= b ? a : b; }
inline void*    MIN(void* a,void* b)    { return a <= b ? a : b; }
inline unsigned char    MIN(unsigned char a, unsigned char b)   { return a <= b ? a : b; }
inline unsigned short   MIN(unsigned short a, unsigned short b) { return a <= b ? a : b; }
inline unsigned int     MIN(unsigned int a, unsigned int b)     { return a <= b ? a : b; }
inline unsigned long    MIN(unsigned long a, unsigned long b)   { return a <= b ? a : b; }

static class NIHCL {
private:                        // static member variables
        static int initCount;           // see NIHCL::NIHCL() and NIHCL::~NIHCL()
        static bool init;               // YES if NIHCL initialization complete
        static unsigned char    char_bit_mask[sizeof(char)*8];
        static unsigned short   short_bit_mask[sizeof(short)*8];
        static unsigned int     int_bit_mask[sizeof(int)*8];
        static unsigned char    bit_count[256];
        static unsigned char    bit_reverse[256];
private:                        // static member functions
        static void initTables();       // initialize tables
public:                         // static member functions
        NIHCL();
        ~NIHCL();
        static unsigned char charBitMask(int i)         { return char_bit_mask[i]; }
        static unsigned short shortBitMask(int i)       { return short_bit_mask[i]; }
        static unsigned int intBitMask(int i)           { return int_bit_mask[i]; }
        static unsigned char bitCount(unsigned i)       { return bit_count[i]; }
        static unsigned char bitReverse(unsigned i)     { return bit_reverse[i]; }
        static void initialize();       // library initialization
        static bool initialized()       { return init; }
        static void setError(int error, int sev ...);   // set an NIHCL error condition
} NIHCL_init;

class ClassList : public NIHCL {
        Class** clp;
        friend class Class;
public:
        ClassList(const char*, ...);
        ~ClassList() {}         // that's right -- don't delete clp
};

#ifdef MI

#define DECLARE_CASTDOWN(classname) \
        static classname& castdown(Object& p) \
                { return *(classname*)(&p ? p._safe_castdown(*desc()) : 0); } \
        static const classname& castdown(const Object& p) \
                { return *(const classname*)(&p ? p._safe_castdown(*desc()) : 0); } \
        static classname* castdown(Object* p) \
                { return (classname*)(p ? p->_safe_castdown(*desc()) : 0); } \
        static const classname* castdown(const Object* p) \
                { return (const classname*)(p ? p->_safe_castdown(*desc()) : 0); } \

#else

#define DECLARE_CASTDOWN(classname) \
        static classname& castdown(Object& p)                   { return (classname&)p; } \
        static const classname& castdown(const Object& p)       { return (const classname&)p; } \
        static classname* castdown(Object* p)                   { return (classname*)p; } \
        static const classname* castdown(const Object* p)       { return (const classname*)p; } \

#endif

#define DECLARE_MEMBERS(classname) \
private: \
        static Class classDesc; \
public: \
        DECLARE_CASTDOWN(classname) \
        static const Class* desc()  { return &classDesc; } \
        static classname* readFrom(OIOin& strm) { return castdown(desc()->readFrom(strm)); } \
        static classname* readFrom(OIOifd& fd) { return castdown(desc()->readFrom(fd)); } \
        classname(OIOin&); \
        classname(OIOifd&); \
        virtual const Class* isA() const; \
        virtual Object* shallowCopy() const; \
        virtual void* _castdown(const Class&) const; \
protected: \
        void deepenVBase(); \
        void storeVBaseOn(OIOofd&) const; \
        void storeVBaseOn(OIOout&) const; \
/* WATCOM private: */ public: \
        static Object* reader(OIOin& strm); \
        static Object* reader(OIOifd& fd) \

/*
The STRINGIZE preprocessor macro converts a name into a character
string.  It can use one of three possible ways to accomplish this.
ANSI C preprocessors, which define the symbol __STDC__, recognize "#".
If you define the symbol BS_NL, the name will be separated from
surrounding double quotes by "\\\n"; otherwise, the name is simply
embedded in double quotes.
*/
#if defined(mc300)
#define   BS_NL
#endif

#ifdef __STDC__

#define STRINGIZE(s) #s

#else
#ifdef BS_NL

#define STRINGIZE(s) "\
s\
"

#else

#define STRINGIZE(s) "s"

#endif
#endif

#define _DEFINE_CLASS(classname) \
Object* classname::reader(OIOin& strm)  { return new classname(strm); } \
Object* classname::reader(OIOifd& fd)   { return new classname(fd); } \
Object* classname::shallowCopy() const  { return new classname(*this); } \

#define _DEFINE_ABSTRACT_CLASS(classname) \
extern const int NIHCL_RDABSTCLASS; \
Object* classname::reader(OIOin&)       { setError(NIHCL_RDABSTCLASS,DEFAULT,STRINGIZE(classname)); return 0; } \
Object* classname::reader(OIOifd&)      { setError(NIHCL_RDABSTCLASS,DEFAULT,STRINGIZE(classname)); return 0; } \
Object* classname::shallowCopy() const  { derivedClassResponsibility("shallowCopy"); return nil; } \

#define _DEFINE_CLASS_ALWAYS(classname,version,identification,initor1,initor2) \
Class classname::classDesc(STRINGIZE(classname),\
        ClassList(0,BASE_CLASSES,0), \
        ClassList(0,MEMBER_CLASSES-0,0), \
        ClassList(0,VIRTUAL_BASE_CLASSES-0,0), \
        version, identification, sizeof(classname), \
        classname::reader, classname::reader, \
        initor1, initor2 ); \
const Class* classname::isA() const     { return &classDesc; } \
void classname::deepenVBase() \
{ \
        if (Class::_deepenVBase((void*)this)) \
                classname::deepenShallowCopy(); \
} \
void classname::storeVBaseOn(OIOofd& fd) const \
{ \
        if (Class::_storeVBase((void*)this)) classname::storer(fd); \
} \
void classname::storeVBaseOn(OIOout& strm) const \
{ \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -