home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / vbsample / ivbstrng.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  23.7 KB  |  505 lines

  1. /*******************************************************************************
  2. * FILE NAME: ivbstrng.cpp                                                      *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class(es):                                     *
  6. *    IVBStringPart - IBM VB sample string 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 _IVBSTRNG_
  28.   #include <ivbstrng.hpp>
  29. #endif
  30.  
  31. #ifndef _INOTIFEV_
  32.   #include <inotifev.hpp>
  33. #endif
  34.  
  35. #ifndef _IDATE_
  36.   #include <idate.hpp>
  37. #endif
  38.  
  39. #ifndef _ITIME_
  40.   #include <itime.hpp>
  41. #endif
  42.  
  43. #ifndef _IAPP_
  44.   #include <iapp.hpp>
  45. #endif
  46.  
  47.  
  48.  
  49. /*------------------------------------------------------------------------------
  50. | IVBStringPart::IVBStringPart                                                 |
  51. |                                                                              |
  52. | Standard constructor.                                                        |
  53. ------------------------------------------------------------------------------*/
  54. #pragma export (IVBStringPart::IVBStringPart(const IString& aText),, 2800)
  55. IVBStringPart::IVBStringPart(const IString& aText) : IVBDataTypePart ()
  56.     ,iText (aText)
  57.     ,iDefaultText ("")
  58. {
  59.   enableNotification ();
  60. }
  61.  
  62. /*------------------------------------------------------------------------------
  63. | IVBStringPart::IVBStringPart                                                 |
  64. |                                                                              |
  65. | Standard copy constructor.                                                   |
  66. ------------------------------------------------------------------------------*/
  67. #pragma export (IVBStringPart::IVBStringPart(const IVBStringPart&),, 2801)
  68. IVBStringPart::IVBStringPart (const IVBStringPart& partCopy)
  69.   : IVBDataTypePart (partCopy)
  70.     ,iText (partCopy.text ())
  71.     ,iDefaultText (partCopy.defaultText ())
  72. {
  73.   enableNotification ();
  74. }
  75.  
  76. /*------------------------------------------------------------------------------
  77. | IVBStringPart::IVBStringPart                                                 |
  78. |                                                                              |
  79. | Standard operator=                                                           |
  80. ------------------------------------------------------------------------------*/
  81. #pragma export (IVBStringPart::operator= (const IVBStringPart&),, 2802)
  82. IVBStringPart& IVBStringPart::operator= (const IVBStringPart& aIVBStringPart)
  83. {
  84.   if (this == &aIVBStringPart) {
  85.     return *this;
  86.   } /* endif */
  87.   Inherited::operator=(aIVBStringPart);
  88.   setText(aIVBStringPart.text());
  89.   setDefaultText(aIVBStringPart.defaultText());
  90.   return *this;
  91. }
  92.  
  93. /*------------------------------------------------------------------------------
  94. | IVBStringPart::~IVBStringPart                                                |
  95. |                                                                              |
  96. | IVBStringPart destructor.                                                    |
  97. ------------------------------------------------------------------------------*/
  98. #pragma export (IVBStringPart::~IVBStringPart(),, 2803)
  99. IVBStringPart::~IVBStringPart()
  100. {
  101. }
  102.  
  103. /*------------------------------------------------------------------------------
  104. | IVBStringPart::text                                                          |
  105. |                                                                              |
  106. | Return the text attribute.                                                   |
  107. ------------------------------------------------------------------------------*/
  108. #pragma export (IVBStringPart::text() const,, 2804)
  109. IString IVBStringPart::text () const
  110. {
  111.   return iText;
  112. }
  113.  
  114. /*------------------------------------------------------------------------------
  115. | IVBStringPart::setText                                                       |
  116. |                                                                              |
  117. | Set the text attribute.                                                      |
  118. ------------------------------------------------------------------------------*/
  119. #pragma export (IVBStringPart::setText(const IString&),, 2805)
  120. IVBStringPart& IVBStringPart::setText (const IString& aText)
  121. {
  122.   if (iText != aText) {
  123.     IString oldValue = iText;
  124.     iText = aText;
  125.     IString eventData(iText);
  126.     notifyObservers(INotificationEvent(textId, *this,
  127.                       true, (void*)&eventData));
  128.     if (iText == defaultText()) {
  129.       notifyObservers(INotificationEvent(textEqualDefaultId, *this,
  130.                       true, (void*)&eventData));
  131.     }
  132.     else {
  133.       if (iDefaultText == oldValue) {
  134.         notifyObservers(INotificationEvent(textNotEqualDefaultId, *this,
  135.                         true, (void*)&eventData));
  136.       } ; /* endif */
  137.     } ; /* endif */
  138.     if (iText.isLowerCase()) {
  139.       if (!(oldValue.isLowerCase())) {
  140.         notifyObservers(INotificationEvent(lowerCaseId, *this,
  141.                         true, (void*)&eventData));
  142.       } ; /* endif */
  143.     } ; /* endif */
  144.     if (iText.isUpperCase()) {
  145.       if (!(oldValue.isUpperCase())) {
  146.         notifyObservers(INotificationEvent(upperCaseId, *this,
  147.                         true, (void*)&eventData));
  148.       } ; /* endif */
  149.     } ; /* endif */
  150.     if (iText.length() != oldValue.length()) {
  151.       notifyObservers(INotificationEvent(textLengthId, *this,
  152.                       true, (void*)&eventData));
  153.     } ; /* endif */
  154.   } ; /* endif */
  155.   return *this;
  156. }
  157.  
  158. /*------------------------------------------------------------------------------
  159. | IVBStringPart::setText                                                       |
  160. |                                                                              |
  161. | Set the text attribute.                                                      |
  162. ------------------------------------------------------------------------------*/
  163. #pragma export (IVBStringPart::setText(),, 2806)
  164. IVBStringPart& IVBStringPart::setText ()
  165. {
  166.   return setText (defaultText());
  167. }
  168.  
  169. /*------------------------------------------------------------------------------
  170. | IVBStringPart::textAsLowerCase                                               |
  171. |                                                                              |
  172. | Return the textAsLowerCase attribute.                                        |
  173. ------------------------------------------------------------------------------*/
  174. #pragma export (IVBStringPart::textAsLowerCase() const,, 2807)
  175. IString IVBStringPart::textAsLowerCase () const
  176. {
  177.   return IString::lowerCase(text());
  178. }
  179.  
  180. /*------------------------------------------------------------------------------
  181. | IVBStringPart::textAsUpperCase                                               |
  182. |                                                                              |
  183. | Return the textAsUpperCase attribute.                                        |
  184. ------------------------------------------------------------------------------*/
  185. #pragma export (IVBStringPart::textAsUpperCase() const,, 2808)
  186. IString IVBStringPart::textAsUpperCase () const
  187. {
  188.   return IString::upperCase(text());
  189. }
  190.  
  191. /*------------------------------------------------------------------------------
  192. | IVBStringPart::defaultText                                                   |
  193. |                                                                              |
  194. | Return the defaultText attribute.                                            |
  195. ------------------------------------------------------------------------------*/
  196. #pragma export (IVBStringPart::defaultText() const,, 2809)
  197. IString IVBStringPart::defaultText () const
  198. {
  199.   return iDefaultText;
  200. }
  201.  
  202. /*------------------------------------------------------------------------------
  203. | IVBStringPart::setDefaultText                                                |
  204. |                                                                              |
  205. | Set the defaultText attribute.                                               |
  206. ------------------------------------------------------------------------------*/
  207. #pragma export (IVBStringPart::setDefaultText(const IString&),, 2810)
  208. IVBStringPart& IVBStringPart::setDefaultText (const IString& aDefaultText)
  209. {
  210.   if (iDefaultText != aDefaultText) {
  211.     iDefaultText = aDefaultText;
  212.     IString eventData(iDefaultText);
  213.     notifyObservers(INotificationEvent(defaultTextId, *this,
  214.                       true, (void*)&eventData));
  215.     if (iDefaultText == text()) {
  216.       notifyObservers(INotificationEvent(textEqualDefaultId, *this,
  217.                       true, (void*)&eventData));
  218.     }
  219.     else {
  220.       notifyObservers(INotificationEvent(textNotEqualDefaultId, *this,
  221.                       true, (void*)&eventData));
  222.     } /* endif */
  223.   } /* endif */
  224.   return *this;
  225. }
  226.  
  227. /*------------------------------------------------------------------------------
  228. | IVBStringPart::isTextEqualDefault                                            |
  229. |                                                                              |
  230. | Return the textEqualDefault attribute.                                       |
  231. ------------------------------------------------------------------------------*/
  232. #pragma export (IVBStringPart::isTextEqualDefault() const,, 2811)
  233. Boolean IVBStringPart::isTextEqualDefault () const
  234. {
  235.   return (text() == defaultText ()) ;
  236. }
  237.  
  238. /*------------------------------------------------------------------------------
  239. | IVBStringPart::isTextNotEqualDefault                                         |
  240. |                                                                              |
  241. | Return the textNotEqualDefault attribute.                                    |
  242. ------------------------------------------------------------------------------*/
  243. #pragma export (IVBStringPart::isTextNotEqualDefault() const,, 2812)
  244. Boolean IVBStringPart::isTextNotEqualDefault () const
  245. {
  246.   return (text() != defaultText ()) ;
  247. }
  248.  
  249. /*------------------------------------------------------------------------------
  250. | IVBStringPart::textLength                                                    |
  251. |                                                                              |
  252. | Return the textLength attribute.                                             |
  253. ------------------------------------------------------------------------------*/
  254. #pragma export (IVBStringPart::textLength() const,, 2813)
  255. unsigned long IVBStringPart::textLength () const
  256. {
  257.   return iText.length();
  258. }
  259.  
  260. /*------------------------------------------------------------------------------
  261. | IVBStringPart::isLowerCase                                                   |
  262. |                                                                              |
  263. | Return the lowerCase attribute.                                              |
  264. ------------------------------------------------------------------------------*/
  265. #pragma export (IVBStringPart::isLowerCase() const,, 2814)
  266. Boolean IVBStringPart::isLowerCase () const
  267. {
  268.   return iText.isLowerCase();
  269. }
  270.  
  271. /*------------------------------------------------------------------------------
  272. | IVBStringPart::isUpperCase                                                   |
  273. |                                                                              |
  274. | Return the upperCase attribute.                                              |
  275. ------------------------------------------------------------------------------*/
  276. #pragma export (IVBStringPart::isUpperCase() const,, 2815)
  277. Boolean IVBStringPart::isUpperCase () const
  278. {
  279.   return iText.isUpperCase();
  280. }
  281.  
  282. /*------------------------------------------------------------------------------
  283. | IVBStringPart::isDigits                                                      |
  284. |                                                                              |
  285. | Return the digits attribute.                                                 |
  286. ------------------------------------------------------------------------------*/
  287. #pragma export (IVBStringPart::isDigits() const,, 2816)
  288. Boolean IVBStringPart::isDigits () const
  289. {
  290.   return iText.length();
  291. }
  292.  
  293. /*------------------------------------------------------------------------------
  294. | IVBStringPart::assignTextToEmpty                                             |
  295. |                                                                              |
  296. | Assign the text attribute to empty.                                          |
  297. ------------------------------------------------------------------------------*/
  298. #pragma export (IVBStringPart::assignTextToEmpty(),, 2817)
  299. IVBStringPart& IVBStringPart::assignTextToEmpty ()
  300. {
  301.   return setText (IString("")) ;
  302. }
  303.  
  304. /*------------------------------------------------------------------------------
  305. | IVBStringPart::assignTextToDateToday                                         |
  306. |                                                                              |
  307. | Assign the text attribute to today's date.                                   |
  308. ------------------------------------------------------------------------------*/
  309. #pragma export (IVBStringPart::assignTextToDateToday(),, 2818)
  310. IVBStringPart& IVBStringPart::assignTextToDateToday ()
  311. {
  312.   return setText (IDate::today().asString()) ;
  313. }
  314.  
  315. /*------------------------------------------------------------------------------
  316. | IVBStringPart::assignTextToTimeNow                                           |
  317. |                                                                              |
  318. | Assign the text attribute to time now.                                       |
  319. ------------------------------------------------------------------------------*/
  320. #pragma export (IVBStringPart::assignTextToTimeNow(),, 2819)
  321. IVBStringPart& IVBStringPart::assignTextToTimeNow ()
  322. {
  323.   return setText (ITime::now().asString()) ;
  324. }
  325.  
  326. /*------------------------------------------------------------------------------
  327. | IVBStringPart::assignTextToCmdLineParm0                                      |
  328. |                                                                              |
  329. | Assign the text attribute to commad line parameter 0.                        |
  330. ------------------------------------------------------------------------------*/
  331. #pragma export (IVBStringPart::assignTextToCmdLineParm0(),, 2820)
  332. IVBStringPart& IVBStringPart::assignTextToCmdLineParm0 ()
  333. {
  334.   return setText (IApplication::current().argv(0)) ;
  335. }
  336.  
  337. /*------------------------------------------------------------------------------
  338. | IVBStringPart::assignTextToCmdLineParm1                                      |
  339. |                                                                              |
  340. | Assign the text attribute to commad line parameter 1.                        |
  341. ------------------------------------------------------------------------------*/
  342. #pragma export (IVBStringPart::assignTextToCmdLineParm1(),, 2821)
  343. IVBStringPart& IVBStringPart::assignTextToCmdLineParm1 ()
  344. {
  345.   return setText (IApplication::current().argv(1)) ;
  346. }
  347.  
  348. /*------------------------------------------------------------------------------
  349. | IVBStringPart::assignTextToDefault                                           |
  350. |                                                                              |
  351. | Assign the text attribute to default.                                        |
  352. ------------------------------------------------------------------------------*/
  353. #pragma export (IVBStringPart::assignTextToDefault(),, 2822)
  354. IVBStringPart& IVBStringPart::assignTextToDefault ()
  355. {
  356.   return setText (defaultText ()) ;
  357. }
  358.  
  359. /*------------------------------------------------------------------------------
  360. | IVBStringPart::changeTextToLowerCase                                         |
  361. |                                                                              |
  362. | Change the text attribute to lower case.                                     |
  363. ------------------------------------------------------------------------------*/
  364. #pragma export (IVBStringPart::changeTextToLowerCase(),, 2823)
  365. IVBStringPart& IVBStringPart::changeTextToLowerCase ()
  366. {
  367.   return setText (IString::lowerCase(text())) ;
  368. }
  369.  
  370. /*------------------------------------------------------------------------------
  371. | IVBStringPart::changeTextToUpperCase                                         |
  372. |                                                                              |
  373. | Change the text attribute to upper case.                                     |
  374. ------------------------------------------------------------------------------*/
  375. #pragma export (IVBStringPart::changeTextToUpperCase(),, 2824)
  376. IVBStringPart& IVBStringPart::changeTextToUpperCase ()
  377. {
  378.   return setText (IString::upperCase(text())) ;
  379. }
  380.  
  381. /*------------------------------------------------------------------------------
  382. | IVBStringPart::reverseText                                                   |
  383. |                                                                              |
  384. | Reverse the text attribute.                                                  |
  385. ------------------------------------------------------------------------------*/
  386. #pragma export (IVBStringPart::reverseText(),, 2825)
  387. IVBStringPart& IVBStringPart::reverseText()
  388. {
  389.   return setText (text().reverse ()) ;
  390. }
  391.  
  392. /*------------------------------------------------------------------------------
  393. | IVBStringPart::stripBlanksOnText                                             |
  394. |                                                                              |
  395. | Strip blanks on the text attribute.                                          |
  396. ------------------------------------------------------------------------------*/
  397. #pragma export (IVBStringPart::stripBlanksOnText(),, 2826)
  398. IVBStringPart& IVBStringPart::stripBlanksOnText()
  399. {
  400.   return setText (IString::stripBlanks (text())) ;
  401. }
  402.  
  403. /*------------------------------------------------------------------------------
  404. | IVBStringPart::appendText                                                    |
  405. |                                                                              |
  406. | Append a string to the text attribute.                                       |
  407. ------------------------------------------------------------------------------*/
  408. #pragma export (IVBStringPart::appendText(const IString&),, 2827)
  409. IVBStringPart& IVBStringPart::appendText(const IString& appendText)
  410. {
  411.   return setText (text() + appendText) ;
  412. }
  413.  
  414. /*------------------------------------------------------------------------------
  415. | IVBStringPart::preappendText                                                   |
  416. |                                                                              |
  417. | Preppend a string to the text attribute.                                     |
  418. ------------------------------------------------------------------------------*/
  419. #pragma export (IVBStringPart::preappendText(const IString&),, 2828)
  420. IVBStringPart& IVBStringPart::preappendText(const IString& preappendText)
  421. {
  422.   return setText (preappendText + text()) ;
  423. }
  424.  
  425. /*------------------------------------------------------------------------------
  426. | IVBStringPart::operator == (const IVBStringPart & aValue)                    |
  427. |                                                                              |
  428. ------------------------------------------------------------------------------*/
  429. #pragma export (IVBStringPart::operator == (const IVBStringPart&) const,, 2829)
  430. Boolean IVBStringPart::
  431.   operator == (const IVBStringPart& aValue) const
  432. {
  433.   if (text() != aValue.text()) {
  434.     return false;
  435.   } /* endif */
  436.   if (defaultText() != aValue.defaultText()) {
  437.     return false;
  438.   } /* endif */
  439.   return true;
  440. }
  441.  
  442. /*------------------------------------------------------------------------------
  443. | IVBStringPart::operator != (const IVBStringPart & aValue)                    |
  444. |                                                                              |
  445. ------------------------------------------------------------------------------*/
  446. #pragma export (IVBStringPart::operator != (const IVBStringPart&) const,, 2830)
  447. Boolean IVBStringPart::
  448.   operator != (const IVBStringPart& aValue) const
  449. {
  450.   if (text() != aValue.text()) {
  451.     return true;
  452.   } /* endif */
  453.   if (defaultText() != aValue.defaultText()) {
  454.     return true;
  455.   } /* endif */
  456.   return false;
  457. }
  458.  
  459. /*------------------------------------------------------------------------------
  460. | IVBStringPart::operator == (const IVBStringPart * aValue)                    |
  461. |                                                                              |
  462. ------------------------------------------------------------------------------*/
  463. #pragma export (IVBStringPart::operator == (const IVBStringPart*) const,, 2831)
  464. Boolean IVBStringPart::
  465.   operator == (const IVBStringPart* aValue) const
  466. {
  467.   if (text() != aValue->text()) {
  468.     return false;
  469.   } /* endif */
  470.   if (defaultText() != aValue->defaultText()) {
  471.     return false;
  472.   } /* endif */
  473.   return true;
  474. }
  475.  
  476. /*------------------------------------------------------------------------------
  477. | IVBStringPart::operator != (const IVBStringPart * aValue)                    |
  478. |                                                                              |
  479. ------------------------------------------------------------------------------*/
  480. #pragma export (IVBStringPart::operator != (const IVBStringPart*) const,, 2832)
  481. Boolean IVBStringPart::
  482.   operator != (const IVBStringPart* aValue) const
  483. {
  484.   if (text() != aValue->text()) {
  485.     return true;
  486.   } /* endif */
  487.   if (defaultText() != aValue->defaultText()) {
  488.     return true;
  489.   } /* endif */
  490.   return false;
  491. }
  492.  
  493. #ifdef IC_PM
  494. /*------------------------------------------------------------------------------
  495. | IVBStringPart::asString                                                      |
  496. |                                                                              |
  497. | Perform asString.                                                            |
  498. ------------------------------------------------------------------------------*/
  499. #pragma export (IVBStringPart::asString() const,, 2833)
  500. IString IVBStringPart::asString () const
  501. {
  502.   return text();
  503. }
  504. #endif
  505.