home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / R0 < prev    next >
Encoding:
Text File  |  1992-06-07  |  5.3 KB  |  166 lines

  1. #ifndef __RWCOLLECT_H__
  2. #define __RWCOLLECT_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * Declarations for RWCollectables: an abstract base class.
  7.  *
  8.  * $Header:   E:/vcs/rw/collect.h_v   1.8   17 Mar 1992 12:26:36   KEFFER  $
  9.  *
  10.  ****************************************************************************
  11.  *
  12.  * Rogue Wave Software, Inc.
  13.  * P.O. Box 2328
  14.  * Corvallis, OR 97339
  15.  * Voice: (503) 754-3010    FAX: (503) 757-6650
  16.  *
  17.  * Copyright (C) 1989, 1990, 1991. This software is subject to copyright 
  18.  * protection under the laws of the United States and other countries.
  19.  *
  20.  ***************************************************************************
  21.  *
  22.  * $Log:   E:/vcs/rw/collect.h_v  $
  23.  * 
  24.  *    Rev 1.8   17 Mar 1992 12:26:36   KEFFER
  25.  * Removed RWTV3_COMPATIBLE macro hooks.
  26.  * 
  27.  *    Rev 1.7   17 Mar 1992 11:32:36   KEFFER
  28.  * Moved process initialization stuff.
  29.  * Introduced DECLARE_COLLECTABLE macro.
  30.  * Introduced RW generic.h header file.
  31.  * 
  32.  *    Rev 1.6   21 Feb 1992 12:29:26   KEFFER
  33.  * nil collectable now defined when using the DLL.
  34.  * 
  35.  *    Rev 1.5   15 Nov 1991 13:01:06   keffer
  36.  * 
  37.  *    Rev 1.4   13 Nov 1991 11:07:42   keffer
  38.  * More robust DLL code; No longer declares GVector(RWCollectable); store and
  39.  * read tables now maintained by a separate manager.
  40.  * 
  41.  *    Rev 1.3   28 Oct 1991 09:08:10   keffer
  42.  * Changed inclusions to <rw/xxx.h>
  43.  * 
  44.  *    Rev 1.2   09 Oct 1991 18:34:32   keffer
  45.  * Ported to Zortech V3.0
  46.  * 
  47.  */
  48.  
  49. #ifndef __RWTOOLDEFS_H__
  50. #  include "rw/tooldefs.h"
  51. #endif
  52. #ifndef __RWMEMPOOL_H__
  53. #  include "rw/mempool.h"
  54. #endif
  55. #ifndef __RWGENERIC_H__
  56. #  include "rw/generic.h"
  57. #endif
  58. #if !defined(__RWPROCINIT_H__) && defined(RW_MULTI_THREAD)
  59. #  include "rw/procinit.h"
  60. #endif
  61. #ifdef UNDEFINED_REFERENCE_BUG
  62. #  include "rw/rstream.h"
  63. #endif
  64.  
  65. /************************************************************************
  66.  *                                    *
  67.  * The macro DECLARE_COLLECTABLE should be included in the declaration    *
  68.  * of any class that derives from RWCollectable.            *
  69.  *                                    *
  70.  ************************************************************************/
  71.  
  72. #define DECLARE_COLLECTABLE(className)                \
  73. public:                                \
  74.   virtual ClassID        isA() const;            \
  75.   virtual RWCollectable*    newSpecies() const;
  76.  
  77.  
  78. // Base class for collectable objects.
  79.  
  80. class RWExport RWCollectable {
  81.  
  82.   DECLARE_COLLECTABLE(RWCollectable)
  83.  
  84. public:
  85.  
  86.   RWCollectable();
  87.   virtual            ~RWCollectable();
  88.  
  89.   virtual unsigned        binaryStoreSize() const;
  90.   virtual int            compareTo(const RWCollectable*) const;
  91.   virtual unsigned        hash() const;
  92.   virtual RWBoolean        isEqual(const RWCollectable*) const;
  93.   virtual void            restoreGuts(RWFile&);
  94.   virtual void            restoreGuts(RWvistream&);
  95.   virtual void            saveGuts(RWFile&) const;
  96.   virtual void            saveGuts(RWvostream&) const;
  97.   unsigned            shallowStoreSize() const;
  98.   static RWCollectable*        restoreFrom(RWFile&);
  99.   static RWCollectable*        restoreFrom(RWvistream&);
  100.   void                saveOn(RWFile&) const;
  101.   void                saveOn(RWvostream&) const;
  102. };
  103.  
  104. extern void                rwexport rwDestroy(RWCollectable*, void*);
  105. extern RWBoolean           rwexport rwIsEqualFun(const void* a, const void* b);
  106. extern void                rwexport rwAddToFactory(userCreator fn, ClassID id);
  107. extern RWCollectable*      rwexport rwCreateFromFactory(ClassID);
  108. extern void                rwexport rwRemoveFromFactory(ClassID);
  109.  
  110. #ifdef RW_MULTI_THREAD
  111.   // Multi-thread situation; get nil object from the instance mgr.
  112.   extern RWCollectable* getRWNilCollectable();
  113. # define RWnilCollectable (getRWNilCollectable())
  114. #else
  115.    // Not a multi-threaded situation; use a global nil object.
  116.    extern RWCollectable* RWnilCollectable;
  117. #endif
  118.  
  119. /************************************************************************
  120.  *                                    *
  121.  * The macro DEFINE_COLLECTABLE presently serves two functions:        *
  122.  * 1) To define and insert a "creator function" to be inserted        *
  123.  *    into the one-of-a-kind global RWFactory pointed to by theFactory.    *
  124.  * 2) To provide a definition for newSpecies().                *
  125.  *                                    *
  126.  *    They cannot be combined using a pointer to member function    *
  127.  *    because there is no global instance that can be used to        *
  128.  *    dereference it.                            *
  129.  ************************************************************************/
  130.  
  131. #define Init(className)        name2(className,Init)
  132. #define createFN(className)    name2(className,createFN)
  133.  
  134. #define DEFINE_COLLECTABLE(className)                \
  135.                                 \
  136. /* Member function to create an instance of the class.*/    \
  137. RWCollectable* className::newSpecies() const            \
  138. { return new className; }                    \
  139.                                 \
  140. struct Init(className) {                    \
  141.   Init(className)();                        \
  142.   ~Init(className)();                        \
  143. };                                \
  144.                                   \
  145. /* Global function to create an instance of the class.*/    \
  146. RWCollectable*                            \
  147. createFN(className)()                        \
  148. { return new className; }                    \
  149.                                       \
  150. /* The constructor adds the function to the Factory. */        \
  151. Init(className)::Init(className)(){                \
  152.   className temp;                        \
  153.   rwAddToFactory(createFN(className), temp.isA());        \
  154. }                                \
  155.                                 \
  156. Init(className)::~Init(className)(){                \
  157.   className temp;                        \
  158.   rwRemoveFromFactory(temp.isA());                \
  159. }                                \
  160.                                 \
  161. /* Invoke the constructor to do the job: */              \
  162. Init(className) name2(Dummy,className);
  163.  
  164. pragma pop_align_members();
  165. #endif /* __RWCOLLECT_H__ */
  166.