home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / VBSAMPLE / IVBSTRNG.CPP < prev    next >
Text File  |  1995-05-13  |  24KB  |  491 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) 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 _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.   setText(aIVBStringPart.text());
  88.   setDefaultText(aIVBStringPart.defaultText());
  89.   return *this;
  90. }
  91.  
  92. /*------------------------------------------------------------------------------
  93. | IVBStringPart::~IVBStringPart                                                |
  94. |                                                                              |
  95. | IVBStringPart destructor.                                                    |
  96. ------------------------------------------------------------------------------*/
  97. #pragma export (IVBStringPart::~IVBStringPart(),, 2803)
  98. IVBStringPart::~IVBStringPart()
  99. {
  100. }
  101.  
  102. /*------------------------------------------------------------------------------
  103. | IVBStringPart::text                                                          |
  104. |                                                                              |
  105. | Return the text attribute.                                                   |
  106. ------------------------------------------------------------------------------*/
  107. #pragma export (IVBStringPart::text() const,, 2804)
  108. IString IVBStringPart::text () const
  109. {
  110.   return iText;
  111. }
  112.  
  113. /*------------------------------------------------------------------------------
  114. | IVBStringPart::setText                                                       |
  115. |                                                                              |
  116. | Set the text attribute.                                                      |
  117. ------------------------------------------------------------------------------*/
  118. #pragma export (IVBStringPart::setText(const IString&),, 2805)
  119. IVBStringPart& IVBStringPart::setText (const IString& aText)
  120. {
  121.   if (iText != aText) {
  122.     IString oldValue = iText;
  123.     iText = aText;
  124.     IString eventData(iText);
  125.     notifyObservers(INotificationEvent(textId, *this,
  126.                       true, (void*)&eventData));
  127.     if (iText == defaultText()) {
  128.       notifyObservers(INotificationEvent(textEqualDefaultId, *this,
  129.                       true, (void*)&eventData));
  130.     }
  131.     else {
  132.       if (iDefaultText == oldValue) {
  133.         notifyObservers(INotificationEvent(textNotEqualDefaultId, *this,
  134.                         true, (void*)&eventData));
  135.       } ; /* endif */
  136.     } ; /* endif */
  137.     if (iText.isLowerCase()) {
  138.       if (!(oldValue.isLowerCase())) {
  139.         notifyObservers(INotificationEvent(lowerCaseId, *this,
  140.                         true, (void*)&eventData));
  141.       } ; /* endif */
  142.     } ; /* endif */
  143.     if (iText.isUpperCase()) {
  144.       if (!(oldValue.isUpperCase())) {
  145.         notifyObservers(INotificationEvent(upperCaseId, *this,
  146.                         true, (void*)&eventData));
  147.       } ; /* endif */
  148.     } ; /* endif */
  149.     if (iText.length() != oldValue.length()) {
  150.       notifyObservers(INotificationEvent(textLengthId, *this,
  151.                       true, (void*)&eventData));
  152.     } ; /* endif */
  153.   } ; /* endif */
  154.   return *this;
  155. }
  156.  
  157. /*------------------------------------------------------------------------------
  158. | IVBStringPart::setText                                                       |
  159. |                                                                              |
  160. | Set the text attribute.                                                      |
  161. ------------------------------------------------------------------------------*/
  162. #pragma export (IVBStringPart::setText(),, 2806)
  163. IVBStringPart& IVBStringPart::setText ()
  164. {
  165.   return setText (defaultText());
  166. }
  167.  
  168. /*------------------------------------------------------------------------------
  169. | IVBStringPart::textAsLowerCase                                               |
  170. |                                                                              |
  171. | Return the textAsLowerCase attribute.                                        |
  172. ------------------------------------------------------------------------------*/
  173. #pragma export (IVBStringPart::textAsLowerCase() const,, 2807)
  174. IString IVBStringPart::textAsLowerCase () const
  175. {
  176.   return IString::lowerCase(text());
  177. }
  178.  
  179. /*------------------------------------------------------------------------------
  180. | IVBStringPart::textAsUpperCase                                               |
  181. |                                                                              |
  182. | Return the textAsUpperCase attribute.                                        |
  183. ------------------------------------------------------------------------------*/
  184. #pragma export (IVBStringPart::textAsUpperCase() const,, 2808)
  185. IString IVBStringPart::textAsUpperCase () const
  186. {
  187.   return IString::upperCase(text());
  188. }
  189.  
  190. /*------------------------------------------------------------------------------
  191. | IVBStringPart::defaultText                                                   |
  192. |                                                                              |
  193. | Return the defaultText attribute.                                            |
  194. ------------------------------------------------------------------------------*/
  195. #pragma export (IVBStringPart::defaultText() const,, 2809)
  196. IString IVBStringPart::defaultText () const
  197. {
  198.   return iDefaultText;
  199. }
  200.  
  201. /*------------------------------------------------------------------------------
  202. | IVBStringPart::setDefaultText                                                |
  203. |                                                                              |
  204. | Set the defaultText attribute.                                               |
  205. ------------------------------------------------------------------------------*/
  206. #pragma export (IVBStringPart::setDefaultText(const IString&),, 2810)
  207. IVBStringPart& IVBStringPart::setDefaultText (const IString& aDefaultText)
  208. {
  209.   if (iDefaultText != aDefaultText) {
  210.     iDefaultText = aDefaultText;
  211.     IString eventData(iDefaultText);
  212.     notifyObservers(INotificationEvent(defaultTextId, *this,
  213.                       true, (void*)&eventData));
  214.     if (iDefaultText == text()) {
  215.       notifyObservers(INotificationEvent(textEqualDefaultId, *this,
  216.                       true, (void*)&eventData));
  217.     }
  218.     else {
  219.       notifyObservers(INotificationEvent(textNotEqualDefaultId, *this,
  220.                       true, (void*)&eventData));
  221.     } /* endif */
  222.   } /* endif */
  223.   return *this;
  224. }
  225.  
  226. /*------------------------------------------------------------------------------
  227. | IVBStringPart::isTextEqualDefault                                            |
  228. |                                                                              |
  229. | Return the textEqualDefault attribute.                                       |
  230. ------------------------------------------------------------------------------*/
  231. #pragma export (IVBStringPart::isTextEqualDefault() const,, 2811)
  232. Boolean IVBStringPart::isTextEqualDefault () const
  233. {
  234.   return (text() == defaultText ()) ;
  235. }
  236.  
  237. /*------------------------------------------------------------------------------
  238. | IVBStringPart::isTextNotEqualDefault                                         |
  239. |                                                                              |
  240. | Return the textNotEqualDefault attribute.                                    |
  241. ------------------------------------------------------------------------------*/
  242. #pragma export (IVBStringPart::isTextNotEqualDefault() const,, 2812)
  243. Boolean IVBStringPart::isTextNotEqualDefault () const
  244. {
  245.   return (text() != defaultText ()) ;
  246. }
  247.  
  248. /*------------------------------------------------------------------------------
  249. | IVBStringPart::textLength                                                    |
  250. |                                                                              |
  251. | Return the textLength attribute.                                             |
  252. ------------------------------------------------------------------------------*/
  253. #pragma export (IVBStringPart::textLength() const,, 2813)
  254. unsigned long IVBStringPart::textLength () const
  255. {
  256.   return iText.length();
  257. }
  258.  
  259. /*------------------------------------------------------------------------------
  260. | IVBStringPart::isLowerCase                                                   |
  261. |                                                                              |
  262. | Return the lowerCase attribute.                                              |
  263. ------------------------------------------------------------------------------*/
  264. #pragma export (IVBStringPart::isLowerCase() const,, 2814)
  265. Boolean IVBStringPart::isLowerCase () const
  266. {
  267.   return iText.isLowerCase();
  268. }
  269.  
  270. /*------------------------------------------------------------------------------
  271. | IVBStringPart::isUpperCase                                                   |
  272. |                                                                              |
  273. | Return the upperCase attribute.                                              |
  274. ------------------------------------------------------------------------------*/
  275. #pragma export (IVBStringPart::isUpperCase() const,, 2815)
  276. Boolean IVBStringPart::isUpperCase () const
  277. {
  278.   return iText.isUpperCase();
  279. }
  280.  
  281. /*------------------------------------------------------------------------------
  282. | IVBStringPart::isDigits                                                      |
  283. |                                                                              |
  284. | Return the digits attribute.                                                 |
  285. ------------------------------------------------------------------------------*/
  286. #pragma export (IVBStringPart::isDigits() const,, 2816)
  287. Boolean IVBStringPart::isDigits () const
  288. {
  289.   return iText.length();
  290. }
  291.  
  292. /*------------------------------------------------------------------------------
  293. | IVBStringPart::assignTextToEmpty                                             |
  294. |                                                                              |
  295. | Assign the text attribute to empty.                                          |
  296. ------------------------------------------------------------------------------*/
  297. #pragma export (IVBStringPart::assignTextToEmpty(),, 2817)
  298. IVBStringPart& IVBStringPart::assignTextToEmpty ()
  299. {
  300.   return setText (IString("")) ;
  301. }
  302.  
  303. /*------------------------------------------------------------------------------
  304. | IVBStringPart::assignTextToDateToday                                         |
  305. |                                                                              |
  306. | Assign the text attribute to today's date.                                   |
  307. ------------------------------------------------------------------------------*/
  308. #pragma export (IVBStringPart::assignTextToDateToday(),, 2818)
  309. IVBStringPart& IVBStringPart::assignTextToDateToday ()
  310. {
  311.   return setText (IDate::today().asString()) ;
  312. }
  313.  
  314. /*------------------------------------------------------------------------------
  315. | IVBStringPart::assignTextToTimeNow                                           |
  316. |                                                                              |
  317. | Assign the text attribute to time now.                                       |
  318. ------------------------------------------------------------------------------*/
  319. #pragma export (IVBStringPart::assignTextToTimeNow(),, 2819)
  320. IVBStringPart& IVBStringPart::assignTextToTimeNow ()
  321. {
  322.   return setText (ITime::now().asString()) ;
  323. }
  324.  
  325. /*------------------------------------------------------------------------------
  326. | IVBStringPart::assignTextToCmdLineParm0                                      |
  327. |                                                                              |
  328. | Assign the text attribute to commad line parameter 0.                        |
  329. ------------------------------------------------------------------------------*/
  330. #pragma export (IVBStringPart::assignTextToCmdLineParm0(),, 2820)
  331. IVBStringPart& IVBStringPart::assignTextToCmdLineParm0 ()
  332. {
  333.   return setText (IApplication::current().argv(0)) ;
  334. }
  335.  
  336. /*------------------------------------------------------------------------------
  337. | IVBStringPart::assignTextToCmdLineParm1                                      |
  338. |                                                                              |
  339. | Assign the text attribute to commad line parameter 1.                        |
  340. ------------------------------------------------------------------------------*/
  341. #pragma export (IVBStringPart::assignTextToCmdLineParm1(),, 2821)
  342. IVBStringPart& IVBStringPart::assignTextToCmdLineParm1 ()
  343. {
  344.   return setText (IApplication::current().argv(1)) ;
  345. }
  346.  
  347. /*------------------------------------------------------------------------------
  348. | IVBStringPart::assignTextToDefault                                           |
  349. |                                                                              |
  350. | Assign the text attribute to default.                                        |
  351. ------------------------------------------------------------------------------*/
  352. #pragma export (IVBStringPart::assignTextToDefault(),, 2822)
  353. IVBStringPart& IVBStringPart::assignTextToDefault ()
  354. {
  355.   return setText (defaultText ()) ;
  356. }
  357.  
  358. /*------------------------------------------------------------------------------
  359. | IVBStringPart::changeTextToLowerCase                                         |
  360. |                                                                              |
  361. | Change the text attribute to lower case.                                     |
  362. ------------------------------------------------------------------------------*/
  363. #pragma export (IVBStringPart::changeTextToLowerCase(),, 2823)
  364. IVBStringPart& IVBStringPart::changeTextToLowerCase ()
  365. {
  366.   return setText (IString::lowerCase(text())) ;
  367. }
  368.  
  369. /*------------------------------------------------------------------------------
  370. | IVBStringPart::changeTextToUpperCase                                         |
  371. |                                                                              |
  372. | Change the text attribute to upper case.                                     |
  373. ------------------------------------------------------------------------------*/
  374. #pragma export (IVBStringPart::changeTextToUpperCase(),, 2824)
  375. IVBStringPart& IVBStringPart::changeTextToUpperCase ()
  376. {
  377.   return setText (IString::upperCase(text())) ;
  378. }
  379.  
  380. /*------------------------------------------------------------------------------
  381. | IVBStringPart::reverseText                                                   |
  382. |                                                                              |
  383. | Reverse the text attribute.                                                  |
  384. ------------------------------------------------------------------------------*/
  385. #pragma export (IVBStringPart::reverseText(),, 2825)
  386. IVBStringPart& IVBStringPart::reverseText()
  387. {
  388.   return setText (text().reverse ()) ;
  389. }
  390.  
  391. /*------------------------------------------------------------------------------
  392. | IVBStringPart::stripBlanksOnText                                             |
  393. |                                                                              |
  394. | Strip blanks on the text attribute.                                          |
  395. ------------------------------------------------------------------------------*/
  396. #pragma export (IVBStringPart::stripBlanksOnText(),, 2826)
  397. IVBStringPart& IVBStringPart::stripBlanksOnText()
  398. {
  399.   return setText (IString::stripBlanks (text())) ;
  400. }
  401.  
  402. /*------------------------------------------------------------------------------
  403. | IVBStringPart::appendText                                                    |
  404. |                                                                              |
  405. | Append a string to the text attribute.                                       |
  406. ------------------------------------------------------------------------------*/
  407. #pragma export (IVBStringPart::appendText(const IString&),, 2827)
  408. IVBStringPart& IVBStringPart::appendText(const IString& appendText)
  409. {
  410.   return setText (text() + appendText) ;
  411. }
  412.  
  413. /*------------------------------------------------------------------------------
  414. | IVBStringPart::preappendText                                                   |
  415. |                                                                              |
  416. | Preppend a string to the text attribute.                                     |
  417. ------------------------------------------------------------------------------*/
  418. #pragma export (IVBStringPart::preappendText(const IString&),, 2828)
  419. IVBStringPart& IVBStringPart::preappendText(const IString& preappendText)
  420. {
  421.   return setText (preappendText + text()) ;
  422. }
  423.  
  424. /*------------------------------------------------------------------------------
  425. | IVBStringPart::operator == (const IVBStringPart & aValue)                    |
  426. |                                                                              |
  427. ------------------------------------------------------------------------------*/
  428. #pragma export (IVBStringPart::operator == (const IVBStringPart&) const,, 2829)
  429. Boolean IVBStringPart::
  430.   operator == (const IVBStringPart& aValue) const
  431. {
  432.   if (text() != aValue.text()) {
  433.     return false;
  434.   } /* endif */
  435.   if (defaultText() != aValue.defaultText()) {
  436.     return false;
  437.   } /* endif */
  438.   return true;
  439. }
  440.  
  441. /*------------------------------------------------------------------------------
  442. | IVBStringPart::operator != (const IVBStringPart & aValue)                    |
  443. |                                                                              |
  444. ------------------------------------------------------------------------------*/
  445. #pragma export (IVBStringPart::operator != (const IVBStringPart&) const,, 2830)
  446. Boolean IVBStringPart::
  447.   operator != (const IVBStringPart& aValue) const
  448. {
  449.   if (text() != aValue.text()) {
  450.     return true;
  451.   } /* endif */
  452.   if (defaultText() != aValue.defaultText()) {
  453.     return true;
  454.   } /* endif */
  455.   return false;
  456. }
  457.  
  458. /*------------------------------------------------------------------------------
  459. | IVBStringPart::operator == (const IVBStringPart * aValue)                    |
  460. |                                                                              |
  461. ------------------------------------------------------------------------------*/
  462. #pragma export (IVBStringPart::operator == (const IVBStringPart*) const,, 2831)
  463. Boolean IVBStringPart::
  464.   operator == (const IVBStringPart* aValue) const
  465. {
  466.   if (text() != aValue->text()) {
  467.     return false;
  468.   } /* endif */
  469.   if (defaultText() != aValue->defaultText()) {
  470.     return false;
  471.   } /* endif */
  472.   return true;
  473. }
  474.  
  475. /*------------------------------------------------------------------------------
  476. | IVBStringPart::operator != (const IVBStringPart * aValue)                    |
  477. |                                                                              |
  478. ------------------------------------------------------------------------------*/
  479. #pragma export (IVBStringPart::operator != (const IVBStringPart*) const,, 2832)
  480. Boolean IVBStringPart::
  481.   operator != (const IVBStringPart* aValue) const
  482. {
  483.   if (text() != aValue->text()) {
  484.     return true;
  485.   } /* endif */
  486.   if (defaultText() != aValue->defaultText()) {
  487.     return true;
  488.   } /* endif */
  489.   return false;
  490. }
  491.