home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / classinc.pak / STREAMBL.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  5KB  |  157 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  STREAMBL.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright (c) 1992, 1994 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
  36.  
  37. #if !defined( CLASSLIB_DEFS_H )
  38. #include <classlib/defs.h>
  39. #endif
  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
  50.  
  51. #if defined( BI_CLASSLIB_NO_po )
  52. #pragma option -po-
  53. #endif
  54.  
  55. #if defined( BI_PLAT_MSW ) && !defined( __WINDOWS_H )
  56. #include <windows.h>
  57. #endif
  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.     _BIDSENTRY 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.     _BIDSENTRY TStreamableClass( const char *n, 
  99.                              BUILDER b, 
  100.                              int d = NoDelta,
  101.                              ModuleId mid = GetModuleId() );
  102.  
  103.     _BIDSENTRY ~TStreamableClass();
  104.  
  105.     int _BIDSENTRY operator == ( const TStreamableClass& n ) const
  106.         {
  107.         if( strcmp( ObjectId, n.ObjectId ) != 0 )
  108.             return 0;
  109.         else
  110.             return (ModId == 0 || n.ModId == 0 || ModId == n.ModId);
  111.         }
  112.  
  113.     int _BIDSENTRY operator < ( const TStreamableClass& n ) const
  114.         {
  115.         int res = strcmp( ObjectId, n.ObjectId );
  116.         if( res < 0 )
  117.             return 1;
  118.         else if( res > 0 )
  119.             return 0;
  120.         else if( ModId == 0 || n.ModId == 0 || ModId == n.ModId )
  121.             return 0;
  122.         else
  123.             return ModId < n.ModId;
  124.         }
  125.  
  126. private:
  127.  
  128.     const char *ObjectId;
  129.     ModuleId ModId;
  130.  
  131. };
  132.  
  133. class _BIDSCLASS TStreamableTypes
  134. {
  135.  
  136. public:
  137.  
  138.     _BIDSENTRY TStreamableTypes() : Types( 5, 5 ) {}
  139.  
  140.     void _BIDSENTRY RegisterType( ModuleId id, TStreamableClass& );
  141.     void _BIDSENTRY UnRegisterType( ModuleId id, TStreamableClass& );
  142.     const ObjectBuilder * _BIDSENTRY Lookup( ModuleId id,
  143.                                          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.