home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IBITFLAG.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  49KB  |  765 lines

  1. #ifndef _IBITFLAG_
  2.   #define _IBITFLAG_
  3. /*******************************************************************************
  4. * FILE NAME: ibitflag.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IBitFlag - Abstract base class for style and attribute classes.          *
  9. *                                                                              *
  10. *   Definition of the macros:                                                  *
  11. *     INESTEDBITFLAGCLASSDEF0  - Subclass definition.                          *
  12. *     INESTEDBITFLAGCLASSDEF1  - Subclass definition.                          *
  13. *     INESTEDBITFLAGCLASSDEF2  - Subclass definition.                          *
  14. *     INESTEDBITFLAGCLASSDEF3  - Subclass definition.                          *
  15. *     INESTEDBITFLAGCLASSDEF4  - Subclass definition.                          *
  16. *     INESTEDBITFLAGCLASSFUNCS - Definition of global functions.               *
  17. *                                                                              *
  18. * COPYRIGHT:                                                                   *
  19. *   Licensed Materials - Property of IBM                                       *
  20. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  21. *   All Rights Reserved                                                        *
  22. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  23. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  24. *                                                                              *
  25. *******************************************************************************/
  26. #ifndef _IBASE_
  27.   #include <ibase.hpp>
  28. #endif
  29.  
  30. /*----------------------------------------------------------------------------*/
  31. /* Align classes on four byte boundary.                                       */
  32. /*----------------------------------------------------------------------------*/
  33. #pragma pack(4)
  34.  
  35. // Forward declarations for other classes:
  36.  
  37.  
  38. class IBitFlag : public IBase {
  39. typedef IBase
  40.   Inherited;
  41. /*******************************************************************************
  42. * IBitFlag is the abstract base class for bitwise styles and attributes used   *
  43. * by window and control classes in the library.  Because this class is an      *
  44. * abstract base class, instances of this class cannot be created.              *
  45. *                                                                              *
  46. * Typically, derived classes of IBitFlag are declared using the macros         *
  47. * accompanying this class.  These macros optionally allow for instances of     *
  48. * one derived class to be constructed from or combined with instances of       *
  49. * another IBitFlag-derived class (for example, using the bitwise OR operator). *
  50. *******************************************************************************/
  51. public:
  52. /*--------------------------------- Accessor -----------------------------------
  53. | This function returns the value of the object.                               |
  54. |   asUnsignedLong - Converts the object to an unsigned long value.            |
  55. ------------------------------------------------------------------------------*/
  56. unsigned long
  57.   asUnsignedLong ( ) const;
  58.  
  59. /*-------------------------------- Comparison ----------------------------------
  60. | The following functions are used to compare bitflag values:                  |
  61. |   operator == - Used to compare two bitflag values for equality.             |
  62. |   operator != - Used to compare two bitflag values for inequality.           |
  63. ------------------------------------------------------------------------------*/
  64. Boolean
  65.   operator ==    ( const IBitFlag &rhs ) const,
  66.   operator !=    ( const IBitFlag &rhs ) const;
  67.  
  68. protected:
  69. /*------------------------- Constructors/Destructors ---------------------------
  70. | The only way to construct instances of this class is from an unsigned        |
  71. | long value.                                                                  |
  72. |                                                                              |
  73. | Note: This constructor is protected because objects derived from this class  |
  74. |       should not be arbitrarily constructed.  To provide type safety for     |
  75. |       window and control constructors, only existing style and attribute     |
  76. |       objects, and combinations of these objects, can be specified.          |
  77. ------------------------------------------------------------------------------*/
  78.   IBitFlag       ( unsigned long value );
  79.  
  80. /*-------------------------------- Assignment ----------------------------------
  81. | This function sets the value of the object.                                  |
  82. |   setValue  - Assigns an unsigned long value to the object.                  |
  83. ------------------------------------------------------------------------------*/
  84. IBitFlag
  85.  &setValue       ( unsigned long value );
  86.  
  87. private:
  88. /*--------------------------------- Private ----------------------------------*/
  89. unsigned long
  90.   ulClValue;
  91. }; /* IBitFlag */
  92.  
  93.  
  94. /*---------------------------- Macro Definitions -------------------------------
  95. | Below are macros to help generate the declaration of classes derived from    |
  96. | IBitFlag and friend functions necessary to combine objects of different      |
  97. | classes.                                                                     |
  98. ------------------------------------------------------------------------------*/
  99.  
  100. /*******************************************************************************
  101. * INESTEDBITFLAGCLASSDEF0 macro                                                *
  102. *                                                                              *
  103. * Used for the declaration of a logical base bitwise flag class scoped to      *
  104. * another class.  A logical base bitwise flag class is a class of bitwise      *
  105. * flag objects that cannot be constructed from a bitwise flag object of        *
  106. * another class.                                                               *
  107. *                                                                              *
  108. * Usage:  INESTEDBITFLAGCLASSDEF0( className, assoc );                         *
  109. *           where                                                              *
  110. *             className is the name of the bitwise flag class being declared,  *
  111. *               and                                                            *
  112. *             assoc is the name of the window class associated with (and       *
  113. *               scoping) the bitwise flag class                                *
  114. *         Examples: INESTEDBITFLAGCLASSDEF0( Style, IWindow );                 *
  115. *                   INESTEDBITFLAGCLASSDEF0( Attribute, IMenuItem );           *
  116. *         This macro is intended to be nested within the associated class      *
  117. *         definition. (For example, the above examples should be used to       *
  118. *         declare the IWindow::Style and IMenuItem::Attribute classes.)        *
  119. *                                                                              *
  120. * Expands to:                                                                  *
  121. *   class className : public IBitFlag                                          *
  122. *   {                                                                          *
  123. *   friend class assoc;                                                        *
  124. *   public:                                                                    *
  125. *     class Negated##className : public IBitFlag                               *
  126. *     {                                                                        *
  127. *     friend class className;                                                  *
  128. *     public:                                                                  *
  129. *       Negated##className  operator & ( const Negated##className &aFlag )     *
  130. *                                                                     const    *
  131. *       {                                                                      *
  132. *       Negated##className aResult ( asUnsignedLong() &                        *
  133. *                                    aFlag.asUnsignedLong() );                 *
  134. *       return aResult;                                                        *
  135. *       }                                                                      *
  136. *     protected:                                                               *
  137. *       Negated##className ( unsigned long val )                               *
  138. *         : IBitFlag ( val ) {}                                                *
  139. *     };                                                                       *
  140. *     className##&  operator |= ( const className &aFlag )                     *
  141. *     {                                                                        *
  142. *       className tmpFlag = *this | aFlag;                                     *
  143. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  144. *       return *this;                                                          *
  145. *     }                                                                        *
  146. *     Negated##className  operator ~ ( ) const                                 *
  147. *     {                                                                        *
  148. *       return Negated##className ( ~asUnsignedLong() );                       *
  149. *     }                                                                        *
  150. *     className##&  operator &= ( const Negated##className &aFlag )            *
  151. *     {                                                                        *
  152. *       className tmpFlag = *this & aFlag;                                     *
  153. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  154. *       return *this;                                                          *
  155. *     }                                                                        *
  156. *     className  operator | ( const className &aFlag ) const                   *
  157. *     {                                                                        *
  158. *       className aResult ( asUnsignedLong() | aFlag.asUnsignedLong() );       *
  159. *       return aResult;                                                        *
  160. *     }                                                                        *
  161. *     className  operator & ( const Negated##className &aFlag ) const          *
  162. *     {                                                                        *
  163. *       className aResult ( asUnsignedLong() & aFlag.asUnsignedLong() );       *
  164. *       return aResult;                                                        *
  165. *     }                                                                        *
  166. *     unsigned long  operator & ( const className &aFlag ) const               *
  167. *     {                                                                        *
  168. *       return ( asUnsignedLong() & aFlag.asUnsignedLong() );                  *
  169. *     }                                                                        *
  170. *   protected:                                                                 *
  171. *     className ( unsigned long val )                                          *
  172. *       : IBitFlag ( val ) {}                                                  *
  173. *   }                                                                          *
  174. *******************************************************************************/
  175. #define INESTEDBITFLAGCLASSDEF0( className, assoc )\
  176. class className : public IBitFlag\
  177. {\
  178. friend class assoc;\
  179. public:\
  180.   class Negated##className : public IBitFlag\
  181.   {\
  182.   friend class className;\
  183.   public:\
  184.     COMMONNEGBITPUBLIC0( className )\
  185.   protected:\
  186.     COMMONNEGBITPROTECTED( className )\
  187.   };\
  188.   COMMONBITPUBLIC( className )\
  189.   COMMONBITPUBLIC0( className )\
  190. protected:\
  191.   COMMONBITPROTECTED( className )\
  192. }
  193.  
  194.  
  195. /*******************************************************************************
  196. * INESTEDBITFLAGCLASSDEF1 macro                                                *
  197. *                                                                              *
  198. * Used for the declaration of a bitwise flag class whose objects can be        *
  199. * constructed from an object of another bitwise flag class.  Both bitwise flag *
  200. * classes are assumed to have the same name and be scoped to another class.    *
  201. *                                                                              *
  202. * Usage:  INESTEDBITFLAGCLASSDEF1( className, assoc, base1 );                  *
  203. *           where                                                              *
  204. *             className is the name of the bitwise flag class being declared,  *
  205. *             assoc is the name of the class associated with (and scoping)     *
  206. *               the bitwise flag class being declared, and                     *
  207. *             base1 is the name of the class scoping the bitwise flag class    *
  208. *               from which the new bitwise flag class can be constructed       *
  209. *         Examples:                                                            *
  210. *           INESTEDBITFLAGCLASSDEF1( Style, IControl, IWindow );               *
  211. *           INESTEDBITFLAGCLASSDEF1( Style, IStaticText, IWindow );            *
  212. *         This macro is intended to be nested within the associated class      *
  213. *         definition. (For example, the above examples should be used to       *
  214. *         declare the IControl::Style and IStaticText::Style classes).         *
  215. *                                                                              *
  216. * Expands to:                                                                  *
  217. *   class className : public IBitFlag                                          *
  218. *   {                                                                          *
  219. *   friend class assoc;                                                        *
  220. *   public:                                                                    *
  221. *     class Negated##className : public IBitFlag                               *
  222. *     {                                                                        *
  223. *     friend class className;                                                  *
  224. *     public:                                                                  *
  225. *       Negated##className ( const base1##::##className##::Negated##className  *
  226. *                                                                    &aFlag )  *
  227. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  228. *       friend Negated##className  operator & ( const Negated##className &lhs, *
  229. *                                             const Negated##className &rhs ); *
  230. *       friend className  operator & ( const Negated##className &lhs,          *
  231. *                                      const className &rhs );                 *
  232. *     protected:                                                               *
  233. *       Negated##className ( unsigned long val )                               *
  234. *         : IBitFlag ( val ) {}                                                *
  235. *     };                                                                       *
  236. *     className##&  operator |= ( const className &aFlag )                     *
  237. *     {                                                                        *
  238. *       className tmpFlag = *this | aFlag;                                     *
  239. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  240. *       return *this;                                                          *
  241. *     }                                                                        *
  242. *     Negated##className  operator ~ ( ) const                                 *
  243. *     {                                                                        *
  244. *       return Negated##className ( ~asUnsignedLong() );                       *
  245. *     }                                                                        *
  246. *     className##&  operator &= ( const Negated##className &aFlag )            *
  247. *     {                                                                        *
  248. *       className tmpFlag = *this & aFlag;                                     *
  249. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  250. *       return *this;                                                          *
  251. *     }                                                                        *
  252. *     className ( const base1##::##className &aFlag )                          *
  253. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  254. *     friend className  operator | ( const className &lhs,                     *
  255. *                                    const className &rhs );                   *
  256. *     friend className  operator & ( const className &lhs,                     *
  257. *                                    const Negated##className &rhs );          *
  258. *   protected:                                                                 *
  259. *     className ( unsigned long val )                                          *
  260. *       : IBitFlag ( val ) {}                                                  *
  261. *   }                                                                          *
  262. *******************************************************************************/
  263. #define INESTEDBITFLAGCLASSDEF1( className, assoc, base1 )\
  264. class className : public IBitFlag\
  265. {\
  266. friend class assoc;\
  267. public:\
  268.   class Negated##className : public IBitFlag\
  269.   {\
  270.   friend class className;\
  271.   public:\
  272.     COMMONNEGBITPUBLIC1( className, base1 )\
  273.   protected:\
  274.     COMMONNEGBITPROTECTED( className )\
  275.   };\
  276.   COMMONBITPUBLIC( className )\
  277.   COMMONBITPUBLIC1( className, base1 )\
  278. protected:\
  279.   COMMONBITPROTECTED( className )\
  280. }
  281.  
  282.  
  283. /*******************************************************************************
  284. * INESTEDBITFLAGCLASSDEF2 macro                                                *
  285. *                                                                              *
  286. * Used for the declaration of a bitwise flag class whose objects can be        *
  287. * constructed from an object of two other bitwise flag classes.  All the       *
  288. * bitwise flag classes are assumed to have the same name and be scoped to      *
  289. * another class.                                                               *
  290. *                                                                              *
  291. * Usage:  INESTEDBITFLAGCLASSDEF2( className, assoc, base1, base2 );           *
  292. *           where                                                              *
  293. *             className is the name of the bitwise flag class being declared,  *
  294. *             assoc is the name of the class associated with (and scoping)     *
  295. *               the bitwise flag class being declared, and                     *
  296. *             base1 and base2 are the names of the classes scoping the bitwise *
  297. *               flag classes from which the new bitwise flag class can be      *
  298. *               constructed                                                    *
  299. *         Examples:                                                            *
  300. *           INESTEDBITFLAGCLASSDEF2( Style, IEntryField, IWindow, IControl );  *
  301. *           INESTEDBITFLAGCLASSDEF2( Style, IButton, IWindow, IControl );      *
  302. *         This macro is intended to be nested within the associated class      *
  303. *         definition. (For example,the above examples should be used to        *
  304. *         declare the IEntryField::Style and IButton::Style classes.)          *
  305. *                                                                              *
  306. * Expands to:                                                                  *
  307. *   class className : public IBitFlag                                          *
  308. *   {                                                                          *
  309. *   friend class assoc;                                                        *
  310. *   public:                                                                    *
  311. *     class Negated##className : public IBitFlag                               *
  312. *     {                                                                        *
  313. *     friend class className;                                                  *
  314. *     public:                                                                  *
  315. *       Negated##className ( const base1##::##className##::Negated##className  *
  316. *                                                                    &aFlag )  *
  317. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  318. *       friend Negated##className  operator & ( const Negated##className &lhs, *
  319. *                                             const Negated##className &rhs ); *
  320. *       friend className  operator & ( const Negated##className &lhs,          *
  321. *                                      const className &rhs );                 *
  322. *       Negated##className ( const base2##::##className##::Negated##className  *
  323. *                                                                     &aFlag ) *
  324. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  325. *     protected:                                                               *
  326. *       Negated##className ( unsigned long val )                               *
  327. *         : IBitFlag ( val ) {}                                                *
  328. *     };                                                                       *
  329. *     className##&  operator |= ( const className &aFlag )                     *
  330. *     {                                                                        *
  331. *       className tmpFlag = *this | aFlag;                                     *
  332. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  333. *       return *this;                                                          *
  334. *     }                                                                        *
  335. *     Negated##className  operator ~ ( ) const                                 *
  336. *     {                                                                        *
  337. *       return Negated##className ( ~asUnsignedLong() );                       *
  338. *     }                                                                        *
  339. *     className##&  operator &= ( const Negated##className &aFlag )            *
  340. *     {                                                                        *
  341. *       className tmpFlag = *this & aFlag;                                     *
  342. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  343. *       return *this;                                                          *
  344. *     }                                                                        *
  345. *     className ( const base1##::##className &aFlag )                          *
  346. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  347. *     friend className  operator | ( const className &lhs,                     *
  348. *                                    const className &rhs );                   *
  349. *     friend className  operator & ( const className &lhs,                     *
  350. *                                    const Negated##className &rhs );          *
  351. *     className ( const base2##::##className &aFlag )                          *
  352. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  353. *   protected:                                                                 *
  354. *     className ( unsigned long val )                                          *
  355. *       : IBitFlag ( val ) {}                                                  *
  356. *   }                                                                          *
  357. *******************************************************************************/
  358. #define INESTEDBITFLAGCLASSDEF2( className, assoc, base1, base2 )\
  359. class className : public IBitFlag\
  360. {\
  361. friend class assoc;\
  362. public:\
  363.   class Negated##className : public IBitFlag\
  364.   {\
  365.   friend class className;\
  366.   public:\
  367.     COMMONNEGBITPUBLIC1( className, base1 )\
  368.     COMMONNEGBITPUBLICn( className, base2 )\
  369.   protected:\
  370.     COMMONNEGBITPROTECTED( className )\
  371.   };\
  372.   COMMONBITPUBLIC( className )\
  373.   COMMONBITPUBLIC1( className, base1 )\
  374.   COMMONBITPUBLICn( className, base2 )\
  375. protected:\
  376.   COMMONBITPROTECTED( className )\
  377. }
  378.  
  379.  
  380. /*******************************************************************************
  381. * INESTEDBITFLAGCLASSDEF3 macro                                                *
  382. *                                                                              *
  383. * Used for the declaration of a bitwise flag class whose objects can be        *
  384. * constructed from an object of three other bitwise flag classes.  All the     *
  385. * bitwise flag classes are assumed to have the same name and be scoped to      *
  386. * another class.                                                               *
  387. *                                                                              *
  388. * Usage:  INESTEDBITFLAGCLASSDEF3( className, assoc, base1, base2, base3 );    *
  389. *           where                                                              *
  390. *             className is the name of the bitwise flag class being declared,  *
  391. *             assoc is the name of the class associated with (and scoping)     *
  392. *               the bitwise flag class being declared, and                     *
  393. *             base1, base2, and base3 are the names of the classes scoping the *
  394. *               bitwise flag classes from which the new bitwise flag class can *
  395. *               be constructed                                                 *
  396. *         Example:                                                             *
  397. *           INESTEDBITFLAGCLASSDEF3( Style, IPushButton, IWindow,              *
  398. *                                                IControl, IButton);           *
  399. *         This macro is intended to be nested within the associated class      *
  400. *         definition. (For example, the above example should be used to        *
  401. *         declare IPushButton::Style class.)                                   *
  402. *                                                                              *
  403. * Expands to:                                                                  *
  404. *   class className : public IBitFlag                                          *
  405. *   {                                                                          *
  406. *   friend class assoc;                                                        *
  407. *   public:                                                                    *
  408. *     class Negated##className : public IBitFlag                               *
  409. *     {                                                                        *
  410. *     friend class className;                                                  *
  411. *     public:                                                                  *
  412. *       Negated##className ( const base1##::##className##::Negated##className  *
  413. *                                                                     &aFlag ) *
  414. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  415. *       friend Negated##className  operator & ( const Negated##className &lhs, *
  416. *                                             const Negated##className &rhs ); *
  417. *       friend className  operator & ( const Negated##className &lhs,          *
  418. *                                      const className &rhs );                 *
  419. *       Negated##className ( const base2##::##className##::Negated##className  *
  420. *                                                                     &aFlag ) *
  421. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  422. *       Negated##className ( const base3##::##className##::Negated##className  *
  423. *                                                                     &aFlag ) *
  424. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  425. *     protected:                                                               *
  426. *       Negated##className ( unsigned long val )                               *
  427. *         : IBitFlag ( val ) {}                                                *
  428. *     };                                                                       *
  429. *     className##&  operator |= ( const className &aFlag )                     *
  430. *     {                                                                        *
  431. *       className tmpFlag = *this | aFlag;                                     *
  432. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  433. *       return *this;                                                          *
  434. *     }                                                                        *
  435. *     Negated##className  operator ~ ( ) const                                 *
  436. *     {                                                                        *
  437. *       return Negated##className ( ~asUnsignedLong() );                       *
  438. *     }                                                                        *
  439. *     className##&  operator &= ( const Negated##className &aFlag )            *
  440. *     {                                                                        *
  441. *       className tmpFlag = *this & aFlag;                                     *
  442. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  443. *       return *this;                                                          *
  444. *     }                                                                        *
  445. *     className ( const base1##::##className &aFlag )                          *
  446. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  447. *     friend className  operator | ( const className &lhs,                     *
  448. *                                    const className &rhs );                   *
  449. *     friend className  operator & ( const className &lhs,                     *
  450. *                                    const Negated##className &rhs );          *
  451. *     className ( const base2##::##className &aFlag )                          *
  452. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  453. *     className ( const base3##::##className &aFlag )                          *
  454. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  455. *   protected:                                                                 *
  456. *     className ( unsigned long val )                                          *
  457. *       : IBitFlag ( val ) {}                                                  *
  458. *   }                                                                          *
  459. *******************************************************************************/
  460. #define INESTEDBITFLAGCLASSDEF3( className, assoc, base1, base2, base3 )\
  461. class className : public IBitFlag\
  462. {\
  463. friend class assoc;\
  464. public:\
  465.   class Negated##className : public IBitFlag\
  466.   {\
  467.   friend class className;\
  468.   public:\
  469.     COMMONNEGBITPUBLIC1( className, base1 )\
  470.     COMMONNEGBITPUBLICn( className, base2 )\
  471.     COMMONNEGBITPUBLICn( className, base3 )\
  472.   protected:\
  473.     COMMONNEGBITPROTECTED( className )\
  474.   };\
  475.   COMMONBITPUBLIC( className )\
  476.   COMMONBITPUBLIC1( className, base1 )\
  477.   COMMONBITPUBLICn( className, base2 )\
  478.   COMMONBITPUBLICn( className, base3 )\
  479. protected:\
  480.   COMMONBITPROTECTED( className )\
  481. }
  482.  
  483.  
  484. /*******************************************************************************
  485. * INESTEDBITFLAGCLASSDEF4 macro                                                *
  486. *                                                                              *
  487. * Used for the declaration of a bitwise flag class whose objects can be        *
  488. * constructed from an object of four other bitwise flag classes.  All the      *
  489. * bitwise flag classes are assumed to have the same name and be scoped to      *
  490. * another class.                                                               *
  491. *                                                                              *
  492. * Usage:  INESTEDBITFLAGCLASSDEF4( className, assoc, base1, base2,             *
  493. *                                                     base3, base4 );          *
  494. *           where                                                              *
  495. *             className is the name of the bitwise flag class being declared,  *
  496. *             assoc is the name of the class associated with (and scoping)     *
  497. *               the bitwise flag class being declared, and                     *
  498. *             base1, base2, base3, and base4 are the names of the classes      *
  499. *               scoping the bitwise flag classes from which the new bitwise    *
  500. *               flag class can be constructed                                  *
  501. *         This macro is intended to be nested within the associated class      *
  502. *         definition.                                                          *
  503. *                                                                              *
  504. * Expands to:                                                                  *
  505. *   class className : public IBitFlag                                          *
  506. *   {                                                                          *
  507. *   friend class assoc;                                                        *
  508. *   public:                                                                    *
  509. *     class Negated##className : public IBitFlag                               *
  510. *     {                                                                        *
  511. *     friend class className;                                                  *
  512. *     public:                                                                  *
  513. *       Negated##className ( const base1##::##className##::Negated##className  *
  514. *                                                                     &aFlag ) *
  515. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  516. *       friend Negated##className  operator & ( const Negated##className &lhs, *
  517. *                                             const Negated##className &rhs ); *
  518. *       friend className  operator & ( const Negated##className &lhs,          *
  519. *                                      const className &rhs );                 *
  520. *       Negated##className ( const base2##::##className##::Negated##className  *
  521. *                                                                     &aFlag ) *
  522. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  523. *       Negated##className ( const base3##::##className##::Negated##className  *
  524. *                                                                     &aFlag ) *
  525. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  526. *       Negated##className ( const base4##::##className##::Negated##className  *
  527. *                                                                     &aFlag ) *
  528. *         : IBitFlag ( aFlag.asUnsignedLong() ) {}                             *
  529. *     protected:                                                               *
  530. *       Negated##className ( unsigned long val )                               *
  531. *         : IBitFlag ( val ) {}                                                *
  532. *     };                                                                       *
  533. *     className##&  operator |= ( const className &aFlag )                     *
  534. *     {                                                                        *
  535. *       className tmpFlag = *this | aFlag;                                     *
  536. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  537. *       return *this;                                                          *
  538. *     }                                                                        *
  539. *     Negated##className  operator ~ ( ) const                                 *
  540. *     {                                                                        *
  541. *       return Negated##className ( ~asUnsignedLong() );                       *
  542. *     }                                                                        *
  543. *     className##&  operator &= ( const Negated##className &aFlag )            *
  544. *     {                                                                        *
  545. *       className tmpFlag = *this & aFlag;                                     *
  546. *       this->setValue ( tmpFlag.asUnsignedLong() );                           *
  547. *       return *this;                                                          *
  548. *     }                                                                        *
  549. *     className ( const base1##::##className &aFlag )                          *
  550. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  551. *     friend className  operator | ( const className &lhs,                     *
  552. *                                    const className &rhs );                   *
  553. *     friend className  operator & ( const className &lhs,                     *
  554. *                                    const Negated##className &rhs );          *
  555. *     className ( const base2##::##className &aFlag )                          *
  556. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  557. *     className ( const base3##::##className &aFlag )                          *
  558. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  559. *     className ( const base4##::##className &aFlag )                          *
  560. *       : IBitFlag ( aFlag.asUnsignedLong() ) {}                               *
  561. *   protected:                                                                 *
  562. *     className ( unsigned long val )                                          *
  563. *       : IBitFlag ( val ) {}                                                  *
  564. *   }                                                                          *
  565. *******************************************************************************/
  566. #define INESTEDBITFLAGCLASSDEF4( className, assoc, base1, base2, base3, base4 )\
  567. class className : public IBitFlag\
  568. {\
  569. friend class assoc;\
  570. public:\
  571.   class Negated##className : public IBitFlag\
  572.   {\
  573.   friend class className;\
  574.   public:\
  575.     COMMONNEGBITPUBLIC1( className, base1 )\
  576.     COMMONNEGBITPUBLICn( className, base2 )\
  577.     COMMONNEGBITPUBLICn( className, base3 )\
  578.     COMMONNEGBITPUBLICn( className, base4 )\
  579.   protected:\
  580.     COMMONNEGBITPROTECTED( className )\
  581.   };\
  582.   COMMONBITPUBLIC( className )\
  583.   COMMONBITPUBLIC1( className, base1 )\
  584.   COMMONBITPUBLICn( className, base2 )\
  585.   COMMONBITPUBLICn( className, base3 )\
  586.   COMMONBITPUBLICn( className, base4 )\
  587. protected:\
  588.   COMMONBITPROTECTED( className )\
  589. }
  590.  
  591.  
  592. /*******************************************************************************
  593. * INESTEDBITFLAGCLASSFUNCS macro                                               *
  594. *                                                                              *
  595. * Used for the definition of global functions that operate on a class of       *
  596. * bitwise flag objects scoped to another class.  The functions are global,     *
  597. * rather than member functions, to allow for commutative operations between    *
  598. * objects of different bitwise flag classes.                                   *
  599. *                                                                              *
  600. * Note: This macro should not be used to define global functions for a logical *
  601. *       base style class (one declared with the INESTEDBITFLAGCLASSDEF0        *
  602. *       macro).                                                                *
  603. *                                                                              *
  604. * Usage:  INESTEDBITFLAGCLASSFUNCS( className, assoc );                        *
  605. *           where                                                              *
  606. *             className is the name of the bitwise flag class, and             *
  607. *             assoc is the name of the class associated with (and scoping)     *
  608. *               the bitwise flag class                                         *
  609. *         Examples: INESTEDBITFLAGCLASSFUNCS( Style, IControl );               *
  610. *                   INESTEDBITFLAGCLASSFUNCS( Style, IEntryField );            *
  611. *         This macro should be used at global scope (outside of all class      *
  612. *         definitions.                                                         *
  613. *                                                                              *
  614. * Expands to:                                                                  *
  615. *   inline assoc##::##className  operator | ( const assoc##::##className &lhs, *
  616. *                                            const assoc##::##className &rhs ) *
  617. *   {                                                                          *
  618. *     assoc##::##className aResult ( lhs.asUnsignedLong() |                    *
  619. *                                    rhs.asUnsignedLong() );                   *
  620. *     return aResult;                                                          *
  621. *   }                                                                          *
  622. *   inline assoc##::##className                                                *
  623. *     operator & ( const assoc##::##className &lhs,                            *
  624. *                  const assoc##::##className##::Negated##className &rhs )     *
  625. *   {                                                                          *
  626. *     assoc##::##className aResult ( lhs.asUnsignedLong() &                    *
  627. *                                    rhs.asUnsignedLong() );                   *
  628. *     return aResult;                                                          *
  629. *   }                                                                          *
  630. *   inline assoc##::##className##::Negated##className                          *
  631. *     operator & ( const assoc##::##className##::Negated##className &lhs,      *
  632. *                  const assoc##::##className##::Negated##className &rhs )     *
  633. *   {                                                                          *
  634. *     assoc##::##className##::Negated##className                               *
  635. *                     aResult ( lhs.asUnsignedLong() & rhs.asUnsignedLong() ); *
  636. *     return aResult;                                                          *
  637. *   }                                                                          *
  638. *   inline assoc##::##className                                                *
  639. *     operator & ( const assoc##::##className##::Negated##className &lhs,      *
  640. *                  const assoc##::##className &rhs )                           *
  641. *   {                                                                          *
  642. *     return rhs & lhs;                                                        *
  643. *   }                                                                          *
  644. *   inline unsigned long  operator & ( const assoc##::##className &lhs,        *
  645. *                                      const assoc##::##className &rhs )       *
  646. *   {                                                                          *
  647. *     return ( lhs.asUnsignedLong() & rhs.asUnsignedLong() );                  *
  648. *   }                                                                          *
  649. *******************************************************************************/
  650. #define INESTEDBITFLAGCLASSFUNCS( className, assoc )\
  651. inline assoc##::##className  operator | ( const assoc##::##className &lhs,\
  652.                                           const assoc##::##className &rhs )\
  653. {\
  654.   assoc##::##className aResult ( lhs.asUnsignedLong() | rhs.asUnsignedLong() );\
  655.   return aResult;\
  656. }\
  657. inline assoc##::##className\
  658.   operator & ( const assoc##::##className &lhs,\
  659.                const assoc##::##className##::Negated##className &rhs )\
  660. {\
  661.   assoc##::##className aResult ( lhs.asUnsignedLong() & rhs.asUnsignedLong() );\
  662.   return aResult;\
  663. }\
  664. inline assoc##::##className##::Negated##className\
  665.   operator & ( const assoc##::##className##::Negated##className &lhs,\
  666.                const assoc##::##className##::Negated##className &rhs )\
  667. {\
  668.   assoc##::##className##::Negated##className aResult ( lhs.asUnsignedLong() & rhs.asUnsignedLong() );\
  669.   return aResult;\
  670. }\
  671. inline assoc##::##className\
  672.   operator & ( const assoc##::##className##::Negated##className &lhs,\
  673.                const assoc##::##className &rhs )\
  674. {\
  675.   return rhs & lhs;\
  676. }\
  677. inline unsigned long  operator & ( const assoc##::##className &lhs,\
  678.                                    const assoc##::##className &rhs )\
  679. {\
  680.   return ( lhs.asUnsignedLong() & rhs.asUnsignedLong() );\
  681. } \
  682. inline unsigned long  operator & ( const assoc##::##className &lhs,\
  683.                                    const assoc##::##className &rhs )
  684.  
  685.  
  686. /*******************************************************************************
  687. * Helper macros.                                                               *
  688. * These are not intended to be used outside of this file.                      *
  689. *******************************************************************************/
  690. #define COMMONBITPUBLIC( className )\
  691.   className##&  operator |= ( const className &aFlag )\
  692.   {\
  693.     className tmpFlag = *this | aFlag;\
  694.     this->setValue ( tmpFlag.asUnsignedLong() );\
  695.     return *this;\
  696.   }\
  697.   Negated##className  operator ~ ( ) const\
  698.   {\
  699.     Negated##className aResult ( ~asUnsignedLong() );\
  700.     return aResult;\
  701.   }\
  702.   className##&  operator &= ( const Negated##className &aFlag )\
  703.   {\
  704.     className tmpFlag = *this & aFlag;\
  705.     this->setValue ( tmpFlag.asUnsignedLong() );\
  706.     return *this;\
  707.   }
  708. #define COMMONBITPUBLIC0( className )\
  709.   className  operator | ( const className &aFlag ) const\
  710.   {\
  711.     className aResult ( asUnsignedLong() | aFlag.asUnsignedLong() );\
  712.     return aResult;\
  713.   }\
  714.   className  operator & ( const Negated##className &aFlag ) const\
  715.   {\
  716.     className aResult ( asUnsignedLong() & aFlag.asUnsignedLong() );\
  717.     return aResult;\
  718.   }\
  719.   unsigned long  operator & ( const className &aFlag ) const\
  720.   {\
  721.     return ( asUnsignedLong() & aFlag.asUnsignedLong() );\
  722.   }
  723. #define COMMONBITPUBLIC1( className, baseName )\
  724.   COMMONBITPUBLICn ( className, baseName )\
  725.   friend className  operator | ( const className &lhs,\
  726.                                  const className &rhs );\
  727.   friend className  operator & ( const className &lhs,\
  728.                                  const Negated##className &rhs );
  729. #define COMMONBITPUBLICn( className, baseName )\
  730.   className ( const baseName##::##className &aFlag )\
  731.     : IBitFlag ( aFlag.asUnsignedLong() ) {}
  732. #define COMMONNEGBITPUBLIC0( className )\
  733.     Negated##className  operator & ( const Negated##className &aFlag ) const\
  734.     {\
  735.       Negated##className aResult ( asUnsignedLong() & aFlag.asUnsignedLong() );\
  736.       return aResult;\
  737.     }
  738. #define COMMONNEGBITPUBLIC1( className, baseName )\
  739.     COMMONNEGBITPUBLICn( className, baseName )\
  740.     friend Negated##className  operator & ( const Negated##className &lhs,\
  741.                                             const Negated##className &rhs );\
  742.     friend className  operator & ( const Negated##className &lhs,\
  743.                                    const className &rhs );
  744. #define COMMONNEGBITPUBLICn( className, baseName )\
  745.     Negated##className ( const baseName##::##className##::Negated##className &aFlag )\
  746.       : IBitFlag ( aFlag.asUnsignedLong() ) {}
  747. #define COMMONBITPROTECTED( className )\
  748.     className ( unsigned long val )\
  749.       : IBitFlag ( val ) {}
  750. #define COMMONNEGBITPROTECTED( className )\
  751.     Negated##className ( unsigned long val )\
  752.       : IBitFlag ( val ) {}
  753.  
  754. /*----------------------------------------------------------------------------*/
  755. /* Resume compiler default packing.                                           */
  756. /*----------------------------------------------------------------------------*/
  757. #pragma pack()
  758.  
  759. /*----------------------------- Inline Functions -----------------------------*/
  760. #ifndef I_NO_INLINES
  761.   #include <ibitflag.inl>
  762. #endif
  763.  
  764. #endif /* _IBITFLAG_ */
  765.