home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / vbsample / icust.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  23.5 KB  |  551 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) 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 _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.   Inherited::operator=(aICustomer);
  122.   setName(aICustomer.name());
  123.   setAddress(new IAddress(*aICustomer.address()));
  124.   setHomePhone(aICustomer.homePhone());
  125.   setWorkPhone(aICustomer.workPhone());
  126.   setDate(aICustomer.date());
  127.   setTime(aICustomer.time());
  128.   return *this;
  129. }
  130.  
  131. /*------------------------------------------------------------------------------
  132. | ICustomer::~ICustomer                                                        |
  133. |                                                                              |
  134. | ICustomer destructor.                                                        |
  135. ------------------------------------------------------------------------------*/
  136. #pragma export (ICustomer::~ICustomer(),, 1210)
  137. ICustomer::~ICustomer()
  138. {
  139.   if (iAddress)
  140.     delete iAddress;
  141. }
  142.  
  143. /*------------------------------------------------------------------------------
  144. | ICustomer::asString                                                          |
  145. |                                                                              |
  146. | Perform asString.                                                            |
  147. ------------------------------------------------------------------------------*/
  148. #pragma export (ICustomer::asString() const,, 1211)
  149. IString ICustomer::asString () const
  150. {
  151.   return name();
  152. }
  153.  
  154. /*------------------------------------------------------------------------------
  155. | ICustomer::name                                                              |
  156. |                                                                              |
  157. | Return the name attribute.                                                   |
  158. ------------------------------------------------------------------------------*/
  159. #pragma export (ICustomer::name() const,, 1212)
  160. IString ICustomer::name () const
  161. {
  162.   return iName;
  163. }
  164.  
  165. /*------------------------------------------------------------------------------
  166. | ICustomer::setName                                                           |
  167. |                                                                              |
  168. | Set the name attribute.                                                      |
  169. ------------------------------------------------------------------------------*/
  170. #pragma export (ICustomer::setName(const IString&),, 1213)
  171. ICustomer& ICustomer::setName (const IString& aName)
  172. {
  173.   if (iName != aName) {
  174.     iName = aName;
  175.     IString eventData(iName);
  176.     notifyObservers(INotificationEvent(nameId, *this,
  177.                       true, (void*)&eventData));
  178.   } /* endif */
  179.   return *this;
  180. }
  181.  
  182. /*------------------------------------------------------------------------------
  183. | ICustomer::address                                                           |
  184. |                                                                              |
  185. | Return the address attribute.                                                |
  186. ------------------------------------------------------------------------------*/
  187. #pragma export (ICustomer::address() const,, 1214)
  188. IAddress* ICustomer::address () const
  189. {
  190.   return iAddress;
  191. }
  192.  
  193. /*------------------------------------------------------------------------------
  194. | ICustomer::setAddress                                                        |
  195. |                                                                              |
  196. | Set the address attribute.                                                   |
  197. ------------------------------------------------------------------------------*/
  198. #pragma export (ICustomer::setAddress(const IAddress*),, 1215)
  199. ICustomer& ICustomer::setAddress (IAddress* aAddress)
  200. {
  201.   if (iAddress != aAddress) {
  202.     if (iAddress)
  203.       delete iAddress;
  204.     iAddress = aAddress;
  205.     notifyObservers(INotificationEvent(addressId, *this,
  206.                       true, (void*)iAddress));
  207.   } /* endif */
  208.   return *this;
  209. }
  210.  
  211. /*------------------------------------------------------------------------------
  212. | ICustomer::setAddress                                                        |
  213. |                                                                              |
  214. | Set the address attribute.                                                   |
  215. ------------------------------------------------------------------------------*/
  216. #pragma export (ICustomer::setAddress(const IAddress&),, 1216)
  217. ICustomer& ICustomer::setAddress (const IAddress& aAddress)
  218. {
  219.   return setAddress(new IAddress(aAddress));
  220. }
  221.  
  222. /*------------------------------------------------------------------------------
  223. | ICustomer::homePhone                                                         |
  224. |                                                                              |
  225. | Return the homePhone attribute.                                              |
  226. ------------------------------------------------------------------------------*/
  227. #pragma export (ICustomer::homePhone() const,, 1217)
  228. IString ICustomer::homePhone () const
  229. {
  230.   return iHomePhone;
  231. }
  232.  
  233. /*------------------------------------------------------------------------------
  234. | ICustomer::setHomePhone                                                      |
  235. |                                                                              |
  236. | Set the homePhone attribute.                                                 |
  237. ------------------------------------------------------------------------------*/
  238. #pragma export (ICustomer::setHomePhone(const IString&),, 1218)
  239. ICustomer& ICustomer::setHomePhone (const IString& aHomePhone)
  240. {
  241.   if (iHomePhone != aHomePhone) {
  242.     iHomePhone = aHomePhone;
  243.     IString eventData(iHomePhone);
  244.     notifyObservers(INotificationEvent(homePhoneId, *this,
  245.                       true, (void*)&eventData));
  246.   } /* endif */
  247.   return *this;
  248. }
  249.  
  250. /*------------------------------------------------------------------------------
  251. | ICustomer::workPhone                                                         |
  252. |                                                                              |
  253. | Return the workPhone attribute.                                              |
  254. ------------------------------------------------------------------------------*/
  255. #pragma export (ICustomer::workPhone() const,, 1219)
  256. IString ICustomer::workPhone () const
  257. {
  258.   return iWorkPhone;
  259. }
  260.  
  261. /*------------------------------------------------------------------------------
  262. | ICustomer::setWorkPhone                                                      |
  263. |                                                                              |
  264. | Set the workPhone attribute.                                                 |
  265. ------------------------------------------------------------------------------*/
  266. #pragma export (ICustomer::setWorkPhone(const IString&),, 1220)
  267. ICustomer& ICustomer::setWorkPhone (const IString& aWorkPhone)
  268. {
  269.   if (iWorkPhone != aWorkPhone) {
  270.     iWorkPhone = aWorkPhone;
  271.     IString eventData(iWorkPhone);
  272.     notifyObservers(INotificationEvent(workPhoneId, *this,
  273.                       true, (void*)&eventData));
  274.   } /* endif */
  275.   return *this;
  276. }
  277.  
  278. /*------------------------------------------------------------------------------
  279. | ICustomer::date                                                              |
  280. |                                                                              |
  281. | Return the date attribute.                                                   |
  282. ------------------------------------------------------------------------------*/
  283. #pragma export (ICustomer::date() const,, 1221)
  284. IDate ICustomer::date () const
  285. {
  286.   return iDate;
  287. }
  288.  
  289. /*------------------------------------------------------------------------------
  290. | ICustomer::setDate                                                           |
  291. |                                                                              |
  292. | Set the date attribute.                                                      |
  293. ------------------------------------------------------------------------------*/
  294. #pragma export (ICustomer::setDate(const IDate&),, 1222)
  295. ICustomer& ICustomer::setDate (const IDate& aDate)
  296. {
  297.   if (iDate != aDate) {
  298.     iDate = aDate;
  299.     IDate eventData(iDate);
  300.     notifyObservers(INotificationEvent(dateId, *this,
  301.                       true, (void*)&eventData));
  302.   } /* endif */
  303.   return *this;
  304. }
  305.  
  306. /*------------------------------------------------------------------------------
  307. | ICustomer::time                                                              |
  308. |                                                                              |
  309. | Return the time attribute.                                                   |
  310. ------------------------------------------------------------------------------*/
  311. #pragma export (ICustomer::time() const,, 1223)
  312. ITime ICustomer::time () const
  313. {
  314.   return iTime;
  315. }
  316.  
  317. /*------------------------------------------------------------------------------
  318. | ICustomer::setTime                                                           |
  319. |                                                                              |
  320. | Set the time attribute.                                                      |
  321. ------------------------------------------------------------------------------*/
  322. #pragma export (ICustomer::setTime(const ITime&),, 1224)
  323. ICustomer& ICustomer::setTime (const ITime& aTime)
  324. {
  325.   if (iTime != aTime)
  326.   {
  327.     iTime = aTime;
  328.     ITime eventData(iTime);
  329.     notifyObservers(INotificationEvent(timeId, *this,
  330.                       true, (void*)&eventData));
  331.   } /* endif */
  332.   return *this;
  333. }
  334.  
  335. /*------------------------------------------------------------------------------
  336. | ICustomer::setNameToDefault                                                  |
  337. |                                                                              |
  338. | Perform the setNameToDefault action.                                         |
  339. ------------------------------------------------------------------------------*/
  340. #pragma export (ICustomer::setNameToDefault(),, 1225)
  341. ICustomer& ICustomer::setNameToDefault ()
  342. {
  343.   return setName("Ken");
  344. }
  345.  
  346. /*------------------------------------------------------------------------------
  347. | ICustomer::setAddressToDefault                                               |
  348. |                                                                              |
  349. | Perform the setAddressToDefault action.                                      |
  350. ------------------------------------------------------------------------------*/
  351. #pragma export (ICustomer::setAddressToDefault(),, 1226)
  352. ICustomer& ICustomer::setAddressToDefault ()
  353. {
  354.   if (address())
  355.     address()->setToDefault();
  356.   return *this;
  357. }
  358.  
  359. /*------------------------------------------------------------------------------
  360. | ICustomer::setHomePhoneToDefault                                             |
  361. |                                                                              |
  362. | Perform the setHomePhoneToDefault action.                                    |
  363. ------------------------------------------------------------------------------*/
  364. #pragma export (ICustomer::setHomePhoneToDefault(),, 1227)
  365. ICustomer& ICustomer::setHomePhoneToDefault ()
  366. {
  367.   return setHomePhone("555-1212");
  368. }
  369.  
  370. /*------------------------------------------------------------------------------
  371. | ICustomer::setWorkPhoneToDefault                                             |
  372. |                                                                              |
  373. | Perform the setWorkPhoneToDefault action.                                    |
  374. ------------------------------------------------------------------------------*/
  375. #pragma export (ICustomer::setWorkPhoneToDefault(),, 1228)
  376. ICustomer& ICustomer::setWorkPhoneToDefault ()
  377. {
  378.   return setWorkPhone("555-1212");
  379. }
  380.  
  381. /*------------------------------------------------------------------------------
  382. | ICustomer::operator == (const ICustomer & aValue)                            |
  383. |                                                                              |
  384. ------------------------------------------------------------------------------*/
  385. #pragma export (ICustomer::operator == (const ICustomer&) const,, 1229)
  386. Boolean ICustomer::
  387.   operator == (const ICustomer& aValue) const
  388. {
  389.   if (name() != aValue.name()) {
  390.     return false;
  391.   } /* endif */
  392.   if (address() != aValue.address()) {
  393.     return false;
  394.   } /* endif */
  395.   if (homePhone() != aValue.homePhone()) {
  396.     return false;
  397.   } /* endif */
  398.   if (workPhone() != aValue.workPhone()) {
  399.     return false;
  400.   } /* endif */
  401.   if (date() != aValue.date()) {
  402.     return false;
  403.   } /* endif */
  404.   if (time() != aValue.time()) {
  405.     return false;
  406.   } /* endif */
  407.   return true;
  408. }
  409.  
  410. /*------------------------------------------------------------------------------
  411. | ICustomer::operator != (const ICustomer & aValue)                            |
  412. |                                                                              |
  413. ------------------------------------------------------------------------------*/
  414. #pragma export (ICustomer::operator != (const ICustomer&) const,, 1230)
  415. Boolean ICustomer::
  416.   operator != (const ICustomer& aValue) const
  417. {
  418.   if (name() != aValue.name()) {
  419.     return true;
  420.   } /* endif */
  421.   if (address() != aValue.address()) {
  422.     return true;
  423.   } /* endif */
  424.   if (homePhone() != aValue.homePhone()) {
  425.     return true;
  426.   } /* endif */
  427.   if (workPhone() != aValue.workPhone()) {
  428.     return true;
  429.   } /* endif */
  430.   if (date() != aValue.date()) {
  431.     return true;
  432.   } /* endif */
  433.   if (time() != aValue.time()) {
  434.     return true;
  435.   } /* endif */
  436.   return false;
  437. }
  438.  
  439. /*------------------------------------------------------------------------------
  440. | ICustomer::operator == (const ICustomer * aValue)                            |
  441. |                                                                              |
  442. ------------------------------------------------------------------------------*/
  443. #pragma export (ICustomer::operator == (const ICustomer*) const,, 1231)
  444. Boolean ICustomer::
  445.   operator == (const ICustomer* aValue) const
  446. {
  447.   if (name() != aValue->name()) {
  448.     return false;
  449.   } /* endif */
  450.   if (address() != aValue->address()) {
  451.     return false;
  452.   } /* endif */
  453.   if (homePhone() != aValue->homePhone()) {
  454.     return false;
  455.   } /* endif */
  456.   if (workPhone() != aValue->workPhone()) {
  457.     return false;
  458.   } /* endif */
  459.   if (date() != aValue->date()) {
  460.     return false;
  461.   } /* endif */
  462.   if (time() != aValue->time()) {
  463.     return false;
  464.   } /* endif */
  465.   return true;
  466. }
  467.  
  468. /*------------------------------------------------------------------------------
  469. | ICustomer::operator != (const ICustomer * aValue)                            |
  470. |                                                                              |
  471. ------------------------------------------------------------------------------*/
  472. #pragma export (ICustomer::operator != (const ICustomer*) const,, 1232)
  473. Boolean ICustomer::
  474.   operator != (const ICustomer* aValue) const
  475. {
  476.   if (name() != aValue->name()) {
  477.     return true;
  478.   } /* endif */
  479.   if (address() != aValue->address()) {
  480.     return true;
  481.   } /* endif */
  482.   if (homePhone() != aValue->homePhone()) {
  483.     return true;
  484.   } /* endif */
  485.   if (workPhone() != aValue->workPhone()) {
  486.     return true;
  487.   } /* endif */
  488.   if (date() != aValue->date()) {
  489.     return true;
  490.   } /* endif */
  491.   if (time() != aValue->time()) {
  492.     return true;
  493.   } /* endif */
  494.   return false;
  495. }
  496.  
  497. /*------------------------------------------------------------------------------
  498. | ICustomer::operator < (const ICustomer * aValue)                             |
  499. |                                                                              |
  500. ------------------------------------------------------------------------------*/
  501. #pragma export (ICustomer::operator < (const ICustomer*) const,, 1233)
  502. Boolean ICustomer::
  503.   operator < (const ICustomer* aValue) const
  504. {
  505.   return (name() < (aValue->name()));
  506. }
  507.  
  508. /*------------------------------------------------------------------------------
  509. | ICustomer::operator < (const ICustomer & aValue)                             |
  510. |                                                                              |
  511. ------------------------------------------------------------------------------*/
  512. #pragma export (ICustomer::operator < (const ICustomer&) const,, 1234)
  513. Boolean ICustomer::
  514.   operator < (const ICustomer& aValue) const
  515. {
  516.   return (name() < (aValue.name()));
  517. }
  518.  
  519. /*------------------------------------------------------------------------------
  520. | ICustomer::operator < (ICustomer* const & aValue)                            |
  521. |                                                                              |
  522. ------------------------------------------------------------------------------*/
  523. #pragma export (ICustomer::operator < (ICustomer* const&) const,, 1235)
  524. Boolean ICustomer::
  525.   operator < (ICustomer* const& aValue) const
  526. {
  527.   return (name() < (aValue->name()));
  528. }
  529.  
  530. /*------------------------------------------------------------------------------
  531. | ICustomer::operator < (ICustomerElemPtr const & aValue)                      |
  532. |                                                                              |
  533. ------------------------------------------------------------------------------*/
  534. #pragma export (ICustomer::operator < (ICustomerElemPtr const&) const,, 1236)
  535. Boolean ICustomer::
  536.   operator < (ICustomerElemPtr const& aValue) const
  537. {
  538.   return (name() < (aValue->name()));
  539. }
  540.  
  541. /*------------------------------------------------------------------------------
  542. | ICustomer::operator < (ICustomerMngPtr const & aValue)                       |
  543. |                                                                              |
  544. ------------------------------------------------------------------------------*/
  545. #pragma export (ICustomer::operator < (ICustomerMngPtr const&) const,, 1237)
  546. Boolean ICustomer::
  547.   operator < (ICustomerMngPtr const& aValue) const
  548. {
  549.   return (name() < (aValue->name()));
  550. }
  551.