home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / tvpal / tvpal.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-09  |  2.8 KB  |  118 lines

  1. //
  2. // PALETTE.CPP
  3. //
  4. // Copyright (c) 1992 CC Software
  5. // All rights reserved
  6. //
  7.  
  8. // Contents ===========================================================
  9. //
  10. //      TStreamPalette::read
  11. //      TStreamPalette::write
  12. //      TStreamPalette::build
  13. //
  14. // Description
  15. //
  16. //      TStreamPalette non-inline member functions
  17. //
  18. // END Contents =======================================================
  19.  
  20. #include "TVPal.h"
  21.  
  22.  
  23. // Stream Registration Records //
  24.  
  25. TStreamableClass RStreamPalette(
  26.                    TStreamPalette::name,
  27.                    TStreamPalette::build,
  28.                    __DELTA(TStreamPalette)
  29.                  );
  30.  
  31.  
  32. // Static Class Data //
  33.  
  34. char _FAR* TStreamPalette::name = "TStreamPalette";
  35.  
  36.  
  37. // Member Function //
  38.  
  39. TStreamable _FAR* TStreamPalette::build()
  40. // Summary ------------------------------------------------------------
  41. //
  42. //      Returns a "dumb" TStreamPalette object to be filled from a
  43. //      stream read.
  44. //
  45. // END Summary --------------------------------------------------------
  46. {
  47.   return new TStreamPalette( streamableInit );
  48. };
  49. // END TStreamPalette::build ------------------------------------------
  50.  
  51.  
  52.  
  53. // Member function //
  54.  
  55. void TStreamPalette::write( opstream _FAR& os )
  56. // Summary ------------------------------------------------------------
  57. //
  58. //      Writes the object to the stream.  We first write the palette
  59. //      length (which is stored in the zero index), then the actual
  60. //      palette entries.
  61. //
  62. // Parameters
  63. //
  64. //      os
  65. //
  66. //      An opstream derived class to write on.
  67. //
  68. // END Summary --------------------------------------------------------
  69. {
  70.   ushort len = operator[](0);
  71.   os.writeBytes( &len, sizeof(len) );
  72.  
  73.   if ( len )
  74.      os.writeBytes( &(operator[](1)), len );
  75. };
  76. // END TStreamPalette::write ------------------------------------------
  77.  
  78.  
  79.  
  80. // Member function //
  81.  
  82. void *TStreamPalette::read( ipstream _FAR& is )
  83. // Summary ------------------------------------------------------------
  84. //
  85. //      Reads the palette in from the stream.  The actual stream object
  86. //      is first read into a data buffer, then the convenient operator=
  87. //      for the TPalette is called on the (*this) operator to assign the
  88. //      bytes to this object.
  89. //
  90. // Parameters
  91. //
  92. //      is
  93. //
  94. //      Input stream we are reading the bytes from.
  95. //
  96. // Return Value
  97. //
  98. //      Returns this.
  99. //
  100. // END Summary --------------------------------------------------------
  101. {
  102.   TPalette *tp;
  103.   ushort len = 0;
  104.   char *data = NULL;
  105.  
  106.   is.readBytes( &len, sizeof(len) );
  107.   if ( len )
  108.   {
  109.     data = new char[ len ];
  110.     is.readBytes( data, len );
  111.     tp = new TPalette( data, len );
  112.     *this = *tp;
  113.     delete data;
  114.     delete tp;
  115.   };
  116.   return this;
  117. };
  118. // END TStreamPalette::read -------------------------------------------