home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / CLASSINC.PAK / STREAMBL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.0 KB  |  160 lines

  1. //----------------------------------------------------------------------------
  2. // Borland Class Library
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   5.7  $
  6. //
  7. // Class definitions for object streaming
  8. //
  9. //
  10. //                 +----------------+  +-------------+
  11. //                 |TStreamableTypes|  |ObjectBuilder|
  12. //                 +--+----------+--+  +-------------+
  13. //                    |class name|     |  BUILDER    |
  14. //                    +----------+     |  delta      |
  15. //                          |          +-------------+
  16. //                          |                 |
  17. //                          |                 /\ .
  18. //                          |         +--------
  19. //                          |         |
  20. //                          |         |
  21. //                        +----------------+
  22. //                        |TStreamableClass|
  23. //                        +----------------+
  24. //                        |  Module ID     |
  25. //                        +----------------+
  26. //
  27. //----------------------------------------------------------------------------
  28. #if !defined(CLASSLIB_STREAMBL_H)
  29. #define CLASSLIB_STREAMBL_H
  30.  
  31. #if !defined(CLASSLIB_DEFS_H)
  32. # include <classlib/defs.h>
  33. #endif
  34. #if !defined(__STRING_H) && !defined(_INC_STRING)
  35. # include <string.h>
  36. #endif
  37. #if !defined (__TCHAR_H)
  38. # include <tchar.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. #if defined(BI_PLAT_MSW) && !defined(SERVICES_WSYSINC_H)
  51. # include <services/wsysinc.h>
  52. #endif
  53.  
  54. #if defined( BI_CLASSLIB_NO_po )
  55. # pragma option -po-
  56. #endif
  57.  
  58. #if defined(BI_NAMESPACE)
  59. namespace ClassLib {
  60. #endif
  61.  
  62. #if defined( BI_NO_PER_INSTANCE_DATA ) && defined(_BIDSDLL)
  63.  
  64.   typedef unsigned ModuleId;
  65.   inline ModuleId GetModuleId() { return (unsigned)_hInstance; }
  66.  
  67. #else
  68.  
  69.   typedef unsigned ModuleId;
  70.   inline ModuleId GetModuleId() { return 1; }
  71.  
  72. #endif
  73.  
  74. class _BIDSCLASS _BIDSFASTTHIS _RTTI TStreamer;
  75. class _BIDSCLASS _BIDSFASTTHIS _RTTI TStreamableBase;
  76.  
  77. typedef TStreamer* _CALLCNVN (*BUILDER)( TStreamableBase * );
  78.  
  79. struct _BIDSCLASS ObjectBuilder
  80. {
  81.  
  82.     enum { NoDelta = -1 };
  83.  
  84.     _BIDSCTOR ObjectBuilder( BUILDER b, int d ) : Builder( b ), Delta( d ) {}
  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.     _BIDSCTOR TStreamableClass( const _TCHAR *n,
  99.                              BUILDER b,
  100.                              int d = NoDelta,
  101.                              ModuleId mid = GetModuleId() );
  102.  
  103.     _BIDSCTOR ~TStreamableClass();
  104.  
  105.     int _BIDSENTRY operator == ( const TStreamableClass& n ) const
  106.         {
  107.         if( _tcscmp( 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 = _tcscmp( 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 _TCHAR *ObjectId;
  129.     ModuleId ModId;
  130.  
  131. };
  132.  
  133. class _BIDSCLASS TStreamableTypes
  134. {
  135.  
  136. public:
  137.  
  138.     _BIDSCTOR 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 _TCHAR *name ) const;
  144.  
  145. private:
  146.  
  147.     TISVectorImp< TStreamableClass > Types;
  148.  
  149. };
  150.  
  151. #if defined(BI_NAMESPACE)
  152. }   // namespace ClassLib
  153. #endif
  154.  
  155. #if defined( BI_CLASSLIB_NO_po )
  156. # pragma option -po.
  157. #endif
  158.  
  159. #endif  // CLASSLIB_STREAMBLE_H
  160.