home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 12.ddi / CLASSINC.PAK / STREAMBL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  4.8 KB  |  157 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  STREAMBL.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright (c) 1992, 1993 Borland International                        */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*  Class definitions for object streaming                                */
  9. /*                                                                        */
  10. /*                                                                        */
  11. /*                 +----------------+  +-------------+                    */
  12. /*                 |TStreamableTypes|  |ObjectBuilder|                    */
  13. /*                 +--+----------+--+  +-------------+                    */
  14. /*                    |class name|     |  BUILDER    |                    */
  15. /*                    +----------+     |  delta      |                    */
  16. /*                          |          +-------------+                    */
  17. /*                          |                 |                           */
  18. /*                          |                /\                           */
  19. /*                          |         +--------                           */
  20. /*                          |         |                                   */
  21. /*                          |         |                                   */
  22. /*                        +----------------+                              */
  23. /*                        |TStreamableClass|                              */
  24. /*                        +----------------+                              */
  25. /*                        |  Module ID     |                              */
  26. /*                        +----------------+                              */
  27. /*                                                                        */
  28. /*------------------------------------------------------------------------*/
  29.  
  30. #if !defined( __CLASSLIB_STREAMBL_H )
  31. #define __CLASSLIB_STREAMBL_H
  32.  
  33. #if !defined( __STRING_H )
  34. #include <string.h>
  35. #endif  // __STRING_H
  36.  
  37. #if !defined( __CLASSLIB_DEFS_H )
  38. #include "classlib\defs.h"
  39. #endif  // __CLASSLIB_DEFS_H
  40.  
  41. #if defined(_FASTTHIS)
  42. #  define _BIDSFASTTHIS __fastthis
  43. #else
  44. #  define _BIDSFASTTHIS
  45. #endif
  46.  
  47. #if !defined( __CLASSLIB_VECTIMP_H )
  48. #include "classlib\vectimp.h"
  49. #endif  // __CLASSLIB_VECTIMP_H
  50.  
  51. #if defined( BI_CLASSLIB_NO_po )
  52. #pragma option -po-
  53. #endif
  54.  
  55. #if defined( __WINDOWS__ ) && !defined( __WINDOWS_H )
  56. #include <windows.h>
  57. #endif  // __WINDOWS__ && __WINDOWS_H
  58.  
  59. #if defined( BI_NO_PER_INSTANCE_DATA ) && defined(_BIDSDLL)
  60.  
  61. extern HINSTANCE _hInstance;
  62. typedef unsigned ModuleId;
  63. inline ModuleId GetModuleId() { return (unsigned)_hInstance; }
  64.  
  65. #else
  66.  
  67. typedef unsigned ModuleId;
  68. inline ModuleId GetModuleId() { return 1; }
  69.  
  70. #endif
  71.  
  72. class _BIDSCLASS _BIDSFASTTHIS _RTTI TStreamer;
  73. class _BIDSCLASS _BIDSFASTTHIS _RTTI TStreamableBase;
  74.  
  75. typedef TStreamer *(* BUILDER)( TStreamableBase * );
  76.  
  77. struct _BIDSCLASS ObjectBuilder
  78. {
  79.  
  80.     enum { NoDelta = -1 };
  81.  
  82.     ObjectBuilder( BUILDER b, int d ) : Builder( b ), Delta( d )
  83.     {
  84.     }
  85.  
  86.     BUILDER Builder;
  87.     int Delta;
  88.  
  89. };
  90.  
  91. #define __DELTA( d ) (FP_OFF((TStreamable *)(d *)1)-1)
  92.  
  93. class _BIDSCLASS TStreamableClass : public ObjectBuilder
  94. {
  95.  
  96. public:
  97.  
  98.     TStreamableClass( const char *n, 
  99.                       BUILDER b, 
  100.                       int d = NoDelta,
  101.                       ModuleId mid = GetModuleId()
  102.                     );
  103.  
  104.     ~TStreamableClass();
  105.  
  106.     int operator == ( const TStreamableClass& n ) const
  107.         {
  108.         if( strcmp( ObjectId, n.ObjectId ) != 0 )
  109.             return 0;
  110.         else
  111.             return (ModId == 0 || n.ModId == 0 || ModId == n.ModId);
  112.         }
  113.  
  114.     int operator < ( const TStreamableClass& n ) const
  115.         {
  116.         int res = strcmp( ObjectId, n.ObjectId );
  117.         if( res < 0 )
  118.             return 1;
  119.         else if( res > 0 )
  120.             return 0;
  121.         else if( ModId == 0 || n.ModId == 0 || ModId == n.ModId )
  122.             return 0;
  123.         else
  124.             return ModId < n.ModId;
  125.         }
  126.  
  127. private:
  128.  
  129.     const char *ObjectId;
  130.     ModuleId ModId;
  131.  
  132. };
  133.  
  134. class _BIDSCLASS TStreamableTypes
  135. {
  136.  
  137. public:
  138.  
  139.     TStreamableTypes() : Types( 5, 5 ) {}
  140.  
  141.     void RegisterType( ModuleId id, TStreamableClass& );
  142.     void UnRegisterType( ModuleId id, TStreamableClass& );
  143.     const ObjectBuilder *Lookup( ModuleId id, const char *name ) const;
  144.  
  145. private:
  146.  
  147.     TISVectorImp< TStreamableClass > Types;
  148.  
  149. };
  150.  
  151. #if defined( BI_CLASSLIB_NO_po )
  152. #pragma option -po.
  153. #endif
  154.  
  155. #endif  // __CLASSLIB_STREAMBLE_H
  156.  
  157.