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

  1. /*******************************************************************************
  2. * FILE NAME: icust.cpp                                                         *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class(es):                                     *
  6. *    ICustomer - IBM sample customer 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 _ICUST_
  28.   #include <icust.hpp>
  29. #endif
  30.  
  31. #ifndef _INOTIFEV_
  32.   #include <inotifev.hpp>
  33. #endif
  34.  
  35. #include <iadd.hpp>
  36.  
  37. #pragma export (ICustomer::nameId,, 1200)
  38. const INotificationId ICustomer::nameId =
  39.                      "ICustomer::name";
  40. #pragma export (ICustomer::addressId,, 1201)
  41. const INotificationId ICustomer::addressId =
  42.                      "ICustomer::address";
  43. #pragma export (ICustomer::homePhoneId,, 1202)
  44. const INotificationId ICustomer::homePhoneId =
  45.                      "ICustomer::homePhone";
  46. #pragma export (ICustomer::workPhoneId,, 1203)
  47. const INotificationId ICustomer::workPhoneId =
  48.                      "ICustomer::workPhone";
  49. #pragma export (ICustomer::dateId,, 1204)
  50. const INotificationId ICustomer::dateId =
  51.                      "ICustomer::date";
  52. #pragma export (ICustomer::timeId,, 1205)
  53. const INotificationId ICustomer::timeId =
  54.                      "ICustomer::time";
  55.  
  56. /*------------------------------------------------------------------------------
  57. | ICustomer::ICustomer                                                         |
  58. |                                                                              |
  59. | Standard constructor.                                                        |
  60. ------------------------------------------------------------------------------*/
  61. #pragma export (ICustomer::ICustomer(),, 1206)
  62. ICustomer::ICustomer() : IStandardNotifier ()
  63.     ,iName ("Ken")
  64.     ,iAddress (new IAddress())
  65.     ,iHomePhone ("555-1212")
  66.     ,iWorkPhone ("555-1212")
  67.     ,iDate ()
  68.     ,iTime ()
  69. {
  70.   enableNotification ();
  71. }
  72.  
  73. /*------------------------------------------------------------------------------
  74. | ICustomer::ICustomer                                                         |
  75. |                                                                              |
  76. | Constructor with name parameter.                                             |
  77. ------------------------------------------------------------------------------*/
  78. #pragma export (ICustomer::ICustomer(const IString& aName),, 1207)
  79. ICustomer::ICustomer(const IString& aName) :
  80.   IStandardNotifier (),
  81.   iName ("Ken"),
  82.   iAddress (new IAddress()),
  83.   iHomePhone ("555-1212"),
  84.   iWorkPhone ("555-1212"),
  85.   iDate (),
  86.   iTime ()
  87. {
  88.   setName(aName);
  89.   enableNotification ();
  90. }
  91.  
  92. /*------------------------------------------------------------------------------
  93. | ICustomer::ICustomer                                                         |
  94. |                                                                              |
  95. | Standard copy constructor.                                                   |
  96. ------------------------------------------------------------------------------*/
  97. #pragma export (ICustomer::ICustomer(const ICustomer&),, 1208)
  98. ICustomer::ICustomer (const ICustomer& partCopy)
  99.   : IStandardNotifier (partCopy)
  100.     ,iName (partCopy.name ())
  101.     ,iAddress (partCopy.address ())
  102.     ,iHomePhone (partCopy.homePhone ())
  103.     ,iWorkPhone (partCopy.workPhone ())
  104.     ,iDate (partCopy.date ())
  105.     ,iTime (partCopy.time ())
  106. {
  107.   enableNotification ();
  108. }
  109.  
  110. /*------------------------------------------------------------------------------
  111. | ICustomer::ICustomer                                                         |
  112. |                                                                              |
  113. | Standard operator=                                                           |
  114. ------------------------------------------------------------------------------*/
  115. #pragma export (ICustomer::operator= (const ICustomer&),, 1209)
  116. ICustomer& ICustomer::operator= (const ICustomer& aICustomer)
  117. {
  118.   if (this == &aICustomer) {
  119.     return *this;
  120.   } /* endif */
  121.   setName(aICustomer.name());
  122.   setAddress(aICustomer.address());
  123.   setHomePhone(aICustomer.homePhone());
  124.   setWorkPhone(aICustomer.workPhone());
  125.   setDate(aICustomer.date());
  126.   setTime(aICustomer.time());
  127.   return *this;
  128. }
  129.  
  130. /*------------------------------------------------------------------------------
  131. | ICustomer::~ICustomer                                                        |
  132. |                                                                              |
  133. | ICustomer destructor.                                                        |
  134. ------------------------------------------------------------------------------*/
  135. #pragma export (ICustomer::~ICustomer(),, 1210)
  136. ICustomer::~ICustomer()
  137. {
  138.   if (iAddress)
  139.     delete iAddress;
  140. }
  141.  
  142. /*------------------------------------------------------------------------------
  143. | ICustomer::asString                                                          |
  144. |                                                                              |
  145. | Perform asString.                                                            |
  146. ------------------------------------------------------------------------------*/
  147. #pragma export (ICustomer::asString() const,, 1211)
  148. IString ICustomer::asString () const
  149. {
  150.   return name();
  151. }
  152.  
  153. /*------------------------------------------------------------------------------
  154. | ICustomer::name                                                              |
  155. |                                                                              |
  156. | Return the name attribute.                                                   |
  157. ------------------------------------------------------------------------------*/
  158. #pragma export (ICustomer::name() const,, 1212)
  159. IString ICustomer::name () const
  160. {
  161.   return iName;
  162. }
  163.  
  164. /*------------------------------------------------------------------------------
  165. | ICustomer::setName                                                           |
  166. |                                                                              |
  167. | Set the name attribute.                                                      |
  168. ------------------------------------------------------------------------------*/
  169. #pragma export (ICustomer::setName(const IString&),, 1213)
  170. ICustomer& ICustomer::setName (const IString& aName)
  171. {
  172.   if (iName != aName) {
  173.     iName = aName;
  174.     IString eventData(iName);
  175.     notifyObservers(INotificationEvent(nameId, *this,
  176.                       true, (void*)&eventData));
  177.   } /* endif */
  178.   return *this;
  179. }
  180.  
  181. /*------------------------------------------------------------------------------
  182. | ICustomer::address                                                           |
  183. |                                                                              |
  184. | Return the address attribute.                                                |
  185. ------------------------------------------------------------------------------*/
  186. #pragma export (ICustomer::address() const,, 1214)
  187. IAddress* ICustomer::address () const
  188. {
  189.   return iAddress;
  190. }
  191.  
  192. /*------------------------------------------------------------------------------
  193. | ICustomer::setAddress                                                        |
  194. |                                                                              |
  195. | Set the address attribute.                                                   |
  196. ------------------------------------------------------------------------------*/
  197. #pragma export (ICustomer::setAddress(const IAddress*),, 1215)
  198. ICustomer& ICustomer::setAddress (IAddress* aAddress)
  199. {
  200.   if (iAddress != aAddress) {
  201.     if (iAddress)
  202.       delete iAddress;
  203.     iAddress = aAddress;
  204.     notifyObservers(INotificationEvent(addressId, *this,
  205.                       true, (void*)iAddress));
  206.   } /* endif */
  207.   return *this;
  208. }
  209.  
  210. /*------------------------------------------------------------------------------
  211. | ICustomer::setAddress                                                        |
  212. |                                                                              |
  213. | Set the address attribute.                                                   |
  214. ------------------------------------------------------------------------------*/
  215. #pragma export (ICustomer::setAddress(const IAddress&),, 1216)
  216. ICustomer& ICustomer::setAddress (const IAddress& aAddress)
  217. {
  218.   return setAddress(new IAddress(aAddress));
  219. }
  220.  
  221. /*------------------------------------------------------------------------------
  222. | ICustomer::homePhone                                                         |
  223. |                                                                              |
  224. | Return the homePhone attribute.                                              |
  225. ------------------------------------------------------------------------------*/
  226. #pragma export (ICustomer::homePhone() const,, 1217)
  227. IString ICustomer::homePhone () const
  228. {
  229.   return iHomePhone;
  230. }
  231.  
  232. /*------------------------------------------------------------------------------
  233. | ICustomer::setHomePhone                                                      |
  234. |                                                                              |
  235. | Set the homePhone attribute.                                                 |
  236. ------------------------------------------------------------------------------*/
  237. #pragma export (ICustomer::setHomePhone(const IString&),, 1218)
  238. ICustomer& ICustomer::setHomePhone (const IString& aHomePhone)
  239. {
  240.   if (iHomePhone != aHomePhone) {
  241.     iHomePhone = aHomePhone;
  242.     IString eventData(iHomePhone);
  243.     notifyObservers(INotificationEvent(homePhoneId, *this,
  244.                       true, (void*)&eventData));
  245.   } /* endif */
  246.   return *this;
  247. }
  248.  
  249. /*------------------------------------------------------------------------------
  250. | ICustomer::workPhone                                                         |
  251. |                                                                              |
  252. | Return the workPhone attribute.                                              |
  253. ------------------------------------------------------------------------------*/
  254. #pragma export (ICustomer::workPhone() const,, 1219)
  255. IString ICustomer::workPhone () const
  256. {
  257.   return iWorkPhone;
  258. }
  259.  
  260. /*------------------------------------------------------------------------------
  261. | ICustomer::setWorkPhone                                                      |
  262. |                                                                              |
  263. | Set the workPhone attribute.                                                 |
  264. ------------------------------------------------------------------------------*/
  265. #pragma export (ICustomer::setWorkPhone(const IString&),, 1220)
  266. ICustomer& ICustomer::setWorkPhone (const IString& aWorkPhone)
  267. {
  268.   if (iWorkPhone != aWorkPhone) {
  269.     iWorkPhone = aWorkPhone;
  270.     IString eventData(iWorkPhone);
  271.     notifyObservers(INotificationEvent(workPhoneId, *this,
  272.                       true, (void*)&eventData));
  273.   } /* endif */
  274.   return *this;
  275. }
  276.  
  277. /*------------------------------------------------------------------------------
  278. | ICustomer::date                                                              |
  279. |                                                                              |
  280. | Return the date attribute.                                                   |
  281. ------------------------------------------------------------------------------*/
  282. #pragma export (ICustomer::date() const,, 1221)
  283. IDate ICustomer::date () const
  284. {
  285.   return iDate;
  286. }
  287.  
  288. /*------------------------------------------------------------------------------
  289. | ICustomer::setDate                                                           |
  290. |                                                                              |
  291. | Set the date attribute.                                                      |
  292. ------------------------------------------------------------------------------*/
  293. #pragma export (ICustomer::setDate(const IDate&),, 1222)
  294. ICustomer& ICustomer::setDate (const IDate& aDate)
  295. {
  296.   if (iDate != aDate) {
  297.     iDate = aDate;
  298.     IDate eventData(iDate);
  299.     notifyObservers(INotificationEvent(dateId, *this,
  300.                       true, (void*)&eventData));
  301.   } /* endif */
  302.   return *this;
  303. }
  304.  
  305. /*------------------------------------------------------------------------------
  306. | ICustomer::time                                                              |
  307. |                                                                              |
  308. | Return the time attribute.                                                   |
  309. ------------------------------------------------------------------------------*/
  310. #pragma export (ICustomer::time() const,, 1223)
  311. ITime ICustomer::time () const
  312. {
  313.   return iTime;
  314. }
  315.  
  316. /*------------------------------------------------------------------------------
  317. | ICustomer::setTime                                                           |
  318. |                                                                              |
  319. | Set the time attribute.                                                      |
  320. ------------------------------------------------------------------------------*/
  321. #pragma export (ICustomer::setTime(const ITime&),, 1224)
  322. ICustomer& ICustomer::setTime (const ITime& aTime)
  323. {
  324.   if (iTime != aTime)
  325.   {
  326.     iTime = aTime;
  327.     ITime eventData(iTime);
  328.     notifyObservers(INotificationEvent(timeId, *this,
  329.                       true, (void*)&eventData));
  330.   } /* endif */
  331.   return *this;
  332. }
  333.  
  334. /*------------------------------------------------------------------------------
  335. | ICustomer::setNameToDefault                                                  |
  336. |                                                                              |
  337. | Perform the setNameToDefault action.                                         |
  338. ------------------------------------------------------------------------------*/
  339. #pragma export (ICustomer::setNameToDefault(),, 1225)
  340. ICustomer& ICustomer::setNameToDefault ()
  341. {
  342.   return setName("Ken");
  343. }
  344.  
  345. /*------------------------------------------------------------------------------
  346. | ICustomer::setAddressToDefault                                               |
  347. |                                                                              |
  348. | Perform the setAddressToDefault action.                                      |
  349. ------------------------------------------------------------------------------*/
  350. #pragma export (ICustomer::setAddressToDefault(),, 1226)
  351. ICustomer& ICustomer::setAddressToDefault ()
  352. {
  353.   if (address())
  354.     address()->setToDefault();
  355.   return *this;
  356. }
  357.  
  358. /*------------------------------------------------------------------------------
  359. | ICustomer::setHomePhoneToDefault                                             |
  360. |                                                                              |
  361. | Perform the setHomePhoneToDefault action.                                    |
  362. ------------------------------------------------------------------------------*/
  363. #pragma export (ICustomer::setHomePhoneToDefault(),, 1227)
  364. ICustomer& ICustomer::setHomePhoneToDefault ()
  365. {
  366.   return setHomePhone("555-1212");
  367. }
  368.  
  369. /*------------------------------------------------------------------------------
  370. | ICustomer::setWorkPhoneToDefault                                             |
  371. |                                                                              |
  372. | Perform the setWorkPhoneToDefault action.                                    |
  373. ------------------------------------------------------------------------------*/
  374. #pragma export (ICustomer::setWorkPhoneToDefault(),, 1228)
  375. ICustomer& ICustomer::setWorkPhoneToDefault ()
  376. {
  377.   return setWorkPhone("555-1212");
  378. }
  379.  
  380. /*------------------------------------------------------------------------------
  381. | ICustomer::operator == (const ICustomer & aValue)                            |
  382. |                                                                              |
  383. ------------------------------------------------------------------------------*/
  384. #pragma export (ICustomer::operator == (const ICustomer&) const,, 1229)
  385. Boolean ICustomer::
  386.   operator == (const ICustomer& aValue) const
  387. {
  388.   if (name() != aValue.name()) {
  389.     return false;
  390.   } /* endif */
  391.   if (address() != aValue.address()) {
  392.     return false;
  393.   } /* endif */
  394.   if (homePhone() != aValue.homePhone()) {
  395.     return false;
  396.   } /* endif */
  397.   if (workPhone() != aValue.workPhone()) {
  398.     return false;
  399.   } /* endif */
  400.   if (date() != aValue.date()) {
  401.     return false;
  402.   } /* endif */
  403.   if (time() != aValue.time()) {
  404.     return false;
  405.   } /* endif */
  406.   return true;
  407. }
  408.  
  409. /*------------------------------------------------------------------------------
  410. | ICustomer::operator != (const ICustomer & aValue)                            |
  411. |                                                                              |
  412. ------------------------------------------------------------------------------*/
  413. #pragma export (ICustomer::operator != (const ICustomer&) const,, 1230)
  414. Boolean ICustomer::
  415.   operator != (const ICustomer& aValue) const
  416. {
  417.   if (name() != aValue.name()) {
  418.     return true;
  419.   } /* endif */
  420.   if (address() != aValue.address()) {
  421.     return true;
  422.   } /* endif */
  423.   if (homePhone() != aValue.homePhone()) {
  424.     return true;
  425.   } /* endif */
  426.   if (workPhone() != aValue.workPhone()) {
  427.     return true;
  428.   } /* endif */
  429.   if (date() != aValue.date()) {
  430.     return true;
  431.   } /* endif */
  432.   if (time() != aValue.time()) {
  433.     return true;
  434.   } /* endif */
  435.   return false;
  436. }
  437.  
  438. /*------------------------------------------------------------------------------
  439. | ICustomer::operator == (const ICustomer * aValue)                            |
  440. |                                                                              |
  441. ------------------------------------------------------------------------------*/
  442. #pragma export (ICustomer::operator == (const ICustomer*) const,, 1231)
  443. Boolean ICustomer::
  444.   operator == (const ICustomer* aValue) const
  445. {
  446.   if (name() != aValue->name()) {
  447.     return false;
  448.   } /* endif */
  449.   if (address() != aValue->address()) {
  450.     return false;
  451.   } /* endif */
  452.   if (homePhone() != aValue->homePhone()) {
  453.     return false;
  454.   } /* endif */
  455.   if (workPhone() != aValue->workPhone()) {
  456.     return false;
  457.   } /* endif */
  458.   if (date() != aValue->date()) {
  459.     return false;
  460.   } /* endif */
  461.   if (time() != aValue->time()) {
  462.     return false;
  463.   } /* endif */
  464.   return true;
  465. }
  466.  
  467. /*------------------------------------------------------------------------------
  468. | ICustomer::operator != (const ICustomer * aValue)                            |
  469. |                                                                              |
  470. ------------------------------------------------------------------------------*/
  471. #pragma export (ICustomer::operator != (const ICustomer*) const,, 1232)
  472. Boolean ICustomer::
  473.   operator != (const ICustomer* aValue) const
  474. {
  475.   if (name() != aValue->name()) {
  476.     return true;
  477.   } /* endif */
  478.   if (address() != aValue->address()) {
  479.     return true;
  480.   } /* endif */
  481.   if (homePhone() != aValue->homePhone()) {
  482.     return true;
  483.   } /* endif */
  484.   if (workPhone() != aValue->workPhone()) {
  485.     return true;
  486.   } /* endif */
  487.   if (date() != aValue->date()) {
  488.     return true;
  489.   } /* endif */
  490.   if (time() != aValue->time()) {
  491.     return true;
  492.   } /* endif */
  493.   return false;
  494. }
  495.  
  496. /*------------------------------------------------------------------------------
  497. | ICustomer::operator < (const ICustomer * aValue)                             |
  498. |                                                                              |
  499. ------------------------------------------------------------------------------*/
  500. #pragma export (ICustomer::operator < (const ICustomer*) const,, 1233)
  501. Boolean ICustomer::
  502.   operator < (const ICustomer* aValue) const
  503. {
  504.   return (name() < (aValue->name()));
  505. }
  506.  
  507. /*------------------------------------------------------------------------------
  508. | ICustomer::operator < (const ICustomer & aValue)                             |
  509. |                                                                              |
  510. ------------------------------------------------------------------------------*/
  511. #pragma export (ICustomer::operator < (const ICustomer&) const,, 1234)
  512. Boolean ICustomer::
  513.   operator < (const ICustomer& aValue) const
  514. {
  515.   return (name() < (aValue.name()));
  516. }
  517.  
  518. /*------------------------------------------------------------------------------
  519. | ICustomer::operator < (ICustomer* const & aValue)                            |
  520. |                                                                              |
  521. ------------------------------------------------------------------------------*/
  522. #pragma export (ICustomer::operator < (ICustomer* const&) const,, 1235)
  523. Boolean ICustomer::
  524.   operator < (ICustomer* const& aValue) const
  525. {
  526.   return (name() < (aValue->name()));
  527. }
  528.  
  529. /*------------------------------------------------------------------------------
  530. | ICustomer::operator < (ICustomerElemPtr const & aValue)                      |
  531. |                                                                              |
  532. ------------------------------------------------------------------------------*/
  533. #pragma export (ICustomer::operator < (ICustomerElemPtr const&) const,, 1236)
  534. Boolean ICustomer::
  535.   operator < (ICustomerElemPtr const& aValue) const
  536. {
  537.   return (name() < (aValue->name()));
  538. }
  539.  
  540. /*------------------------------------------------------------------------------
  541. | ICustomer::operator < (ICustomerMngPtr const & aValue)                       |
  542. |                                                                              |
  543. ------------------------------------------------------------------------------*/
  544. #pragma export (ICustomer::operator < (ICustomerMngPtr const&) const,, 1237)
  545. Boolean ICustomer::
  546.   operator < (ICustomerMngPtr const& aValue) const
  547. {
  548.   return (name() < (aValue->name()));
  549. }
  550.