home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / vbsample / ivbbool.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  22.7 KB  |  484 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) for C++                                               *
  10. *   (C) Copyright International Business Machines Corporation 1991, 1996       *
  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.   Inherited::operator=(aIVBBooleanPart);
  78.   setValue(aIVBBooleanPart.value());
  79.   setDefaultValue(aIVBBooleanPart.defaultValue());
  80.   return *this;
  81. }
  82.  
  83. /*------------------------------------------------------------------------------
  84. | IVBBooleanPart::~IVBBooleanPart                                              |
  85. |                                                                              |
  86. | IVBBooleanPart destructor.                                                   |
  87. ------------------------------------------------------------------------------*/
  88. #pragma export (IVBBooleanPart::~IVBBooleanPart(),, 2103)
  89. IVBBooleanPart::~IVBBooleanPart()
  90. {
  91. }
  92.  
  93. /*------------------------------------------------------------------------------
  94. | IVBBooleanPart::asString                                                     |
  95. |                                                                              |
  96. | Perform asString.                                                            |
  97. ------------------------------------------------------------------------------*/
  98. #pragma export (IVBBooleanPart::asString() const,, 2104)
  99. IString IVBBooleanPart::asString () const
  100. {
  101.   return valueAsText();
  102. }
  103.  
  104. /*------------------------------------------------------------------------------
  105. | IVBBooleanPart::value                                                        |
  106. |                                                                              |
  107. | Return the value attribute.                                                  |
  108. ------------------------------------------------------------------------------*/
  109. #pragma export (IVBBooleanPart::value() const,, 2105)
  110. Boolean IVBBooleanPart::value () const
  111. {
  112.   return iValue;
  113. }
  114.  
  115. /*------------------------------------------------------------------------------
  116. | IVBBooleanPart::setValue                                                     |
  117. |                                                                              |
  118. | Set the value attribute.                                                     |
  119. ------------------------------------------------------------------------------*/
  120. #pragma export (IVBBooleanPart::setValue(const Boolean),, 2106)
  121. IVBBooleanPart& IVBBooleanPart::setValue (Boolean aValue)
  122. {
  123.   if (iValue != aValue) {
  124.     iValue = aValue;
  125.     notifyObservers(INotificationEvent(valueId, *this,
  126.                     true, (void*)iValue));
  127.     if (isValueEqualDefault ()) {
  128.       notifyObservers(INotificationEvent(valueEqualDefaultId, *this,
  129.                       true, (void*)iValue));
  130.     }
  131.     else {
  132.       notifyObservers(INotificationEvent(valueNotEqualDefaultId, *this,
  133.                       true, (void*)iValue));
  134.     } ; /* endif */
  135.   } ; /* endif */
  136.   return *this;
  137. }
  138.  
  139. /*------------------------------------------------------------------------------
  140. | IVBBooleanPart::setValue                                                     |
  141. |                                                                              |
  142. | Set the value attribute.                                                     |
  143. ------------------------------------------------------------------------------*/
  144. #pragma export (IVBBooleanPart::setValue(),, 2107)
  145. IVBBooleanPart& IVBBooleanPart::setValue ()
  146. {
  147.   return setValue (defaultValue());
  148. }
  149.  
  150. /*------------------------------------------------------------------------------
  151. | IVBBooleanPart::notValue                                                     |
  152. |                                                                              |
  153. | Return the notValue attribute.                                               |
  154. ------------------------------------------------------------------------------*/
  155. #pragma export (IVBBooleanPart::notValue() const,, 2108)
  156. Boolean IVBBooleanPart::notValue () const
  157. {
  158.   return !value();
  159. }
  160.  
  161. /*------------------------------------------------------------------------------
  162. | IVBBooleanPart::setNotValue                                                  |
  163. |                                                                              |
  164. | Set the notValue attribute.                                                  |
  165. ------------------------------------------------------------------------------*/
  166. #pragma export (IVBBooleanPart::setNotValue(const Boolean),, 2109)
  167. IVBBooleanPart& IVBBooleanPart::setNotValue (Boolean aNotValue)
  168. {
  169.   return setValue(!aNotValue);
  170. }
  171.  
  172. /*------------------------------------------------------------------------------
  173. | IVBBooleanPart::setNotValue                                                  |
  174. |                                                                              |
  175. | Set the notValue attribute.                                                  |
  176. ------------------------------------------------------------------------------*/
  177. #pragma export (IVBBooleanPart::setNotValue(),, 2110)
  178. IVBBooleanPart& IVBBooleanPart::setNotValue ()
  179. {
  180.   return setNotValue (defaultValue());
  181. }
  182.  
  183. /*------------------------------------------------------------------------------
  184. | IVBBooleanPart::valueAsText                                                  |
  185. |                                                                              |
  186. | Return the valueAsText attribute.                                            |
  187. ------------------------------------------------------------------------------*/
  188. #pragma export (IVBBooleanPart::valueAsText() const,, 2111)
  189. IString IVBBooleanPart::valueAsText () const
  190. {
  191.   if (value()) {
  192.     return IString("1");
  193.   } ; /* endif */
  194.   return IString("0");
  195. }
  196.  
  197. /*------------------------------------------------------------------------------
  198. | IVBBooleanPart::setValueAsText                                               |
  199. |                                                                              |
  200. | Set the valueAsText attribute.                                               |
  201. ------------------------------------------------------------------------------*/
  202. #pragma export (IVBBooleanPart::setValueAsText(const IString&),, 2112)
  203. IVBBooleanPart& IVBBooleanPart::setValueAsText (const IString& aValueAsText)
  204. {
  205.   if (aValueAsText == "0") {
  206.     return setValue (false);
  207.   }
  208.   return setValue (true);
  209. }
  210.  
  211. /*------------------------------------------------------------------------------
  212. | IVBBooleanPart::setValueAsText                                               |
  213. |                                                                              |
  214. | Set the valueAsText attribute.                                               |
  215. ------------------------------------------------------------------------------*/
  216. #pragma export (IVBBooleanPart::setValueAsText(const IString*),, 2113)
  217. IVBBooleanPart& IVBBooleanPart::setValueAsText (const IString* aValueAsText)
  218. {
  219.   return setValueAsText (*aValueAsText);
  220. }
  221.  
  222. /*------------------------------------------------------------------------------
  223. | IVBBooleanPart::notValueAsText                                               |
  224. |                                                                              |
  225. | Return the notValueAsText attribute.                                         |
  226. ------------------------------------------------------------------------------*/
  227. #pragma export (IVBBooleanPart::notValueAsText() const,, 2114)
  228. IString IVBBooleanPart::notValueAsText () const
  229. {
  230.   if (notValue()) {
  231.     return IString("1");
  232.   } ; /* endif */
  233.   return IString("0");
  234. }
  235.  
  236. /*------------------------------------------------------------------------------
  237. | IVBBooleanPart::setNotValueAsText                                            |
  238. |                                                                              |
  239. | Set the notValueAsText attribute.                                            |
  240. ------------------------------------------------------------------------------*/
  241. #pragma export (IVBBooleanPart::setNotValueAsText(const IString&),, 2115)
  242. IVBBooleanPart& IVBBooleanPart::setNotValueAsText (const IString& aNotValueAsText)
  243. {
  244.   if (aNotValueAsText == "0") {
  245.     return setValue (true);
  246.   }
  247.   return setValue (false);
  248. }
  249.  
  250. /*------------------------------------------------------------------------------
  251. | IVBBooleanPart::setNotValueAsText                                            |
  252. |                                                                              |
  253. | Set the notValueAsText attribute.                                            |
  254. ------------------------------------------------------------------------------*/
  255. #pragma export (IVBBooleanPart::setNotValueAsText(const IString*),, 2116)
  256. IVBBooleanPart& IVBBooleanPart::setNotValueAsText (const IString* aNotValueAsText)
  257. {
  258.   return setNotValueAsText (*aNotValueAsText);
  259. }
  260.  
  261. /*------------------------------------------------------------------------------
  262. | IVBBooleanPart::defaultValue                                                 |
  263. |                                                                              |
  264. | Return the defaultValue attribute.                                           |
  265. ------------------------------------------------------------------------------*/
  266. #pragma export (IVBBooleanPart::defaultValue() const,, 2117)
  267. Boolean IVBBooleanPart::defaultValue () const
  268. {
  269.   return iDefaultValue;
  270. }
  271.  
  272. /*------------------------------------------------------------------------------
  273. | IVBBooleanPart::setDefaultValue                                              |
  274. |                                                                              |
  275. | Set the defaultValue attribute.                                              |
  276. ------------------------------------------------------------------------------*/
  277. #pragma export (IVBBooleanPart::setDefaultValue(const Boolean),, 2118)
  278. IVBBooleanPart& IVBBooleanPart::setDefaultValue (Boolean aDefaultValue)
  279. {
  280.   if (iDefaultValue != aDefaultValue) {
  281.     iDefaultValue = aDefaultValue;
  282.     if (isValueEqualDefault ()) {
  283.       notifyObservers(INotificationEvent(valueEqualDefaultId, *this,
  284.                       true, (void*)iValue));
  285.     }
  286.     else {
  287.       notifyObservers(INotificationEvent(valueNotEqualDefaultId, *this,
  288.                       true, (void*)iValue));
  289.     } /* endif */
  290.   } /* endif */
  291.   return *this;
  292. }
  293.  
  294. /*------------------------------------------------------------------------------
  295. | IVBBooleanPart::isValueEqualDefault                                          |
  296. |                                                                              |
  297. | Return the valueEqualDefault attribute.                                      |
  298. ------------------------------------------------------------------------------*/
  299. #pragma export (IVBBooleanPart::isValueEqualDefault() const,, 2119)
  300. Boolean IVBBooleanPart::isValueEqualDefault () const
  301. {
  302.   return (value() == defaultValue ()) ;
  303. }
  304.  
  305. /*------------------------------------------------------------------------------
  306. | IVBBooleanPart::isValueNotEqualDefault                                       |
  307. |                                                                              |
  308. | Return the valueNotEqualDefault attribute.                                   |
  309. ------------------------------------------------------------------------------*/
  310. #pragma export (IVBBooleanPart::isValueNotEqualDefault() const,, 2120)
  311. Boolean IVBBooleanPart::isValueNotEqualDefault () const
  312. {
  313.   return (value() != defaultValue ()) ;
  314. }
  315.  
  316. /*------------------------------------------------------------------------------
  317. | IVBBooleanPart::assignValueToTrue                                            |
  318. |                                                                              |
  319. | Assign the value attribute to true.                                          |
  320. ------------------------------------------------------------------------------*/
  321. #pragma export (IVBBooleanPart::assignValueToTrue(),, 2121)
  322. IVBBooleanPart& IVBBooleanPart::assignValueToTrue ()
  323. {
  324.   return setValue (true) ;
  325. }
  326.  
  327. /*------------------------------------------------------------------------------
  328. | IVBBooleanPart::assignValueToFalse                                           |
  329. |                                                                              |
  330. | Assign the value attribute to false.                                         |
  331. ------------------------------------------------------------------------------*/
  332. #pragma export (IVBBooleanPart::assignValueToFalse(),, 2122)
  333. IVBBooleanPart& IVBBooleanPart::assignValueToFalse ()
  334. {
  335.   return setValue (false) ;
  336. }
  337.  
  338. /*------------------------------------------------------------------------------
  339. | IVBBooleanPart::assignValueToDefault                                         |
  340. |                                                                              |
  341. | Assign the value attribute to default.                                       |
  342. ------------------------------------------------------------------------------*/
  343. #pragma export (IVBBooleanPart::assignValueToDefault(),, 2123)
  344. IVBBooleanPart& IVBBooleanPart::assignValueToDefault ()
  345. {
  346.   return setValue (defaultValue ()) ;
  347. }
  348.  
  349. /*------------------------------------------------------------------------------
  350. | IVBBooleanPart::copyValueToDefault                                           |
  351. |                                                                              |
  352. | Copy the value attribute to default.                                         |
  353. ------------------------------------------------------------------------------*/
  354. #pragma export (IVBBooleanPart::copyValueToDefault(),, 2124)
  355. IVBBooleanPart& IVBBooleanPart::copyValueToDefault ()
  356. {
  357.   return setDefaultValue (value()) ;
  358. }
  359.  
  360. /*------------------------------------------------------------------------------
  361. | IVBBooleanPart::logicalNotValue                                              |
  362. |                                                                              |
  363. | Perform the logical not operator to the value attribute.                     |
  364. ------------------------------------------------------------------------------*/
  365. #pragma export (IVBBooleanPart::logicalNotValue(),, 2125)
  366. IVBBooleanPart& IVBBooleanPart::logicalNotValue()
  367. {
  368.   return setValue (!value()) ;
  369. }
  370.  
  371. /*------------------------------------------------------------------------------
  372. | IVBBooleanPart::logicalAndValue                                               |
  373. |                                                                              |
  374. | Perform the logical And operator to the value attribute.                      |
  375. ------------------------------------------------------------------------------*/
  376. #pragma export (IVBBooleanPart::logicalAndValue (Boolean),, 2126)
  377. IVBBooleanPart& IVBBooleanPart::logicalAndValue (Boolean anAndValue)
  378. {
  379.   return setValue (value() && anAndValue) ;
  380. }
  381.  
  382. /*------------------------------------------------------------------------------
  383. | IVBBooleanPart::logicalOrValue                                               |
  384. |                                                                              |
  385. | Perform the logical Or operator to the value attribute.                      |
  386. ------------------------------------------------------------------------------*/
  387. #pragma export (IVBBooleanPart::logicalOrValue (Boolean),, 2127)
  388. IVBBooleanPart& IVBBooleanPart::logicalOrValue (Boolean anOrValue)
  389. {
  390.   return setValue (value() || anOrValue) ;
  391. }
  392.  
  393. /*------------------------------------------------------------------------------
  394. | IVBBooleanPart::operator == (const IVBBooleanPart & aValue)                  |
  395. |                                                                              |
  396. ------------------------------------------------------------------------------*/
  397. #pragma export (IVBBooleanPart::operator == (const IVBBooleanPart&) const,, 2128)
  398. Boolean IVBBooleanPart::
  399.   operator == (const IVBBooleanPart& aValue) const
  400. {
  401.   if (value() != aValue.value()) {
  402.     return false;
  403.   } /* endif */
  404.   if (defaultValue() != aValue.defaultValue()) {
  405.     return false;
  406.   } /* endif */
  407.   if (isValueEqualDefault() != aValue.isValueEqualDefault()) {
  408.     return false;
  409.   } /* endif */
  410.   if (isValueNotEqualDefault() != aValue.isValueNotEqualDefault()) {
  411.     return false;
  412.   } /* endif */
  413.   return true;
  414. }
  415.  
  416. /*------------------------------------------------------------------------------
  417. | IVBBooleanPart::operator != (const IVBBooleanPart & aValue)                  |
  418. |                                                                              |
  419. ------------------------------------------------------------------------------*/
  420. #pragma export (IVBBooleanPart::operator != (const IVBBooleanPart&) const,, 2129)
  421. Boolean IVBBooleanPart::
  422.   operator != (const IVBBooleanPart& aValue) const
  423. {
  424.   if (value() != aValue.value()) {
  425.     return true;
  426.   } /* endif */
  427.   if (defaultValue() != aValue.defaultValue()) {
  428.     return true;
  429.   } /* endif */
  430.   if (isValueEqualDefault() != aValue.isValueEqualDefault()) {
  431.     return true;
  432.   } /* endif */
  433.   if (isValueNotEqualDefault() != aValue.isValueNotEqualDefault()) {
  434.     return true;
  435.   } /* endif */
  436.   return false;
  437. }
  438.  
  439. /*------------------------------------------------------------------------------
  440. | IVBBooleanPart::operator == (const IVBBooleanPart * aValue)                  |
  441. |                                                                              |
  442. ------------------------------------------------------------------------------*/
  443. #pragma export (IVBBooleanPart::operator == (const IVBBooleanPart*) const,, 2130)
  444. Boolean IVBBooleanPart::
  445.   operator == (const IVBBooleanPart* aValue) const
  446. {
  447.   if (value() != aValue->value()) {
  448.     return false;
  449.   } /* endif */
  450.   if (defaultValue() != aValue->defaultValue()) {
  451.     return false;
  452.   } /* endif */
  453.   if (isValueEqualDefault() != aValue->isValueEqualDefault()) {
  454.     return false;
  455.   } /* endif */
  456.   if (isValueNotEqualDefault() != aValue->isValueNotEqualDefault()) {
  457.     return false;
  458.   } /* endif */
  459.   return true;
  460. }
  461.  
  462. /*------------------------------------------------------------------------------
  463. | IVBBooleanPart::operator != (const IVBBooleanPart * aValue)                  |
  464. |                                                                              |
  465. ------------------------------------------------------------------------------*/
  466. #pragma export (IVBBooleanPart::operator != (const IVBBooleanPart*) const,, 2131)
  467. Boolean IVBBooleanPart::
  468.   operator != (const IVBBooleanPart* aValue) const
  469. {
  470.   if (value() != aValue->value()) {
  471.     return true;
  472.   } /* endif */
  473.   if (defaultValue() != aValue->defaultValue()) {
  474.     return true;
  475.   } /* endif */
  476.   if (isValueEqualDefault() != aValue->isValueEqualDefault()) {
  477.     return true;
  478.   } /* endif */
  479.   if (isValueNotEqualDefault() != aValue->isValueNotEqualDefault()) {
  480.     return true;
  481.   } /* endif */
  482.   return false;
  483. }
  484.