home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 10.ddi / TVSRC.ZIP / PALETTE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.9 KB  |  63 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       palette.cpp                               */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TPalette member functions                 */
  6. /*------------------------------------------------------------*/
  7.                                                               
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TPalette
  19. #include <tv.h>
  20.  
  21. #if !defined( __MEM_H )
  22. #include <Mem.h>
  23. #endif  // __MEM_H
  24.  
  25.  
  26. TPalette::TPalette( const char* d, ushort len ) :
  27.     data( new char[ len+1 ] )
  28. {
  29.     data[0] = len;
  30.     memcpy( data+1, d, len );
  31. }
  32.  
  33. TPalette::TPalette( const TPalette& tp ) :
  34.     data( new char[ tp.data[0] ] )
  35. {
  36.     memcpy( data, tp.data, tp.data[0] );
  37. }
  38.  
  39. TPalette::~TPalette()
  40. {
  41.     delete data;
  42. }
  43.  
  44. TPalette& TPalette::operator = ( const TPalette& tp )
  45. {
  46.     if( data != tp.data )
  47.         {
  48.         if( data[0] != tp.data[0] )
  49.             {
  50.             delete data;
  51.             data = new char[ tp.data[0] ];
  52.             data[0] = tp.data[0];
  53.             }
  54.         memcpy( data+1, tp.data+1, data[0] );
  55.         }
  56.     return *this;
  57. }
  58.  
  59. char& TPalette::operator[]( int index ) const
  60. {
  61.     return data[index];
  62. }
  63.