home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20os2.zip / src / TCommandSet.cpp < prev    next >
C/C++ Source or Header  |  1998-01-19  |  2KB  |  109 lines

  1. /*
  2.  * TCommandSet.cc
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #define Uses_TCommandSet
  13. #include <tvision/tv.h>
  14.  
  15. int TCommandSet::masks[8] =
  16. {
  17.     0x0001,
  18.     0x0002,
  19.     0x0004,
  20.     0x0008,
  21.     0x0010,
  22.     0x0020,
  23.     0x0040,
  24.     0x0080
  25. };
  26.  
  27. TCommandSet::TCommandSet()
  28. {
  29.     for( int i = 0; i < 32; i++ )
  30.         cmds[i] = 0;
  31. }
  32.  
  33. TCommandSet::TCommandSet( const TCommandSet& tc )
  34. {
  35.     for( int i = 0; i < 32; i++ )
  36.         cmds[i] = tc.cmds[i];
  37. }
  38.  
  39. Boolean TCommandSet::has( int cmd )
  40. {
  41.     return Boolean( (cmds[ loc( cmd ) ] & mask( cmd )) != 0 );
  42. }
  43.  
  44. void TCommandSet::disableCmd( int cmd )
  45. {
  46.     cmds[ loc( cmd ) ] &= ~mask( cmd );
  47. }
  48.  
  49. void TCommandSet::enableCmd( const TCommandSet& tc )
  50. {
  51.     for( int i = 0; i < 32; i++ )
  52.         cmds[i] |= tc.cmds[i];
  53. }
  54.  
  55. void TCommandSet::disableCmd( const TCommandSet& tc )
  56. {
  57.     for( int i = 0; i < 32; i++ )
  58.         cmds[i] &= ~(tc.cmds[i]);
  59. }
  60.  
  61. void TCommandSet::enableCmd( int cmd )
  62. {
  63.     cmds[ loc( cmd ) ] |= mask( cmd );
  64. }
  65.  
  66. TCommandSet& TCommandSet::operator &= ( const TCommandSet& tc )
  67. {
  68.     for( int i = 0; i < 32; i++ )
  69.         cmds[i] &= tc.cmds[i];
  70.     return *this;
  71. }
  72.  
  73. TCommandSet& TCommandSet::operator |= ( const TCommandSet& tc )
  74. {
  75.     for( int i = 0; i < 32; i++ )
  76.         cmds[i] |= tc.cmds[i];
  77.     return *this;
  78. }
  79.  
  80. TCommandSet operator & ( const TCommandSet& tc1, const TCommandSet& tc2 )
  81. {
  82.     TCommandSet temp( tc1 );
  83.     temp &= tc2;
  84.     return temp;
  85. }
  86.  
  87. TCommandSet operator | ( const TCommandSet& tc1, const TCommandSet& tc2 )
  88. {
  89.     TCommandSet temp( tc1 );
  90.     temp |= tc2;
  91.     return temp;
  92. }
  93.  
  94. Boolean TCommandSet::isEmpty()
  95. {
  96.     for( int i = 0; i < 32; i++ )
  97.         if( cmds[i] != 0 )
  98.             return False;
  99.     return True;
  100. }
  101.  
  102. int operator == ( const TCommandSet& tc1, const TCommandSet& tc2 )
  103. {
  104.     for( int i = 0; i < 32; i++ )
  105.         if( tc1.cmds[i] != tc2.cmds[i] )
  106.             return 0;
  107.     return 1;
  108. }
  109.