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

  1. /*------------------------------------------------------------*/
  2. /* filename -       tcmdset.cpp                               */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TCommandSet 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_TCommandSet
  19. #include <tv.h>
  20.  
  21. int near TCommandSet::masks[8] =
  22. {
  23.     0x0001,
  24.     0x0002,
  25.     0x0004,
  26.     0x0008,
  27.     0x0010,
  28.     0x0020,
  29.     0x0040,
  30.     0x0080
  31. };
  32.  
  33. TCommandSet::TCommandSet()
  34. {
  35.     for( int i = 0; i < 32; i++ )
  36.         cmds[i] = 0;
  37. }
  38.  
  39. TCommandSet::TCommandSet( const TCommandSet& tc )
  40. {
  41.     for( int i = 0; i < 32; i++ )
  42.         cmds[i] = tc.cmds[i];
  43. }
  44.  
  45. Boolean TCommandSet::has( int cmd )
  46. {
  47.     return Boolean( (cmds[ loc( cmd ) ] & mask( cmd )) != 0 );
  48. }
  49.  
  50. void TCommandSet::disableCmd( int cmd )
  51. {
  52.     cmds[ loc( cmd ) ] &= ~mask( cmd );
  53. }
  54.  
  55. void TCommandSet::enableCmd( const TCommandSet& tc )
  56. {
  57.     for( int i = 0; i < 32; i++ )
  58.         cmds[i] |= tc.cmds[i];
  59. }
  60.  
  61. void TCommandSet::disableCmd( const TCommandSet& tc )
  62. {
  63.     for( int i = 0; i < 32; i++ )
  64.         cmds[i] &= ~(tc.cmds[i]);
  65. }
  66.  
  67. void TCommandSet::enableCmd( int cmd )
  68. {
  69.     cmds[ loc( cmd ) ] |= mask( cmd );
  70. }
  71.  
  72. TCommandSet& TCommandSet::operator &= ( const TCommandSet& tc )
  73. {
  74.     for( int i = 0; i < 32; i++ )
  75.         cmds[i] &= tc.cmds[i];
  76.     return *this;
  77. }
  78.  
  79. TCommandSet& TCommandSet::operator |= ( const TCommandSet& tc )
  80. {
  81.     for( int i = 0; i < 32; i++ )
  82.         cmds[i] |= tc.cmds[i];
  83.     return *this;
  84. }
  85.  
  86. TCommandSet operator & ( const TCommandSet& tc1, const TCommandSet& tc2 )
  87. {
  88.     TCommandSet temp( tc1 );
  89.     temp &= tc2;
  90.     return temp;
  91. }
  92.  
  93. TCommandSet operator | ( const TCommandSet& tc1, const TCommandSet& tc2 )
  94. {
  95.     TCommandSet temp( tc1 );
  96.     temp |= tc2;
  97.     return temp;
  98. }
  99.  
  100. Boolean TCommandSet::isEmpty()
  101. {
  102.     for( int i = 0; i < 32; i++ )
  103.         if( cmds[i] != 0 )
  104.             return False;
  105.     return True;
  106. }
  107.  
  108. int operator == ( const TCommandSet& tc1, const TCommandSet& tc2 )
  109. {
  110.     for( int i = 0; i < 32; i++ )
  111.         if( tc1.cmds[i] != tc2.cmds[i] )
  112.             return 0;
  113.     return 1;
  114. }
  115.  
  116.