home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / STREAMS.PAK / STRMPNT.H < prev   
C/C++ Source or Header  |  1995-08-29  |  3KB  |  101 lines

  1. // ---------------------------------------------------------------------------
  2. // Copyright (C) 1994 Borland International
  3. //  strmpnt.h
  4. // ---------------------------------------------------------------------------
  5. #ifndef STRMPNT_H
  6. #define STRMPNT_H
  7.  
  8. #include <classlib/objstrm.h>
  9. #include <iostream.h>
  10.  
  11. //
  12. // T2DPoint
  13. //
  14. // Simple object used for streaming.
  15. // 
  16. const int T2DPointVersion = 1;
  17.  
  18. class T2DPoint : public virtual TStreamableBase {
  19.   public:
  20.     T2DPoint(int i=0, int j=0);
  21.     virtual void Draw();
  22.  
  23.   protected:
  24.     int X;
  25.     int Y;
  26.  
  27.   DECLARE_STREAMABLE(, T2DPoint, T2DPointVersion);
  28. };
  29.  
  30.  
  31. // 
  32. // T3DPoint
  33. // 
  34. // Multiple-derived object used for streaming.
  35. // 
  36. const int T3DPointVersion = 2;
  37.  
  38. class T3DPoint : public T2DPoint {
  39.   public:
  40.     T3DPoint(int i=0, int j=0, int k=0);
  41.     virtual void Draw();
  42.  
  43.   protected:
  44.     int Z;
  45.  
  46.   DECLARE_STREAMABLE(, T3DPoint, T3DPointVersion);
  47. };
  48.  
  49. // 
  50. // TColor
  51. // 
  52. // A non-streamable base class to show streaming of a multiply inherited
  53. // class.
  54. // 
  55. const int TColorVersion=3;
  56.  
  57. class TColor {
  58.   public:
  59.     TColor(int i=0, int j=0, int k=0);
  60.     virtual void DisplayColor();
  61.  
  62.   protected:
  63.     int R;
  64.     int G;
  65.     int B;
  66. };
  67.  
  68. // T2DPointColor                                                   
  69. //    Streaming of a multiply inherited class where one branch     
  70. //    of inheritence is streamable (T2DPoint) and one branch       
  71. //    is not (TColor).                                             
  72. //                                                                 
  73. //    Notice in the definition of                                  
  74. //      Streamer::Read and Streamer::Write                         
  75. //    there's code to stream the data members of the TColor.       
  76. //    If the code is not provided, then the members of TColor      
  77. //    will be lost.                                                
  78. //    If all branches of the inheritence are already streamable,   
  79. //    then the Read and Write functions are easily defined.        
  80. //    For example,                                                 
  81. //        void Derived::Streamer::Write(opstream &os) const        
  82. //        {                                                        
  83. //          WriteBaseObject((Base1 *)GetObject(), os);             
  84. //          WriteBaseObject((Base2 *)GetObject(), os);             
  85. //          ...                                                    
  86. //          os << NewDataMember1;                                  
  87. //          os << NewDataMember2;                                  
  88. //          ...                                                    
  89. //        }                                                        
  90. //    Similarly for the Read function.                             
  91. const int T2DPointColorVersion=3;
  92.  
  93. class T2DPointColor : public T2DPoint, public TColor {
  94.   public:
  95.     T2DPointColor(int x, int y, int r, int g, int b);
  96.     virtual void Draw();
  97.  
  98.   DECLARE_STREAMABLE(, T2DPointColor, T2DPointColorVersion);
  99. };
  100.  
  101. #endif