home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / VBSAMPLE / IVBBOOL.CPP < prev    next >
Text File  |  1995-05-12  |  23KB  |  483 lines

  1. /*******************************************************************************
  2. * FILE NAME: ivbbool.cpp                                                       *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class(es):                                     *
  6. *    IVBBooleanPart - VB Boolean Part.                                         *
  7. *                                                                              *
  8. * COPYRIGHT:                                                                   *
  9. *   IBM(R) VisualAge(TM) C++ for OS/2(R), Version 3                            *
  10. *   (C) Copyright IBM Corporation 1991, 1995.                                  *
  11. *    - Licensed Material - Program-Property of IBM - All Rights Reserved.      *
  12. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  13. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  14. *                                                                              *
  15. *   This program will not run in DOS mode.                                     *
  16. *                                                                              *
  17. * DISCLAIMER OF WARRANTIES:                                                    *
  18. *   The following [enclosed] code is sample code created by IBM                *
  19. *   Corporation.  This sample code is not part of any standard IBM product     *
  20. *   and is provided to you solely for the purpose of assisting you in the      *
  21. *   development of your applications.  The code is provided "AS IS",           *
  22. *   without warranty of any kind.  IBM shall not be liable for any damages     *
  23. *   arising out of your use of the sample code, even if they have been         *
  24. *   advised of the possibility of such damages.                                *
  25. *******************************************************************************/
  26.  
  27. #ifndef _IVBBOOL_
  28.   #include <ivbbool.hpp>
  29. #endif
  30.  
  31. #ifndef _INOTIFEV_
  32.   #include <inotifev.hpp>
  33. #endif
  34.  
  35.  
  36.  
  37. /*------------------------------------------------------------------------------
  38. | IVBBooleanPart::IVBBooleanPart                                               |
  39. |                                                                              |
  40. | Standard constructor.                                                        |
  41. ------------------------------------------------------------------------------*/
  42. #pragma export (IVBBooleanPart::IVBBooleanPart(Boolean aValue),, 2100)
  43. IVBBooleanPart::IVBBooleanPart(Boolean aValue) : IVBDataTypePart ()
  44.     ,iValue (aValue)
  45.     ,iDefaultValue (false)
  46.     ,iValueEqualDefault (false)
  47.     ,iValueNotEqualDefault (false)
  48. {
  49.   enableNotification ();
  50. }
  51.  
  52. /*------------------------------------------------------------------------------
  53. | IVBBooleanPart::IVBBooleanPart                                               |
  54. |                                                                              |
  55. | Standard copy constructor.                                                   |
  56. ------------------------------------------------------------------------------*/
  57. #pragma export (IVBBooleanPart::IVBBooleanPart(const IVBBooleanPart&),, 2101)
  58. IVBBooleanPart::IVBBooleanPart (const IVBBooleanPart& partCopy)
  59.   : IVBDataTypePart (partCopy)
  60.     ,iValue (partCopy.value ())
  61.     ,iDefaultValue (partCopy.defaultValue ())
  62. {
  63.   enableNotification ();
  64. }
  65.  
  66. /*------------------------------------------------------------------------------
  67. | IVBBooleanPart::IVBBooleanPart                                               |
  68. |                                                                              |
  69. | Standard operator=                                                           |
  70. ------------------------------------------------------------------------------*/
  71. #pragma export (IVBBooleanPart::operator= (const IVBBooleanPart&),, 2102)
  72. IVBBooleanPart& IVBBooleanPart::operator= (const IVBBooleanPart& aIVBBooleanPart)
  73. {
  74.   if (this == &aIVBBooleanPart) {
  75.     return *this;
  76.   } /* endif */
  77.   setValue(aIVBBooleanPart.value());
  78.   setDefaultValue(aIVBBooleanPart.defaultValue());
  79.   return *this;
  80. }
  81.  
  82. /*------------------------------------------------------------------------------
  83. | IVBBooleanPart::~IVBBooleanPart                                              |
  84. |                                                                              |
  85. | IVBBooleanPart destructor.                                                   |
  86. ------------------------------------------------------------------------------*/
  87. #pragma export (IVBBooleanPart::~IVBBooleanPart(),, 2103)
  88. IVBBooleanPart::~IVBBooleanPart()
  89. {
  90. }
  91.  
  92. /*------------------------------------------------------------------------------
  93. | IVBBooleanPart::asString                                                     |
  94. |                                                                              |
  95. | Perform asString.                                                            |
  96. ------------------------------------------------------------------------------*/
  97. #pragma export (IVBBooleanPart::asString() const,, 2104)
  98. IString IVBBooleanPart::asString () const
  99. {
  100.   return valueAsText();
  101. }
  102.  
  103. /*------------------------------------------------------------------------------
  104. | IVBBooleanPart::value                                                        |
  105. |                                                                              |
  106. | Return the value attribute.                                                  |
  107. ------------------------------------------------------------------------------*/
  108. #pragma export (IVBBooleanPart::value() const,, 2105)
  109. Boolean IVBBooleanPart::value () const
  110. {
  111.   return iValue;
  112. }
  113.  
  114. /*------------------------------------------------------------------------------
  115. | IVBBooleanPart::setValue                                                     |
  116. |                                                                              |
  117. | Set the value attribute.                                                     |
  118. ------------------------------------------------------------------------------*/
  119. #pragma export (IVBBooleanPart::setValue(const Boolean),, 2106)
  120. IVBBooleanPart& IVBBooleanPart::setValue (Boolean aValue)
  121. {
  122.   if (iValue != aValue) {
  123.     iValue = aValue;
  124.     notifyObservers(INotificationEvent(valueId, *this,
  125.                     true, (void*)iValue));
  126.     if (isValueEqualDefault ()) {
  127.       notifyObservers(INotificationEvent(valueEqualDefaultId, *this,
  128.                       true, (void*)iValue));
  129.     }
  130.     else {
  131.       notifyObservers(INotificationEvent(valueNotEqualDefaultId, *this,
  132.                       true, (void*)iValue));
  133.     } ; /* endif */
  134.   } ; /* endif */
  135.   return *this;
  136. }
  137.  
  138. /*------------------------------------------------------------------------------
  139. | IVBBooleanPart::setValue                                                     |
  140. |                                                                              |
  141. | Set the value attribute.                                                     |
  142. ------------------------------------------------------------------------------*/
  143. #pragma export (IVBBooleanPart::setValue(),, 2107)
  144. IVBBooleanPart& IVBBooleanPart::setValue ()
  145. {
  146.   return setValue (defaultValue());
  147. }
  148.  
  149. /*------------------------------------------------------------------------------
  150. | IVBBooleanPart::notValue                                                     |
  151. |                                                                              |
  152. | Return the notValue attribute.                                               |
  153. ------------------------------------------------------------------------------*/
  154. #pragma export (IVBBooleanPart::notValue() const,, 2108)
  155. Boolean IVBBooleanPart::notValue () const
  156. {
  157.   return !value();
  158. }
  159.  
  160. /*------------------------------------------------------------------------------
  161. | IVBBooleanPart::setNotValue                                                  |
  162. |                                                                              |
  163. | Set the notValue attribute.                                                  |
  164. ------------------------------------------------------------------------------*/
  165. #pragma export (IVBBooleanPart::setNotValue(const Boolean),, 2109)
  166. IVBBooleanPart& IVBBooleanPart::setNotValue (Boolean aNotValue)
  167. {
  168.   return setValue(!aNotValue);
  169. }
  170.  
  171. /*------------------------------------------------------------------------------
  172. | IVBBooleanPart::setNotValue                                                  |
  173. |                                                                              |
  174. | Set the notValue attribute.                                                  |
  175. ------------------------------------------------------------------------------*/
  176. #pragma export (IVBBooleanPart::setNotValue(),, 2110)
  177. IVBBooleanPart& IVBBooleanPart::setNotValue ()
  178. {
  179.   return setNotValue (defaultValue());
  180. }
  181.  
  182. /*------------------------------------------------------------------------------
  183. | IVBBooleanPart::valueAsText                                                  |
  184. |                                                                              |
  185. | Return the valueAsText attribute.                                            |
  186. ------------------------------------------------------------------------------*/
  187. #pragma export (IVBBooleanPart::valueAsText() const,, 2111)
  188. IString IVBBooleanPart::valueAsText () const
  189. {
  190.   if (value()) {
  191.     return IString("1");
  192.   } ; /* endif */
  193.   return IString("0");
  194. }
  195.  
  196. /*------------------------------------------------------------------------------
  197. | IVBBooleanPart::setValueAsText                                               |
  198. |                                                                              |
  199. | Set the valueAsText attribute.                                               |
  200. ------------------------------------------------------------------------------*/
  201. #pragma export (IVBBooleanPart::setValueAsText(const IString&),, 2112)
  202. IVBBooleanPart& IVBBooleanPart::setValueAsText (const IString& aValueAsText)
  203. {
  204.   if (aValueAsText == "0") {
  205.     return setValue (false);
  206.   }
  207.   return setValue (true);
  208. }
  209.  
  210. /*------------------------------------------------------------------------------
  211. | IVBBooleanPart::setValueAsText                                               |
  212. |                                                                              |
  213. | Set the valueAsText attribute.                                               |
  214. ------------------------------------------------------------------------------*/
  215. #pragma export (IVBBooleanPart::setValueAsText(const IString*),, 2113)
  216. IVBBooleanPart& IVBBooleanPart::setValueAsText (const IString* aValueAsText)
  217. {
  218.   return setValueAsText (*aValueAsText);
  219. }
  220.  
  221. /*------------------------------------------------------------------------------
  222. | IVBBooleanPart::notValueAsText                                               |
  223. |                                                                              |
  224. | Return the notValueAsText attribute.                                         |
  225. ------------------------------------------------------------------------------*/
  226. #pragma export (IVBBooleanPart::notValueAsText() const,, 2114)
  227. IString IVBBooleanPart::notValueAsText () const
  228. {
  229.   if (notValue()) {
  230.     return IString("1");
  231.   } ; /* endif */
  232.   return IString("0");
  233. }
  234.  
  235. /*------------------------------------------------------------------------------
  236. | IVBBooleanPart::setNotValueAsText                                            |
  237. |                                                                              |
  238. | Set the notValueAsText attribute.                                            |
  239. ------------------------------------------------------------------------------*/
  240. #pragma export (IVBBooleanPart::setNotValueAsText(const IString&),, 2115)
  241. IVBBooleanPart& IVBBooleanPart::setNotValueAsText (const IString& aNotValueAsText)
  242. {
  243.   if (aNotValueAsText == "0") {
  244.     return setValue (true);
  245.   }
  246.   return setValue (false);
  247. }
  248.  
  249. /*------------------------------------------------------------------------------
  250. | IVBBooleanPart::setNotValueAsText                                            |
  251. |                                                                              |
  252. | Set the notValueAsText attribute.                                            |
  253. ------------------------------------------------------------------------------*/
  254. #pragma export (IVBBooleanPart::setNotValueAsText(const IString*),, 2116)
  255. IVBBooleanPart& IVBBooleanPart::setNotValueAsText (const IString* aNotValueAsText)
  256. {
  257.   return setNotValueAsText (*aNotValueAsText);
  258. }
  259.  
  260. /*------------------------------------------------------------------------------
  261. | IVBBooleanPart::defaultValue                                                 |
  262. |                                                                              |
  263. | Return the defaultValue attribute.                                           |
  264. ------------------------------------------------------------------------------*/
  265. #pragma export (IVBBooleanPart::defaultValue() const,, 2117)
  266. Boolean IVBBooleanPart::defaultValue () const
  267. {
  268.   return iDefaultValue;
  269. }
  270.  
  271. /*------------------------------------------------------------------------------
  272. | IVBBooleanPart::setDefaultValue                                              |
  273. |                                                                              |
  274. | Set the defaultValue attribute.                                              |
  275. ------------------------------------------------------------------------------*/
  276. #pragma export (IVBBooleanPart::setDefaultValue(const Boolean),, 2118)
  277. IVBBooleanPart& IVBBooleanPart::setDefaultValue (Boolean aDefaultValue)
  278. {
  279.   if (iDefaultValue != aDefaultValue) {
  280.     iDefaultValue = aDefaultValue;
  281.     if (isValueEqualDefault ()) {
  282.       notifyObservers(INotificationEvent(valueEqualDefaultId, *this,
  283.                       true, (void*)iValue));
  284.     }
  285.     else {
  286.       notifyObservers(INotificationEvent(valueNotEqualDefaultId, *this,
  287.                       true, (void*)iValue));
  288.     } /* endif */
  289.   } /* endif */
  290.   return *this;
  291. }
  292.  
  293. /*------------------------------------------------------------------------------
  294. | IVBBooleanPart::isValueEqualDefault                                          |
  295. |                                                                              |
  296. | Return the valueEqualDefault attribute.                                      |
  297. ------------------------------------------------------------------------------*/
  298. #pragma export (IVBBooleanPart::isValueEqualDefault() const,, 2119)
  299. Boolean IVBBooleanPart::isValueEqualDefault () const
  300. {
  301.   return (value() == defaultValue ()) ;
  302. }
  303.  
  304. /*------------------------------------------------------------------------------
  305. | IVBBooleanPart::isValueNotEqualDefault                                       |
  306. |                                                                              |
  307. | Return the valueNotEqualDefault attribute.                                   |
  308. ------------------------------------------------------------------------------*/
  309. #pragma export (IVBBooleanPart::isValueNotEqualDefault() const,, 2120)
  310. Boolean IVBBooleanPart::isValueNotEqualDefault () const
  311. {
  312.   return (value() != defaultValue ()) ;
  313. }
  314.  
  315. /*------------------------------------------------------------------------------
  316. | IVBBooleanPart::assignValueToTrue                                            |
  317. |                                                                              |
  318. | Assign the value attribute to true.                                          |
  319. ------------------------------------------------------------------------------*/
  320. #pragma export (IVBBooleanPart::assignValueToTrue(),, 2121)
  321. IVBBooleanPart& IVBBooleanPart::assignValueToTrue ()
  322. {
  323.   return setValue (true) ;
  324. }
  325.  
  326. /*------------------------------------------------------------------------------
  327. | IVBBooleanPart::assignValueToFalse                                           |
  328. |                                                                              |
  329. | Assign the value attribute to false.                                         |
  330. ------------------------------------------------------------------------------*/
  331. #pragma export (IVBBooleanPart::assignValueToFalse(),, 2122)
  332. IVBBooleanPart& IVBBooleanPart::assignValueToFalse ()
  333. {
  334.   return setValue (false) ;
  335. }
  336.  
  337. /*------------------------------------------------------------------------------
  338. | IVBBooleanPart::assignValueToDefault                                         |
  339. |                                                                              |
  340. | Assign the value attribute to default.                                       |
  341. ------------------------------------------------------------------------------*/
  342. #pragma export (IVBBooleanPart::assignValueToDefault(),, 2123)
  343. IVBBooleanPart& IVBBooleanPart::assignValueToDefault ()
  344. {
  345.   return setValue (defaultValue ()) ;
  346. }
  347.  
  348. /*------------------------------------------------------------------------------
  349. | IVBBooleanPart::copyValueToDefault                                           |
  350. |                                                                              |
  351. | Copy the value attribute to default.                                         |
  352. ------------------------------------------------------------------------------*/
  353. #pragma export (IVBBooleanPart::copyValueToDefault(),, 2124)
  354. IVBBooleanPart& IVBBooleanPart::copyValueToDefault ()
  355. {
  356.   return setDefaultValue (value()) ;
  357. }
  358.  
  359. /*------------------------------------------------------------------------------
  360. | IVBBooleanPart::logicalNotValue                                              |
  361. |                                                                              |
  362. | Perform the logical not operator to the value attribute.                     |
  363. ------------------------------------------------------------------------------*/
  364. #pragma export (IVBBooleanPart::logicalNotValue(),, 2125)
  365. IVBBooleanPart& IVBBooleanPart::logicalNotValue()
  366. {
  367.   return setValue (!value()) ;
  368. }
  369.  
  370. /*------------------------------------------------------------------------------
  371. | IVBBooleanPart::logicalAndValue                                               |
  372. |                                                                              |
  373. | Perform the logical And operator to the value attribute.                      |
  374. ------------------------------------------------------------------------------*/
  375. #pragma export (IVBBooleanPart::logicalAndValue (Boolean),, 2126)
  376. IVBBooleanPart& IVBBooleanPart::logicalAndValue (Boolean anAndValue)
  377. {
  378.   return setValue (value() && anAndValue) ;
  379. }
  380.  
  381. /*------------------------------------------------------------------------------
  382. | IVBBooleanPart::logicalOrValue                                               |
  383. |                                                                              |
  384. | Perform the logical Or operator to the value attribute.                      |
  385. ------------------------------------------------------------------------------*/
  386. #pragma export (IVBBooleanPart::logicalOrValue (Boolean),, 2127)
  387. IVBBooleanPart& IVBBooleanPart::logicalOrValue (Boolean anOrValue)
  388. {
  389.   return setValue (value() || anOrValue) ;
  390. }
  391.  
  392. /*------------------------------------------------------------------------------
  393. | IVBBooleanPart::operator == (const IVBBooleanPart & aValue)                  |
  394. |                                                                              |
  395. ------------------------------------------------------------------------------*/
  396. #pragma export (IVBBooleanPart::operator == (const IVBBooleanPart&) const,, 2128)
  397. Boolean IVBBooleanPart::
  398.   operator == (const IVBBooleanPart& aValue) const
  399. {
  400.   if (value() != aValue.value()) {
  401.     return false;
  402.   } /* endif */
  403.   if (defaultValue() != aValue.defaultValue()) {
  404.     return false;
  405.   } /* endif */
  406.   if (isValueEqualDefault() != aValue.isValueEqualDefault()) {
  407.     return false;
  408.   } /* endif */
  409.   if (isValueNotEqualDefault() != aValue.isValueNotEqualDefault()) {
  410.     return false;
  411.   } /* endif */
  412.   return true;
  413. }
  414.  
  415. /*------------------------------------------------------------------------------
  416. | IVBBooleanPart::operator != (const IVBBooleanPart & aValue)                  |
  417. |                                                                              |
  418. ------------------------------------------------------------------------------*/
  419. #pragma export (IVBBooleanPart::operator != (const IVBBooleanPart&) const,, 2129)
  420. Boolean IVBBooleanPart::
  421.   operator != (const IVBBooleanPart& aValue) const
  422. {
  423.   if (value() != aValue.value()) {
  424.     return true;
  425.   } /* endif */
  426.   if (defaultValue() != aValue.defaultValue()) {
  427.     return true;
  428.   } /* endif */
  429.   if (isValueEqualDefault() != aValue.isValueEqualDefault()) {
  430.     return true;
  431.   } /* endif */
  432.   if (isValueNotEqualDefault() != aValue.isValueNotEqualDefault()) {
  433.     return true;
  434.   } /* endif */
  435.   return false;
  436. }
  437.  
  438. /*------------------------------------------------------------------------------
  439. | IVBBooleanPart::operator == (const IVBBooleanPart * aValue)                  |
  440. |                                                                              |
  441. ------------------------------------------------------------------------------*/
  442. #pragma export (IVBBooleanPart::operator == (const IVBBooleanPart*) const,, 2130)
  443. Boolean IVBBooleanPart::
  444.   operator == (const IVBBooleanPart* aValue) const
  445. {
  446.   if (value() != aValue->value()) {
  447.     return false;
  448.   } /* endif */
  449.   if (defaultValue() != aValue->defaultValue()) {
  450.     return false;
  451.   } /* endif */
  452.   if (isValueEqualDefault() != aValue->isValueEqualDefault()) {
  453.     return false;
  454.   } /* endif */
  455.   if (isValueNotEqualDefault() != aValue->isValueNotEqualDefault()) {
  456.     return false;
  457.   } /* endif */
  458.   return true;
  459. }
  460.  
  461. /*------------------------------------------------------------------------------
  462. | IVBBooleanPart::operator != (const IVBBooleanPart * aValue)                  |
  463. |                                                                              |
  464. ------------------------------------------------------------------------------*/
  465. #pragma export (IVBBooleanPart::operator != (const IVBBooleanPart*) const,, 2131)
  466. Boolean IVBBooleanPart::
  467.   operator != (const IVBBooleanPart* aValue) const
  468. {
  469.   if (value() != aValue->value()) {
  470.     return true;
  471.   } /* endif */
  472.   if (defaultValue() != aValue->defaultValue()) {
  473.     return true;
  474.   } /* endif */
  475.   if (isValueEqualDefault() != aValue->isValueEqualDefault()) {
  476.     return true;
  477.   } /* endif */
  478.   if (isValueNotEqualDefault() != aValue->isValueNotEqualDefault()) {
  479.     return true;
  480.   } /* endif */
  481.   return false;
  482. }
  483.