home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmodf.zip / CUSTOMER.ZIP / ICUST.CPP < prev    next >
Text File  |  1995-06-13  |  21KB  |  493 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. *   Licensed Materials - Property of IBM                                       *
  10. *   (C) Copyright IBM Corporation 1994, 1995                                   *
  11. *   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. * DISCLAIMER OF WARRANTIES:                                                    *
  16. *   The following [enclosed] code is sample code created by IBM                *
  17. *   Corporation.  This sample code is not part of any standard IBM product     *
  18. *   and is provided to you solely for the purpose of assisting you in the      *
  19. *   development of your applications.  The code is provided "AS IS",           *
  20. *   without warranty of any kind.  IBM shall not be liable for any damages     *
  21. *   arising out of your use of the sample code, even if they have been         *
  22. *   advised of the possibility of such damages.                                *
  23. *******************************************************************************/
  24.  
  25. #ifndef _ICUST_
  26.   #include <icust.hpp>
  27. #endif
  28.  
  29. #ifndef _INOTIFEV_
  30.   #include <inotifev.hpp>
  31. #endif
  32.  
  33. #include <iadd.hpp>
  34.  
  35. #pragma export (ICustomer::nameId,, 1200)
  36. const INotificationId ICustomer::nameId =
  37.                      "ICustomer::name";
  38. #pragma export (ICustomer::addressId,, 1201)
  39. const INotificationId ICustomer::addressId =
  40.                      "ICustomer::address";
  41. #pragma export (ICustomer::homePhoneId,, 1202)
  42. const INotificationId ICustomer::homePhoneId =
  43.                      "ICustomer::homePhone";
  44. #pragma export (ICustomer::workPhoneId,, 1203)
  45. const INotificationId ICustomer::workPhoneId =
  46.                      "ICustomer::workPhone";
  47. #pragma export (ICustomer::dateId,, 1204)
  48. const INotificationId ICustomer::dateId =
  49.                      "ICustomer::date";
  50. #pragma export (ICustomer::timeId,, 1205)
  51. const INotificationId ICustomer::timeId =
  52.                      "ICustomer::time";
  53.  
  54. /*------------------------------------------------------------------------------
  55. | ICustomer::ICustomer                                                         |
  56. |                                                                              |
  57. | Standard constructor.                                                        |
  58. ------------------------------------------------------------------------------*/
  59. #pragma export (ICustomer::ICustomer(),, 1206)
  60. ICustomer::ICustomer() : IPart ()
  61.     ,iName ("Ken")
  62.     ,iAddress (new IAddress())
  63.     ,iHomePhone ("555-1212")
  64.     ,iWorkPhone ("555-1212")
  65.     ,iDate ()
  66.     ,iTime ()
  67. {
  68.   enableNotification ();
  69. }
  70.  
  71. /*------------------------------------------------------------------------------
  72. | ICustomer::ICustomer                                                         |
  73. |                                                                              |
  74. | Constructor with name parameter.                                             |
  75. ------------------------------------------------------------------------------*/
  76. #pragma export (ICustomer::ICustomer(const IString& aName),, 1207)
  77. ICustomer::ICustomer(const IString& aName) :
  78.   IPart (),
  79.   iName ("Ken"),
  80.   iAddress (new IAddress()),
  81.   iHomePhone ("555-1212"),
  82.   iWorkPhone ("555-1212"),
  83.   iDate (),
  84.   iTime ()
  85. {
  86.   setName(aName);
  87.   enableNotification ();
  88. }
  89.  
  90. /*------------------------------------------------------------------------------
  91. | ICustomer::ICustomer                                                         |
  92. |                                                                              |
  93. | Standard copy constructor.                                                   |
  94. ------------------------------------------------------------------------------*/
  95. #pragma export (ICustomer::ICustomer(const ICustomer&),, 1208)
  96. ICustomer::ICustomer (const ICustomer& partCopy)
  97.   : IPart (partCopy)
  98.     ,iName (partCopy.name ())
  99.     ,iAddress (partCopy.address ())
  100.     ,iHomePhone (partCopy.homePhone ())
  101.     ,iWorkPhone (partCopy.workPhone ())
  102.     ,iDate (partCopy.date ())
  103.     ,iTime (partCopy.time ())
  104. {
  105.   enableNotification ();
  106. }
  107.  
  108. /*------------------------------------------------------------------------------
  109. | ICustomer::ICustomer                                                         |
  110. |                                                                              |
  111. | Standard operator=                                                           |
  112. ------------------------------------------------------------------------------*/
  113. #pragma export (ICustomer::operator= (const ICustomer&),, 1209)
  114. ICustomer& ICustomer::operator= (const ICustomer& aICustomer)
  115. {
  116.   if (this == &aICustomer) {
  117.     return *this;
  118.   } /* endif */
  119.   setName(aICustomer.name());
  120.   setAddress(aICustomer.address());
  121.   setHomePhone(aICustomer.homePhone());
  122.   setWorkPhone(aICustomer.workPhone());
  123.   setDate(aICustomer.date());
  124.   setTime(aICustomer.time());
  125.   return *this;
  126. }
  127.  
  128. /*------------------------------------------------------------------------------
  129. | ICustomer::~ICustomer                                                        |
  130. |                                                                              |
  131. | ICustomer destructor.                                                        |
  132. ------------------------------------------------------------------------------*/
  133. #pragma export (ICustomer::~ICustomer(),, 1210)
  134. ICustomer::~ICustomer()
  135. {
  136.   if (iAddress)
  137.     delete iAddress;
  138. }
  139.  
  140. /*------------------------------------------------------------------------------
  141. | ICustomer::asString                                                          |
  142. |                                                                              |
  143. | Perform asString.                                                            |
  144. ------------------------------------------------------------------------------*/
  145. #pragma export (ICustomer::asString() const,, 1211)
  146. IString ICustomer::asString () const
  147. {
  148.   return name();
  149. }
  150.  
  151. /*------------------------------------------------------------------------------
  152. | ICustomer::name                                                              |
  153. |                                                                              |
  154. | Return the name attribute.                                                   |
  155. ------------------------------------------------------------------------------*/
  156. #pragma export (ICustomer::name() const,, 1212)
  157. IString ICustomer::name () const
  158. {
  159.   return iName;
  160. }
  161.  
  162. /*------------------------------------------------------------------------------
  163. | ICustomer::setName                                                           |
  164. |                                                                              |
  165. | Set the name attribute.                                                      |
  166. ------------------------------------------------------------------------------*/
  167. #pragma export (ICustomer::setName(const IString&),, 1213)
  168. ICustomer& ICustomer::setName (const IString& aName)
  169. {
  170.   if (iName != aName) {
  171.     iName = aName;
  172.     IString eventData(iName);
  173.     notifyObservers(INotificationEvent(nameId, *this,
  174.                       true, (void*)&eventData));
  175.   } /* endif */
  176.   return *this;
  177. }
  178.  
  179. /*------------------------------------------------------------------------------
  180. | ICustomer::address                                                           |
  181. |                                                                              |
  182. | Return the address attribute.                                                |
  183. ------------------------------------------------------------------------------*/
  184. #pragma export (ICustomer::address() const,, 1214)
  185. IAddress* ICustomer::address () const
  186. {
  187.   return iAddress;
  188. }
  189.  
  190. /*------------------------------------------------------------------------------
  191. | ICustomer::setAddress                                                        |
  192. |                                                                              |
  193. | Set the address attribute.                                                   |
  194. ------------------------------------------------------------------------------*/
  195. #pragma export (ICustomer::setAddress(const IAddress*),, 1215)
  196. ICustomer& ICustomer::setAddress (IAddress* aAddress)
  197. {
  198.   if (iAddress != aAddress) {
  199.     if (iAddress)
  200.       delete iAddress;
  201.     iAddress = aAddress;
  202.     notifyObservers(INotificationEvent(addressId, *this,
  203.                       true, (void*)iAddress));
  204.   } /* endif */
  205.   return *this;
  206. }
  207.  
  208. /*------------------------------------------------------------------------------
  209. | ICustomer::setAddress                                                        |
  210. |                                                                              |
  211. | Set the address attribute.                                                   |
  212. ------------------------------------------------------------------------------*/
  213. #pragma export (ICustomer::setAddress(const IAddress&),, 1216)
  214. ICustomer& ICustomer::setAddress (const IAddress& aAddress)
  215. {
  216.   return setAddress(new IAddress(aAddress));
  217. }
  218.  
  219. /*------------------------------------------------------------------------------
  220. | ICustomer::homePhone                                                         |
  221. |                                                                              |
  222. | Return the homePhone attribute.                                              |
  223. ------------------------------------------------------------------------------*/
  224. #pragma export (ICustomer::homePhone() const,, 1217)
  225. IString ICustomer::homePhone () const
  226. {
  227.   return iHomePhone;
  228. }
  229.  
  230. /*------------------------------------------------------------------------------
  231. | ICustomer::setHomePhone                                                      |
  232. |                                                                              |
  233. | Set the homePhone attribute.                                                 |
  234. ------------------------------------------------------------------------------*/
  235. #pragma export (ICustomer::setHomePhone(const IString&),, 1218)
  236. ICustomer& ICustomer::setHomePhone (const IString& aHomePhone)
  237. {
  238.   if (iHomePhone != aHomePhone) {
  239.     iHomePhone = aHomePhone;
  240.     IString eventData(iHomePhone);
  241.     notifyObservers(INotificationEvent(homePhoneId, *this,
  242.                       true, (void*)&eventData));
  243.   } /* endif */
  244.   return *this;
  245. }
  246.  
  247. /*------------------------------------------------------------------------------
  248. | ICustomer::workPhone                                                         |
  249. |                                                                              |
  250. | Return the workPhone attribute.                                              |
  251. ------------------------------------------------------------------------------*/
  252. #pragma export (ICustomer::workPhone() const,, 1219)
  253. IString ICustomer::workPhone () const
  254. {
  255.   return iWorkPhone;
  256. }
  257.  
  258. /*------------------------------------------------------------------------------
  259. | ICustomer::setWorkPhone                                                      |
  260. |                                                                              |
  261. | Set the workPhone attribute.                                                 |
  262. ------------------------------------------------------------------------------*/
  263. #pragma export (ICustomer::setWorkPhone(const IString&),, 1220)
  264. ICustomer& ICustomer::setWorkPhone (const IString& aWorkPhone)
  265. {
  266.   if (iWorkPhone != aWorkPhone) {
  267.     iWorkPhone = aWorkPhone;
  268.     IString eventData(iWorkPhone);
  269.     notifyObservers(INotificationEvent(workPhoneId, *this,
  270.                       true, (void*)&eventData));
  271.   } /* endif */
  272.   return *this;
  273. }
  274.  
  275. /*------------------------------------------------------------------------------
  276. | ICustomer::date                                                              |
  277. |                                                                              |
  278. | Return the date attribute.                                                   |
  279. ------------------------------------------------------------------------------*/
  280. #pragma export (ICustomer::date() const,, 1221)
  281. IDate ICustomer::date () const
  282. {
  283.   return iDate;
  284. }
  285.  
  286. /*------------------------------------------------------------------------------
  287. | ICustomer::setDate                                                           |
  288. |                                                                              |
  289. | Set the date attribute.                                                      |
  290. ------------------------------------------------------------------------------*/
  291. #pragma export (ICustomer::setDate(const IDate&),, 1222)
  292. ICustomer& ICustomer::setDate (const IDate& aDate)
  293. {
  294.   if (iDate != aDate) {
  295.     iDate = aDate;
  296.     IDate eventData(iDate);
  297.     notifyObservers(INotificationEvent(dateId, *this,
  298.                       true, (void*)&eventData));
  299.   } /* endif */
  300.   return *this;
  301. }
  302.  
  303. /*------------------------------------------------------------------------------
  304. | ICustomer::time                                                              |
  305. |                                                                              |
  306. | Return the time attribute.                                                   |
  307. ------------------------------------------------------------------------------*/
  308. #pragma export (ICustomer::time() const,, 1223)
  309. ITime ICustomer::time () const
  310. {
  311.   return iTime;
  312. }
  313.  
  314. /*------------------------------------------------------------------------------
  315. | ICustomer::setTime                                                           |
  316. |                                                                              |
  317. | Set the time attribute.                                                      |
  318. ------------------------------------------------------------------------------*/
  319. #pragma export (ICustomer::setTime(const ITime&),, 1224)
  320. ICustomer& ICustomer::setTime (const ITime& aTime)
  321. {
  322.   if (iTime != aTime)
  323.   {
  324.     iTime = aTime;
  325.     ITime eventData(iTime);
  326.     notifyObservers(INotificationEvent(timeId, *this,
  327.                       true, (void*)&eventData));
  328.   } /* endif */
  329.   return *this;
  330. }
  331.  
  332. /*------------------------------------------------------------------------------
  333. | ICustomer::setNameToDefault                                                  |
  334. |                                                                              |
  335. | Perform the setNameToDefault action.                                         |
  336. ------------------------------------------------------------------------------*/
  337. #pragma export (ICustomer::setNameToDefault(),, 1225)
  338. ICustomer& ICustomer::setNameToDefault ()
  339. {
  340.   return setName("Ken");
  341. }
  342.  
  343. /*------------------------------------------------------------------------------
  344. | ICustomer::setAddressToDefault                                               |
  345. |                                                                              |
  346. | Perform the setAddressToDefault action.                                      |
  347. ------------------------------------------------------------------------------*/
  348. #pragma export (ICustomer::setAddressToDefault(),, 1226)
  349. ICustomer& ICustomer::setAddressToDefault ()
  350. {
  351.   if (address())
  352.     address()->setToDefault();
  353.   return *this;
  354. }
  355.  
  356. /*------------------------------------------------------------------------------
  357. | ICustomer::setHomePhoneToDefault                                             |
  358. |                                                                              |
  359. | Perform the setHomePhoneToDefault action.                                    |
  360. ------------------------------------------------------------------------------*/
  361. #pragma export (ICustomer::setHomePhoneToDefault(),, 1227)
  362. ICustomer& ICustomer::setHomePhoneToDefault ()
  363. {
  364.   return setHomePhone("555-1212");
  365. }
  366.  
  367. /*------------------------------------------------------------------------------
  368. | ICustomer::setWorkPhoneToDefault                                             |
  369. |                                                                              |
  370. | Perform the setWorkPhoneToDefault action.                                    |
  371. ------------------------------------------------------------------------------*/
  372. #pragma export (ICustomer::setWorkPhoneToDefault(),, 1228)
  373. ICustomer& ICustomer::setWorkPhoneToDefault ()
  374. {
  375.   return setWorkPhone("555-1212");
  376. }
  377.  
  378. /*------------------------------------------------------------------------------
  379. | ICustomer::operator == (const ICustomer & aValue)                            |
  380. |                                                                              |
  381. ------------------------------------------------------------------------------*/
  382. #pragma export (ICustomer::operator == (const ICustomer&) const,, 1229)
  383. Boolean ICustomer::
  384.   operator == (const ICustomer& aValue) const
  385. {
  386.   if (name() != aValue.name()) {
  387.     return false;
  388.   } /* endif */
  389.   if (address() != aValue.address()) {
  390.     return false;
  391.   } /* endif */
  392.   if (homePhone() != aValue.homePhone()) {
  393.     return false;
  394.   } /* endif */
  395.   if (workPhone() != aValue.workPhone()) {
  396.     return false;
  397.   } /* endif */
  398.   if (date() != aValue.date()) {
  399.     return false;
  400.   } /* endif */
  401.   if (time() != aValue.time()) {
  402.     return false;
  403.   } /* endif */
  404.   return true;
  405. }
  406.  
  407. /*------------------------------------------------------------------------------
  408. | ICustomer::operator != (const ICustomer & aValue)                            |
  409. |                                                                              |
  410. ------------------------------------------------------------------------------*/
  411. #pragma export (ICustomer::operator != (const ICustomer&) const,, 1230)
  412. Boolean ICustomer::
  413.   operator != (const ICustomer& aValue) const
  414. {
  415.   if (name() != aValue.name()) {
  416.     return true;
  417.   } /* endif */
  418.   if (address() != aValue.address()) {
  419.     return true;
  420.   } /* endif */
  421.   if (homePhone() != aValue.homePhone()) {
  422.     return true;
  423.   } /* endif */
  424.   if (workPhone() != aValue.workPhone()) {
  425.     return true;
  426.   } /* endif */
  427.   if (date() != aValue.date()) {
  428.     return true;
  429.   } /* endif */
  430.   if (time() != aValue.time()) {
  431.     return true;
  432.   } /* endif */
  433.   return false;
  434. }
  435.  
  436. /*------------------------------------------------------------------------------
  437. | ICustomer::operator == (const ICustomer * aValue)                            |
  438. |                                                                              |
  439. ------------------------------------------------------------------------------*/
  440. #pragma export (ICustomer::operator == (const ICustomer*) const,, 1231)
  441. Boolean ICustomer::
  442.   operator == (const ICustomer* aValue) const
  443. {
  444.   if (name() != aValue->name()) {
  445.     return false;
  446.   } /* endif */
  447.   if (address() != aValue->address()) {
  448.     return false;
  449.   } /* endif */
  450.   if (homePhone() != aValue->homePhone()) {
  451.     return false;
  452.   } /* endif */
  453.   if (workPhone() != aValue->workPhone()) {
  454.     return false;
  455.   } /* endif */
  456.   if (date() != aValue->date()) {
  457.     return false;
  458.   } /* endif */
  459.   if (time() != aValue->time()) {
  460.     return false;
  461.   } /* endif */
  462.   return true;
  463. }
  464.  
  465. /*------------------------------------------------------------------------------
  466. | ICustomer::operator != (const ICustomer * aValue)                            |
  467. |                                                                              |
  468. ------------------------------------------------------------------------------*/
  469. #pragma export (ICustomer::operator != (const ICustomer*) const,, 1232)
  470. Boolean ICustomer::
  471.   operator != (const ICustomer* aValue) const
  472. {
  473.   if (name() != aValue->name()) {
  474.     return true;
  475.   } /* endif */
  476.   if (address() != aValue->address()) {
  477.     return true;
  478.   } /* endif */
  479.   if (homePhone() != aValue->homePhone()) {
  480.     return true;
  481.   } /* endif */
  482.   if (workPhone() != aValue->workPhone()) {
  483.     return true;
  484.   } /* endif */
  485.   if (date() != aValue->date()) {
  486.     return true;
  487.   } /* endif */
  488.   if (time() != aValue->time()) {
  489.     return true;
  490.   } /* endif */
  491.   return false;
  492. }
  493.